SUBDIRS = ltdl \
base \
+ cJSON \
jsonrpc \
configfilecomponent \
configrpccomponent \
using namespace icinga;
-Application::Ptr Application::Instance;
+Application::Ptr I2_EXPORT Application::Instance;
Application::Application(void)
{
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;
+}
\ No newline at end of file
DEFINE_EXCEPTION_CLASS(ComponentLoadException);
-class Application : public Object {
+class I2_BASE_API Application : public Object {
private:
bool m_ShuttingDown;
ConfigHive::Ptr m_ConfigHive;
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 */
</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>
<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">
</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>
<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>
namespace icinga
{
-class Component : public Object
+class I2_BASE_API Component : public Object
{
private:
Application::WeakPtr m_Application;
namespace icinga
{
-class condvar
+class I2_BASE_API condvar
{
private:
#ifdef _WIN32
class ConfigHive;
-class ConfigCollection : public Object
+class I2_BASE_API ConfigCollection : public Object
{
private:
weak_ptr<ConfigHive> m_Hive;
namespace icinga
{
-class ConfigHive : public Object
+class I2_BASE_API ConfigHive : public Object
{
public:
typedef shared_ptr<ConfigHive> Ptr;
class ConfigHive;
-struct ConfigObjectEventArgs : public EventArgs
+struct I2_BASE_API ConfigObjectEventArgs : public EventArgs
{
typedef shared_ptr<ConfigObjectEventArgs> Ptr;
typedef weak_ptr<ConfigObjectEventArgs> WeakPtr;
string OldValue;
};
-class ConfigObject : public Object
+class I2_BASE_API ConfigObject : public Object
{
private:
weak_ptr<ConfigHive> m_Hive;
namespace icinga
{
-struct EventArgs : public Object
+struct I2_BASE_API EventArgs : public Object
{
typedef shared_ptr<EventArgs> Ptr;
typedef weak_ptr<EventArgs> WeakPtr;
namespace icinga
{
-class Exception
+class I2_BASE_API Exception
{
private:
string m_Message;
namespace icinga
{
-class FIFO : public Object
+class I2_BASE_API FIFO : public Object
{
private:
char *m_Buffer;
#ifdef _MSC_VER
# define HAVE_CXX11
+# pragma warning(disable:4251)
#else /* _MSC_VER */
# include "config.h"
#endif /* _MSC_VER */
# 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"
DEFINE_EXCEPTION_CLASS(OutOfMemoryException);
-class Memory
+class I2_BASE_API Memory
{
private:
Memory(void);
namespace icinga
{
-class mutex
+class I2_BASE_API mutex
{
private:
#ifdef _WIN32
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>
namespace icinga {
-struct SocketErrorEventArgs : public EventArgs
+struct I2_BASE_API SocketErrorEventArgs : public EventArgs
{
typedef shared_ptr<SocketErrorEventArgs> Ptr;
typedef weak_ptr<SocketErrorEventArgs> WeakPtr;
string Message;
};
-class Socket : public Object
+class I2_BASE_API Socket : public Object
{
private:
SOCKET m_FD;
namespace icinga
{
-class TCPClient : public TCPSocket
+class I2_BASE_API TCPClient : public TCPSocket
{
private:
string m_PeerHost;
namespace icinga
{
-struct NewClientEventArgs : public EventArgs
+struct I2_BASE_API NewClientEventArgs : public EventArgs
{
typedef shared_ptr<NewClientEventArgs> Ptr;
typedef weak_ptr<NewClientEventArgs> WeakPtr;
TCPSocket::Ptr Client;
};
-class TCPServer : public TCPSocket
+class I2_BASE_API TCPServer : public TCPSocket
{
private:
int ReadableEventHandler(EventArgs::Ptr ea);
namespace icinga
{
-class TCPSocket : public Socket
+class I2_BASE_API TCPSocket : public Socket
{
public:
typedef shared_ptr<TCPSocket> Ptr;
namespace icinga
{
-class thread
+class I2_BASE_API thread
{
private:
#ifdef _WIN32
namespace icinga {
-struct TimerEventArgs : public EventArgs
+struct I2_BASE_API TimerEventArgs : public EventArgs
{
typedef shared_ptr<TimerEventArgs> Ptr;
typedef weak_ptr<TimerEventArgs> WeakPtr;
EventArgs::Ptr UserArgs;
};
-class Timer : public Object
+class I2_BASE_API Timer : public Object
{
private:
EventArgs::Ptr m_UserArgs;
--- /dev/null
+## Process this file with automake to produce Makefile.in
+
+
+noinst_LTLIBRARIES = \
+ libcJSON.la
+
+libcJSON_la_SOURCES = \
+ cJSON.c \
+ cJSON.h
--- /dev/null
+<?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>
\ No newline at end of file
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
\ No newline at end of file
+libconfigfilecomponent_la_LIBADD = ${top_builddir}/base/libbase.la ${top_builddir}/cJSON/libcJSON.la
\ No newline at end of file
</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'">
<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>
<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>
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
{
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)
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;
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;
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;
class ConfigRpcComponent : public Component
{
private:
+ VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
+
IcingaApplication::Ptr GetIcingaApplication(void);
int FetchObjectsHandler(NewMessageEventArgs::Ptr ea);
<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'">
<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'">
<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" />
AC_OUTPUT([
Makefile
base/Makefile
+cJSON/Makefile
configfilecomponent/Makefile
configrpccomponent/Makefile
icinga/Makefile
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
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
{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
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
\ No newline at end of file
+ $(top_builddir)/base/libbase.la \
+ ${top_builddir}/cJSON/libcJSON.la
\ No newline at end of file
+++ /dev/null
-#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);
- }
-}
--- /dev/null
+#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;
+}
--- /dev/null
+#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 */
--- /dev/null
+#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);
+ }
+ }
+}
-#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);
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 */
#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 */
<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'">
<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'">
<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">
IcingaApplication::IcingaApplication(void)
{
- m_ConnectionManager = make_shared<ConnectionManager>();
+ m_EndpointManager = make_shared<EndpointManager>();
}
int IcingaApplication::Main(const vector<string>& args)
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)
Log("Creating JSON-RPC listener on port %d", port);
- GetConnectionManager()->AddListener(port);
+ GetEndpointManager()->AddListener(port);
return 0;
}
Log("Creating JSON-RPC connection to %s:%d", hostname.c_str(), port);
- GetConnectionManager()->AddConnection(hostname, port);
+ GetEndpointManager()->AddConnection(hostname, port);
return 0;
}
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);
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);
};
}
--- /dev/null
+#include "i2-icinga.h"
+
+using namespace icinga;
--- /dev/null
+#ifndef JSONRPCENDPOINT_H
+#define JSONRPCENDPOINT_H
+
+namespace icinga
+{
+
+class I2_ICINGA_API JsonRpcEndpoint : public Endpoint
+{
+public:
+};
+
+}
+
+#endif /* JSONRPCENDPOINT_H */
\ No newline at end of file
--- /dev/null
+#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);
+}
--- /dev/null
+#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 */
libjsonrpc.la
libjsonrpc_la_SOURCES = \
- cJSON.c \
- cJSON.h \
i2-jsonrpc.h \
jsonrpcclient.cpp \
jsonrpcclient.h \
#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"
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="cJSON.h" />
<ClInclude Include="i2-jsonrpc.h" />
<ClInclude Include="jsonrpcclient.h" />
<ClInclude Include="jsonrpcmessage.h" />
<ClInclude Include="netstring.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="cJSON.c" />
<ClCompile Include="jsonrpcclient.cpp" />
<ClCompile Include="jsonrpcmessage.cpp" />
<ClCompile Include="jsonrpcserver.cpp" />
</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>
</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'">
</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>
<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>
namespace icinga
{
-struct NewMessageEventArgs : public EventArgs
+struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs
{
typedef shared_ptr<NewMessageEventArgs> Ptr;
typedef weak_ptr<NewMessageEventArgs> WeakPtr;
JsonRpcMessage::Ptr Message;
};
-class JsonRpcClient : public TCPClient
+class I2_JSONRPC_API JsonRpcClient : public TCPClient
{
private:
int DataAvailableHandler(EventArgs::Ptr ea);
namespace icinga
{
-class JsonRpcMessage : public Object
+class I2_JSONRPC_API JsonRpcMessage : public Object
{
private:
cJSON *m_JSON;
namespace icinga
{
-class JsonRpcServer : public TCPServer
+class I2_JSONRPC_API JsonRpcServer : public TCPServer
{
public:
typedef shared_ptr<JsonRpcServer> Ptr;
namespace icinga
{
-class Netstring : public Object
+class I2_JSONRPC_API Netstring : public Object
{
private:
size_t m_Length;