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 #include <unistd.h>
36 extern "C" {
37 #include <sys/poll.h>
38 }
39 #define NOTQTPROCESS_MAIN_APP 0
40 #define NOTQTPROCESS_FAILURE -1
41 
42 // Possible errors to be generated
43 #define NOTQPROCNOERROR 0
44 #define NOTQPROCFAILEDTOSTART 1
45 #define NOTQPROCCRASHED 2
46 #define NOTQPROCTIMEDOUT 3
47 #define NOTQPROCWRITEERR 4
48 #define NOTQPROCREADERR 5
49 #define NOTQPROCUNKNOWN 6
50 
51 using namespace std;
52 
53 #ifdef DEBUG
54 extern ofstream debugLogFile;
55 # define dbgln(msg) debugLogFile << __FUNCTION__ << ": " << msg << endl;
56 # define dbglln(msg) debugLogFile << __PRETTY_FUNCTION__ << ": " << msg << endl;
57 # define dbg(msg) debugLogFile << msg;
58 #else
59 # define dbgln(msg)
60 # define dbglln(msg)
61 # define dbg(msg)
62 #endif
63 
64 namespace nxcl {
65 
72  {
73  public:
75  virtual ~notQProcessCallbacks() {}
76  virtual void startedSignal (string) {}
77  virtual void errorSignal (int) {}
78  virtual void processFinishedSignal (string) {}
79  virtual void readyReadStandardOutputSignal (void) {}
80  virtual void readyReadStandardErrorSignal (void) {}
81  };
82 
87  {
88  public:
89  notQProcess();
90  ~notQProcess();
94  void writeIn (string& input);
98  int start (const string& program, const list<string>& args);
102  void terminate (void);
103 
112  void probeProcess (void);
113 
118  pid_t getPid (void) { return this->pid; }
119  int getError (void) { return this->error; }
120  void setError (int e) { this->error = e; }
121 
122  int getParentFD()
123  {
124  this->parentFD = this->parentToChild[1];
125  close(this->childToParent[0]);
126 
127  // Create new pipes
128  pipe(this->parentToChild);
129  pipe(this->childToParent);
130 
131  return this->parentFD;
132  }
133 
137  void setCallbacks (notQProcessCallbacks * cb) { this->callbacks = cb; }
139 
144  string readAllStandardOutput (void);
145  string readAllStandardError (void);
151  bool waitForStarted (void);
153  private:
157  string progName;
161  list<string> environment;
165  int error;
169  pid_t pid;
175  bool signalledStart;
179  int parentToChild[2];
183  int childToParent[2];
187  int childErrToParent[2];
191  struct pollfd * p;
195  notQProcessCallbacks * callbacks;
196 
200  int parentFD;
201  };
202 
207  {
208  public:
216  void open (void);
220  void write (string input);
224  void close (void);
228  string fileName (void);
232  void remove (void);
233 
234  private:
238  string theFileName;
242  fstream f;
243  };
244 
249  {
250  public:
251  notQtUtilities();
252  ~notQtUtilities();
253 
255  static string simplify (string& input);
259  static void splitString (string& line, char token, vector<string>& rtn);
263  static void splitString (string& line, char token, list<string>& rtn);
267  static int ensureUnixNewlines (std::string& input);
268  };
269 
270 } // namespace
271 #endif
nxcl::notQProcess::setCallbacks
void setCallbacks(notQProcessCallbacks *cb)
Definition: notQt.h:137
nxcl::notQProcess
Definition: notQt.h:86
nxcl::notQProcessCallbacks
Definition: notQt.h:71
nxcl::notQProcess::getPid
pid_t getPid(void)
Definition: notQt.h:118
nxcl::notQTemporaryFile
Definition: notQt.h:206
nxcl::notQtUtilities
Definition: notQt.h:248