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