50 #ifndef SystemCompat_H_
51 #define SystemCompat_H_
57 #if ENABLE_MEM_LEAK_DETECTION
58 #ifndef _CRTDBG_MAP_ALLOC
59 #define _CRTDBG_MAP_ALLOC
60 #endif //_CRTDBG_MAP_ALLOC
62 #define _ATL_DISABLE_NOTHROW_NEW
65 #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
71 #endif //ENABLE_MEM_LEAK_DETECTION
89 #define isnan(x) ((x) != (x))
93 #define snprintf sprintf_s
96 #include <sys/timeb.h>
97 #include <sys/types.h>
103 #include <winsock2.h>
105 #include <Ws2tcpip.h>
107 #pragma comment(lib,"ws2_32.lib")
110 #define COMP_API __declspec(dllexport)
112 #define COMP_API __declspec(dllimport)
115 #else // For Linux and Mac OS Snow Leopard (10.6)
116 #if (defined __APPLE__ || defined HAVE_MACH_SL_H ) // For Mac OS Snow Leopard (10.6)
117 #include <mach/mach.h>
118 #include <mach/mach_host.h>
119 #include <mach/mach_types.h>
120 #include <mach/vm_statistics.h>
121 #include <sys/sysctl.h>
122 #include <sys/types.h>
123 #elif (HAVE_SYS_SYSINFO_H) // For Linux only
124 #include <sys/sysinfo.h>
127 #if (defined HAVE_SYS_SOCKET_H || defined HAVE_IF_H)
138 #include <sys/param.h>
140 #include <sys/resource.h>
142 #include <sys/utsname.h>
144 #include <sys/types.h>
145 #include <sys/stat.h>
146 #include <sys/ioctl.h>
147 #include <sys/time.h>
148 #include <netinet/in.h>
149 #include <arpa/inet.h>
152 #ifdef HAVE_SYS_SOCKET_H
153 #include <sys/socket.h>
164 #include "util/functions.h"
165 using namespace ::br::pucrio::telemidia::util;
174 #define INT64_C(c) (c ## LL)
178 #define UINT64_C(c) (c ## ULL)
182 #define __INT64_C int64_t
189 #if defined(_WIN32) && !defined(__MINGW32__)
192 static const int CLOCK_REALTIME = 0;
193 static const int CLOCK_MONOTONIC = 1;
194 static const int CLOCK_PROCESS_CPUTIME_ID = 2;
195 static const int CLOCK_THREAD_CPUTIME_ID = 3;
197 #define DELTA_EPOCH_IN_SEC INT64_C(11644473600)
198 #define DELTA_EPOCH_IN_USEC INT64_C(11644473600000000)
199 #define DELTA_EPOCH_IN_100NS INT64_C(116444736000000000)
200 #define DELTA_EPOCH_IN_NS INT64_C(11644473600000000000)
202 #define POW10_2 INT64_C(100)
203 #define POW10_3 INT64_C(1000)
204 #define POW10_4 INT64_C(10000)
205 #define POW10_6 INT64_C(1000000)
206 #define POW10_7 INT64_C(10000000)
207 #define POW10_9 INT64_C(1000000000)
216 typedef HANDLE PipeDescriptor;
219 typedef int PipeDescriptor;
242 namespace telemidia {
249 static string filesPref;
250 static string ctxFilesPref;
251 static string installPref;
252 static string userCurrentPath;
253 static string gingaCurrentPath;
257 static string gingaPrefix;
258 static bool initialized;
259 static void* cmInstance;
261 static void checkValues();
262 static void initializeGingaPrefix();
263 static void initializeGingaPath();
264 static void initializeUserCurrentPath();
265 static void initializeGingaConfigFile();
267 static void sigpipeHandler(
int x)
throw(
const char*);
273 static string getGingaPrefix();
274 static string updatePath(
string dir);
275 static string updatePath(
string dir,
string separator);
276 static bool isXmlStr(
string location);
277 static bool checkUriPrefix(
string uri);
278 static bool isAbsolutePath(
string path);
280 static string getIUriD();
281 static string getFUriD();
283 static string getPath(
string filename);
284 static string convertRelativePath(
string relPath);
286 static string getGingaBinPath();
287 static string getUserCurrentPath();
293 static void setGingaContextPrefix(
string newBaseDir);
298 static string getGingaContextPrefix();
304 static string appendGingaFilesPrefix(
string relUrl);
310 static string appendGingaInstallPrefix(
string relUrl);
316 static void* getComponentManagerInstance();
317 static void setComponentManagerInstance(
void* cmInstance);
319 static string appendLibExt(
string libName);
321 static void* loadComponent(
322 string libName,
void** llib,
string symName);
324 static bool releaseComponent(
void* component);
329 static void initializeSigpipeHandler();
335 static string getOperatingSystem();
336 static float getClockSpeed();
337 static float getMemorySize();
343 static void strError (
int err,
char *buf,
size_t size);
344 static int changeDir (
const char *path);
345 static void makeDir(
const char* dirName,
unsigned int mode);
346 static void uSleep(
unsigned int microseconds);
347 static string getTemporaryDir();
349 static void gingaProcessExit(
short status);
351 static const short LOG_NULL = 0;
352 static const short LOG_STDO = 1;
353 static const short LOG_FILE = 2;
354 static void setLogTo(
short logType,
string sufix=
"");
359 static int gettimeofday(
struct timeval *tv,
struct timezone *tz);
360 static int getUserClock(
struct timeval* usrClk);
361 static int clockGetTime(
int clockType,
struct timespec* tv);
367 static int rint (
double x);
373 static string checkPipeName(
string pipeName);
376 static void checkPipeDescriptor(PipeDescriptor pd);
379 static bool createPipe(
string pipeName, PipeDescriptor* pd);
380 static bool openPipe(
string pipeName, PipeDescriptor* pd);
381 static void closePipe(PipeDescriptor pd);
382 static int readPipe(PipeDescriptor pd,
char* buffer,
int buffSize);
383 static int writePipe(PipeDescriptor pd,
char* data,
int dataSize);
388 static int zip_directory(
const string &zipfile_path,
const string &directory_path,
const string &iUriD);
389 static int zipwalker(
void* zipfile,
string initdir,
string dirpath,
string iUriD);
390 static int unzip_file(
const char *zipname,
const char *filedir);
391 static bool getZipError(
struct zip* file,
string* strError);
396 static bool initMemCheck();
397 static void memCheckPoint();
398 static bool finishMemCheck();
Definition: SystemCompat.h:247