00001 #ifndef _PROCESS_INVOKER_H_ 00002 #define _PROCESS_INVOKER_H_ 00003 00004 #include <qobject.h> 00005 #include <sys/wait.h> 00006 #include <sys/types.h> 00007 #include <sys/time.h> 00008 #include <signal.h> 00009 #include <stdio.h> 00010 #include <unistd.h> 00011 #include <errno.h> 00012 00013 #include <qtimer.h> 00014 #include <qdatastream.h> 00015 #include <qcstring.h> 00016 #include <qpe/qcopenvelope_qws.h> 00017 #include <qpe/global.h> 00018 //#include "KHUtil.h" 00019 #include "StringParser.h" 00020 00021 typedef void Sigfunc(int); 00022 00023 #define SC_CHANNEL "QPE/ShellCommander" 00024 00025 /* Sigleton Object */ 00026 class ProcessInvoker : public QObject 00027 { 00028 Q_OBJECT 00029 public: 00030 static ProcessInvoker& getInstance() 00031 { 00032 static ProcessInvoker instance; 00033 return(instance); 00034 } 00035 00036 bool run(); 00037 bool run(const QString& args); 00038 void terminate(); 00039 void terminate(pid_t pid); 00040 void kill(); 00041 void kill(pid_t pid); 00042 void setCommand(const QString& command){ 00043 m_arguments.clear(); 00044 addArgument(command); 00045 } 00046 void setArguments(const QStringList& arglist){ 00047 m_arguments = arglist; 00048 } 00049 void setArguments(const QString& arguments){ 00050 //setArguments(KHUtil::parseArgs(arguments)); 00051 setArguments(StringParser::split(' ', arguments)); 00052 } 00053 void addArgument(const QString& argument){ 00054 m_arguments.append(argument); 00055 } 00056 void addArguments(const QString& arguments){ 00057 QStringList arglist; 00058 //arglist = KHUtil::parseArgs(arguments); 00059 arglist = StringParser::split(' ', arguments); 00060 addArguments(arglist); 00061 } 00062 void addArguments(const QStringList& arglist){ 00063 for(QStringList::ConstIterator it=arglist.begin(); 00064 it!=arglist.end(); ++it){ 00065 addArgument(*it); 00066 } 00067 } 00068 //const QStringList parseArgs(const QString& arguments); 00069 void setRunning(int pid); 00070 void setNotify(bool enable=true){ 00071 m_isNotify = enable; 00072 } 00073 00074 bool isRunning(){ 00075 return(m_isRunning); 00076 } 00077 void notifyFinish(int status, bool success=true); 00078 00079 pid_t m_child; 00080 00081 friend class Dummy; /* for compile warning */ 00082 signals: 00083 void start(int, QStringList); 00084 void finish(QString,int); 00085 private: 00086 ProcessInvoker(); 00087 ProcessInvoker(const ProcessInvoker&); 00088 ProcessInvoker& operator=(const ProcessInvoker&); 00089 ~ProcessInvoker(); 00090 00091 class Dummy{}; /* for compile warning */ 00092 00093 QTimer* m_pTimer; 00094 QStringList m_arguments; 00095 00096 bool m_isRunning; 00097 bool m_isNotify; 00098 00099 Sigfunc* m_defChildHandler; 00100 00101 int m_stdfd[2]; 00102 int m_errfd[2]; 00103 int m_maxfdp1; 00104 00105 bool openPipe(); 00106 void closePipe(int fd[] = NULL, int n = 2); 00107 void notifyStatus(const QString& result, int code); 00108 00109 void workerProc(); 00110 private slots: 00111 void readOutputs(); 00112 }; 00113 00114 #endif /* _PROCESS_INVOKER_H_ */
1.4.2