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:
33  explicit MythSystemLegacyIOHandler(bool read);
35  void run(void) override; // MThread
36 
37  void insert(int fd, QBuffer *buff);
38  void Wait(int fd);
39  void remove(int fd);
40  void wake();
41 
42  private:
43  void HandleRead(int fd, QBuffer *buff);
44  void HandleWrite(int fd, QBuffer *buff);
45  void BuildFDs();
46 
47  QMutex m_pWaitLock;
48  QWaitCondition m_pWait;
49  QMutex m_pLock;
51 
52  fd_set m_fds;
53  int m_maxfd {-1};
54  bool m_read;
55  char m_readbuf[65536];
56 };
57 
58 // spawn separate thread for signals to prevent manager
59 // thread from blocking in some slot
61 {
62  public:
64  : MThread("SystemManager") {}
66  void run(void) override; // MThread
68  void jumpAbort(void);
69  private:
71  QMutex m_mapLock;
72  bool m_jumpAbort {false};
73  QMutex m_jumpLock;
74  QWaitCondition m_wait;
75 };
76 
78 {
79  public:
81  : MThread("SystemSignalManager") {}
83  void run(void) override; // MThread
84  private:
85 };
86 
87 
89 {
90  Q_OBJECT
91 
92  public:
93  explicit MythSystemLegacyUnix(MythSystemLegacy *parent);
94  ~MythSystemLegacyUnix() = default;
95 
96  void Fork(time_t timeout) override; // MythSystemLegacyPrivate
97  void Manage(void) override; // MythSystemLegacyPrivate
98 
99  void Term(bool force=false) override; // MythSystemLegacyPrivate
100  void Signal(int sig) override; // MythSystemLegacyPrivate
101  void JumpAbort(void) override; // MythSystemLegacyPrivate
102 
103  bool ParseShell(const QString &cmd, QString &abscmd,
104  QStringList &args) override; // MythSystemLegacyPrivate
105 
109 
110  private:
111  pid_t m_pid {0};
112  time_t m_timeout {0};
113 
114  int m_stdpipe[3];
115 };
116 
117 #endif // _MYTHSYSTEM_UNIX_H_
118 
119 /*
120  * vim:ts=4:sw=4:ai:et:si:sts=4
121  */
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
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 *)