GCC 4.3.x fixes for cabman and sysreg
[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 #include <cstdlib>
26
27 #ifndef _MSC_VER
28 #include <sys/time.h>
29 #endif
30
31 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
32
33 namespace System_
34 {
35 //---------------------------------------------------------------------------------------
36 ///
37 /// class OsSupport
38 ///
39 /// Description: this class encapsulates operating system specific functions
40 ///
41 ///
42
43 class OsSupport
44 {
45 public:
46 #ifdef WIN32
47 typedef DWORD ProcessID;
48 #else
49 typedef pid_t ProcessID;
50 #endif
51
52 //---------------------------------------------------------------------------------------
53 ///
54 /// OsSupport
55 ///
56 /// Description: constructor of class OsSupport
57
58 virtual ~OsSupport()
59 {}
60
61 //---------------------------------------------------------------------------------------
62 ///
63 /// createProcess
64 ///
65 /// Description: this functions creates a new process and returns its pid on success
66 ///
67 /// @param procname name of the file to execute
68 /// @param procargsnum num of arguments for the new process
69 /// @param procargs arguments for the new process
70 ///
71 ///
72
73 static ProcessID createProcess(const char * procname, int procargsnum, const char ** procargs, bool wait);
74
75 //---------------------------------------------------------------------------------------
76 ///
77 /// terminateProcess
78 ///
79 /// Description: this function terminates a process given by its pid
80 ///
81 /// Note: returns true if the process with the given pid was terminated
82 ///
83 /// @param pid process id of the process to terminate
84 /// @param exitcode for the killed process
85
86 static bool terminateProcess(ProcessID pid, int exitcode);
87
88
89 //----------------------------------------------------------------------------------------
90 ///
91 /// delayExecution
92 ///
93 /// Description: this function sleeps the current process for the amount given in seconds
94 ///
95 /// @param sec amount of seconds to sleep
96
97 static void delayExecution(long sec);
98
99 ///---------------------------------------------------------------------------------------
100 ///
101 /// initializeTimer
102 ///
103 /// Description: this function initializes an alarm. When the alarm expires, it will terminate
104 /// the given process
105
106 static void setAlarm(long sec, OsSupport::ProcessID pid);
107
108 ///---------------------------------------------------------------------------------------
109 ///
110 /// cancelAlarms
111 ///
112 /// Description: this function cancels all available timers
113
114 static void cancelAlarms();
115
116 ///---------------------------------------------------------------------------------------
117 ///
118 /// checkAlarms
119 ///
120 /// Description: this function checks for expired alarams
121
122 static void checkAlarms();
123
124 ///---------------------------------------------------------------------------------------
125 ///
126 /// hasAlarms
127 ///
128 /// Description: this function checks wether there are alarms set active
129
130 static bool hasAlarms();
131
132 protected:
133 //---------------------------------------------------------------------------------------
134 ///
135 /// OsSupport
136 ///
137 /// Description: constructor of class OsSupport
138
139 OsSupport()
140 {}
141
142 #ifdef __LINUX__
143 static struct sigaction s_sact;
144 #else
145 static HANDLE s_hThread;
146 #endif
147
148 typedef struct
149 {
150 struct timeval tm;
151 ProcessID pid;
152 }TIME_ENTRY, *PTIME_ENTRY;
153 typedef std::vector<PTIME_ENTRY> TimeEntryVector;
154 static TimeEntryVector s_Entries;
155 }; // end of class OsSupport
156
157 } // end of namespace System_
158
159 #endif /* end of OS_SUPPORT_H__ */