Made build system more Windows-friendly

Implemented endpoint system for the discovery service
This commit is contained in:
Gunnar Beutner 2012-04-06 08:56:52 +02:00
parent 8e7787e315
commit 390a00e546
55 changed files with 591 additions and 310 deletions

View File

@ -3,6 +3,7 @@
SUBDIRS = ltdl \
base \
cJSON \
jsonrpc \
configfilecomponent \
configrpccomponent \

View File

@ -6,7 +6,7 @@
using namespace icinga;
Application::Ptr Application::Instance;
Application::Ptr I2_EXPORT Application::Instance;
Application::Application(void)
{
@ -371,3 +371,62 @@ void Application::SigIntHandler(int signum)
sigaction(SIGINT, &sa, NULL);
#endif /* _WIN32 */
}
static void application_sigint_handler(int signum)
{
Application::Instance->SigIntHandler(signum);
}
int application_main(int argc, char **argv, Application::Ptr instance)
{
int result;
Application::Instance = instance;
#ifndef _WIN32
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sigint_handler;
sigaction(SIGINT, &sa, NULL);
#endif /* _WIN32 */
vector<string> args;
for (int i = 0; i < argc; i++)
args.push_back(string(argv[i]));
Application::Instance->SetArguments(args);
if (Application::Instance->IsDebugging()) {
result = Application::Instance->Main(args);
} else {
try {
result = Application::Instance->Main(args);
} catch (const Exception& ex) {
cout << "---" << endl;
string klass = typeid(ex).name();
#ifdef HAVE_GCC_ABI_DEMANGLE
int status;
char *realname = abi::__cxa_demangle(klass.c_str(), 0, 0, &status);
if (realname != NULL) {
klass = string(realname);
free(realname);
}
#endif /* HAVE_GCC_ABI_DEMANGLE */
cout << "Exception: " << klass << endl;
cout << "Message: " << ex.GetMessage() << endl;
return EXIT_FAILURE;
}
}
Application::Instance.reset();
assert(Object::ActiveObjects == 0);
return result;
}

View File

@ -7,7 +7,7 @@ class Component;
DEFINE_EXCEPTION_CLASS(ComponentLoadException);
class Application : public Object {
class I2_BASE_API Application : public Object {
private:
bool m_ShuttingDown;
ConfigHive::Ptr m_ConfigHive;
@ -48,71 +48,14 @@ public:
void SigIntHandler(int signum);
};
inline void sigint_handler(int signum)
{
Application::Instance->SigIntHandler(signum);
}
template<class T>
int application_main(int argc, char **argv)
{
int result;
int I2_EXPORT application_main(int argc, char **argv, icinga::Application::Ptr instance);
Application::Instance = make_shared<T>();
#ifndef _WIN32
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sigint_handler;
sigaction(SIGINT, &sa, NULL);
#endif /* _WIN32 */
vector<string> args;
for (int i = 0; i < argc; i++)
args.push_back(string(argv[i]));
Application::Instance->SetArguments(args);
if (Application::Instance->IsDebugging()) {
result = Application::Instance->Main(args);
} else {
try {
result = Application::Instance->Main(args);
} catch (const Exception& ex) {
cout << "---" << endl;
string klass = typeid(ex).name();
#ifdef HAVE_GCC_ABI_DEMANGLE
int status;
char *realname = abi::__cxa_demangle(klass.c_str(), 0, 0, &status);
if (realname != NULL) {
klass = string(realname);
free(realname);
}
#endif /* HAVE_GCC_ABI_DEMANGLE */
cout << "Exception: " << klass << endl;
cout << "Message: " << ex.GetMessage() << endl;
return EXIT_FAILURE;
}
#define SET_START_CLASS(klass) \
int main(int argc, char **argv) { \
shared_ptr<klass> instance = make_shared<klass>(); \
return application_main(argc, argv, instance); \
}
Application::Instance.reset();
assert(Object::ActiveObjects == 0);
return result;
}
#define SET_START_CLASS(klass) \
int main(int argc, char **argv) { \
return application_main<klass>(argc, argv); \
}
}
#endif /* APPLICATION_H */

View File

@ -65,7 +65,7 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
@ -73,7 +73,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@ -92,11 +92,12 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDLL;I2_BASE_BUILD;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;imagehlp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>ws2_32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>ws2_32.lib;shlwapi.lib</AdditionalDependencies>
@ -110,13 +111,14 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WINDLL;I2_BASE_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>ws2_32.lib;imagehlp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>ws2_32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>ws2_32.lib;shlwapi.lib</AdditionalDependencies>

View File

@ -4,7 +4,7 @@
namespace icinga
{
class Component : public Object
class I2_BASE_API Component : public Object
{
private:
Application::WeakPtr m_Application;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class condvar
class I2_BASE_API condvar
{
private:
#ifdef _WIN32

View File

@ -6,7 +6,7 @@ namespace icinga
class ConfigHive;
class ConfigCollection : public Object
class I2_BASE_API ConfigCollection : public Object
{
private:
weak_ptr<ConfigHive> m_Hive;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class ConfigHive : public Object
class I2_BASE_API ConfigHive : public Object
{
public:
typedef shared_ptr<ConfigHive> Ptr;

View File

@ -8,7 +8,7 @@ namespace icinga
class ConfigHive;
struct ConfigObjectEventArgs : public EventArgs
struct I2_BASE_API ConfigObjectEventArgs : public EventArgs
{
typedef shared_ptr<ConfigObjectEventArgs> Ptr;
typedef weak_ptr<ConfigObjectEventArgs> WeakPtr;
@ -17,7 +17,7 @@ struct ConfigObjectEventArgs : public EventArgs
string OldValue;
};
class ConfigObject : public Object
class I2_BASE_API ConfigObject : public Object
{
private:
weak_ptr<ConfigHive> m_Hive;

View File

@ -4,7 +4,7 @@
namespace icinga
{
struct EventArgs : public Object
struct I2_BASE_API EventArgs : public Object
{
typedef shared_ptr<EventArgs> Ptr;
typedef weak_ptr<EventArgs> WeakPtr;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class Exception
class I2_BASE_API Exception
{
private:
string m_Message;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class FIFO : public Object
class I2_BASE_API FIFO : public Object
{
private:
char *m_Buffer;

View File

@ -3,6 +3,7 @@
#ifdef _MSC_VER
# define HAVE_CXX11
# pragma warning(disable:4251)
#else /* _MSC_VER */
# include "config.h"
#endif /* _MSC_VER */
@ -55,6 +56,12 @@ using namespace std::tr1::placeholders;
# include "unix.h"
#endif
#ifdef I2_BASE_BUILD
# define I2_BASE_API I2_EXPORT
#else /* I2_BASE_BUILD */
# define I2_BASE_API I2_IMPORT
#endif /* I2_BASE_BUILD */
#include "mutex.h"
#include "condvar.h"
#include "thread.h"

View File

@ -6,7 +6,7 @@ namespace icinga
DEFINE_EXCEPTION_CLASS(OutOfMemoryException);
class Memory
class I2_BASE_API Memory
{
private:
Memory(void);

View File

@ -4,7 +4,7 @@
namespace icinga
{
class mutex
class I2_BASE_API mutex
{
private:
#ifdef _WIN32

View File

@ -4,21 +4,20 @@
namespace icinga
{
class Object : public enable_shared_from_this<Object>
class I2_BASE_API Object : public enable_shared_from_this<Object>
{
private:
Object(const Object &other);
protected:
Object(void);
virtual ~Object(void);
public:
typedef shared_ptr<Object> Ptr;
typedef weak_ptr<Object> WeakPtr;
static unsigned long ActiveObjects;
virtual ~Object(void);
};
template<class T>

View File

@ -3,7 +3,7 @@
namespace icinga {
struct SocketErrorEventArgs : public EventArgs
struct I2_BASE_API SocketErrorEventArgs : public EventArgs
{
typedef shared_ptr<SocketErrorEventArgs> Ptr;
typedef weak_ptr<SocketErrorEventArgs> WeakPtr;
@ -12,7 +12,7 @@ struct SocketErrorEventArgs : public EventArgs
string Message;
};
class Socket : public Object
class I2_BASE_API Socket : public Object
{
private:
SOCKET m_FD;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class TCPClient : public TCPSocket
class I2_BASE_API TCPClient : public TCPSocket
{
private:
string m_PeerHost;

View File

@ -4,7 +4,7 @@
namespace icinga
{
struct NewClientEventArgs : public EventArgs
struct I2_BASE_API NewClientEventArgs : public EventArgs
{
typedef shared_ptr<NewClientEventArgs> Ptr;
typedef weak_ptr<NewClientEventArgs> WeakPtr;
@ -12,7 +12,7 @@ struct NewClientEventArgs : public EventArgs
TCPSocket::Ptr Client;
};
class TCPServer : public TCPSocket
class I2_BASE_API TCPServer : public TCPSocket
{
private:
int ReadableEventHandler(EventArgs::Ptr ea);

View File

@ -4,7 +4,7 @@
namespace icinga
{
class TCPSocket : public Socket
class I2_BASE_API TCPSocket : public Socket
{
public:
typedef shared_ptr<TCPSocket> Ptr;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class thread
class I2_BASE_API thread
{
private:
#ifdef _WIN32

View File

@ -5,7 +5,7 @@
namespace icinga {
struct TimerEventArgs : public EventArgs
struct I2_BASE_API TimerEventArgs : public EventArgs
{
typedef shared_ptr<TimerEventArgs> Ptr;
typedef weak_ptr<TimerEventArgs> WeakPtr;
@ -13,7 +13,7 @@ struct TimerEventArgs : public EventArgs
EventArgs::Ptr UserArgs;
};
class Timer : public Object
class I2_BASE_API Timer : public Object
{
private:
EventArgs::Ptr m_UserArgs;

9
cJSON/Makefile.am Normal file
View File

@ -0,0 +1,9 @@
## Process this file with automake to produce Makefile.in
noinst_LTLIBRARIES = \
libcJSON.la
libcJSON_la_SOURCES = \
cJSON.c \
cJSON.h

80
cJSON/cJSON.vcxproj Normal file
View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="cJSON.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="cJSON.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{66BED474-C33F-48F9-90BA-BBCFEDC006B8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>cJSON</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -11,4 +11,4 @@ libconfigfilecomponent_la_SOURCES = \
libconfigfilecomponent_la_CXXFLAGS = -I${top_srcdir}/base -I${top_srcdir}/jsonrpc
libconfigfilecomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined
libconfigfilecomponent_la_LIBADD = ${top_builddir}/base/libbase.la ${top_builddir}/jsonrpc/libjsonrpc.la
libconfigfilecomponent_la_LIBADD = ${top_builddir}/base/libbase.la ${top_builddir}/cJSON/libcJSON.la

View File

@ -45,11 +45,11 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -63,7 +63,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>base.lib;jsonrpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>
@ -85,7 +85,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>base.lib;jsonrpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>$(OutDir)\base.lib;$(OutDir)\jsonrpc.lib</AdditionalDependencies>

View File

@ -11,4 +11,6 @@ libconfigrpccomponent_la_SOURCES = \
libconfigrpccomponent_la_CXXFLAGS = -I${top_srcdir}/base -I${top_srcdir}/jsonrpc -I${top_srcdir}/icinga
libconfigrpccomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined -pthread
libconfigrpccomponent_la_LIBADD = ${top_builddir}/base/libbase.la ${top_builddir}/jsonrpc/libjsonrpc.la
libconfigrpccomponent_la_LIBADD = ${top_builddir}/base/libbase.la \
${top_builddir}/jsonrpc/libjsonrpc.la \
${top_builddir}/cJSON/libcJSON.la

View File

@ -16,21 +16,29 @@ void ConfigRpcComponent::Start(void)
{
IcingaApplication::Ptr icingaApp = GetIcingaApplication();
ConnectionManager::Ptr connectionManager = icingaApp->GetConnectionManager();
EndpointManager::Ptr endpointManager = icingaApp->GetEndpointManager();
ConfigHive::Ptr configHive = icingaApp->GetConfigHive();
m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
int configSource;
if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
connectionManager->RegisterMethod("config::FetchObjects", bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
m_ConfigRpcEndpoint->RegisterMethodHandler("config::FetchObjects", bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
configHive->OnObjectCreated += bind_weak(&ConfigRpcComponent::LocalObjectCreatedHandler, shared_from_this());
configHive->OnObjectRemoved += bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this());
configHive->OnPropertyChanged += bind_weak(&ConfigRpcComponent::LocalPropertyChangedHandler, shared_from_this());
m_ConfigRpcEndpoint->RegisterMethodSource("config::ObjectCreated");
m_ConfigRpcEndpoint->RegisterMethodSource("config::ObjectRemoved");
m_ConfigRpcEndpoint->RegisterMethodSource("config::PropertyChanged");
}
connectionManager->RegisterMethod("config::ObjectCreated", bind_weak(&ConfigRpcComponent::RemoteObjectUpdatedHandler, shared_from_this()));
connectionManager->RegisterMethod("config::ObjectRemoved", bind_weak(&ConfigRpcComponent::RemoteObjectRemovedHandler, shared_from_this()));
connectionManager->RegisterMethod("config::PropertyChanged", bind_weak(&ConfigRpcComponent::RemoteObjectUpdatedHandler, shared_from_this()));
m_ConfigRpcEndpoint->RegisterMethodHandler("config::ObjectCreated", bind_weak(&ConfigRpcComponent::RemoteObjectUpdatedHandler, shared_from_this()));
m_ConfigRpcEndpoint->RegisterMethodHandler("config::ObjectRemoved", bind_weak(&ConfigRpcComponent::RemoteObjectRemovedHandler, shared_from_this()));
m_ConfigRpcEndpoint->RegisterMethodHandler("config::PropertyChanged", bind_weak(&ConfigRpcComponent::RemoteObjectUpdatedHandler, shared_from_this()));
endpointManager->RegisterEndpoint(m_ConfigRpcEndpoint);
}
void ConfigRpcComponent::Stop(void)
@ -88,8 +96,8 @@ int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigObjectEventArgs::Ptr ea)
object->GetPropertyInteger("replicate", &replicate);
if (replicate) {
ConnectionManager::Ptr connectionManager = GetIcingaApplication()->GetConnectionManager();
connectionManager->SendMessage(MakeObjectMessage(object, "config::ObjectCreated", true));
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
mgr->SendMessage(m_ConfigRpcEndpoint, NULL, MakeObjectMessage(object, "config::ObjectCreated", true));
}
return 0;
@ -103,8 +111,8 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(ConfigObjectEventArgs::Ptr ea)
object->GetPropertyInteger("replicate", &replicate);
if (replicate) {
ConnectionManager::Ptr connectionManager = GetIcingaApplication()->GetConnectionManager();
connectionManager->SendMessage(MakeObjectMessage(object, "config::ObjectRemoved", false));
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
mgr->SendMessage(m_ConfigRpcEndpoint, NULL, MakeObjectMessage(object, "config::ObjectRemoved", false));
}
return 0;
@ -129,8 +137,8 @@ int ConfigRpcComponent::LocalPropertyChangedHandler(ConfigObjectEventArgs::Ptr e
cJSON_AddStringToObject(properties, ea->Property.c_str(), value.c_str());
ConnectionManager::Ptr connectionManager = GetIcingaApplication()->GetConnectionManager();
connectionManager->SendMessage(msg);
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
mgr->SendMessage(m_ConfigRpcEndpoint, NULL, msg);
}
return 0;

View File

@ -7,6 +7,8 @@ namespace icinga
class ConfigRpcComponent : public Component
{
private:
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
IcingaApplication::Ptr GetIcingaApplication(void);
int FetchObjectsHandler(NewMessageEventArgs::Ptr ea);

View File

@ -46,12 +46,12 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -65,7 +65,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>base.lib;jsonrpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -83,7 +83,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>base.lib;jsonrpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -43,6 +43,7 @@ fi
AC_OUTPUT([
Makefile
base/Makefile
cJSON/Makefile
configfilecomponent/Makefile
configrpccomponent/Makefile
icinga/Makefile

View File

@ -5,6 +5,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "base\base.vcxproj",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jsonrpc", "jsonrpc\jsonrpc.vcxproj", "{8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}"
ProjectSection(ProjectDependencies) = postProject
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
EndProjectSection
EndProject
@ -15,24 +16,29 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga", "icinga\icinga.vcxproj", "{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}"
ProjectSection(ProjectDependencies) = postProject
{697C6D7E-3109-484C-A7AF-384D28711610} = {697C6D7E-3109-484C-A7AF-384D28711610}
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{E58F1DA7-B723-412B-B2B7-7FF58E2A944E} = {E58F1DA7-B723-412B-B2B7-7FF58E2A944E}
{8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} = {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "configfilecomponent", "configfilecomponent\configfilecomponent.vcxproj", "{E58F1DA7-B723-412B-B2B7-7FF58E2A944E}"
ProjectSection(ProjectDependencies) = postProject
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} = {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "configrpccomponent", "configrpccomponent\configrpccomponent.vcxproj", "{697C6D7E-3109-484C-A7AF-384D28711610}"
ProjectSection(ProjectDependencies) = postProject
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8}
{9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} = {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cJSON", "cJSON\cJSON.vcxproj", "{66BED474-C33F-48F9-90BA-BBCFEDC006B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -59,6 +65,10 @@ Global
{697C6D7E-3109-484C-A7AF-384D28711610}.Debug|Win32.Build.0 = Debug|Win32
{697C6D7E-3109-484C-A7AF-384D28711610}.Release|Win32.ActiveCfg = Release|Win32
{697C6D7E-3109-484C-A7AF-384D28711610}.Release|Win32.Build.0 = Release|Win32
{66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Debug|Win32.ActiveCfg = Debug|Win32
{66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Debug|Win32.Build.0 = Debug|Win32
{66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Release|Win32.ActiveCfg = Release|Win32
{66BED474-C33F-48F9-90BA-BBCFEDC006B8}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -5,14 +5,21 @@ bin_PROGRAMS = \
icinga
icinga_SOURCES = \
connectionmanager.cpp \
connectionmanager.h \
endpoint.cpp \
endpoint.h \
endpointmanager.cpp \
endpointmanager.h \
icingaapplication.cpp \
icingaapplication.h \
i2-icinga.h
i2-icinga.h \
jsonrpcendpoint.cpp \
jsonrpcendpoint.h \
virtualendpoint.cpp \
virtualendpoint.h
icinga_CXXFLAGS = -I${top_srcdir}/base \
-I${top_srcdir}/jsonrpc -I${top_srcdir}
icinga_LDFLAGS = $(top_builddir)/jsonrpc/libjsonrpc.la \
$(top_builddir)/base/libbase.la
$(top_builddir)/base/libbase.la \
${top_builddir}/cJSON/libcJSON.la

View File

@ -1,149 +0,0 @@
#include "i2-icinga.h"
using namespace icinga;
void ConnectionManager::SetIdentity(string identity)
{
m_Identity = identity;
}
string ConnectionManager::GetIdentity(void)
{
return m_Identity;
}
void ConnectionManager::AddListener(unsigned short port)
{
JsonRpcServer::Ptr server = make_shared<JsonRpcServer>();
RegisterServer(server);
server->MakeSocket();
server->Bind(port);
server->Listen();
server->Start();
}
void ConnectionManager::AddConnection(string host, short port)
{
JsonRpcClient::Ptr client = make_shared<JsonRpcClient>();
RegisterClient(client);
client->MakeSocket();
client->Connect(host, port);
client->Start();
}
void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
{
m_Servers.push_front(server);
server->OnNewClient += bind_weak(&ConnectionManager::NewClientHandler, shared_from_this());
}
void ConnectionManager::UnregisterServer(JsonRpcServer::Ptr server)
{
m_Servers.remove(server);
// TODO: unbind event
}
void ConnectionManager::RegisterClient(JsonRpcClient::Ptr client)
{
m_Clients.push_front(client);
client->OnNewMessage += bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this());
client->OnClosed += bind_weak(&ConnectionManager::CloseClientHandler, shared_from_this());
client->OnError += bind_weak(&ConnectionManager::ErrorClientHandler, shared_from_this());
}
void ConnectionManager::UnregisterClient(JsonRpcClient::Ptr client)
{
m_Clients.remove(client);
// TODO: unbind event
}
int ConnectionManager::NewClientHandler(NewClientEventArgs::Ptr ncea)
{
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ncea->Client);
RegisterClient(client);
return 0;
}
int ConnectionManager::CloseClientHandler(EventArgs::Ptr ea)
{
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->Source);
UnregisterClient(client);
if (client->GetPeerHost() != string()) {
Timer::Ptr timer = make_shared<Timer>();
timer->SetInterval(30);
timer->SetUserArgs(ea);
timer->OnTimerExpired += bind_weak(&ConnectionManager::ReconnectClientHandler, shared_from_this());
timer->Start();
m_ReconnectTimers.push_front(timer);
}
return 0;
}
int ConnectionManager::ErrorClientHandler(SocketErrorEventArgs::Ptr ea)
{
cout << "Error occured for JSON-RPC socket: Code=" << ea->Code << "; Message=" << ea->Message << endl;
return 0;
}
int ConnectionManager::ReconnectClientHandler(TimerEventArgs::Ptr ea)
{
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->UserArgs->Source);
Timer::Ptr timer = static_pointer_cast<Timer>(ea->Source);
AddConnection(client->GetPeerHost(), client->GetPeerPort());
timer->Stop();
m_ReconnectTimers.remove(timer);
return 0;
}
int ConnectionManager::NewMessageHandler(NewMessageEventArgs::Ptr nmea)
{
JsonRpcMessage::Ptr request = nmea->Message;
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(nmea->Source);
map<string, event<NewMessageEventArgs::Ptr> >::iterator i;
i = m_Methods.find(request->GetMethod());
if (i == m_Methods.end()) {
JsonRpcMessage::Ptr response = make_shared<JsonRpcMessage>();
response->SetVersion("2.0");
response->SetError("Unknown method.");
response->SetID(request->GetID());
Netstring::WriteJSONToFIFO(client->GetSendQueue(), response->GetJSON());
return 0;
}
i->second(nmea);
return 0;
}
void ConnectionManager::RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback)
{
m_Methods[method] += callback;
}
void ConnectionManager::UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback)
{
// TODO: implement
//m_Methods[method] -= callback;
}
void ConnectionManager::SendMessage(JsonRpcMessage::Ptr message)
{
/* TODO: filter messages based on event subscriptions; also loopback message to our own handlers */
for (list<JsonRpcClient::Ptr>::iterator i = m_Clients.begin(); i != m_Clients.end(); i++)
{
JsonRpcClient::Ptr client = *i;
client->SendMessage(message);
}
}

18
icinga/endpoint.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "i2-icinga.h"
using namespace icinga;
Endpoint::Endpoint(void)
{
m_Connected = false;
}
void Endpoint::SetConnected(bool connected)
{
m_Connected = connected;
}
bool Endpoint::GetConnected(void)
{
return m_Connected;
}

28
icinga/endpoint.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef ENDPOINT_H
#define ENDPOINT_H
namespace icinga
{
class EndpointManager;
class I2_ICINGA_API Endpoint : public Object
{
private:
bool m_Connected;
public:
typedef shared_ptr<Endpoint> Ptr;
typedef weak_ptr<Endpoint> WeakPtr;
Endpoint(void);
virtual void SetConnected(bool connected);
virtual bool GetConnected(void);
virtual void SendMessage(Endpoint::Ptr source, JsonRpcMessage::Ptr message) = 0;
};
}
#endif /* ENDPOINT_H */

139
icinga/endpointmanager.cpp Normal file
View File

@ -0,0 +1,139 @@
#include "i2-icinga.h"
using namespace icinga;
void EndpointManager::SetIdentity(string identity)
{
m_Identity = identity;
}
string EndpointManager::GetIdentity(void) const
{
return m_Identity;
}
void EndpointManager::AddListener(unsigned short port)
{
JsonRpcServer::Ptr server = make_shared<JsonRpcServer>();
RegisterServer(server);
server->MakeSocket();
server->Bind(port);
server->Listen();
server->Start();
}
void EndpointManager::AddConnection(string host, short port)
{
JsonRpcClient::Ptr client = make_shared<JsonRpcClient>();
RegisterClient(client);
client->MakeSocket();
client->Connect(host, port);
client->Start();
}
void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
{
m_Servers.push_front(server);
server->OnNewClient += bind_weak(&EndpointManager::NewClientHandler, shared_from_this());
}
void EndpointManager::UnregisterServer(JsonRpcServer::Ptr server)
{
m_Servers.remove(server);
// TODO: unbind event
}
void EndpointManager::RegisterClient(JsonRpcClient::Ptr client)
{
m_Clients.push_front(client);
client->OnNewMessage += bind_weak(&EndpointManager::NewMessageHandler, shared_from_this());
client->OnClosed += bind_weak(&EndpointManager::CloseClientHandler, shared_from_this());
client->OnError += bind_weak(&EndpointManager::ErrorClientHandler, shared_from_this());
}
void EndpointManager::UnregisterClient(JsonRpcClient::Ptr client)
{
m_Clients.remove(client);
// TODO: unbind event
}
int EndpointManager::NewClientHandler(NewClientEventArgs::Ptr ncea)
{
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ncea->Client);
RegisterClient(client);
return 0;
}
int EndpointManager::CloseClientHandler(EventArgs::Ptr ea)
{
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->Source);
UnregisterClient(client);
if (client->GetPeerHost() != string()) {
Timer::Ptr timer = make_shared<Timer>();
timer->SetInterval(30);
timer->SetUserArgs(ea);
timer->OnTimerExpired += bind_weak(&EndpointManager::ReconnectClientHandler, shared_from_this());
timer->Start();
m_ReconnectTimers.push_front(timer);
}
return 0;
}
int EndpointManager::ErrorClientHandler(SocketErrorEventArgs::Ptr ea)
{
cout << "Error occured for JSON-RPC socket: Code=" << ea->Code << "; Message=" << ea->Message << endl;
return 0;
}
int EndpointManager::ReconnectClientHandler(TimerEventArgs::Ptr ea)
{
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->UserArgs->Source);
Timer::Ptr timer = static_pointer_cast<Timer>(ea->Source);
AddConnection(client->GetPeerHost(), client->GetPeerPort());
timer->Stop();
m_ReconnectTimers.remove(timer);
return 0;
}
int EndpointManager::NewMessageHandler(NewMessageEventArgs::Ptr nmea)
{
// TODO: implement
return 0;
}
void EndpointManager::RegisterEndpoint(Endpoint::Ptr endpoint)
{
m_Endpoints.push_front(endpoint);
}
void EndpointManager::UnregisterEndpoint(Endpoint::Ptr endpoint)
{
m_Endpoints.remove(endpoint);
}
void EndpointManager::SendMessage(Endpoint::Ptr source, Endpoint::Ptr destination, JsonRpcMessage::Ptr message)
{
if (destination) {
destination->SendMessageA(source, message);
} else {
for (list<Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
{
Endpoint::Ptr endpoint = *i;
if (endpoint == source)
continue;
endpoint->SendMessage(source, message);
}
}
}

View File

@ -1,15 +1,15 @@
#ifndef CONNECTIONMANAGER_H
#define CONNECTIONMANAGER_H
#ifndef ENDPOINTMANAGER_H
#define ENDPOINTMANAGER_H
namespace icinga
{
class ConnectionManager : public Object
class I2_ICINGA_API EndpointManager : public Object
{
list<JsonRpcServer::Ptr> m_Servers;
list<JsonRpcClient::Ptr> m_Clients;
map< string, event<NewMessageEventArgs::Ptr> > m_Methods;
list<Timer::Ptr> m_ReconnectTimers;
list<Endpoint::Ptr> m_Endpoints;
string m_Identity;
int NewClientHandler(NewClientEventArgs::Ptr ncea);
@ -23,22 +23,23 @@ class ConnectionManager : public Object
void RegisterServer(JsonRpcServer::Ptr server);
void UnregisterServer(JsonRpcServer::Ptr server);
public:
typedef shared_ptr<ConnectionManager> Ptr;
typedef weak_ptr<ConnectionManager> WeakPtr;
typedef shared_ptr<EndpointManager> Ptr;
typedef weak_ptr<EndpointManager> WeakPtr;
void SetIdentity(string identity);
string GetIdentity(void);
string GetIdentity(void) const;
void AddListener(unsigned short port);
void AddConnection(string host, short port);
void RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback);
void UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback);
void RegisterEndpoint(Endpoint::Ptr endpoint);
void UnregisterEndpoint(Endpoint::Ptr endpoint);
void SendMessage(JsonRpcMessage::Ptr message);
void SendMessage(Endpoint::Ptr source, Endpoint::Ptr destination, JsonRpcMessage::Ptr message);
};
}
#endif /* CONNECTIONMANAGER_H */
#endif /* ENDPOINTMANAGER_H */

View File

@ -4,7 +4,16 @@
#include <i2-base.h>
#include <i2-jsonrpc.h>
#include "connectionmanager.h"
#ifdef I2_ICINGA_BUILD
# define I2_ICINGA_API I2_EXPORT
#else /* I2_ICINGA_BUILD */
# define I2_ICINGA_API I2_IMPORT
#endif /* I2_ICINGA_BUILD */
#include "endpoint.h"
#include "jsonrpcendpoint.h"
#include "virtualendpoint.h"
#include "endpointmanager.h"
#include "icingaapplication.h"
#endif /* I2ICINGA_H */

View File

@ -40,12 +40,12 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\config;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\config;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -59,7 +59,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>base.lib;jsonrpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -77,17 +77,23 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>base.lib;jsonrpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="connectionmanager.cpp" />
<ClCompile Include="endpoint.cpp" />
<ClCompile Include="endpointmanager.cpp" />
<ClCompile Include="icingaapplication.cpp" />
<ClCompile Include="jsonrpcendpoint.cpp" />
<ClCompile Include="virtualendpoint.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="connectionmanager.h" />
<ClInclude Include="endpoint.h" />
<ClInclude Include="endpointmanager.h" />
<ClInclude Include="icingaapplication.h" />
<ClInclude Include="i2-icinga.h" />
<ClInclude Include="jsonrpcendpoint.h" />
<ClInclude Include="virtualendpoint.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -11,7 +11,7 @@ using namespace icinga;
IcingaApplication::IcingaApplication(void)
{
m_ConnectionManager = make_shared<ConnectionManager>();
m_EndpointManager = make_shared<EndpointManager>();
}
int IcingaApplication::Main(const vector<string>& args)
@ -71,9 +71,9 @@ void IcingaApplication::PrintUsage(const string& programPath)
cout << "Syntax: " << programPath << " <config-file>" << endl;
}
ConnectionManager::Ptr IcingaApplication::GetConnectionManager(void)
EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
{
return m_ConnectionManager;
return m_EndpointManager;
}
int IcingaApplication::NewComponentHandler(ConfigObjectEventArgs::Ptr ea)
@ -114,7 +114,7 @@ int IcingaApplication::NewRpcListenerHandler(ConfigObjectEventArgs::Ptr ea)
Log("Creating JSON-RPC listener on port %d", port);
GetConnectionManager()->AddListener(port);
GetEndpointManager()->AddListener(port);
return 0;
}
@ -140,7 +140,7 @@ int IcingaApplication::NewRpcConnectionHandler(ConfigObjectEventArgs::Ptr ea)
Log("Creating JSON-RPC connection to %s:%d", hostname.c_str(), port);
GetConnectionManager()->AddConnection(hostname, port);
GetEndpointManager()->AddConnection(hostname, port);
return 0;
}

View File

@ -4,10 +4,10 @@
namespace icinga
{
class IcingaApplication : public Application
class I2_ICINGA_API IcingaApplication : public Application
{
private:
ConnectionManager::Ptr m_ConnectionManager;
EndpointManager::Ptr m_EndpointManager;
int NewComponentHandler(ConfigObjectEventArgs::Ptr ea);
int DeletedComponentHandler(ConfigObjectEventArgs::Ptr ea);
@ -24,11 +24,11 @@ public:
IcingaApplication(void);
virtual int Main(const vector<string>& args);
int Main(const vector<string>& args);
void PrintUsage(const string& programPath);
virtual ConnectionManager::Ptr GetConnectionManager(void);
EndpointManager::Ptr GetEndpointManager(void);
};
}

View File

@ -0,0 +1,3 @@
#include "i2-icinga.h"
using namespace icinga;

14
icinga/jsonrpcendpoint.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef JSONRPCENDPOINT_H
#define JSONRPCENDPOINT_H
namespace icinga
{
class I2_ICINGA_API JsonRpcEndpoint : public Endpoint
{
public:
};
}
#endif /* JSONRPCENDPOINT_H */

View File

@ -0,0 +1,48 @@
#include "i2-icinga.h"
using namespace icinga;
VirtualEndpoint::VirtualEndpoint()
{
SetConnected(true);
}
void VirtualEndpoint::RegisterMethodHandler(string method, function<int (NewMessageEventArgs::Ptr)> callback)
{
m_MethodHandlers[method] += callback;
}
void VirtualEndpoint::UnregisterMethodHandler(string method, function<int (NewMessageEventArgs::Ptr)> callback)
{
// TODO: implement
//m_Methods[method] -= callback;
}
void VirtualEndpoint::RegisterMethodSource(string method)
{
m_MethodSources.push_front(method);
}
void VirtualEndpoint::UnregisterMethodSource(string method)
{
m_MethodSources.remove(method);
}
void VirtualEndpoint::SendMessage(Endpoint::Ptr source, JsonRpcMessage::Ptr message)
{
map<string, event<NewMessageEventArgs::Ptr> >::iterator i;
i = m_MethodHandlers.find(message->GetMethod());
if (i == m_MethodHandlers.end()) {
JsonRpcMessage::Ptr response = make_shared<JsonRpcMessage>();
response->SetVersion("2.0");
response->SetError("Unknown method.");
response->SetID(message->GetID());
source->SendMessage(static_pointer_cast<Endpoint>(shared_from_this()), response);
}
NewMessageEventArgs::Ptr nmea = make_shared<NewMessageEventArgs>();
nmea->Source = shared_from_this();
nmea->Message = message;
i->second(nmea);
}

30
icinga/virtualendpoint.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef VIRTUALENDPOINT_H
#define VIRTUALENDPOINT_H
namespace icinga
{
class I2_ICINGA_API VirtualEndpoint : public Endpoint
{
private:
map< string, event<NewMessageEventArgs::Ptr> > m_MethodHandlers;
list<string> m_MethodSources;
public:
typedef shared_ptr<VirtualEndpoint> Ptr;
typedef weak_ptr<VirtualEndpoint> WeakPtr;
VirtualEndpoint();
virtual void RegisterMethodHandler(string method, function<int (NewMessageEventArgs::Ptr)> callback);
virtual void UnregisterMethodHandler(string method, function<int (NewMessageEventArgs::Ptr)> callback);
virtual void RegisterMethodSource(string method);
virtual void UnregisterMethodSource(string method);
virtual void SendMessage(Endpoint::Ptr source, JsonRpcMessage::Ptr message);
};
}
#endif /* VIRTUALENDPOINT_H */

View File

@ -5,8 +5,6 @@ noinst_LTLIBRARIES = \
libjsonrpc.la
libjsonrpc_la_SOURCES = \
cJSON.c \
cJSON.h \
i2-jsonrpc.h \
jsonrpcclient.cpp \
jsonrpcclient.h \

View File

@ -3,8 +3,14 @@
#include <map>
#include <i2-base.h>
#include <cJSON.h>
#ifdef I2_JSONRPC_BUILD
# define I2_JSONRPC_API I2_EXPORT
#else /* I2_JSONRPC_BUILD */
# define I2_JSONRPC_API I2_IMPORT
#endif /* I2_JSONRPC_BUILD */
#include "cJSON.h"
#include "netstring.h"
#include "jsonrpcmessage.h"
#include "jsonrpcclient.h"

View File

@ -11,7 +11,6 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cJSON.h" />
<ClInclude Include="i2-jsonrpc.h" />
<ClInclude Include="jsonrpcclient.h" />
<ClInclude Include="jsonrpcmessage.h" />
@ -19,7 +18,6 @@
<ClInclude Include="netstring.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cJSON.c" />
<ClCompile Include="jsonrpcclient.cpp" />
<ClCompile Include="jsonrpcmessage.cpp" />
<ClCompile Include="jsonrpcserver.cpp" />
@ -32,12 +30,12 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
@ -53,11 +51,11 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(ProjectDir)\..\base;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(ProjectDir)\..\base;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -66,11 +64,12 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;I2_JSONRPC_BUILD;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>base.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>
@ -85,13 +84,14 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;I2_JSONRPC_BUILD;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>base.lib;cJSON.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>

View File

@ -4,7 +4,7 @@
namespace icinga
{
struct NewMessageEventArgs : public EventArgs
struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs
{
typedef shared_ptr<NewMessageEventArgs> Ptr;
typedef weak_ptr<NewMessageEventArgs> WeakPtr;
@ -12,7 +12,7 @@ struct NewMessageEventArgs : public EventArgs
JsonRpcMessage::Ptr Message;
};
class JsonRpcClient : public TCPClient
class I2_JSONRPC_API JsonRpcClient : public TCPClient
{
private:
int DataAvailableHandler(EventArgs::Ptr ea);

View File

@ -4,7 +4,7 @@
namespace icinga
{
class JsonRpcMessage : public Object
class I2_JSONRPC_API JsonRpcMessage : public Object
{
private:
cJSON *m_JSON;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class JsonRpcServer : public TCPServer
class I2_JSONRPC_API JsonRpcServer : public TCPServer
{
public:
typedef shared_ptr<JsonRpcServer> Ptr;

View File

@ -4,7 +4,7 @@
namespace icinga
{
class Netstring : public Object
class I2_JSONRPC_API Netstring : public Object
{
private:
size_t m_Length;