diff --git a/Makefile.am b/Makefile.am index 1f2d5b6bd..ea056e09b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = ltdl \ base \ + cJSON \ jsonrpc \ configfilecomponent \ configrpccomponent \ diff --git a/base/application.cpp b/base/application.cpp index 98c85d8a9..1f50c454f 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -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 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 diff --git a/base/application.h b/base/application.h index e4211146b..2806a16e2 100644 --- a/base/application.h +++ b/base/application.h @@ -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 -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(); - -#ifndef _WIN32 - struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sigint_handler; - sigaction(SIGINT, &sa, NULL); -#endif /* _WIN32 */ - - vector 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 instance = make_shared(); \ + 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(argc, argv); \ - } - -} - #endif /* APPLICATION_H */ diff --git a/base/base.vcxproj b/base/base.vcxproj index 5564b5393..6ad5a6c67 100644 --- a/base/base.vcxproj +++ b/base/base.vcxproj @@ -65,7 +65,7 @@ - StaticLibrary + DynamicLibrary true MultiByte @@ -73,7 +73,7 @@ false true MultiByte - StaticLibrary + DynamicLibrary @@ -92,11 +92,12 @@ Level3 Disabled + _WINDLL;I2_BASE_BUILD;_DEBUG;%(PreprocessorDefinitions) Windows true - ws2_32.lib;imagehlp.lib;%(AdditionalDependencies) + ws2_32.lib;shlwapi.lib;%(AdditionalDependencies) ws2_32.lib;shlwapi.lib @@ -110,13 +111,14 @@ MaxSpeed true true + _WINDLL;I2_BASE_BUILD;%(PreprocessorDefinitions) Windows true true true - ws2_32.lib;imagehlp.lib;%(AdditionalDependencies) + ws2_32.lib;shlwapi.lib;%(AdditionalDependencies) ws2_32.lib;shlwapi.lib diff --git a/base/component.h b/base/component.h index 4415a17e8..68da36b5c 100644 --- a/base/component.h +++ b/base/component.h @@ -4,7 +4,7 @@ namespace icinga { -class Component : public Object +class I2_BASE_API Component : public Object { private: Application::WeakPtr m_Application; diff --git a/base/condvar.h b/base/condvar.h index b34689be1..2c51a09ee 100644 --- a/base/condvar.h +++ b/base/condvar.h @@ -4,7 +4,7 @@ namespace icinga { -class condvar +class I2_BASE_API condvar { private: #ifdef _WIN32 diff --git a/base/configcollection.h b/base/configcollection.h index 6d30b3a59..b8ea38512 100644 --- a/base/configcollection.h +++ b/base/configcollection.h @@ -6,7 +6,7 @@ namespace icinga class ConfigHive; -class ConfigCollection : public Object +class I2_BASE_API ConfigCollection : public Object { private: weak_ptr m_Hive; diff --git a/base/confighive.h b/base/confighive.h index 8a6fb58df..c7e54c33e 100644 --- a/base/confighive.h +++ b/base/confighive.h @@ -4,7 +4,7 @@ namespace icinga { -class ConfigHive : public Object +class I2_BASE_API ConfigHive : public Object { public: typedef shared_ptr Ptr; diff --git a/base/configobject.h b/base/configobject.h index be4882185..a084b5b47 100644 --- a/base/configobject.h +++ b/base/configobject.h @@ -8,7 +8,7 @@ namespace icinga class ConfigHive; -struct ConfigObjectEventArgs : public EventArgs +struct I2_BASE_API ConfigObjectEventArgs : public EventArgs { typedef shared_ptr Ptr; typedef weak_ptr 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 m_Hive; diff --git a/base/event.h b/base/event.h index 60d9ecf19..e306d73b0 100644 --- a/base/event.h +++ b/base/event.h @@ -4,7 +4,7 @@ namespace icinga { -struct EventArgs : public Object +struct I2_BASE_API EventArgs : public Object { typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; diff --git a/base/exception.h b/base/exception.h index 4853dde68..d454f79e3 100644 --- a/base/exception.h +++ b/base/exception.h @@ -4,7 +4,7 @@ namespace icinga { -class Exception +class I2_BASE_API Exception { private: string m_Message; diff --git a/base/fifo.h b/base/fifo.h index 2b2d82e54..6cf57d401 100644 --- a/base/fifo.h +++ b/base/fifo.h @@ -4,7 +4,7 @@ namespace icinga { -class FIFO : public Object +class I2_BASE_API FIFO : public Object { private: char *m_Buffer; diff --git a/base/i2-base.h b/base/i2-base.h index 2b9626175..a7afa25db 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -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" diff --git a/base/memory.h b/base/memory.h index 9abd0d28c..70d5d4e25 100644 --- a/base/memory.h +++ b/base/memory.h @@ -6,7 +6,7 @@ namespace icinga DEFINE_EXCEPTION_CLASS(OutOfMemoryException); -class Memory +class I2_BASE_API Memory { private: Memory(void); diff --git a/base/mutex.h b/base/mutex.h index 2d8d317b4..9c632bc04 100644 --- a/base/mutex.h +++ b/base/mutex.h @@ -4,7 +4,7 @@ namespace icinga { -class mutex +class I2_BASE_API mutex { private: #ifdef _WIN32 diff --git a/base/object.h b/base/object.h index 71c278ead..ffb609bb8 100644 --- a/base/object.h +++ b/base/object.h @@ -4,21 +4,20 @@ namespace icinga { -class Object : public enable_shared_from_this +class I2_BASE_API Object : public enable_shared_from_this { private: Object(const Object &other); protected: Object(void); + virtual ~Object(void); public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; static unsigned long ActiveObjects; - - virtual ~Object(void); }; template diff --git a/base/socket.h b/base/socket.h index ca6179b43..9b9e7da9f 100644 --- a/base/socket.h +++ b/base/socket.h @@ -3,7 +3,7 @@ namespace icinga { -struct SocketErrorEventArgs : public EventArgs +struct I2_BASE_API SocketErrorEventArgs : public EventArgs { typedef shared_ptr Ptr; typedef weak_ptr 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; diff --git a/base/tcpclient.h b/base/tcpclient.h index 607ed299a..91c027730 100644 --- a/base/tcpclient.h +++ b/base/tcpclient.h @@ -4,7 +4,7 @@ namespace icinga { -class TCPClient : public TCPSocket +class I2_BASE_API TCPClient : public TCPSocket { private: string m_PeerHost; diff --git a/base/tcpserver.h b/base/tcpserver.h index caef7bbf7..44a438d6f 100644 --- a/base/tcpserver.h +++ b/base/tcpserver.h @@ -4,7 +4,7 @@ namespace icinga { -struct NewClientEventArgs : public EventArgs +struct I2_BASE_API NewClientEventArgs : public EventArgs { typedef shared_ptr Ptr; typedef weak_ptr 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); diff --git a/base/tcpsocket.h b/base/tcpsocket.h index 394f89000..8a3feb50d 100644 --- a/base/tcpsocket.h +++ b/base/tcpsocket.h @@ -4,7 +4,7 @@ namespace icinga { -class TCPSocket : public Socket +class I2_BASE_API TCPSocket : public Socket { public: typedef shared_ptr Ptr; diff --git a/base/thread.h b/base/thread.h index a5b364fbd..17a0e993b 100644 --- a/base/thread.h +++ b/base/thread.h @@ -4,7 +4,7 @@ namespace icinga { -class thread +class I2_BASE_API thread { private: #ifdef _WIN32 diff --git a/base/timer.h b/base/timer.h index 5732c271c..da27900af 100644 --- a/base/timer.h +++ b/base/timer.h @@ -5,7 +5,7 @@ namespace icinga { -struct TimerEventArgs : public EventArgs +struct I2_BASE_API TimerEventArgs : public EventArgs { typedef shared_ptr Ptr; typedef weak_ptr 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; diff --git a/cJSON/Makefile.am b/cJSON/Makefile.am new file mode 100644 index 000000000..a4d45f77c --- /dev/null +++ b/cJSON/Makefile.am @@ -0,0 +1,9 @@ +## Process this file with automake to produce Makefile.in + + +noinst_LTLIBRARIES = \ + libcJSON.la + +libcJSON_la_SOURCES = \ + cJSON.c \ + cJSON.h diff --git a/jsonrpc/cJSON.c b/cJSON/cJSON.c similarity index 100% rename from jsonrpc/cJSON.c rename to cJSON/cJSON.c diff --git a/jsonrpc/cJSON.h b/cJSON/cJSON.h similarity index 100% rename from jsonrpc/cJSON.h rename to cJSON/cJSON.h diff --git a/cJSON/cJSON.vcxproj b/cJSON/cJSON.vcxproj new file mode 100644 index 000000000..a14805982 --- /dev/null +++ b/cJSON/cJSON.vcxproj @@ -0,0 +1,80 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + {66BED474-C33F-48F9-90BA-BBCFEDC006B8} + Win32Proj + cJSON + + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + + \ No newline at end of file diff --git a/configfilecomponent/Makefile.am b/configfilecomponent/Makefile.am index 23adca4ce..f148af252 100644 --- a/configfilecomponent/Makefile.am +++ b/configfilecomponent/Makefile.am @@ -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 \ 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 diff --git a/configfilecomponent/configfilecomponent.vcxproj b/configfilecomponent/configfilecomponent.vcxproj index fa0f9ff5f..bf7d0199c 100644 --- a/configfilecomponent/configfilecomponent.vcxproj +++ b/configfilecomponent/configfilecomponent.vcxproj @@ -45,11 +45,11 @@ - $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) - $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) @@ -63,7 +63,7 @@ Windows true - base.lib;jsonrpc.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies) @@ -85,7 +85,7 @@ true true true - base.lib;jsonrpc.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies) $(OutDir)\base.lib;$(OutDir)\jsonrpc.lib diff --git a/configrpccomponent/Makefile.am b/configrpccomponent/Makefile.am index f76aec842..8a57eb2cb 100644 --- a/configrpccomponent/Makefile.am +++ b/configrpccomponent/Makefile.am @@ -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 diff --git a/configrpccomponent/configrpccomponent.cpp b/configrpccomponent/configrpccomponent.cpp index 7606c02f8..08317cdb0 100644 --- a/configrpccomponent/configrpccomponent.cpp +++ b/configrpccomponent/configrpccomponent.cpp @@ -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(); + 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; diff --git a/configrpccomponent/configrpccomponent.h b/configrpccomponent/configrpccomponent.h index 150a85dc3..dcf2f740b 100644 --- a/configrpccomponent/configrpccomponent.h +++ b/configrpccomponent/configrpccomponent.h @@ -7,6 +7,8 @@ namespace icinga class ConfigRpcComponent : public Component { private: + VirtualEndpoint::Ptr m_ConfigRpcEndpoint; + IcingaApplication::Ptr GetIcingaApplication(void); int FetchObjectsHandler(NewMessageEventArgs::Ptr ea); diff --git a/configrpccomponent/configrpccomponent.vcxproj b/configrpccomponent/configrpccomponent.vcxproj index 61feb47d9..66fc0443b 100644 --- a/configrpccomponent/configrpccomponent.vcxproj +++ b/configrpccomponent/configrpccomponent.vcxproj @@ -46,12 +46,12 @@ true - $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) false - $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\icinga;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) @@ -65,7 +65,7 @@ Windows true - base.lib;jsonrpc.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies) @@ -83,7 +83,7 @@ true true true - base.lib;jsonrpc.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;icinga.lib;cJSON.lib;%(AdditionalDependencies) diff --git a/configure.ac b/configure.ac index c2b8ae07d..8a2b0a35a 100644 --- a/configure.ac +++ b/configure.ac @@ -43,6 +43,7 @@ fi AC_OUTPUT([ Makefile base/Makefile +cJSON/Makefile configfilecomponent/Makefile configrpccomponent/Makefile icinga/Makefile diff --git a/icinga.sln b/icinga.sln index cfe447411..5fd6e76cc 100644 --- a/icinga.sln +++ b/icinga.sln @@ -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 diff --git a/icinga/Makefile.am b/icinga/Makefile.am index bd090f8cd..17173c70c 100644 --- a/icinga/Makefile.am +++ b/icinga/Makefile.am @@ -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 \ No newline at end of file + $(top_builddir)/base/libbase.la \ + ${top_builddir}/cJSON/libcJSON.la \ No newline at end of file diff --git a/icinga/connectionmanager.cpp b/icinga/connectionmanager.cpp deleted file mode 100644 index 3688efffc..000000000 --- a/icinga/connectionmanager.cpp +++ /dev/null @@ -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(); - RegisterServer(server); - - server->MakeSocket(); - server->Bind(port); - server->Listen(); - server->Start(); -} - -void ConnectionManager::AddConnection(string host, short port) -{ - JsonRpcClient::Ptr client = make_shared(); - 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(ncea->Client); - RegisterClient(client); - - return 0; -} - -int ConnectionManager::CloseClientHandler(EventArgs::Ptr ea) -{ - JsonRpcClient::Ptr client = static_pointer_cast(ea->Source); - UnregisterClient(client); - - if (client->GetPeerHost() != string()) { - Timer::Ptr timer = make_shared(); - 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(ea->UserArgs->Source); - Timer::Ptr timer = static_pointer_cast(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(nmea->Source); - - map >::iterator i; - i = m_Methods.find(request->GetMethod()); - - if (i == m_Methods.end()) { - JsonRpcMessage::Ptr response = make_shared(); - 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 callback) -{ - m_Methods[method] += callback; -} - -void ConnectionManager::UnregisterMethod(string method, function 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::iterator i = m_Clients.begin(); i != m_Clients.end(); i++) - { - JsonRpcClient::Ptr client = *i; - client->SendMessage(message); - } -} diff --git a/icinga/endpoint.cpp b/icinga/endpoint.cpp new file mode 100644 index 000000000..b7c61b157 --- /dev/null +++ b/icinga/endpoint.cpp @@ -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; +} diff --git a/icinga/endpoint.h b/icinga/endpoint.h new file mode 100644 index 000000000..c02ad6959 --- /dev/null +++ b/icinga/endpoint.h @@ -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 Ptr; + typedef weak_ptr 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 */ diff --git a/icinga/endpointmanager.cpp b/icinga/endpointmanager.cpp new file mode 100644 index 000000000..a4875a9d6 --- /dev/null +++ b/icinga/endpointmanager.cpp @@ -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(); + RegisterServer(server); + + server->MakeSocket(); + server->Bind(port); + server->Listen(); + server->Start(); +} + +void EndpointManager::AddConnection(string host, short port) +{ + JsonRpcClient::Ptr client = make_shared(); + 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(ncea->Client); + RegisterClient(client); + + return 0; +} + +int EndpointManager::CloseClientHandler(EventArgs::Ptr ea) +{ + JsonRpcClient::Ptr client = static_pointer_cast(ea->Source); + UnregisterClient(client); + + if (client->GetPeerHost() != string()) { + Timer::Ptr timer = make_shared(); + 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(ea->UserArgs->Source); + Timer::Ptr timer = static_pointer_cast(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::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++) + { + Endpoint::Ptr endpoint = *i; + + if (endpoint == source) + continue; + + endpoint->SendMessage(source, message); + } + } +} diff --git a/icinga/connectionmanager.h b/icinga/endpointmanager.h similarity index 58% rename from icinga/connectionmanager.h rename to icinga/endpointmanager.h index 2cd2f2fd8..6d0f1f0e6 100644 --- a/icinga/connectionmanager.h +++ b/icinga/endpointmanager.h @@ -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 m_Servers; list m_Clients; - map< string, event > m_Methods; list m_ReconnectTimers; + list 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 Ptr; - typedef weak_ptr WeakPtr; + typedef shared_ptr Ptr; + typedef weak_ptr 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 callback); - void UnregisterMethod(string method, function 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 */ diff --git a/icinga/i2-icinga.h b/icinga/i2-icinga.h index 61d091e8a..cd37106b4 100644 --- a/icinga/i2-icinga.h +++ b/icinga/i2-icinga.h @@ -4,7 +4,16 @@ #include #include -#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 */ diff --git a/icinga/icinga.vcxproj b/icinga/icinga.vcxproj index 748c46120..81cbcd947 100644 --- a/icinga/icinga.vcxproj +++ b/icinga/icinga.vcxproj @@ -40,12 +40,12 @@ true - $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\config;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) false - $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\config;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\jsonrpc;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) @@ -59,7 +59,7 @@ Console true - base.lib;jsonrpc.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies) @@ -77,17 +77,23 @@ true true true - base.lib;jsonrpc.lib;%(AdditionalDependencies) + base.lib;jsonrpc.lib;cJSON.lib;%(AdditionalDependencies) - + + + + - + + + + diff --git a/icinga/icingaapplication.cpp b/icinga/icingaapplication.cpp index e39aaa52d..3ffdae972 100644 --- a/icinga/icingaapplication.cpp +++ b/icinga/icingaapplication.cpp @@ -11,7 +11,7 @@ using namespace icinga; IcingaApplication::IcingaApplication(void) { - m_ConnectionManager = make_shared(); + m_EndpointManager = make_shared(); } int IcingaApplication::Main(const vector& args) @@ -71,9 +71,9 @@ void IcingaApplication::PrintUsage(const string& programPath) cout << "Syntax: " << programPath << " " << 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; } diff --git a/icinga/icingaapplication.h b/icinga/icingaapplication.h index 71b7bbfff..30485b8de 100644 --- a/icinga/icingaapplication.h +++ b/icinga/icingaapplication.h @@ -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& args); + int Main(const vector& args); void PrintUsage(const string& programPath); - virtual ConnectionManager::Ptr GetConnectionManager(void); + EndpointManager::Ptr GetEndpointManager(void); }; } diff --git a/icinga/jsonrpcendpoint.cpp b/icinga/jsonrpcendpoint.cpp new file mode 100644 index 000000000..22bbf7ddb --- /dev/null +++ b/icinga/jsonrpcendpoint.cpp @@ -0,0 +1,3 @@ +#include "i2-icinga.h" + +using namespace icinga; diff --git a/icinga/jsonrpcendpoint.h b/icinga/jsonrpcendpoint.h new file mode 100644 index 000000000..ffced0d14 --- /dev/null +++ b/icinga/jsonrpcendpoint.h @@ -0,0 +1,14 @@ +#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 diff --git a/icinga/virtualendpoint.cpp b/icinga/virtualendpoint.cpp new file mode 100644 index 000000000..c7146d0fc --- /dev/null +++ b/icinga/virtualendpoint.cpp @@ -0,0 +1,48 @@ +#include "i2-icinga.h" + +using namespace icinga; + +VirtualEndpoint::VirtualEndpoint() +{ + SetConnected(true); +} + +void VirtualEndpoint::RegisterMethodHandler(string method, function callback) +{ + m_MethodHandlers[method] += callback; +} + +void VirtualEndpoint::UnregisterMethodHandler(string method, function 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 >::iterator i; + i = m_MethodHandlers.find(message->GetMethod()); + + if (i == m_MethodHandlers.end()) { + JsonRpcMessage::Ptr response = make_shared(); + response->SetVersion("2.0"); + response->SetError("Unknown method."); + response->SetID(message->GetID()); + source->SendMessage(static_pointer_cast(shared_from_this()), response); + } + + NewMessageEventArgs::Ptr nmea = make_shared(); + nmea->Source = shared_from_this(); + nmea->Message = message; + i->second(nmea); +} diff --git a/icinga/virtualendpoint.h b/icinga/virtualendpoint.h new file mode 100644 index 000000000..8c94dc92f --- /dev/null +++ b/icinga/virtualendpoint.h @@ -0,0 +1,30 @@ +#ifndef VIRTUALENDPOINT_H +#define VIRTUALENDPOINT_H + +namespace icinga +{ + +class I2_ICINGA_API VirtualEndpoint : public Endpoint +{ +private: + map< string, event > m_MethodHandlers; + list m_MethodSources; + +public: + typedef shared_ptr Ptr; + typedef weak_ptr WeakPtr; + + VirtualEndpoint(); + + virtual void RegisterMethodHandler(string method, function callback); + virtual void UnregisterMethodHandler(string method, function callback); + + virtual void RegisterMethodSource(string method); + virtual void UnregisterMethodSource(string method); + + virtual void SendMessage(Endpoint::Ptr source, JsonRpcMessage::Ptr message); +}; + +} + +#endif /* VIRTUALENDPOINT_H */ diff --git a/jsonrpc/Makefile.am b/jsonrpc/Makefile.am index 7ec7558c2..bef23d8dd 100644 --- a/jsonrpc/Makefile.am +++ b/jsonrpc/Makefile.am @@ -5,8 +5,6 @@ noinst_LTLIBRARIES = \ libjsonrpc.la libjsonrpc_la_SOURCES = \ - cJSON.c \ - cJSON.h \ i2-jsonrpc.h \ jsonrpcclient.cpp \ jsonrpcclient.h \ diff --git a/jsonrpc/i2-jsonrpc.h b/jsonrpc/i2-jsonrpc.h index 1a2b43110..a9962f22f 100644 --- a/jsonrpc/i2-jsonrpc.h +++ b/jsonrpc/i2-jsonrpc.h @@ -3,8 +3,14 @@ #include #include +#include + +#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" diff --git a/jsonrpc/jsonrpc.vcxproj b/jsonrpc/jsonrpc.vcxproj index 2a321fab9..87cbda58b 100644 --- a/jsonrpc/jsonrpc.vcxproj +++ b/jsonrpc/jsonrpc.vcxproj @@ -11,7 +11,6 @@ - @@ -19,7 +18,6 @@ - @@ -32,12 +30,12 @@ - StaticLibrary + DynamicLibrary true MultiByte - StaticLibrary + DynamicLibrary false true MultiByte @@ -53,11 +51,11 @@ - $(ProjectDir)\..\base;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) - $(ProjectDir)\..\base;$(IncludePath) + $(ProjectDir)\..\base;$(ProjectDir)\..\cJSON;$(IncludePath) $(OutDir);$(LibraryPath) @@ -66,11 +64,12 @@ Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;I2_JSONRPC_BUILD;_DEBUG;_LIB;%(PreprocessorDefinitions) Windows true + base.lib;cJSON.lib;%(AdditionalDependencies) @@ -85,13 +84,14 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;I2_JSONRPC_BUILD;NDEBUG;_LIB;%(PreprocessorDefinitions) Windows true true true + base.lib;cJSON.lib;%(AdditionalDependencies) diff --git a/jsonrpc/jsonrpcclient.h b/jsonrpc/jsonrpcclient.h index ceb13a490..408248fbf 100644 --- a/jsonrpc/jsonrpcclient.h +++ b/jsonrpc/jsonrpcclient.h @@ -4,7 +4,7 @@ namespace icinga { -struct NewMessageEventArgs : public EventArgs +struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs { typedef shared_ptr Ptr; typedef weak_ptr 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); diff --git a/jsonrpc/jsonrpcmessage.h b/jsonrpc/jsonrpcmessage.h index 22056a94f..f6b97f700 100644 --- a/jsonrpc/jsonrpcmessage.h +++ b/jsonrpc/jsonrpcmessage.h @@ -4,7 +4,7 @@ namespace icinga { -class JsonRpcMessage : public Object +class I2_JSONRPC_API JsonRpcMessage : public Object { private: cJSON *m_JSON; diff --git a/jsonrpc/jsonrpcserver.h b/jsonrpc/jsonrpcserver.h index fd84d71aa..b7feb4ea8 100644 --- a/jsonrpc/jsonrpcserver.h +++ b/jsonrpc/jsonrpcserver.h @@ -4,7 +4,7 @@ namespace icinga { -class JsonRpcServer : public TCPServer +class I2_JSONRPC_API JsonRpcServer : public TCPServer { public: typedef shared_ptr Ptr; diff --git a/jsonrpc/netstring.h b/jsonrpc/netstring.h index 6e6f4c3e2..d5c382bd7 100644 --- a/jsonrpc/netstring.h +++ b/jsonrpc/netstring.h @@ -4,7 +4,7 @@ namespace icinga { -class Netstring : public Object +class I2_JSONRPC_API Netstring : public Object { private: size_t m_Length;