00001 #ifndef SYSTEM_UNIX_H_ 00002 #define SYSTEM_UNIX_H_ 00003 00004 #include <sys/select.h> 00005 #include <signal.h> 00006 00007 #include <QObject> 00008 #include <QString> 00009 #include <QStringList> 00010 #include <QMap> 00011 #include <QList> 00012 #include <QBuffer> 00013 #include <QWaitCondition> 00014 #include <QMutex> 00015 #include <QPointer> 00016 00017 #include "mythbaseexp.h" 00018 #include "mythsystem.h" 00019 #include "mthread.h" 00020 00021 class MythSystemUnix; 00022 00023 typedef QMap<pid_t, QPointer<MythSystemUnix> > MSMap_t; 00024 typedef QMap<int, QBuffer *> PMap_t; 00025 typedef QList<QPointer<MythSystemUnix> > MSList_t; 00026 00027 class MythSystemIOHandler: public MThread 00028 { 00029 public: 00030 MythSystemIOHandler(bool read); 00031 ~MythSystemIOHandler() { wait(); } 00032 void run(void); 00033 00034 void insert(int fd, QBuffer *buff); 00035 void remove(int fd); 00036 void wake(); 00037 00038 private: 00039 void HandleRead(int fd, QBuffer *buff); 00040 void HandleWrite(int fd, QBuffer *buff); 00041 void BuildFDs(); 00042 00043 QMutex m_pWaitLock; 00044 QWaitCondition m_pWait; 00045 QMutex m_pLock; 00046 PMap_t m_pMap; 00047 00048 fd_set m_fds; 00049 int m_maxfd; 00050 bool m_read; 00051 char m_readbuf[65536]; 00052 }; 00053 00054 class MythSystemManager : public MThread 00055 { 00056 public: 00057 MythSystemManager(); 00058 ~MythSystemManager() { wait(); } 00059 void run(void); 00060 void append(MythSystemUnix *); 00061 void jumpAbort(void); 00062 private: 00063 MSMap_t m_pMap; 00064 QMutex m_mapLock; 00065 bool m_jumpAbort; 00066 QMutex m_jumpLock; 00067 }; 00068 00069 class MythSystemSignalManager : public MThread 00070 { 00071 public: 00072 MythSystemSignalManager(); 00073 ~MythSystemSignalManager() { wait(); } 00074 void run(void); 00075 private: 00076 }; 00077 00078 00079 class MBASE_PUBLIC MythSystemUnix : public MythSystemPrivate 00080 { 00081 Q_OBJECT 00082 00083 public: 00084 MythSystemUnix(MythSystem *parent); 00085 ~MythSystemUnix(); 00086 00087 virtual void Fork(time_t timeout); 00088 virtual void Manage(); 00089 00090 virtual void Term(bool force=false); 00091 virtual void Signal(int sig); 00092 virtual void JumpAbort(void); 00093 00094 virtual bool ParseShell(const QString cmd, QString &abscmd, 00095 QStringList &args); 00096 00097 friend class MythSystemManager; 00098 friend class MythSystemSignalManager; 00099 friend class MythSystemIOHandler; 00100 00101 private: 00102 pid_t m_pid; 00103 time_t m_timeout; 00104 00105 int m_stdpipe[3]; 00106 }; 00107 00108 #endif 00109 00110 /* 00111 * vim:ts=4:sw=4:ai:et:si:sts=4 00112 */
1.6.3