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 <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 "mythsystemlegacy.h"
23 #include "mthread.h"
24 
26 
27 using MSMap_t = QMap<pid_t, QPointer<MythSystemLegacyUnix> >;
28 using PMap_t = QMap<int, QBuffer *>;
29 using MSList_t = QList<QPointer<MythSystemLegacyUnix> >;
30 
32 {
33  public:
35  : MThread(QString("SystemIOHandler%1").arg(read ? "R" : "W")),
36  m_read(read) {};
37  ~MythSystemLegacyIOHandler() override { wait(); }
38  void run(void) override; // MThread
39 
40  void insert(int fd, QBuffer *buff);
41  void Wait(int fd);
42  void remove(int fd);
43  void wake();
44 
45  private:
46  void HandleRead(int fd, QBuffer *buff);
47  void HandleWrite(int fd, QBuffer *buff);
48  void BuildFDs();
49 
50  QMutex m_pWaitLock;
51  QWaitCondition m_pWait;
52  QMutex m_pLock;
54 
55  fd_set m_fds {};
56  int m_maxfd {-1};
57  bool m_read {true};
58  std::array<char,65536> m_readbuf {};
59 };
60 
61 // spawn separate thread for signals to prevent manager
62 // thread from blocking in some slot
64 {
65  public:
67  : MThread("SystemManager") {}
68  ~MythSystemLegacyManager() override { wait(); }
69  void run(void) override; // MThread
70  void append(MythSystemLegacyUnix *ms);
71  void jumpAbort(void);
72  private:
74  QMutex m_mapLock;
75  bool m_jumpAbort {false};
76  QMutex m_jumpLock;
77  QWaitCondition m_wait;
78 };
79 
81 {
82  public:
84  : MThread("SystemSignalManager") {}
86  void run(void) override; // MThread
87  private:
88 };
89 
90 
92 {
93  Q_OBJECT
94 
95  public:
96  explicit MythSystemLegacyUnix(MythSystemLegacy *parent);
97  ~MythSystemLegacyUnix() override = default;
98 
99  void Fork(time_t timeout) override; // MythSystemLegacyPrivate
100  void Manage(void) override; // MythSystemLegacyPrivate
101 
102  void Term(bool force=false) override; // MythSystemLegacyPrivate
103  void Signal(int sig) override; // MythSystemLegacyPrivate
104  void JumpAbort(void) override; // MythSystemLegacyPrivate
105 
106  bool ParseShell(const QString &cmd, QString &abscmd,
107  QStringList &args) override; // MythSystemLegacyPrivate
108 
112 
113  private:
114  pid_t m_pid {0};
115  time_t m_timeout {0};
116 
117  std::array<int,3> m_stdpipe {-1, -1, -1};
118 };
119 
120 #endif // MYTHSYSTEM_UNIX_H
121 
122 /*
123  * vim:ts=4:sw=4:ai:et:si:sts=4
124  */
force
bool force
Definition: mythtv/programs/mythcommflag/main.cpp:75
build_compdb.args
args
Definition: build_compdb.py:11
MythSystemLegacyIOHandler::Wait
void Wait(int fd)
Definition: mythsystemunix.cpp:217
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythSystemLegacyIOHandler::m_pLock
QMutex m_pLock
Definition: mythsystemunix.h:52
MythSystemLegacyManager::m_pMap
MSMap_t m_pMap
Definition: mythsystemunix.h:73
MythSystemLegacyManager
Definition: mythsystemunix.h:64
MythSystemLegacyUnix
Definition: mythsystemunix.h:92
MythSystemLegacy
Definition: mythsystemlegacy.h:68
MythSystemLegacyManager::m_mapLock
QMutex m_mapLock
Definition: mythsystemunix.h:74
MythSystemLegacyPrivate
Definition: mythsystemprivate.h:26
MythSystemLegacyManager::run
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mythsystemunix.cpp:263
discid.disc.read
def read(device=None, features=[])
Definition: disc.py:35
mythbaseexp.h
MythSystemLegacyPrivate::Term
virtual void Term(bool force=false)=0
arg
arg(title).arg(filename).arg(doDelete))
mythsystemprivate.h
MythSystemLegacySignalManager::MythSystemLegacySignalManager
MythSystemLegacySignalManager()
Definition: mythsystemunix.h:83
MSMap_t
QMap< pid_t, QPointer< MythSystemLegacyUnix > > MSMap_t
Definition: mythsystemunix.h:27
MythSystemLegacyIOHandler::m_maxfd
int m_maxfd
Definition: mythsystemunix.h:56
MythSystemLegacySignalManager::run
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mythsystemunix.cpp:489
MythSystemLegacyPrivate::ParseShell
virtual bool ParseShell(const QString &cmd, QString &abscmd, QStringList &args)=0
mythsystemlegacy.h
MythSystemLegacyManager::MythSystemLegacyManager
MythSystemLegacyManager()
Definition: mythsystemunix.h:66
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
PMap_t
QMap< int, QBuffer * > PMap_t
Definition: mythsystemunix.h:28
MythSystemLegacyIOHandler
Definition: mythsystemunix.h:32
MSList_t
QList< QPointer< MythSystemLegacyUnix > > MSList_t
Definition: mythsystemunix.h:29
MythSystemLegacyManager::jumpAbort
void jumpAbort(void)
Definition: mythsystemunix.cpp:482
MythSystemLegacyManager::m_jumpLock
QMutex m_jumpLock
Definition: mythsystemunix.h:76
MythSystemLegacyUnix::~MythSystemLegacyUnix
~MythSystemLegacyUnix() override=default
MythSystemLegacyPrivate::Fork
virtual void Fork(time_t timeout)=0
MythSystemLegacyIOHandler::m_fds
fd_set m_fds
Definition: mythsystemunix.h:55
MythSystemLegacyPrivate::Signal
virtual void Signal(int sig)=0
MythSystemLegacyManager::m_wait
QWaitCondition m_wait
Definition: mythsystemunix.h:77
MythSystemLegacyIOHandler::MythSystemLegacyIOHandler
MythSystemLegacyIOHandler(bool read)
Definition: mythsystemunix.h:34
MythSystemLegacyManager::~MythSystemLegacyManager
~MythSystemLegacyManager() override
Definition: mythsystemunix.h:68
MythSystemLegacyIOHandler::HandleWrite
void HandleWrite(int fd, QBuffer *buff)
Definition: mythsystemunix.cpp:180
MythSystemLegacySignalManager
Definition: mythsystemunix.h:81
MythSystemLegacyIOHandler::m_read
bool m_read
Definition: mythsystemunix.h:57
MythSystemLegacyManager::append
void append(MythSystemLegacyUnix *ms)
Definition: mythsystemunix.cpp:440
MythSystemLegacyIOHandler::BuildFDs
void BuildFDs()
Definition: mythsystemunix.cpp:249
MythSystemLegacyIOHandler::remove
void remove(int fd)
Definition: mythsystemunix.cpp:228
MythSystemLegacyIOHandler::m_pWait
QWaitCondition m_pWait
Definition: mythsystemunix.h:51
MythSystemLegacyIOHandler::wake
void wake()
Definition: mythsystemunix.cpp:243
MythSystemLegacyIOHandler::m_readbuf
std::array< char, 65536 > m_readbuf
Definition: mythsystemunix.h:58
MythSystemLegacyManager::m_jumpAbort
bool m_jumpAbort
Definition: mythsystemunix.h:75
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
mthread.h
MythSystemLegacyPrivate::JumpAbort
virtual void JumpAbort(void)=0
MythSystemLegacySignalManager::~MythSystemLegacySignalManager
~MythSystemLegacySignalManager() override
Definition: mythsystemunix.h:85
MythSystemLegacyIOHandler::~MythSystemLegacyIOHandler
~MythSystemLegacyIOHandler() override
Definition: mythsystemunix.h:37
MythSystemLegacyIOHandler::insert
void insert(int fd, QBuffer *buff)
Definition: mythsystemunix.cpp:208
MThread::wait
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:306
MythSystemLegacyIOHandler::run
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mythsystemunix.cpp:79
MythSystemLegacyIOHandler::m_pWaitLock
QMutex m_pWaitLock
Definition: mythsystemunix.h:50
MythSystemLegacyIOHandler::m_pMap
PMap_t m_pMap
Definition: mythsystemunix.h:53
MythSystemLegacyPrivate::Manage
virtual void Manage(void)=0
MythSystemLegacyIOHandler::HandleRead
void HandleRead(int fd, QBuffer *buff)
Definition: mythsystemunix.cpp:148