SUMO - Simulation of Urban MObility
|
00001 /******************************************************************************** 00002 * * 00003 * FOX extension library: Definitions, Types, and Macros * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************/ 00022 #ifndef FXEXDEFS_H 00023 #define FXEXDEFS_H 00024 00025 #ifdef _MSC_VER 00026 #include <windows_config.h> 00027 #else 00028 #include <config.h> 00029 #endif 00030 00031 #include <fx.h> 00032 00033 #ifdef WIN32 00034 #include <windows.h> 00035 #endif 00036 00037 // loads the FOX defs 00038 #ifndef FXDEFS_H 00039 #include <fxdefs.h> 00044 using namespace FX; 00045 #endif 00046 00047 // Disable warnings on extern before template instantiation for the Microsoft compiler. 00048 // see "HOWTO: Exporting STL Components Inside & Outside of a Class" on the microsoft website 00049 #if defined(WIN32) && defined(_MSC_VER) 00050 #pragma warning (disable : 4231) 00051 #endif 00052 00053 00054 // implement CALLBACK for unix 00055 #ifndef CALLBACK 00056 #define CALLBACK 00057 #endif 00058 00065 namespace FXEX { 00066 00067 // provide an extern mechanism 00068 #ifdef WIN32 00069 #ifdef FOXDLL 00070 #ifndef FOXDLL_EXPORTS 00071 #define FXEXTERN extern 00072 #endif 00073 #endif 00074 #endif 00075 00076 #ifndef FXEXTERN 00077 #define FXEXTERN 00078 #endif 00079 00080 00081 // Valid compression factors for Bzip and Gzip compression libraries 00082 #define COMPRESS_MAX 9 00083 #define COMPRESS_NORMAL 6 00084 #define COMPRESS_FAST 1 00085 #define COMPRESS_NONE 0 00086 00087 00088 // Win32 defines INFINITE to be -1, we might as well do it too. 00089 #ifndef WIN32 00090 # define INFINITE (-1) 00091 #endif 00092 00093 00094 // determine the newline charater(s) 00095 #ifdef WIN32 00096 #define FXNEWLINE "\r\n" 00097 #endif 00098 #ifdef MAC 00099 #define FXNEWLINE "\r" 00100 #endif 00101 #ifndef FXNEWLINE 00102 #define FXNEWLINE "\n" 00103 #endif 00104 00105 00106 // make a short from two chars 00107 #define MKUSHORT(l,h) ((((FX::FXuchar)(l))&0xff) | (((FX::FXuchar)(h))<<8)) 00108 00109 /* !!!! 00110 // Make a long from two ints - provided longs are twice the size of an int 00111 #ifdef FX_LONG 00112 # define MKULONG(l,h) ((((FX::FXuint)(l))&0xffffffff) | (((FX::FXuint)(h))<<32)) 00113 #else 00114 # if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 00115 # error "You wanted 64bit file sizes (actually 63), but I couldn't make it so..." 00116 # endif 00117 #endif 00118 !!!! */ 00119 00124 #define FXDeclare(Class) \ 00125 FXDECLARE(Class) 00126 #define FXDeclareAbstract(Class) \ 00127 FXDECLARE_ABSTRACT(Class) 00128 #define FXDefMap(Class) \ 00129 FXDEFMAP(Class) Class##Map[] 00130 #define FXImplementAbstract(Class,Parent) \ 00131 FXIMPLEMENT_ABSTRACT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map)) 00132 #define FXImplement(Class,Parent) \ 00133 FXIMPLEMENT(Class,Parent,Class##Map,ARRAYNUMBER(Class##Map)) 00134 #define FXFuncDecl(Func) \ 00135 long on##Func (FXObject*,FXSelector,void*) 00136 #define FXFuncImpl(Class,Func,tgt,sel,ptr) \ 00137 long Class::on##Func (FXOject *tgt,FXSelector sel, void *ptr) 00138 #define FXMapTypes(Class,FromType,ToType,Func) \ 00139 FXMAPTYPES(SEL_##FromType,SEL_##ToType,Class::on##Func) 00140 #define FXMapType(Class,SelType,Func) \ 00141 FXMAPTYPE(SEL_##SelType,Class::on##Func) 00142 #define FXMapFuncs(Class,SelType,FromId,ToId,Func) \ 00143 FXMAPFUNCS(SEL_##SelType,Class::ID_##FromId,Class::ID_##ToId,Class::on#Func) 00144 #define FXMapFunc(Class,SelType,Id,Func) \ 00145 FXMAPFUNC(SEL_##SelType,Class::ID_##Id,Class::on##Func) 00146 00147 00149 #define FXSEND(tgt,sel,msg,ptr) \ 00150 (tgt->handle(this,FXSEL(sel,msg),ptr) 00151 #define FXROUTE(src,tgt,sel,msg,ptr) \ 00152 (tgt->handle(src,FXSEL(sel,msg),ptr) 00153 00154 00155 // debugging macros 00156 #ifndef NDEBUG 00157 # define FXCTOR() fxtrace (100,"%s::%s %p\n",getClassName(),getClassName(),this) 00158 # define FXMETHOD(methodname) fxtrace (100,"%s::%s %p\n",getClassName(),#methodname,this) 00159 # define FXDTOR() fxtrace (100,"%s::~%s %p\n",getClassName(),getClassName(),this) 00160 #else 00161 # define FXCTOR() 00162 # define FXMETHOD(methodname) 00163 # define FXDTOR() 00164 #endif 00165 00166 00167 // New selector types 00168 enum { 00169 SEL_DATA = FX::SEL_LAST, // form of data as an event 00170 SEL_THREAD, // thread/runnable events 00171 SEL_WAITABLE_WAIT, // waitable event such as a Condition variable, semaphore, etc 00172 SEL_WAITABLE_ACTIVATE, // waitable event such as a Condition variable, semaphore, etc 00173 SEL_INTERLOCK, // interlocked event; object went into lock 00174 SEL_BARRIER_LOCK, // barrier event; thread waiting in barrier lock 00175 SEL_BARRIER_UNLOCK, // barrier event; barrier object reset, threads released 00176 SEL_INPUT, // some type of input event 00177 SEL_OUTPUT, // some type of output event 00178 SEL_ERROR, // some type of error event 00179 SEL_IO, // Some form of IO 00180 SEL_IO_CONNECT, // Connection event 00181 SEL_EVENT, // a generic event 00182 SEL_BEGIN, // en event defining some begining 00183 SEL_END, // an event defining some ending 00184 SEL_TAG, // tag event 00185 SEL_CONTENT, // content event 00186 SEL_REGISTRY, // a registry event (TODO I have a plan for this...) 00187 SEL_LASTEX,// Last message 00188 SEL_THREAD_EVENT 00189 }; 00190 00191 00193 typedef FXint FXIOStatus; 00194 enum { 00195 FXIOStatusUnknown = -2, 00196 FXIOStatusError = -1, 00197 FXIOStatusOk = 0, 00198 FXIOStatusOK = 0, 00199 FXIOStatusLast 00200 }; 00201 #ifndef INVALID_HANDLE 00202 # ifdef WIN32 00203 # define INVALID_HANDLE INVALID_HANDLE_VALUE 00204 # else 00205 # define INVALID_HANDLE -1 00206 # endif 00207 #endif 00208 00209 #ifndef VALID_RESULT 00210 # define VALID_RESULT 0 00211 #endif 00212 00213 00215 typedef FXint FXIOState; 00216 enum { 00217 FXIOStateUnknown = -1, 00218 FXIOStateNone = -1, 00219 FXIOStateOk = 0, 00220 FXIOStateOK = 0, 00221 FXIOStateUnconnected, 00222 FXIOStateConnected, 00223 FXIOStateOpen = FXIOStateConnected, 00224 FXIOStateListener, 00225 FXIOStateAccepted, 00226 FXIOStateDuplicated, 00227 FXIOStateLast 00228 }; 00229 00230 00234 00235 enum FXSocketType { 00236 FXSocketTypeNone = 0, // unknown socket type 00237 FXSocketTypeStream, // TCP socket 00238 FXSocketTypeTCP = FXSocketTypeStream, // TCP socket 00239 FXSocketTypeDatagram, // UDP socket 00240 FXSocketTypeUDP = FXSocketTypeDatagram // UDP socket 00241 }; 00242 00244 enum FXSocketFamily { 00245 FXSocketFamilyNone = 0, // unknown socket family 00246 FXSocketFamilyLocal, // Local domain socket (on nearly every system, same as Unix domain) 00247 FXSocketFamilyInet, // Internet domain socket, version 4 (ie the default internet family) 00248 FXSocketFamilyInet6, // Internet domain socket, version 6 00249 FXSocketFamilyAutomatic, // automatically choose UNIX domain (local) socket, when connecting 00250 // to localhost, internet domain for internet sockets 00251 FXSocketFamilyUnix = FXSocketFamilyLocal 00252 }; 00253 00254 00274 enum FXFilePermission { 00275 FILEPERM_NONE = 0, // file has no permissions 00276 FILEPERM_USER_READ = 0x00000001, // user can read from file 00277 FILEPERM_USER_WRITE = 0x00000002, // user can write to file 00278 FILEPERM_USER_EXEC = 0X00000004, // user can execute file 00279 FILEPERM_GROUP_READ = 0x00000010, // group can read from file 00280 FILEPERM_GROUP_WRITE = 0x00000020, // group can write to file 00281 FILEPERM_GROUP_EXEC = 0x00000040, // group can execute the file 00282 FILEPERM_OTHER_READ = 0x00000100, // everybody can read from file 00283 FILEPERM_OTHER_WRITE = 0x00000200, // everybody can write to file 00284 FILEPERM_OTHER_EXEC = 0x00000400, // everybody can execute the file 00285 FILEPERM_READ = 0x00000111, // file read mask; set all read permissions 00286 FILEPERM_WRITE = 0x00000222, // file write mask; set all write permissions 00287 FILEPERM_EXEC = 0x00000444, // file execute mask; set all execute permissions 00288 FILEPERM_ALL = 0x00000777, // permissions mask; set all permissions 00289 FILEPERM_SET_UID = 0x00001000, // set the UID permission 00290 FILEPERM_SET_GID = 0x00002000, // set the GID permisssion 00291 FILEPERM_STICKY = 0x00004000, // set the STICKY permission 00292 FILEPERM_SECURE_IO = FILEPERM_USER_READ | FILEPERM_USER_WRITE, // permissions suitable for single user IO access 00293 FILEPERM_DEFAULT_IO = FILEPERM_READ | FILEPERM_USER_WRITE | FILEPERM_GROUP_WRITE, // permissions suitable for group IO access 00294 FILEPERM_DEFAULT_EXEC = FILEPERM_READ | FILEPERM_USER_WRITE | FILEPERM_GROUP_WRITE | FILEPERM_EXEC // permissions suitable for all users to execute a file 00295 }; 00296 00297 00298 // thread stuff 00299 #ifndef WIN32 00300 typedef void* FXThreadHandle; // handle to a thread 00301 typedef void* FXThreadMutex; // handle to a mutex 00302 typedef void* FXThreadCondition; // handle to a condition variable 00303 typedef void* FXThreadSemaphore; // handle to a semaphore 00304 typedef FXInputHandle* FXThreadEventHandle; // handle to a thread event object 00305 #else 00306 #include <windows.h> 00307 typedef HANDLE FXThreadHandle; // handle to a thread 00308 typedef HANDLE FXThreadMutex; // handle to a mutex 00309 typedef HANDLE FXThreadCondition; // handle to a condition variable 00310 typedef HANDLE FXThreadSemaphore; // handle to a semaphore 00311 typedef FXInputHandle FXThreadEventHandle; // handle to a thread event object 00312 #endif 00313 00314 00315 // dynamic library loading 00316 #ifndef WIN32 00317 typedef void* FXDLLHandle; // handle to a dynamically loaded file 00318 #else 00319 typedef HMODULE FXDLLHandle; // handle to a dynamically loaded file 00320 #endif 00321 00322 00323 // database interface handle 00324 //typedef void* FXDatabaseHandle; // handle to a database connection 00325 00326 00327 namespace FXUtils { 00328 00330 00332 extern FXAPI const FXuchar fxexversion[3]; 00333 00334 00336 00338 #ifdef WIN32 00339 static void get_time_now(unsigned long* abs_sec, unsigned long* abs_nsec); 00340 static DWORD get_timeout(unsigned long secs, unsigned long nsecs, DWORD default_to); 00341 #else 00342 void convert_timeval(struct timeval* tv, FXuint ms); 00343 void convert_timespec(struct timespec* ts, FXuint ms); 00344 #endif 00345 00346 } // namespace FXUtils 00347 } // namespace FXEX 00348 00349 #endif // FXEXDEFS_H 00350