From: Gunnar Beutner Date: Mon, 2 Apr 2012 08:26:38 +0000 (+0200) Subject: Moved platform-specific code into separate files. X-Git-Tag: v0.0.1~664 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55efd625a39bbfcba0db73afa177e002f1079617;p=icinga2 Moved platform-specific code into separate files. --- diff --git a/base/Makefile.am b/base/Makefile.am index a8a970e99..77758017c 100644 --- a/base/Makefile.am +++ b/base/Makefile.am @@ -38,5 +38,7 @@ libbase_a_SOURCES = \ thread.h \ timer.cpp \ timer.h \ + unix.cpp \ unix.h \ + win32.cpp \ win32.h diff --git a/base/base.vcxproj b/base/base.vcxproj index 943a18abb..1f4e82545 100644 --- a/base/base.vcxproj +++ b/base/base.vcxproj @@ -26,6 +26,7 @@ + diff --git a/base/i2-base.h b/base/i2-base.h index 9ecd733d3..47fae22e3 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -36,10 +36,10 @@ using namespace std::tr1::placeholders; #define PLATFORM_UNIX 2 #ifdef _WIN32 -# define I2_PLATFORM Platform_Windows +# define I2_PLATFORM PLATFORM_WINDOWS # include "win32.h" #else -# define I2_PLATFORM Platform_Unix +# define I2_PLATFORM PLATFORM_UNIX # include "unix.h" #endif diff --git a/base/thread.cpp b/base/thread.cpp index 32ef5069d..bbf04c5ea 100644 --- a/base/thread.cpp +++ b/base/thread.cpp @@ -66,4 +66,4 @@ void thread::join(void) #else /* _WIN32 */ pthread_join(m_Thread, NULL); #endif -} \ No newline at end of file +} diff --git a/base/unix.cpp b/base/unix.cpp new file mode 100644 index 000000000..4cdf87edc --- /dev/null +++ b/base/unix.cpp @@ -0,0 +1,43 @@ +#include "i2-base.h" + +#if I2_PLATFORM == PLATFORM_UNIX +#include + +using namespace icinga; + +void Sleep(unsigned long milliseconds) +{ + usleep(milliseconds * 1000); +} + +inline void closesocket(SOCKET fd) +{ + close(fd); +} + +inline HMODULE LoadLibrary(const char *filename) +{ + lt_dlhandle handle = 0; + lt_dladvise advise; + + if (!lt_dladvise_init(&advise) && !lt_dladvise_global(&advise)) { + handle = lt_dlopenadvise(filename, advise); + } + + lt_dladvise_destroy(&advise); + + return handle; +} + +inline void FreeLibrary(HMODULE module) +{ + if (module) + lt_dlclose(module); +} + +inline void *GetProcAddress(HMODULE module, const char *function) +{ + return lt_dlsym(module, function); +} + +#endif /* I2_PLATFORM == PLATFORM_UNIX */ diff --git a/base/unix.h b/base/unix.h index a2bda9804..327fcdd57 100644 --- a/base/unix.h +++ b/base/unix.h @@ -1,8 +1,6 @@ #ifndef UNIX_H #define UNIX_H -#include -#include #include #include #include @@ -13,19 +11,11 @@ #include #include -typedef int SOCKET; +void Sleep(unsigned long milliseconds); +typedef int SOCKET; #define INVALID_SOCKET (-1) - -inline void Sleep(unsigned long milliseconds) -{ - usleep(milliseconds * 1000); -} - -inline void closesocket(int fd) -{ - close(fd); -} +void closesocket(SOCKET fd); #define ioctlsocket ioctl @@ -33,33 +23,12 @@ inline void closesocket(int fd) #define I2_EXPORT #define I2_IMPORT -typedef lt_dlhandle HMODULE; +typedef void *HMODULE; #define INVALID_HANDLE_VALUE NULL -inline HMODULE LoadLibrary(const char *filename) -{ - lt_dlhandle handle = 0; - lt_dladvise advise; - - if (!lt_dladvise_init(&advise) && !lt_dladvise_global(&advise)) { - handle = lt_dlopenadvise(filename, advise); - } - - lt_dladvise_destroy(&advise); - - return handle; -} - -inline void FreeLibrary(HMODULE module) -{ - if (module) - lt_dlclose(module); -} - -inline void *GetProcAddress(HMODULE module, const char *function) -{ - return lt_dlsym(module, function); -} +HMODULE LoadLibrary(const char *filename); +void FreeLibrary(HMODULE module); +void *GetProcAddress(HMODULE module, const char *function); #endif /* UNIX_H */ diff --git a/base/win32.cpp b/base/win32.cpp new file mode 100644 index 000000000..c5fbda37b --- /dev/null +++ b/base/win32.cpp @@ -0,0 +1,9 @@ +#include "i2-base.h" + +#if I2_PLATFORM == PLATFORM_WINDOWS + +using namespace icinga; + +/* nothing here (yet) */ + +#endif /* I2_PLATFORM == PLATFORM_WINDOWS */