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 void run(void) override; // MThread
40
41 void insert(int fd, QBuffer *buff);
42 void Wait(int fd);
43 void remove(int fd);
44 void wake();
45
46 private:
47 void HandleRead(int fd, QBuffer *buff);
48 void HandleWrite(int fd, QBuffer *buff);
49 void BuildFDs();
50
52 QWaitCondition m_pWait;
53 QMutex m_pLock;
55
56 fd_set m_fds {};
57 int m_maxfd {-1};
58 bool m_read {true};
59 std::array<char,65536> m_readbuf {};
60};
61
62// spawn separate thread for signals to prevent manager
63// thread from blocking in some slot
65{
66 public:
68 : MThread("SystemManager") {}
70 void run(void) override; // MThread
72 void jumpAbort(void);
73 private:
75 QMutex m_mapLock;
76 bool m_jumpAbort {false};
77 QMutex m_jumpLock;
78 QWaitCondition m_wait;
79};
80
82{
83 public:
85 : MThread("SystemSignalManager") {}
87 void run(void) override; // MThread
88 private:
89};
90
91
93{
94 Q_OBJECT
95
96 public:
97 explicit MythSystemLegacyUnix(MythSystemLegacy *parent);
98 ~MythSystemLegacyUnix() override = default;
99
100 void Fork(std::chrono::seconds timeout) override; // MythSystemLegacyPrivate
101 void Manage(void) override; // MythSystemLegacyPrivate
102
103 void Term(bool force=false) override; // MythSystemLegacyPrivate
104 void Signal(int sig) override; // MythSystemLegacyPrivate
105 void JumpAbort(void) override; // MythSystemLegacyPrivate
106
107 bool ParseShell(const QString &cmd, QString &abscmd,
108 QStringList &args) override; // MythSystemLegacyPrivate
109
113
114 private:
115 pid_t m_pid {0};
116 SystemTime m_timeout {0s};
117
118 std::array<int,3> m_stdpipe {-1, -1, -1};
119};
120
121#endif // MYTHSYSTEM_UNIX_H
122
123/*
124 * vim:ts=4:sw=4:ai:et:si:sts=4
125 */
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:300
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:15
std::chrono::time_point< SystemClock > SystemTime
Definition: mythchrono.h:67
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