os_wrapper.hh

Go to the documentation of this file.
00001 /*
00002 ** TowBowlTactics, an adaptation of the tabletop game Blood Bowl.
00003 ** 
00004 ** Copyright (C) 2006 The TBT Team.
00005 ** 
00006 ** This program is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU General Public License
00008 ** as published by the Free Software Foundation; either version 2
00009 ** of the License, or (at your option) any later version.
00010 ** 
00011 ** The complete GNU General Public Licence Notice can be found as the
00012 ** `NOTICE' file in the root directory.
00013 ** 
00014 ** The TBT Team consists of people listed in the `AUTHORS' file.
00015 */
00016 
00017 #ifndef OS_WRAPPER_HH_
00018 # define OS_WRAPPER_HH_
00019 
00030 
00031 
00032 
00033 # include <cstdarg>
00034 
00035 //=====================================================================
00036 // WIN32
00037 //=====================================================================
00038 # ifdef WIN32
00039 
00040 #  define NOMINMAX
00041 #  include <WinSock2.h>
00042 
00043 // === Common functions
00044 #  define MAX_PATH PATH_MAX
00045 inline char* realpath(const char* pathname, char resolved_path[PATH_MAX])
00046 {
00047   // FIXME: does nothing.
00048   strcpy(resolved_path, pathname);
00049   return resolved_path;
00050 }
00051 
00052 inline void sleep(int time)
00053 {
00054   Sleep(time);
00055 }
00056 
00057 #  define min(A, B) _cpp_min(A, B)
00058 #  define max(A, B) _cpp_max(A, B)
00059 
00060 
00061 // === Sockets
00062 
00063 typedef int socklen_t;
00064 # define POLLIN 0x0001
00065 struct pollfd {
00066     int fd;
00067     short events;
00068     short revents;
00069 };
00070 // poll() doesn't exists on win32. Wrap using select.
00071 int poll(struct pollfd* pollfds, int nfds, int timeout);
00072 
00073 // === Threads
00074 #  include <process.h>
00075 typedef HANDLE pthread_t;
00076 typedef void* pthread_attr_t; // not used.
00077 typedef CRITICAL_SECTION pthread_mutex_t;
00078 typedef void* pthread_mutexattr_t; // not used.
00079 
00080 inline pthread_t pthread_self()
00081 {
00082   return (pthread_t)GetCurrentThreadId();
00083 }
00084 
00085 inline int pthread_create(pthread_t* thread, 
00086                           pthread_attr_t* attr, 
00087                           void* (*start_routine)(void *), void* arg)
00088 {
00089   if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine,
00090                    arg, 0, NULL) == NULL)
00091     return 1;
00092   return 0;
00093 }
00094 
00095 inline int pthread_join(pthread_t thread, void** value_ptr)
00096 {
00097   // FIXME: todo
00098   return 0;
00099 }
00100 
00101 inline int pthread_mutex_init(pthread_mutex_t* mutex,
00102                               const pthread_mutexattr_t* mutexattr)
00103 {
00104   InitializeCriticalSection(mutex);
00105   return 0;
00106 }
00107 
00108 inline int pthread_mutex_lock(pthread_mutex_t* mutex)
00109 {
00110   EnterCriticalSection(mutex);
00111   return 0;
00112 }
00113 
00114 inline int pthread_mutex_unlock(pthread_mutex_t* mutex)
00115 {
00116   LeaveCriticalSection(mutex);
00117   return 0;
00118 }
00119 
00120 inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
00121 {
00122   DeleteCriticalSection(mutex);
00123   return 0;
00124 }
00125 
00126 // === <config.h> (not generated under windows).
00127 #  define PACKAGE_VERSION "0.7M1"
00128 
00129 //=====================================================================
00130 // NOT WIN32
00131 //=====================================================================
00132 # else
00133 
00134 // unistd.h doesn't exists on windows.
00135 #  include <unistd.h>
00136 #  include <sys/socket.h>
00137 #  include <sys/poll.h>
00138 #  include <sys/time.h>
00139 #  include <netinet/in.h>
00140 #  include <netinet/tcp.h>
00141 #  include <arpa/inet.h>
00142 #  include <netdb.h>
00143 #  define closesocket close
00144 
00145 #  include <pthread.h>
00146 
00147 #  include <config.h>
00148 
00149 # endif // !WIN32
00150 
00151 // hack for BSDs
00152 #ifndef MSG_NOSIGNAL
00153 # define MSG_NOSIGNAL 0
00154 #endif
00155 
00156 void initialize_socket();
00157 
00159 
00160 #endif /* !OS_WRAPPER_HH_ */

Generated on Sat Jun 23 16:07:23 2007 for Stechec/TBT by  doxygen 1.4.7