25f694626851c72af83c5a32fca52891580b0123
[reactos.git] / reactos / tools / sysreg / os_support.h
1 #ifndef OS_SUPPORT_H__
2 #define OS_SUPPORT_H__
3
4 /* $Id: os_support.h 24643 2006-10-24 11:45:21Z janderwald $
5 *
6 * PROJECT: System regression tool for ReactOS
7 * LICENSE: GPL - See COPYING in the top level directory
8 * FILE: tools/sysreg/conf_parser.h
9 * PURPOSE: operating systems specific code
10 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
11 */
12
13 #ifndef __LINUX__
14 #include <windows.h>
15 #else
16 #include <unistd.h>
17 #include <sys/types.h>
18 #include <signal.h>
19 #include <sys/wait.h>
20 #endif
21
22 #include "user_types.h"
23 #include <ctime>
24 #include <vector>
25
26 #ifndef _MSC_VER
27 #include <sys/time.h>
28 #endif
29
30 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
31
32 namespace System_
33 {
34 //---------------------------------------------------------------------------------------
35 ///
36 /// class OsSupport
37 ///
38 /// Description: this class encapsulates operating system specific functions
39 ///
40 ///
41
42 class OsSupport
43 {
44 public:
45 #ifdef WIN32
46 typedef DWORD ProcessID;
47 #else
48 typedef pid_t ProcessID;
49 #endif
50
51 //---------------------------------------------------------------------------------------
52 ///
53 /// OsSupport
54 ///
55 /// Description: constructor of class OsSupport
56
57 virtual ~OsSupport()
58 {}
59
60 //---------------------------------------------------------------------------------------
61 ///
62 /// createProcess
63 ///
64 /// Description: this functions creates a new process and returns its pid on success
65 ///
66 /// @param procname name of the file to execute
67 /// @param procargsnum num of arguments for the new process
68 /// @param procargs arguments for the new process
69 ///
70 ///
71
72 static ProcessID createProcess(const char * procname, int procargsnum, const char ** procargs, bool wait);
73
74 //---------------------------------------------------------------------------------------
75 ///
76 /// terminateProcess
77 ///
78 /// Description: this function terminates a process given by its pid
79 ///
80 /// Note: returns true if the process with the given pid was terminated
81 ///
82 /// @param pid process id of the process to terminate
83 /// @param exitcode for the killed process
84
85 static bool terminateProcess(ProcessID pid, int exitcode);
86
87
88 //----------------------------------------------------------------------------------------
89 ///
90 /// delayExecution
91 ///
92 /// Description: this function sleeps the current process for the amount given in seconds
93 ///
94 /// @param sec amount of seconds to sleep
95
96 static void delayExecution(long sec);
97
98 ///---------------------------------------------------------------------------------------
99 ///
100 /// initializeTimer
101 ///
102 /// Description: this function initializes an alarm. When the alarm expires, it will terminate
103 /// the given process
104
105 static void setAlarm(long sec, OsSupport::ProcessID pid);
106
107 ///---------------------------------------------------------------------------------------
108 ///
109 /// cancelAlarms
110 ///
111 /// Description: this function cancels all available timers
112
113 static void cancelAlarms();
114
115 ///---------------------------------------------------------------------------------------
116 ///
117 /// checkAlarms
118 ///
119 /// Description: this function checks for expired alarams
120
121 static void checkAlarms();
122
123 ///---------------------------------------------------------------------------------------
124 ///
125 /// hasAlarms
126 ///
127 /// Description: this function checks wether there are alarms set active
128
129 static bool hasAlarms();
130
131 protected:
132 //---------------------------------------------------------------------------------------
133 ///
134 /// OsSupport
135 ///
136 /// Description: constructor of class OsSupport
137
138 OsSupport()
139 {}
140
141 #ifdef __LINUX__
142 static struct sigaction s_sact;
143 #else
144 static HANDLE s_hThread;
145 #endif
146
147 typedef struct
148 {
149 struct timeval tm;
150 ProcessID pid;
151 }TIME_ENTRY, *PTIME_ENTRY;
152 typedef std::vector<PTIME_ENTRY> TimeEntryVector;
153 static TimeEntryVector s_Entries;
154 }; // end of class OsSupport
155
156 } // end of namespace System_
157
158 #endif /* end of OS_SUPPORT_H__ */