00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #ifndef _NOTQT_H_
00029 #define _NOTQT_H_
00030
00031 #include "../config.h"
00032
00033 #include <list>
00034 #include <vector>
00035 #include <string>
00036 #include <fstream>
00037 extern "C" {
00038 #include <sys/poll.h>
00039 }
00040 #define NOTQTPROCESS_MAIN_APP 0
00041 #define NOTQTPROCESS_FAILURE -1
00042
00043
00044 #define NOTQPROCNOERROR 0
00045 #define NOTQPROCFAILEDTOSTART 1
00046 #define NOTQPROCCRASHED 2
00047 #define NOTQPROCTIMEDOUT 3
00048 #define NOTQPROCWRITEERR 4
00049 #define NOTQPROCREADERR 5
00050 #define NOTQPROCUNKNOWN 6
00051
00052 using namespace std;
00053
00054 #ifdef DEBUG
00055 extern ofstream debugLogFile;
00056 # define dbgln(msg) debugLogFile << __FUNCTION__ << ": " << msg << endl;
00057 # define dbglln(msg) debugLogFile << __PRETTY_FUNCTION__ << ": " << msg << endl;
00058 # define dbg(msg) debugLogFile << msg;
00059 #else
00060 # define dbgln(msg)
00061 # define dbglln(msg)
00062 # define dbg(msg)
00063 #endif
00064
00065 namespace nxcl {
00066
00072 class notQProcessCallbacks
00073 {
00074 public:
00075 notQProcessCallbacks() {}
00076 virtual ~notQProcessCallbacks() {}
00077 virtual void startedSignal (string) {}
00078 virtual void errorSignal (int) {}
00079 virtual void processFinishedSignal (string) {}
00080 virtual void readyReadStandardOutputSignal (void) {}
00081 virtual void readyReadStandardErrorSignal (void) {}
00082 };
00083
00087 class notQProcess
00088 {
00089 public:
00090 notQProcess();
00091 ~notQProcess();
00095 void writeIn (string& input);
00099 int start (const string& program, const list<string>& args);
00103 void terminate (void);
00104
00113 void probeProcess (void);
00114
00119 pid_t getPid (void) { return this->pid; }
00120 int getError (void) { return this->error; }
00121 void setError (int e) { this->error = e; }
00122
00126 void setCallbacks (notQProcessCallbacks * cb) { this->callbacks = cb; }
00128
00133 string readAllStandardOutput (void);
00134 string readAllStandardError (void);
00140 bool waitForStarted (void);
00142 private:
00146 string progName;
00150 list<string> environment;
00154 int error;
00158 pid_t pid;
00164 bool signalledStart;
00168 int parentToChild[2];
00172 int childToParent[2];
00176 int childErrToParent[2];
00180 struct pollfd * p;
00184 notQProcessCallbacks * callbacks;
00185 };
00186
00190 class notQTemporaryFile
00191 {
00192 public:
00193 notQTemporaryFile();
00194 ~notQTemporaryFile();
00200 void open (void);
00204 void write (string input);
00208 void close (void);
00212 string fileName (void);
00216 void remove (void);
00217
00218 private:
00222 string theFileName;
00226 fstream f;
00227 };
00228
00232 class notQtUtilities
00233 {
00234 public:
00235 notQtUtilities();
00236 ~notQtUtilities();
00237
00239 static string simplify (string& input);
00243 static void splitString (string& line, char token, vector<string>& rtn);
00247 static void splitString (string& line, char token, list<string>& rtn);
00251 static int ensureUnixNewlines (std::string& input);
00252 };
00253
00254 }
00255 #endif