SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fxexdefs.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * FOX extension library: Definitions, Types, and Macros *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 ********************************************************************************/
22 #ifndef FXEXDEFS_H
23 #define FXEXDEFS_H
24 
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <fx.h>
32 
33 #ifdef WIN32
34 #include <windows.h>
35 #endif
36 
37 // loads the FOX defs
38 #ifndef FXDEFS_H
39 #include <fxdefs.h>
44 using namespace FX;
45 #endif
46 
47 // Disable warnings on extern before template instantiation for the Microsoft compiler.
48 // see "HOWTO: Exporting STL Components Inside & Outside of a Class" on the microsoft website
49 #if defined(WIN32) && defined(_MSC_VER)
50 #pragma warning (disable : 4231)
51 #endif
52 
53 
54 // implement CALLBACK for unix
55 #ifndef CALLBACK
56 #define CALLBACK
57 #endif
58 
65 namespace FXEX {
66 
67 // provide an extern mechanism
68 #ifdef WIN32
69 #ifdef FOXDLL
70 #ifndef FOXDLL_EXPORTS
71 #define FXEXTERN extern
72 #endif
73 #endif
74 #endif
75 
76 #ifndef FXEXTERN
77 #define FXEXTERN
78 #endif
79 
80 
81 // Valid compression factors for Bzip and Gzip compression libraries
82 #define COMPRESS_MAX 9
83 #define COMPRESS_NORMAL 6
84 #define COMPRESS_FAST 1
85 #define COMPRESS_NONE 0
86 
87 
88 // Win32 defines INFINITE to be -1, we might as well do it too.
89 #ifndef WIN32
90 # define INFINITE (-1)
91 #endif
92 
93 
94 // determine the newline charater(s)
95 #ifdef WIN32
96 #define FXNEWLINE "\r\n"
97 #endif
98 #ifdef MAC
99 #define FXNEWLINE "\r"
100 #endif
101 #ifndef FXNEWLINE
102 #define FXNEWLINE "\n"
103 #endif
104 
105 
106 // make a short from two chars
107 #define MKUSHORT(l,h) ((((FX::FXuchar)(l))&0xff) | (((FX::FXuchar)(h))<<8))
108 
109 /* !!!!
110 // Make a long from two ints - provided longs are twice the size of an int
111 #ifdef FX_LONG
112 # define MKULONG(l,h) ((((FX::FXuint)(l))&0xffffffff) | (((FX::FXuint)(h))<<32))
113 #else
114 # if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
115 # error "You wanted 64bit file sizes (actually 63), but I couldn't make it so..."
116 # endif
117 #endif
118 !!!! */
119 
124 #define FXDeclare(Class) \
125  FXDECLARE(Class)
126 #define FXDeclareAbstract(Class) \
127  FXDECLARE_ABSTRACT(Class)
128 #define FXDefMap(Class) \
129  FXDEFMAP(Class) Class##Map[]
130 #define FXImplementAbstract(Class,Parent) \
131  FXIMPLEMENT_ABSTRACT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map))
132 #define FXImplement(Class,Parent) \
133  FXIMPLEMENT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map))
134 #define FXFuncDecl(Func) \
135  long on##Func (FXObject*,FXSelector,void*)
136 #define FXFuncImpl(Class,Func,tgt,sel,ptr) \
137  long Class::on##Func (FXOject *tgt,FXSelector sel, void *ptr)
138 #define FXMapTypes(Class,FromType,ToType,Func) \
139  FXMAPTYPES(SEL_##FromType,SEL_##ToType,Class::on##Func)
140 #define FXMapType(Class,SelType,Func) \
141  FXMAPTYPE(SEL_##SelType,Class::on##Func)
142 #define FXMapFuncs(Class,SelType,FromId,ToId,Func) \
143  FXMAPFUNCS(SEL_##SelType,Class::ID_##FromId,Class::ID_##ToId,Class::on#Func)
144 #define FXMapFunc(Class,SelType,Id,Func) \
145  FXMAPFUNC(SEL_##SelType,Class::ID_##Id,Class::on##Func)
146 
147 
149 #define FXSEND(tgt,sel,msg,ptr) \
150  (tgt->handle(this,FXSEL(sel,msg),ptr)
151 #define FXROUTE(src,tgt,sel,msg,ptr) \
152  (tgt->handle(src,FXSEL(sel,msg),ptr)
153 
154 
155 // debugging macros
156 #ifndef NDEBUG
157 # define FXCTOR() fxtrace (100,"%s::%s %p\n",getClassName(),getClassName(),this)
158 # define FXMETHOD(methodname) fxtrace (100,"%s::%s %p\n",getClassName(),#methodname,this)
159 # define FXDTOR() fxtrace (100,"%s::~%s %p\n",getClassName(),getClassName(),this)
160 #else
161 # define FXCTOR()
162 # define FXMETHOD(methodname)
163 # define FXDTOR()
164 #endif
165 
166 
167 // New selector types
168 enum {
169  SEL_DATA = FX::SEL_LAST, // form of data as an event
170  SEL_THREAD, // thread/runnable events
171  SEL_WAITABLE_WAIT, // waitable event such as a Condition variable, semaphore, etc
172  SEL_WAITABLE_ACTIVATE, // waitable event such as a Condition variable, semaphore, etc
173  SEL_INTERLOCK, // interlocked event; object went into lock
174  SEL_BARRIER_LOCK, // barrier event; thread waiting in barrier lock
175  SEL_BARRIER_UNLOCK, // barrier event; barrier object reset, threads released
176  SEL_INPUT, // some type of input event
177  SEL_OUTPUT, // some type of output event
178  SEL_ERROR, // some type of error event
179  SEL_IO, // Some form of IO
180  SEL_IO_CONNECT, // Connection event
181  SEL_EVENT, // a generic event
182  SEL_BEGIN, // en event defining some begining
183  SEL_END, // an event defining some ending
184  SEL_TAG, // tag event
185  SEL_CONTENT, // content event
186  SEL_REGISTRY, // a registry event (TODO I have a plan for this...)
187  SEL_LASTEX,// Last message
189 };
190 
191 
193 typedef FXint FXIOStatus;
194 enum {
200 };
201 #ifndef INVALID_HANDLE
202 # ifdef WIN32
203 # define INVALID_HANDLE INVALID_HANDLE_VALUE
204 # else
205 # define INVALID_HANDLE -1
206 # endif
207 #endif
208 
209 #ifndef VALID_RESULT
210 # define VALID_RESULT 0
211 #endif
212 
213 
215 typedef FXint FXIOState;
216 enum {
228 };
229 
230 
234 
236  FXSocketTypeNone = 0, // unknown socket type
237  FXSocketTypeStream, // TCP socket
239  FXSocketTypeDatagram, // UDP socket
241 };
242 
245  FXSocketFamilyNone = 0, // unknown socket family
246  FXSocketFamilyLocal, // Local domain socket (on nearly every system, same as Unix domain)
247  FXSocketFamilyInet, // Internet domain socket, version 4 (ie the default internet family)
248  FXSocketFamilyInet6, // Internet domain socket, version 6
249  FXSocketFamilyAutomatic, // automatically choose UNIX domain (local) socket, when connecting
250  // to localhost, internet domain for internet sockets
252 };
253 
254 
275  FILEPERM_NONE = 0, // file has no permissions
276  FILEPERM_USER_READ = 0x00000001, // user can read from file
277  FILEPERM_USER_WRITE = 0x00000002, // user can write to file
278  FILEPERM_USER_EXEC = 0X00000004, // user can execute file
279  FILEPERM_GROUP_READ = 0x00000010, // group can read from file
280  FILEPERM_GROUP_WRITE = 0x00000020, // group can write to file
281  FILEPERM_GROUP_EXEC = 0x00000040, // group can execute the file
282  FILEPERM_OTHER_READ = 0x00000100, // everybody can read from file
283  FILEPERM_OTHER_WRITE = 0x00000200, // everybody can write to file
284  FILEPERM_OTHER_EXEC = 0x00000400, // everybody can execute the file
285  FILEPERM_READ = 0x00000111, // file read mask; set all read permissions
286  FILEPERM_WRITE = 0x00000222, // file write mask; set all write permissions
287  FILEPERM_EXEC = 0x00000444, // file execute mask; set all execute permissions
288  FILEPERM_ALL = 0x00000777, // permissions mask; set all permissions
289  FILEPERM_SET_UID = 0x00001000, // set the UID permission
290  FILEPERM_SET_GID = 0x00002000, // set the GID permisssion
291  FILEPERM_STICKY = 0x00004000, // set the STICKY permission
292  FILEPERM_SECURE_IO = FILEPERM_USER_READ | FILEPERM_USER_WRITE, // permissions suitable for single user IO access
293  FILEPERM_DEFAULT_IO = FILEPERM_READ | FILEPERM_USER_WRITE | FILEPERM_GROUP_WRITE, // permissions suitable for group IO access
294  FILEPERM_DEFAULT_EXEC = FILEPERM_READ | FILEPERM_USER_WRITE | FILEPERM_GROUP_WRITE | FILEPERM_EXEC // permissions suitable for all users to execute a file
295 };
296 
297 
298 // thread stuff
299 #ifndef WIN32
300 typedef void* FXThreadHandle; // handle to a thread
301 typedef void* FXThreadMutex; // handle to a mutex
302 typedef void* FXThreadCondition; // handle to a condition variable
303 typedef void* FXThreadSemaphore; // handle to a semaphore
304 typedef FXInputHandle* FXThreadEventHandle; // handle to a thread event object
305 #else
306 #include <windows.h>
307 typedef HANDLE FXThreadHandle; // handle to a thread
308 typedef HANDLE FXThreadMutex; // handle to a mutex
309 typedef HANDLE FXThreadCondition; // handle to a condition variable
310 typedef HANDLE FXThreadSemaphore; // handle to a semaphore
311 typedef FXInputHandle FXThreadEventHandle; // handle to a thread event object
312 #endif
313 
314 
315 // dynamic library loading
316 #ifndef WIN32
317 typedef void* FXDLLHandle; // handle to a dynamically loaded file
318 #else
319 typedef HMODULE FXDLLHandle; // handle to a dynamically loaded file
320 #endif
321 
322 
323 // database interface handle
324 //typedef void* FXDatabaseHandle; // handle to a database connection
325 
326 
327 namespace FXUtils {
328 
330 
332 extern FXAPI const FXuchar fxexversion[3];
333 
334 
336 
338 #ifdef WIN32
339 static void get_time_now(unsigned long* abs_sec, unsigned long* abs_nsec);
340 static DWORD get_timeout(unsigned long secs, unsigned long nsecs, DWORD default_to);
341 #else
342 void convert_timeval(struct timeval* tv, FXuint ms);
343 void convert_timespec(struct timespec* ts, FXuint ms);
344 #endif
345 
346 } // namespace FXUtils
347 } // namespace FXEX
348 
349 #endif // FXEXDEFS_H
350