MythTV master
mythsystemunix.h
Go to the documentation of this file.
1
2
3#ifndef MYTHSYSTEM_UNIX_H
4#define MYTHSYSTEM_UNIX_H
5
6#include <array>
7#include <csignal>
8#include <sys/select.h>
9
10#include <QObject>
11#include <QString>
12#include <QStringList>
13#include <QMap>
14#include <QList>
15#include <QBuffer>
16#include <QWaitCondition>
17#include <QMutex>
18#include <QPointer>
19
20#include "mythsystemprivate.h"
21#include "mythbaseexp.h"
22#include "mythchrono.h"
23#include "mythsystemlegacy.h"
24#include "mthread.h"
25
27
28using MSMap_t = QMap<pid_t, QPointer<MythSystemLegacyUnix> >;
29using PMap_t = QMap<int, QBuffer *>;
30using MSList_t = QList<QPointer<MythSystemLegacyUnix> >;
31
33{
34 public:
36 : MThread(QString("SystemIOHandler%1").arg(read ? "R" : "W")),
37 m_read(read) {};
39
40 void insert(int fd, QBuffer *buff);
41 void Wait(int fd);
42 void remove(int fd);
43 void wake();
44
45 protected:
46 void run(void) override; // MThread
47
48 private:
49 void HandleRead(int fd, QBuffer *buff);
50 void HandleWrite(int fd, QBuffer *buff);
51 void BuildFDs();
52
54 QWaitCondition m_pWait;
55 QMutex m_pLock;
57
58 fd_set m_fds {};
59 int m_maxfd {-1};
60 bool m_read {true};
61 std::array<char,65536> m_readbuf {};
62};
63
64// spawn separate thread for signals to prevent manager
65// thread from blocking in some slot
67{
68 public:
70 : MThread("SystemManager") {}
73 void jumpAbort(void);
74 protected:
75 void run(void) override; // MThread
76 private:
78 QMutex m_mapLock;
79 bool m_jumpAbort {false};
80 QMutex m_jumpLock;
81 QWaitCondition m_wait;
82};
83
85{
86 public:
88 : MThread("SystemSignalManager") {}
90 protected:
91 void run(void) override; // MThread
92 private:
93};
94
95
97{
98 Q_OBJECT
99
100 public:
101 explicit MythSystemLegacyUnix(MythSystemLegacy *parent);
102 ~MythSystemLegacyUnix() override = default;
103
104 void Fork(std::chrono::seconds timeout) override; // MythSystemLegacyPrivate
105 void Manage(void) override; // MythSystemLegacyPrivate
106
107 void Term(bool force=false) override; // MythSystemLegacyPrivate
108 void Signal(int sig) override; // MythSystemLegacyPrivate
109 void JumpAbort(void) override; // MythSystemLegacyPrivate
110
111 bool ParseShell(const QString &cmd, QString &abscmd,
112 QStringList &args) override; // MythSystemLegacyPrivate
113
117
118 private:
119 pid_t m_pid {0};
120 SystemTime m_timeout {0s};
121
122 std::array<int,3> m_stdpipe {-1, -1, -1};
123};
124
125#endif // MYTHSYSTEM_UNIX_H
126
127/*
128 * vim:ts=4:sw=4:ai:et:si:sts=4
129 */
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:284
void HandleWrite(int fd, QBuffer *buff)
MythSystemLegacyIOHandler(bool read)
void insert(int fd, QBuffer *buff)
~MythSystemLegacyIOHandler() override
void HandleRead(int fd, QBuffer *buff)
std::array< char, 65536 > m_readbuf
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
~MythSystemLegacyManager() override
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
void append(MythSystemLegacyUnix *ms)
virtual void Fork(std::chrono::seconds timeout)=0
virtual void Signal(int sig)=0
virtual void Term(bool force=false)=0
virtual bool ParseShell(const QString &cmd, QString &abscmd, QStringList &args)=0
virtual void JumpAbort(void)=0
virtual void Manage(void)=0
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
~MythSystemLegacyUnix() override=default
#define MBASE_PUBLIC
Definition: mythbaseexp.h:8
std::chrono::time_point< SystemClock > SystemTime
Definition: mythchrono.h:56
QList< QPointer< MythSystemLegacyUnix > > MSList_t
QMap< int, QBuffer * > PMap_t
QMap< pid_t, QPointer< MythSystemLegacyUnix > > MSMap_t
def read(device=None, features=[])
Definition: disc.py:35