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 <list>
00032 #include <vector>
00033 #include <string>
00034 #include <fstream>
00035 extern "C" {
00036 #include <sys/poll.h>
00037 }
00038 #define NOTQTPROCESS_MAIN_APP 0
00039 #define NOTQTPROCESS_FAILURE -1
00040
00041
00042 #define NOTQPROCNOERROR 0
00043 #define NOTQPROCFAILEDTOSTART 1
00044 #define NOTQPROCCRASHED 2
00045 #define NOTQPROCTIMEDOUT 3
00046 #define NOTQPROCWRITEERR 4
00047 #define NOTQPROCREADERR 5
00048 #define NOTQPROCUNKNOWN 6
00049
00050 using namespace std;
00051
00052 #ifdef DEBUG
00053 extern ofstream debugLogFile;
00054 # define dbgln(msg) debugLogFile << __FUNCTION__ << ": " << msg << endl;
00055 # define dbglln(msg) debugLogFile << __PRETTY_FUNCTION__ << ": " << msg << endl;
00056 # define dbg(msg) debugLogFile << msg;
00057 #else
00058 # define dbgln(msg)
00059 # define dbglln(msg)
00060 # define dbg(msg)
00061 #endif
00062
00063 namespace nxcl {
00064
00070 class notQProcessCallbacks
00071 {
00072 public:
00073 notQProcessCallbacks() {}
00074 virtual ~notQProcessCallbacks() {}
00075 virtual void startedSignal (string) {}
00076 virtual void errorSignal (int) {}
00077 virtual void processFinishedSignal (string) {}
00078 virtual void readyReadStandardOutputSignal (void) {}
00079 virtual void readyReadStandardErrorSignal (void) {}
00080 };
00081
00085 class notQProcess
00086 {
00087 public:
00088 notQProcess();
00089 ~notQProcess();
00093 void writeIn (string& input);
00097 int start (const string& program, const list<string>& args);
00101 void terminate (void);
00102
00111 void probeProcess (void);
00112
00117 pid_t getPid (void) { return this->pid; }
00118 int getError (void) { return this->error; }
00119 void setError (int e) { this->error = e; }
00120
00121 int getParentFD()
00122 {
00123 this->parentFD = this->parentToChild[1];
00124 close(this->childToParent[0]);
00125
00126
00127 pipe(this->parentToChild);
00128 pipe(this->childToParent);
00129
00130 return this->parentFD;
00131 }
00132
00136 void setCallbacks (notQProcessCallbacks * cb) { this->callbacks = cb; }
00138
00143 string readAllStandardOutput (void);
00144 string readAllStandardError (void);
00150 bool waitForStarted (void);
00152 private:
00156 string progName;
00160 list<string> environment;
00164 int error;
00168 pid_t pid;
00174 bool signalledStart;
00178 int parentToChild[2];
00182 int childToParent[2];
00186 int childErrToParent[2];
00190 struct pollfd * p;
00194 notQProcessCallbacks * callbacks;
00195
00199 int parentFD;
00200 };
00201
00205 class notQTemporaryFile
00206 {
00207 public:
00208 notQTemporaryFile();
00209 ~notQTemporaryFile();
00215 void open (void);
00219 void write (string input);
00223 void close (void);
00227 string fileName (void);
00231 void remove (void);
00232
00233 private:
00237 string theFileName;
00241 fstream f;
00242 };
00243
00247 class notQtUtilities
00248 {
00249 public:
00250 notQtUtilities();
00251 ~notQtUtilities();
00252
00254 static string simplify (string& input);
00258 static void splitString (string& line, char token, vector<string>& rtn);
00262 static void splitString (string& line, char token, list<string>& rtn);
00266 static int ensureUnixNewlines (std::string& input);
00267 };
00268
00269 }
00270 #endif