mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
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 \
|
thread.h \
|
||||||
timer.cpp \
|
timer.cpp \
|
||||||
timer.h \
|
timer.h \
|
||||||
|
unix.cpp \
|
||||||
unix.h \
|
unix.h \
|
||||||
|
win32.cpp \
|
||||||
win32.h
|
win32.h
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
<ClCompile Include="tcpsocket.cpp" />
|
<ClCompile Include="tcpsocket.cpp" />
|
||||||
<ClCompile Include="thread.cpp" />
|
<ClCompile Include="thread.cpp" />
|
||||||
<ClCompile Include="timer.cpp" />
|
<ClCompile Include="timer.cpp" />
|
||||||
|
<ClCompile Include="unix.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="application.h" />
|
<ClInclude Include="application.h" />
|
||||||
|
@ -36,10 +36,10 @@ using namespace std::tr1::placeholders;
|
|||||||
#define PLATFORM_UNIX 2
|
#define PLATFORM_UNIX 2
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# define I2_PLATFORM Platform_Windows
|
# define I2_PLATFORM PLATFORM_WINDOWS
|
||||||
# include "win32.h"
|
# include "win32.h"
|
||||||
#else
|
#else
|
||||||
# define I2_PLATFORM Platform_Unix
|
# define I2_PLATFORM PLATFORM_UNIX
|
||||||
# include "unix.h"
|
# include "unix.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
43
base/unix.cpp
Normal file
43
base/unix.cpp
Normal file
@ -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
|
#ifndef UNIX_H
|
||||||
#define UNIX_H
|
#define UNIX_H
|
||||||
|
|
||||||
#include <ltdl.h>
|
|
||||||
#include <execinfo.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -13,19 +11,11 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
void Sleep(unsigned long milliseconds);
|
||||||
|
|
||||||
typedef int SOCKET;
|
typedef int SOCKET;
|
||||||
|
|
||||||
#define INVALID_SOCKET (-1)
|
#define INVALID_SOCKET (-1)
|
||||||
|
void closesocket(SOCKET fd);
|
||||||
inline void Sleep(unsigned long milliseconds)
|
|
||||||
{
|
|
||||||
usleep(milliseconds * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void closesocket(int fd)
|
|
||||||
{
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ioctlsocket ioctl
|
#define ioctlsocket ioctl
|
||||||
|
|
||||||
@ -33,33 +23,12 @@ inline void closesocket(int fd)
|
|||||||
#define I2_EXPORT
|
#define I2_EXPORT
|
||||||
#define I2_IMPORT
|
#define I2_IMPORT
|
||||||
|
|
||||||
typedef lt_dlhandle HMODULE;
|
typedef void *HMODULE;
|
||||||
|
|
||||||
#define INVALID_HANDLE_VALUE NULL
|
#define INVALID_HANDLE_VALUE NULL
|
||||||
|
|
||||||
inline HMODULE LoadLibrary(const char *filename)
|
HMODULE LoadLibrary(const char *filename);
|
||||||
{
|
void FreeLibrary(HMODULE module);
|
||||||
lt_dlhandle handle = 0;
|
void *GetProcAddress(HMODULE module, const char *function);
|
||||||
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 /* UNIX_H */
|
#endif /* UNIX_H */
|
||||||
|
9
base/win32.cpp
Normal file
9
base/win32.cpp
Normal file
@ -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…
x
Reference in New Issue
Block a user