Eclipse SUMO - Simulation of Urban MObility
fxexdefs.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2004-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 #ifndef FXEXDEFS_H
21 #define FXEXDEFS_H
22 
23 #include <config.h>
24 
25 #include <fx.h>
26 
27 #ifdef WIN32
28 #define NOMINMAX
29 #include <windows.h>
30 #undef NOMINMAX
31 #endif
32 
33 // loads the FOX defs
34 #ifndef FXDEFS_H
35 #include <fxdefs.h>
40 using namespace FX;
41 #endif
42 
43 // Disable warnings on extern before template instantiation for the Microsoft compiler.
44 // see "HOWTO: Exporting STL Components Inside & Outside of a Class" on the microsoft website
45 #if defined(WIN32) && defined(_MSC_VER)
46 #pragma warning (disable : 4231)
47 #endif
48 
49 
50 // implement CALLBACK for unix
51 #ifndef CALLBACK
52 #define CALLBACK
53 #endif
54 
61 namespace FXEX {
62 
63 // provide an extern mechanism
64 #ifdef WIN32
65 #ifdef FOXDLL
66 #ifndef FOXDLL_EXPORTS
67 #define FXEXTERN extern
68 #endif
69 #endif
70 #endif
71 
72 #ifndef FXEXTERN
73 #define FXEXTERN
74 #endif
75 
76 
77 // Valid compression factors for Bzip and Gzip compression libraries
78 #define COMPRESS_MAX 9
79 #define COMPRESS_NORMAL 6
80 #define COMPRESS_FAST 1
81 #define COMPRESS_NONE 0
82 
83 
84 // Win32 defines INFINITE to be -1, we might as well do it too.
85 #ifndef WIN32
86 # define INFINITE (-1)
87 #endif
88 
89 
90 // determine the newline charater(s)
91 #ifdef WIN32
92 #define FXNEWLINE "\r\n"
93 #endif
94 #ifdef MAC
95 #define FXNEWLINE "\r"
96 #endif
97 #ifndef FXNEWLINE
98 #define FXNEWLINE "\n"
99 #endif
100 
101 
102 // make a short from two chars
103 #define MKUSHORT(l,h) ((((FX::FXuchar)(l))&0xff) | (((FX::FXuchar)(h))<<8))
104 
105 /* !!!!
106 // Make a long from two ints - provided longs are twice the size of an int
107 #ifdef FX_LONG
108 # define MKULONG(l,h) ((((FX::FXuint)(l))&0xffffffff) | (((FX::FXuint)(h))<<32))
109 #else
110 # if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
111 # error "You wanted 64bit file sizes (actually 63), but I couldn't make it so..."
112 # endif
113 #endif
114 !!!! */
115 
120 #define FXDeclare(Class) \
121  FXDECLARE(Class)
122 #define FXDeclareAbstract(Class) \
123  FXDECLARE_ABSTRACT(Class)
124 #define FXDefMap(Class) \
125  FXDEFMAP(Class) Class##Map[]
126 #define FXImplementAbstract(Class,Parent) \
127  FXIMPLEMENT_ABSTRACT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map))
128 #define FXImplement(Class,Parent) \
129  FXIMPLEMENT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map))
130 #define FXFuncDecl(Func) \
131  long on##Func (FXObject*,FXSelector,void*)
132 #define FXFuncImpl(Class,Func,tgt,sel,ptr) \
133  long Class::on##Func (FXOject *tgt,FXSelector sel, void *ptr)
134 #define FXMapTypes(Class,FromType,ToType,Func) \
135  FXMAPTYPES(SEL_##FromType,SEL_##ToType,Class::on##Func)
136 #define FXMapType(Class,SelType,Func) \
137  FXMAPTYPE(SEL_##SelType,Class::on##Func)
138 #define FXMapFuncs(Class,SelType,FromId,ToId,Func) \
139  FXMAPFUNCS(SEL_##SelType,Class::ID_##FromId,Class::ID_##ToId,Class::on#Func)
140 #define FXMapFunc(Class,SelType,Id,Func) \
141  FXMAPFUNC(SEL_##SelType,Class::ID_##Id,Class::on##Func)
142 
143 
145 #define FXSEND(tgt,sel,msg,ptr) \
146  (tgt->handle(this,FXSEL(sel,msg),ptr)
147 #define FXROUTE(src,tgt,sel,msg,ptr) \
148  (tgt->handle(src,FXSEL(sel,msg),ptr)
149 
150 
151 // debugging macros
152 #ifndef NDEBUG
153 # define FXCTOR() fxtrace (100,"%s::%s %p\n",getClassName(),getClassName(),this)
154 # define FXMETHOD(methodname) fxtrace (100,"%s::%s %p\n",getClassName(),#methodname,this)
155 # define FXDTOR() fxtrace (100,"%s::~%s %p\n",getClassName(),getClassName(),this)
156 #else
157 # define FXCTOR()
158 # define FXMETHOD(methodname)
159 # define FXDTOR()
160 #endif
161 
162 
163 // New selector types
164 enum {
165  SEL_DATA = FX::SEL_LAST, // form of data as an event
166  SEL_THREAD, // thread/runnable events
167  SEL_WAITABLE_WAIT, // waitable event such as a Condition variable, semaphore, etc
168  SEL_WAITABLE_ACTIVATE, // waitable event such as a Condition variable, semaphore, etc
169  SEL_INTERLOCK, // interlocked event; object went into lock
170  SEL_BARRIER_LOCK, // barrier event; thread waiting in barrier lock
171  SEL_BARRIER_UNLOCK, // barrier event; barrier object reset, threads released
172  SEL_INPUT, // some type of input event
173  SEL_OUTPUT, // some type of output event
174  SEL_ERROR, // some type of error event
175  SEL_IO, // Some form of IO
176  SEL_IO_CONNECT, // Connection event
177  SEL_EVENT, // a generic event
178  SEL_BEGIN, // en event defining some begining
179  SEL_END, // an event defining some ending
180  SEL_TAG, // tag event
181  SEL_CONTENT, // content event
182  SEL_REGISTRY, // a registry event (TODO I have a plan for this...)
183  SEL_LASTEX,// Last message
185 };
186 
187 
189 typedef FXint FXIOStatus;
190 enum {
196 };
197 #ifndef INVALID_HANDLE
198 # ifdef WIN32
199 # define INVALID_HANDLE INVALID_HANDLE_VALUE
200 # else
201 # define INVALID_HANDLE -1
202 # endif
203 #endif
204 
205 #ifndef VALID_RESULT
206 # define VALID_RESULT 0
207 #endif
208 
209 
211 typedef FXint FXIOState;
212 enum {
224 };
225 
226 
230 enum FXSocketType {
232  FXSocketTypeNone = 0, // unknown socket type
233  FXSocketTypeStream, // TCP socket
235  FXSocketTypeDatagram, // UDP socket
237 };
238 
241  FXSocketFamilyNone = 0, // unknown socket family
242  FXSocketFamilyLocal, // Local domain socket (on nearly every system, same as Unix domain)
243  FXSocketFamilyInet, // Internet domain socket, version 4 (ie the default internet family)
244  FXSocketFamilyInet6, // Internet domain socket, version 6
245  FXSocketFamilyAutomatic, // automatically choose UNIX domain (local) socket, when connecting
246  // to localhost, internet domain for internet sockets
248 };
249 
250 
271  FILEPERM_NONE = 0, // file has no permissions
272  FILEPERM_USER_READ = 0x00000001, // user can read from file
273  FILEPERM_USER_WRITE = 0x00000002, // user can write to file
274  FILEPERM_USER_EXEC = 0X00000004, // user can execute file
275  FILEPERM_GROUP_READ = 0x00000010, // group can read from file
276  FILEPERM_GROUP_WRITE = 0x00000020, // group can write to file
277  FILEPERM_GROUP_EXEC = 0x00000040, // group can execute the file
278  FILEPERM_OTHER_READ = 0x00000100, // everybody can read from file
279  FILEPERM_OTHER_WRITE = 0x00000200, // everybody can write to file
280  FILEPERM_OTHER_EXEC = 0x00000400, // everybody can execute the file
281  FILEPERM_READ = 0x00000111, // file read mask; set all read permissions
282  FILEPERM_WRITE = 0x00000222, // file write mask; set all write permissions
283  FILEPERM_EXEC = 0x00000444, // file execute mask; set all execute permissions
284  FILEPERM_ALL = 0x00000777, // permissions mask; set all permissions
285  FILEPERM_SET_UID = 0x00001000, // set the UID permission
286  FILEPERM_SET_GID = 0x00002000, // set the GID permisssion
287  FILEPERM_STICKY = 0x00004000, // set the STICKY permission
288  FILEPERM_SECURE_IO = FILEPERM_USER_READ | FILEPERM_USER_WRITE, // permissions suitable for single user IO access
289  FILEPERM_DEFAULT_IO = FILEPERM_READ | FILEPERM_USER_WRITE | FILEPERM_GROUP_WRITE, // permissions suitable for group IO access
290  FILEPERM_DEFAULT_EXEC = FILEPERM_READ | FILEPERM_USER_WRITE | FILEPERM_GROUP_WRITE | FILEPERM_EXEC // permissions suitable for all users to execute a file
291 };
292 
293 
294 // thread stuff
295 #ifndef WIN32
296 typedef void* FXThreadHandle; // handle to a thread
297 typedef void* FXThreadMutex; // handle to a mutex
298 typedef void* FXThreadCondition; // handle to a condition variable
299 typedef void* FXThreadSemaphore; // handle to a semaphore
300 typedef FXInputHandle* FXThreadEventHandle; // handle to a thread event object
301 #else
302 typedef HANDLE FXThreadHandle; // handle to a thread
303 typedef HANDLE FXThreadMutex; // handle to a mutex
304 typedef HANDLE FXThreadCondition; // handle to a condition variable
305 typedef HANDLE FXThreadSemaphore; // handle to a semaphore
306 typedef FXInputHandle FXThreadEventHandle; // handle to a thread event object
307 #endif
308 
309 
310 // dynamic library loading
311 #ifndef WIN32
312 typedef void* FXDLLHandle; // handle to a dynamically loaded file
313 #else
314 typedef HMODULE FXDLLHandle; // handle to a dynamically loaded file
315 #endif
316 
317 
318 // database interface handle
319 //typedef void* FXDatabaseHandle; // handle to a database connection
320 
321 
322 namespace FXUtils {
323 
325 
327 extern FXAPI const FXuchar fxexversion[3];
328 
329 
331 
333 #ifdef WIN32
334 static void get_time_now(unsigned long* abs_sec, unsigned long* abs_nsec);
335 static DWORD get_timeout(unsigned long secs, unsigned long nsecs, DWORD default_to);
336 #else
337 void convert_timeval(struct timeval* tv, FXuint ms);
338 void convert_timespec(struct timespec* ts, FXuint ms);
339 #endif
340 
341 } // namespace FXUtils
342 } // namespace FXEX
343 
344 #endif // FXEXDEFS_H
345 
void * FXThreadMutex
Definition: fxexdefs.h:297
void * FXThreadCondition
Definition: fxexdefs.h:298
void * FXDLLHandle
Definition: fxexdefs.h:312
void * FXThreadSemaphore
Definition: fxexdefs.h:299
FXInputHandle * FXThreadEventHandle
Definition: fxexdefs.h:300
FXSocketType
Socket types.
Definition: fxexdefs.h:231
void convert_timeval(struct timeval *tv, FXuint ms)
time conversion routines
FXFilePermission
Definition: fxexdefs.h:270
FXSocketFamily
Socket families.
Definition: fxexdefs.h:240
FXint FXIOState
IO state definitions.
Definition: fxexdefs.h:211
FXAPI const FXuchar fxexversion[3]
Version number that the library version is compiled with.
FXint FXIOStatus
IO status definitions.
Definition: fxexdefs.h:189
void convert_timespec(struct timespec *ts, FXuint ms)
void * FXThreadHandle
Definition: fxexdefs.h:296