Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

defs.h

Go to the documentation of this file.
00001 #ifndef _defs_h_
00002 #define _defs_h_
00003 
00004 
00005 // slave/master/client default constants
00006 #define SLAVE_PORT      9001
00007 
00008 #define CLIENT_PORT     9001
00009 
00010 #define MASTER_HOST     "localhost"
00011 #define MASTER_PORT     9000
00012 
00013 // data sharing web server TCP/IP port
00014 #define SLAVE_HTTP_PORT       9001
00015 #define MASTER_HTTP_PORT      9000
00016 
00017 // need them in Win32 for creating/using dlls
00018 #define DLL_EXPORT 1
00019 #define DLL_IMPORT 2
00020 
00021 // need them for UDP communication
00022 #define UDP_MAXSIZE      65000  // max of 64k for a udp packet
00023 #define UDP_SEND_TIMEOUT     1  // confirm timeout for udp (sec)
00024 #define UDP_SEND_COUNT       5  // if no confirm, resend 
00025 
00026 // some common used types
00027 typedef unsigned char uchar;
00028 typedef unsigned int  uint;
00029 #define SZ_UCHAR sizeof (uchar)
00030 #define SZ_UINT  sizeof (uint)
00031 #define SZ_PTR   sizeof (void *)
00032 
00033 
00034 // upload/download function (both return 0 if error, non-zero otherwise)
00035 int getURL (const char *url, const char *file, char *err = 0);
00036 int postURL (const char *url, const char *file, ...);
00037 #ifdef HAVE_CURL
00038 #include <curl/curl.h>
00039 #define MAXERR_URL CURL_ERROR_SIZE
00040 #else
00041 #define MAXERR_URL 1024
00042 #endif
00043 
00044 // read the password from the console
00045 void read_passwd(char *pswd, int maxlen);
00046 
00047 
00048 #if defined(__cplusplus) && defined(__GNUC__)
00049 #define max(a, b)       ((a) >? (b))
00050 #define min(a, b)       ((a) <? (b))
00051 #elif !defined(max)
00052 #define max(a, b)       ((a) > (b) ? (a) : (b))
00053 #define min(a, b)       ((a) < (b) ? (a) : (b))
00054 #endif
00055 
00056 // if we use or not debug functions
00057 #include "dbug.h"
00058 
00059 // win32 specific or not
00060 #ifdef _WIN32
00061 
00062 #include <windows.h>
00063 #include <io.h>
00064 #include <sys/stat.h>
00065 #include <direct.h>
00066 
00067 #ifdef SLV_EXPORTS
00068 #define SLV_API __declspec(dllexport)
00069 #else
00070 #define SLV_API __declspec(dllimport)
00071 #endif
00072 
00073 #define SLV_SERV_LIB "slv_serv.dll"
00074 
00075 #if (COM_EXPORTS == DLL_EXPORT)
00076 #define COM_API __declspec(dllexport)
00077 #elif (COM_EXPORTS == DLL_IMPORT)
00078 #define COM_API __declspec(dllimport)
00079 #else
00080 #define COM_API
00081 #endif
00082 
00083 // macros for shared libraries
00084 #define LIB_HANDLE       HMODULE
00085 #define LIB_ERROR()      GetLastError ()
00086 #define LIB_SYMBOL(h,s)  GetProcAddress (h, s) 
00087 #define LIB_LOAD(l)      LoadLibrary (l)
00088 #define LIB_UNLOAD(h)    FreeLibrary (h)
00089 
00090 // macros for threads
00091 #define THRD_RETURN      DWORD WINAPI
00092 #define THRD_ARG         LPVOID
00093 typedef LPTHREAD_START_ROUTINE THRD_START;
00094 #define THRD_HANDLE      HANDLE
00095 #define THRD_KILL(x)     
00096 //TODO #define THRD_KILL(x)     StopThread (x);
00097 
00098 // macros for files
00099 #define FILE_OPEN    _open
00100 #define FILE_CLOSE   _close
00101 #define FILE_UNLINK  _unlink
00102 #define FILE_RENAME  rename
00103 #define FILE_READ    _read
00104 #define FILE_WRITE   _write
00105 #define DIR_GETCWD   _getcwd
00106 #define DIR_MKDIR(d) _mkdir(d)
00107 #define DIR_CHDIR    _chdir
00108 #define DIR_RMDIR    _rmdir
00109 
00110 // macros for sleep()
00111 #define SLEEP_SEC(t)     Sleep (t*1000)
00112 #define SLEEP_MSEC(t)    Sleep (t)
00113 
00114 // error codes
00115 #define SOCK_ERRNO       WSAGetLastError ()
00116 
00117 #else  // not _WIN32
00118 
00119 #include <dlfcn.h> 
00120 #include <unistd.h> 
00121 #include <time.h>   //nanosleep
00122 
00123 #define SLV_API
00124 #define SLV_SERV_LIB "./slv_serv.so"
00125 
00126 #define COM_API
00127 
00128 // macros for shared libraries
00129 #define LIB_HANDLE       void*
00130 #define LIB_ERROR()      dlerror ()
00131 #define LIB_SYMBOL(h,s)  dlsym (h, s) 
00132 #define LIB_LOAD(l)      dlopen (l, RTLD_NOW)  // RTLD_LAZY
00133 #define LIB_UNLOAD(h)    dlclose (h)
00134 
00135 // macros for threads
00136 #define THRD_RETURN      void*
00137 #define THRD_ARG         void*
00138 typedef void * (*THRD_START)(void *);
00139 #define THRD_HANDLE      pthread_t
00140 #if defined(HAVE_OS_Darwin)
00141 #define THRD_KILL(x)     ;
00142 #else
00143 #define THRD_KILL(x)     pthread_kill(x, SIGALRM);
00144 #endif
00145 
00146 // macros for files
00147 #define FILE_OPEN    open
00148 #define FILE_CLOSE   close
00149 #define FILE_UNLINK  unlink
00150 #define FILE_RENAME  rename
00151 #define FILE_READ    read
00152 #define FILE_WRITE   write
00153 #define DIR_GETCWD   getcwd
00154 #define DIR_MKDIR(d) mkdir(d, S_IRUSR|S_IWUSR|S_IXUSR)
00155 #define DIR_CHDIR    chdir
00156 #define DIR_RMDIR    rmdir
00157 
00158 #if defined(HAVE_OS_Darwin)
00159 
00160 // macros for sleep()
00161 #define SLEEP_SEC(t) \
00162    { \
00163      usleep (t * 1000 * 1000); \
00164    }
00165 #define SLEEP_MSEC(t) \
00166    { \
00167      usleep (t); \
00168    }
00169 
00170 #else
00171 
00172 // macros for sleep()
00173 #define SLEEP_SEC(t) \
00174    { \
00175      struct timespec ts, tr; \
00176      ts.tv_sec  = t; \
00177      ts.tv_nsec = 0; \
00178      nanosleep (&ts, &tr); \
00179    }
00180 #define SLEEP_MSEC(t) \
00181    { \
00182      struct timespec ts, tr; \
00183      ts.tv_sec  = t / 1000; \
00184      ts.tv_nsec = 1000 * 1000 * (t % 1000); \
00185      nanosleep (&ts, &tr); \
00186    }
00187 
00188 #endif
00189 
00190 
00191 // error codes
00192 #define SOCK_ERRNO       errno
00193 
00194 #endif  // _WIN32
00195 
00196 //extracts the pointer to the char just behind the last '/' char in string s
00197 //and assignes this pointer to result.
00198 //const char *s, char *result
00199 #define EXTRACT_FILENAME(s,result) \
00200 {\
00201     const char *_E_F_p, *_E_F_q = s; \
00202     while ((_E_F_p = strchr(_E_F_q, '/'))) _E_F_q = _E_F_p + 1; \
00203     result = _E_F_q; \
00204 }
00205 
00206 #endif  // _defs_h_
00207 
00208 

Generated on Mon Nov 25 12:46:28 2002 for qadpz by doxygen1.2.18