nngn
Loading...
Searching...
No Matches
worker.h
Go to the documentation of this file.
1#ifndef NNGN_TOOLS_WORKER_H
2#define NNGN_TOOLS_WORKER_H
3
4#include <iomanip>
5
6#include <QThread>
7
8#include "utils/log.h"
9
10#include "poller.h"
11
12class Worker : public QThread {
13 Q_OBJECT
14protected:
15 template<typename ...Ts>
16 auto read_values(std::stringstream *s, Ts *...ts);
17 void err(void);
18public:
19 bool init(int fd);
20 bool destroy(void);
21 void run(void) final;
22 constexpr bool ok(void) const { return !this->error; }
23public slots:
24 void finish(void);
25signals:
26 void finished(void);
27private:
28 virtual bool cmd(std::string_view s) = 0;
29 bool error = false;
30 int fd = -1;
32};
33
34template<typename ...Ts>
35auto Worker::read_values(std::stringstream *s, Ts *...ts) {
36 (*s >> ... >> *ts);
37 if(!s->bad())
38 return true;
40 << "failed to read values from "
41 << std::quoted(s->str()) << '\n';
42 return false;
43}
44
45#endif
Definition poller.h:7
Definition worker.h:12
void finish(void)
Definition worker.cpp:14
auto read_values(std::stringstream *s, Ts *...ts)
Definition worker.h:35
bool destroy(void)
Definition worker.cpp:9
bool error
Definition worker.h:29
void err(void)
Definition worker.cpp:13
virtual bool cmd(std::string_view s)=0
constexpr bool ok(void) const
Definition worker.h:22
Poller poller
Definition worker.h:31
void run(void) final
Definition worker.cpp:16
void finished(void)
static std::ostream & l()
Definition log.cpp:56
init
Definition img_common.lua:34
std::chrono::seconds s
Definition timing.cpp:6
std::chrono::duration< float, typename T::period > fd
Definition timing.cpp:8