nxcl  @VERSION@
notQt.h
Go to the documentation of this file.
1 /* -*-c++-*- */
2 /***************************************************************************
3  notQt.h: A set of Qt like functionality, especially related
4  to the starting of processes.
5  -------------------
6  begin : June 2007
7  copyright : (C) 2007 Embedded Software Foundry Ltd. (U.K.)
8  : Author: Sebastian James
9  email : seb@esfnet.co.uk
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
28 #ifndef _NOTQT_H_
29 #define _NOTQT_H_
30 
31 #include <list>
32 #include <vector>
33 #include <string>
34 #include <fstream>
35 extern "C" {
36 #include <sys/poll.h>
37 }
38 #define NOTQTPROCESS_MAIN_APP 0
39 #define NOTQTPROCESS_FAILURE -1
40 
41 // Possible errors to be generated
42 #define NOTQPROCNOERROR 0
43 #define NOTQPROCFAILEDTOSTART 1
44 #define NOTQPROCCRASHED 2
45 #define NOTQPROCTIMEDOUT 3
46 #define NOTQPROCWRITEERR 4
47 #define NOTQPROCREADERR 5
48 #define NOTQPROCUNKNOWN 6
49 
50 using namespace std;
51 
52 #ifdef DEBUG
53 extern ofstream debugLogFile;
54 # define dbgln(msg) debugLogFile << __FUNCTION__ << ": " << msg << endl;
55 # define dbglln(msg) debugLogFile << __PRETTY_FUNCTION__ << ": " << msg << endl;
56 # define dbg(msg) debugLogFile << msg;
57 #else
58 # define dbgln(msg)
59 # define dbglln(msg)
60 # define dbg(msg)
61 #endif
62 
63 namespace nxcl {
64 
71  {
72  public:
74  virtual ~notQProcessCallbacks() {}
75  virtual void startedSignal (string) {}
76  virtual void errorSignal (int) {}
77  virtual void processFinishedSignal (string) {}
78  virtual void readyReadStandardOutputSignal (void) {}
79  virtual void readyReadStandardErrorSignal (void) {}
80  };
81 
86  {
87  public:
88  notQProcess();
89  ~notQProcess();
93  void writeIn (string& input);
97  int start (const string& program, const list<string>& args);
101  void terminate (void);
102 
111  void probeProcess (void);
112 
117  pid_t getPid (void) { return this->pid; }
118  int getError (void) { return this->error; }
119  void setError (int e) { this->error = e; }
120 
121  int getParentFD()
122  {
123  this->parentFD = this->parentToChild[1];
124  close(this->childToParent[0]);
125 
126  // Create new pipes
127  pipe(this->parentToChild);
128  pipe(this->childToParent);
129 
130  return this->parentFD;
131  }
132 
136  void setCallbacks (notQProcessCallbacks * cb) { this->callbacks = cb; }
138 
143  string readAllStandardOutput (void);
144  string readAllStandardError (void);
150  bool waitForStarted (void);
152  private:
156  string progName;
160  list<string> environment;
164  int error;
168  pid_t pid;
174  bool signalledStart;
178  int parentToChild[2];
182  int childToParent[2];
186  int childErrToParent[2];
190  struct pollfd * p;
194  notQProcessCallbacks * callbacks;
195 
199  int parentFD;
200  };
201 
206  {
207  public:
215  void open (void);
219  void write (string input);
223  void close (void);
227  string fileName (void);
231  void remove (void);
232 
233  private:
237  string theFileName;
241  fstream f;
242  };
243 
248  {
249  public:
250  notQtUtilities();
251  ~notQtUtilities();
252 
254  static string simplify (string& input);
258  static void splitString (string& line, char token, vector<string>& rtn);
262  static void splitString (string& line, char token, list<string>& rtn);
266  static int ensureUnixNewlines (std::string& input);
267  };
268 
269 } // namespace
270 #endif
void setCallbacks(notQProcessCallbacks *cb)
Definition: notQt.h:136
Definition: nxcl.h:42
pid_t getPid(void)
Definition: notQt.h:117