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