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 "mythchrono.h"
23 #include "mythsystemlegacy.h"
24 #include "mthread.h"
25 
27 
28 using MSMap_t = QMap<pid_t, QPointer<MythSystemLegacyUnix> >;
29 using PMap_t = QMap<int, QBuffer *>;
30 using MSList_t = QList<QPointer<MythSystemLegacyUnix> >;
31 
33 {
34  public:
36  : MThread(QString("SystemIOHandler%1").arg(read ? "R" : "W")),
37  m_read(read) {};
38  ~MythSystemLegacyIOHandler() override { wait(); }
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 
51  QMutex m_pWaitLock;
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") {}
69  ~MythSystemLegacyManager() override { wait(); }
70  void run(void) override; // MThread
71  void append(MythSystemLegacyUnix *ms);
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  */
force
bool force
Definition: mythtv/programs/mythcommflag/main.cpp:72
build_compdb.args
args
Definition: build_compdb.py:11
MythSystemLegacyIOHandler::Wait
void Wait(int fd)
Definition: mythsystemunix.cpp:232
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythSystemLegacyIOHandler::m_pLock
QMutex m_pLock
Definition: mythsystemunix.h:53
MythSystemLegacyManager::m_pMap
MSMap_t m_pMap
Definition: mythsystemunix.h:74
MythSystemLegacyManager
Definition: mythsystemunix.h:64
MythSystemLegacyUnix
Definition: mythsystemunix.h:92
MythSystemLegacy
Definition: mythsystemlegacy.h:67
MythSystemLegacyManager::m_mapLock
QMutex m_mapLock
Definition: mythsystemunix.h:75
MythSystemLegacyPrivate
-*- Mode: c++ -*-
Definition: mythsystemprivate.h:21
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:278
MThread::wait
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:303
discid.disc.read
def read(device=None, features=[])
Definition: disc.py:35
mythbaseexp.h
SystemTime
std::chrono::time_point< SystemClock > SystemTime
Definition: mythchrono.h:67
MythSystemLegacyPrivate::Term
virtual void Term(bool force=false)=0
mythsystemprivate.h
MythSystemLegacySignalManager::MythSystemLegacySignalManager
MythSystemLegacySignalManager()
Definition: mythsystemunix.h:84
MSMap_t
QMap< pid_t, QPointer< MythSystemLegacyUnix > > MSMap_t
Definition: mythsystemunix.h:28
MythSystemLegacyIOHandler::m_maxfd
int m_maxfd
Definition: mythsystemunix.h:57
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:514
MythSystemLegacyPrivate::ParseShell
virtual bool ParseShell(const QString &cmd, QString &abscmd, QStringList &args)=0
mythsystemlegacy.h
MythSystemLegacyManager::MythSystemLegacyManager
MythSystemLegacyManager()
Definition: mythsystemunix.h:67
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
PMap_t
QMap< int, QBuffer * > PMap_t
Definition: mythsystemunix.h:29
MythSystemLegacyIOHandler
Definition: mythsystemunix.h:32
MSList_t
QList< QPointer< MythSystemLegacyUnix > > MSList_t
Definition: mythsystemunix.h:30
MythSystemLegacyManager::jumpAbort
void jumpAbort(void)
Definition: mythsystemunix.cpp:507
MythSystemLegacyManager::m_jumpLock
QMutex m_jumpLock
Definition: mythsystemunix.h:77
MythSystemLegacyIOHandler::m_fds
fd_set m_fds
Definition: mythsystemunix.h:56
MythSystemLegacyPrivate::Signal
virtual void Signal(int sig)=0
MythSystemLegacyManager::m_wait
QWaitCondition m_wait
Definition: mythsystemunix.h:78
MythSystemLegacyIOHandler::MythSystemLegacyIOHandler
MythSystemLegacyIOHandler(bool read)
Definition: mythsystemunix.h:35
MythSystemLegacyManager::~MythSystemLegacyManager
~MythSystemLegacyManager() override
Definition: mythsystemunix.h:69
MythSystemLegacyIOHandler::HandleWrite
void HandleWrite(int fd, QBuffer *buff)
Definition: mythsystemunix.cpp:195
MythSystemLegacySignalManager
Definition: mythsystemunix.h:81
MythSystemLegacyIOHandler::m_read
bool m_read
Definition: mythsystemunix.h:58
MythSystemLegacyManager::append
void append(MythSystemLegacyUnix *ms)
Definition: mythsystemunix.cpp:465
MythSystemLegacyIOHandler::BuildFDs
void BuildFDs()
Definition: mythsystemunix.cpp:264
MythSystemLegacyIOHandler::remove
void remove(int fd)
Definition: mythsystemunix.cpp:243
MythSystemLegacyIOHandler::m_pWait
QWaitCondition m_pWait
Definition: mythsystemunix.h:52
MythSystemLegacyPrivate::Fork
virtual void Fork(std::chrono::seconds timeout)=0
MythSystemLegacyIOHandler::wake
void wake()
Definition: mythsystemunix.cpp:258
MythSystemLegacyIOHandler::m_readbuf
std::array< char, 65536 > m_readbuf
Definition: mythsystemunix.h:59
MythSystemLegacyManager::m_jumpAbort
bool m_jumpAbort
Definition: mythsystemunix.h:76
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
mythchrono.h
mthread.h
MythSystemLegacyPrivate::JumpAbort
virtual void JumpAbort(void)=0
MythSystemLegacySignalManager::~MythSystemLegacySignalManager
~MythSystemLegacySignalManager() override
Definition: mythsystemunix.h:86
MythSystemLegacyIOHandler::~MythSystemLegacyIOHandler
~MythSystemLegacyIOHandler() override
Definition: mythsystemunix.h:38
MythSystemLegacyIOHandler::insert
void insert(int fd, QBuffer *buff)
Definition: mythsystemunix.cpp:223
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:78
MythSystemLegacyIOHandler::m_pWaitLock
QMutex m_pWaitLock
Definition: mythsystemunix.h:51
MythSystemLegacyIOHandler::m_pMap
PMap_t m_pMap
Definition: mythsystemunix.h:54
MythSystemLegacyPrivate::Manage
virtual void Manage(void)=0
MythSystemLegacyIOHandler::HandleRead
void HandleRead(int fd, QBuffer *buff)
Definition: mythsystemunix.cpp:163