sipxportlib  Version 3.3
OsProcess.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _OsProcess_h_
13 #define _OsProcess_h_
14 
15 // SYSTEM INCLUDES
16 
17 // APPLICATION INCLUDES
18 #include "os/OsDefs.h"
19 #include "os/OsStatus.h"
20 #include "os/OsTime.h"
21 #include "os/OsConfigDb.h"
22 #include "os/OsFS.h"
23 
24 // DEFINES
25 // MACROS
26 // EXTERNAL FUNCTIONS
27 // EXTERNAL VARIABLES
28 // CONSTANTS
29 // STRUCTS
30 // TYPEDEFS
31 typedef int PID;
32 
33 typedef struct OS_PROCESS_STRUCT
34 {
36  //: Process Id of process specified by object
37 
39  //: Parent Process Id of process specified by object
40 
42  //: Name of process. Does not include full path, just executable name.
43 
45  //: Command line used to start the process
46 
47  int prioClass;
48  //: Current priority of process
49 
50 
52 
53 
54 // FORWARD DECLARATIONS
55 
56 //: This encapsulates a pid, and allows querying, killing and all the
57 //: other cool things you want to do to a process.
58 
60 {
61 
62 
63 /* //////////////////////////// PUBLIC //////////////////////////////////// */
64 public:
65  friend class OsProcessIteratorWnt;
66  friend class OsProcessIteratorVxw;
67  friend class OsProcessIteratorLinux;
68  friend class OsProcessMgr;
69 
71  IdlePriorityClass = 0,
72  NormalPriorityClass = 1,
73  HighPriorityClass = 2,
74  RealtimePriorityClass = 3
75  };
76 
77 
82 
83 /* ============================ CREATORS ================================== */
84  OsProcessBase();
85  //:Default constructor
86 
87 /* ============================ MANIPULATORS ============================== */
88  virtual OsStatus launch(UtlString &rAppName, UtlString rParameters[],OsPath &startDir,
89  OsProcessPriorityClass prio = NormalPriorityClass, UtlBoolean bExeclusive = FALSE) = 0;
90  //: Pass the appname and parameters to start the process.
91  //: the Appname could just be the exe name, in which case it is search using your PATH.
92  //: startDir is the default directory the app will start from.
93  //: Returns OS_SUCCESS if process started ok.
94  //: prio specifies the priority class. You may also get the range and manipulate
95  //: the values yourself though setPriority
96  //: If bExclusive is TRUE and another process by the same name already
97  //: is running the return is OS_FAILED
98 
99 
100  virtual OsStatus kill() = 0;
101  //: Kills the process specified by pid
102 
103  virtual OsStatus setPriority(int prio) = 0;
104  //: Changes the process priority. Must own the process for this to be legal.
105  //: Returns TRUE if the priority was set correctly.
106  //: Returns FALSE if the priority could not be set.
107  //: Must be in the range specified by the getMin and Max Priorities.
108 
109  virtual OsStatus setEnv(UtlString &rKey, UtlString &rValue);
110  //: The presets an environment variable. This does NOT set the OS env variable.
111  //: It will set the OS variable just before launch. Then clears it after the launch.
112  //: The process object will continue to contain the env setting, the current OS, however does not.
113 
114  virtual OsStatus unsetEnv(UtlString &rKey);
115  //: The removes the variable from the process object only. It does not modify OS variables.
116 
117 
118  virtual OsStatus setIORedirect(OsPath &rStdInputFilename, OsPath &rStdOutputFilename, OsPath &rStdErrorFilename) = 0;
119  //: Sets the standard input, output and/or stderror
120 
121 
122 /* ============================ ACCESSORS ================================= */
123  static OsStatus getByPID(PID pid, OsProcessBase &rProcess);
124  //: Given a PID, this method will fill in the process passed in so the user
125  //: can then manipulate it
126 
127  static PID getCurrentPID();
128  //: returns the current process ID.
129  // This Id is unique within the entire host, in that any two simultaneous
130  // executions that do not share their memory space will have different
131  // values from getCurrentPID().
132 
133  virtual PID getPID();
134  //: Returns the process id contained by this object
135 
136  virtual PID getParentPID();
137  //: Returns the parent PID for this process.
138 
139  virtual OsStatus getProcessName(UtlString& rProcessName);
140  //: Returns the current process name (full path).
141  //: Returns OS_SUCCESS if name retrieved ok.
142  //: Returns OS_FAILED if process not assigned yet,
143 
144  virtual OsStatus getPriority(int &rPrio) = 0;
145  //: Returns the process priority. (1-255)
146  //: Adjusted based on Priority Class
147 
148  virtual OsStatus getMinPriority(int &rMinPrio) = 0;
149  //:returns the value repesenting the minimum priority
150 
151  virtual OsStatus getMaxPriority(int &rMaxPrio) = 0;
152  //:returns the value repesenting the maximum priority
153 
154  virtual OsStatus getPriorityClass(OsProcessPriorityClass &rPrioClass) = 0;
155  //: Returns the Current PriorityClass specified at launch
156 
157  OsStatus getEnv(UtlString &rKey, UtlString &rValue);
158  //: Returns the os environment variable
159 
160  virtual OsStatus getInfo(OsProcessInfo& rProcessInfo) = 0;
161  //: Returns full information on process, including priority.
162  //: See OsProcessInfo for more information
163 
164  virtual OsStatus getUpTime(OsTime &rUpTime) = 0;
165  //: How long has this process been running for?
166 
167 /* ============================ INQUIRY =================================== */
168 
169  virtual UtlBoolean isRunning () const = 0;
170  //: Returns TRUE if process is still active
171 
172  virtual int wait(int WaitInSecs = -1);
173  //: waits for a process to complete before returning
174  //: or exits when WaitInSecs has completed
175 
176 /* //////////////////////////// PROTECTED ///////////////////////////////// */
177 protected:
178  int mPID;
179  //: Process this object represents
180 
182  //: Parent PID of this process
183 
185  //:Used to store the processname this object represents
186  //:This should also be the FULL path name
187  //:This is what was passed on startup
188 
190  //: Priority Class specified on process startup
191 
193  //: Startup flag which specified whether multiple instances of process
194  //: can exist.
195 
197  //: Parameters specified at startup
198 
200  //: Stores the std error output stream specified by the user.
202  //: Stores the std input stream specified by the user.
204  //: Stores the std output stream specified by the user.
205 
207  //: Place to store the env variables before launching the process
208 
209  virtual OsStatus ApplyEnv();
210  //: Called by object before launch to set any environment variables set by user.
211 
212  virtual ~OsProcessBase();
213  //:Destructor
214 
215 /* //////////////////////////// PRIVATE /////////////////////////////////// */
216 private:
217 
218 };
219 
220 /* ============================ INLINE METHODS ============================ */
221 
222 
223 // Depending on the native OS that we are running on, we include the class
224 // declaration for the appropriate lower level implementation and use a
225 // "typedef" statement to associate the OS-independent class name (OsProcess)
226 // with the OS-dependent realization of that type (e.g., OsMutexWnt).
227 #if defined(_WIN32)
228 # include "os/Wnt/OsProcessWnt.h"
229  typedef class OsProcessWnt OsProcess;
230 #elif defined(_VXWORKS)
231 # include "os/Vxw/OsProcessVxw.h"
232  typedef class OsProcessVxw OsProcess;
233 #elif defined(__pingtel_on_posix__)
234 # include "os/linux/OsProcessLinux.h"
235  typedef class OsProcessLinux OsProcess;
236 #else
237 # error Unsupported target platform.
238 #endif
239 
240 //now add this header.
241 #include "os/OsProcessIterator.h"
242 #include "os/OsProcessMgr.h"
243 
244 #endif // _OsProcess_h_
245 
246 
int mPID
Definition: OsProcess.h:178
Definition: OsProcessIteratorLinux.h:36
UtlString commandline
Definition: OsProcess.h:44
Definition: OsProcessMgr.h:57
UtlString mStdOutputFilename
Definition: OsProcess.h:203
OsProcessPriorityClass mPrioClass
Definition: OsProcess.h:189
PID parentProcessID
Definition: OsProcess.h:38
OsStatus
Definition: OsStatus.h:27
struct OS_PROCESS_STRUCT OsProcessInfo
UtlString mParameters
Definition: OsProcess.h:196
UtlString mProcessName
Definition: OsProcess.h:184
int PID
Definition: OsProcess.h:31
Definition: OsProcessWnt.h:39
Definition: OsProcessIteratorWnt.h:38
OsProcessPriorityClass
Definition: OsProcess.h:70
struct OS_PROCESS_STRUCT * pOsProcessInfo
PID processID
Definition: OsProcess.h:35
OsStatus setIORedirect(OsPath &rStdInputFilename, OsPath &rStdOutputFilename, OsPath &rStdErrorFilename)
Definition: OsProcessMgr.cpp:157
Definition: OsProcess.h:59
Definition: UtlString.h:48
OsConfigDb mEnvList
Definition: OsProcess.h:206
UtlBoolean mExeclusive
Definition: OsProcess.h:192
Definition: OsConfigDb.h:67
Definition: OsTime.h:37
int prioClass
Definition: OsProcess.h:47
int UtlBoolean
Definition: UtlDefs.h:41
Definition: OsProcess.h:33
Definition: OsProcessLinux.h:34
#define FALSE
Definition: UtlDefs.h:21
int mParentPID
Definition: OsProcess.h:181
UtlString mStdInputFilename
Definition: OsProcess.h:201
UtlString name
Definition: OsProcess.h:41
UtlString mStdErrorFilename
Definition: OsProcess.h:199