]> granicus.if.org Git - icinga2/commitdiff
Moved platform-specific code into separate files.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 2 Apr 2012 08:26:38 +0000 (10:26 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 2 Apr 2012 08:26:38 +0000 (10:26 +0200)
base/Makefile.am
base/base.vcxproj
base/i2-base.h
base/thread.cpp
base/unix.cpp [new file with mode: 0644]
base/unix.h
base/win32.cpp [new file with mode: 0644]

index a8a970e9945f1e3e85ee85ac8d24a4fe32ca24bc..77758017c0c49d8b735b9d6e31cf8e435be64efb 100644 (file)
@@ -38,5 +38,7 @@ libbase_a_SOURCES =  \
        thread.h \
        timer.cpp \
        timer.h \
+       unix.cpp \
        unix.h \
+       win32.cpp \
        win32.h
index 943a18abb2e1cc8ad88a4022609e199dfa6e76af..1f4e82545d96c14497f816ef77e24fcb77f60ec2 100644 (file)
@@ -26,6 +26,7 @@
     <ClCompile Include="tcpsocket.cpp" />
     <ClCompile Include="thread.cpp" />
     <ClCompile Include="timer.cpp" />
+    <ClCompile Include="unix.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="application.h" />
index 9ecd733d3ba41062d319e3bc19d59c5f0b8e3606..47fae22e30353e64e4805e03e710faae11db3370 100644 (file)
@@ -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
 
index 32ef5069d822b5c9f98bbcd5b840d9bfb5676ce4..bbf04c5ea8f0b4c8dc1a32623ae973b16f453e36 100644 (file)
@@ -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 (file)
index 0000000..4cdf87e
--- /dev/null
@@ -0,0 +1,43 @@
+#include "i2-base.h"
+
+#if I2_PLATFORM == PLATFORM_UNIX
+#include <ltdl.h>
+
+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 */
index a2bda9804767c9359410901a5c3113cb220ca3be..327fcdd577051f8035199d23dd8b00427d064111 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef UNIX_H
 #define UNIX_H
 
-#include <ltdl.h>
-#include <execinfo.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <arpa/inet.h>
 #include <pthread.h>
 
-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 (file)
index 0000000..c5fbda3
--- /dev/null
@@ -0,0 +1,9 @@
+#include "i2-base.h"
+
+#if I2_PLATFORM == PLATFORM_WINDOWS
+
+using namespace icinga;
+
+/* nothing here (yet) */
+
+#endif /* I2_PLATFORM == PLATFORM_WINDOWS */