mirror of https://github.com/Icinga/icinga2.git
Moved platform-specific code into separate files.
This commit is contained in:
parent
1b6bfb9db5
commit
55efd625a3
|
@ -38,5 +38,7 @@ libbase_a_SOURCES = \
|
|||
thread.h \
|
||||
timer.cpp \
|
||||
timer.h \
|
||||
unix.cpp \
|
||||
unix.h \
|
||||
win32.cpp \
|
||||
win32.h
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -66,4 +66,4 @@ void thread::join(void)
|
|||
#else /* _WIN32 */
|
||||
pthread_join(m_Thread, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
45
base/unix.h
45
base/unix.h
|
@ -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>
|
||||
|
@ -13,19 +11,11 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
|
||||
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 */
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#include "i2-base.h"
|
||||
|
||||
#if I2_PLATFORM == PLATFORM_WINDOWS
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
/* nothing here (yet) */
|
||||
|
||||
#endif /* I2_PLATFORM == PLATFORM_WINDOWS */
|
Loading…
Reference in New Issue