]> granicus.if.org Git - icinga2/commitdiff
Cleaned up jsonrpc library.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 15 May 2012 14:24:04 +0000 (16:24 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 15 May 2012 14:29:46 +0000 (16:29 +0200)
Updated documentation.

30 files changed:
base/application.cpp
base/application.h
components/configrpc/configrpccomponent.cpp
components/configrpc/configrpccomponent.h
components/demo/democomponent.cpp
components/discovery/discoverycomponent.cpp
components/discovery/discoverycomponent.h
components/discovery/discoverymessage.h
icinga-app/icinga1.conf
icinga-app/icinga2.conf
icinga-app/icinga3.conf
icinga/endpoint.cpp
icinga/endpoint.h
icinga/endpointmanager.cpp
icinga/endpointmanager.h
icinga/icingaapplication.cpp
icinga/icingaapplication.h
icinga/icingacomponent.h
icinga/jsonrpcendpoint.cpp
icinga/jsonrpcendpoint.h
icinga/virtualendpoint.cpp
icinga/virtualendpoint.h
jsonrpc/Makefile.am
jsonrpc/i2-jsonrpc.h
jsonrpc/jsonrpc.vcxproj
jsonrpc/jsonrpc.vcxproj.filters
jsonrpc/rpcrequest.cpp [moved from jsonrpc/jsonrpcrequest.cpp with 100% similarity]
jsonrpc/rpcrequest.h [moved from jsonrpc/jsonrpcrequest.h with 90% similarity]
jsonrpc/rpcresponse.cpp [moved from jsonrpc/jsonrpcresponse.cpp with 100% similarity]
jsonrpc/rpcresponse.h [moved from jsonrpc/jsonrpcresponse.h with 90% similarity]

index 5e2e4ab109573d85e8838b93e2b75066370de21c..d854169f9cfb81240460fa95670c1c96f924f5dd 100644 (file)
@@ -302,26 +302,6 @@ void Application::Log(string message)
        cout << "[" << timestamp << "]: " << message << endl;
 }
 
-/**
- * Sets the application's command line arguments.
- *
- * @param arguments The arguments.
- */
-void Application::SetArguments(const vector<string>& arguments)
-{
-       m_Arguments = arguments;
-}
-
-/**
- * Retrieves the application's command line arguments.
- *
- * @returns The arguments.
- */
-const vector<string>& Application::GetArguments(void) const
-{
-       return m_Arguments;
-}
-
 /**
  * Retrieves the directory the application's binary is contained in.
  *
@@ -469,20 +449,17 @@ int Application::Run(int argc, char **argv)
        sigaction(SIGPIPE, &sa, NULL);
 #endif /* _WIN32 */
 
-       vector<string> args;
-
+       m_Arguments.clear();
        for (int i = 0; i < argc; i++)
-               args.push_back(string(argv[i]));
-
-       SetArguments(args);
+               m_Arguments.push_back(string(argv[i]));
 
        if (IsDebugging()) {
-               result = Main(args);
+               result = Main(m_Arguments);
 
                Application::Instance.reset();
        } else {
                try {
-                       result = Main(args);
+                       result = Main(m_Arguments);
                } catch (const Exception& ex) {
                        Application::Instance.reset();
 
index 3b3036d68003bba5cc0d291f5d9df0e0c8df8574..f2ddff47669c3cb502c5f56d6723f20796de3c00 100644 (file)
@@ -54,9 +54,6 @@ public:
 
        virtual int Main(const vector<string>& args) = 0;
 
-       void SetArguments(const vector<string>& arguments);
-       const vector<string>& GetArguments(void) const;
-
        void Shutdown(void);
 
        static void Log(string message);
index 86dbd8d1c1712bf2512ac407f15802d76ebcf0c9..1569ef072d80dcfddaedb7559931c7f80c0bb5a0 100644 (file)
@@ -35,22 +35,22 @@ void ConfigRpcComponent::Start(void)
 
        long configSource;
        if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
-               m_ConfigRpcEndpoint->RegisterMethodHandler("config::FetchObjects",
+               m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
                    bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
 
                configHive->OnObjectCommitted += bind_weak(&ConfigRpcComponent::LocalObjectCommittedHandler, shared_from_this());
                configHive->OnObjectRemoved += bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this());
 
-               m_ConfigRpcEndpoint->RegisterMethodSource("config::ObjectCommitted");
-               m_ConfigRpcEndpoint->RegisterMethodSource("config::ObjectRemoved");
+               m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
+               m_ConfigRpcEndpoint->RegisterPublication("config::ObjectRemoved");
        }
 
        endpointManager->OnNewEndpoint += bind_weak(&ConfigRpcComponent::NewEndpointHandler, shared_from_this());
 
-       m_ConfigRpcEndpoint->RegisterMethodSource("config::FetchObjects");
-       m_ConfigRpcEndpoint->RegisterMethodHandler("config::ObjectCommitted",
+       m_ConfigRpcEndpoint->RegisterPublication("config::FetchObjects");
+       m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectCommitted",
            bind_weak(&ConfigRpcComponent::RemoteObjectCommittedHandler, shared_from_this()));
-       m_ConfigRpcEndpoint->RegisterMethodHandler("config::ObjectRemoved",
+       m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectRemoved",
            bind_weak(&ConfigRpcComponent::RemoteObjectRemovedHandler, shared_from_this()));
 
        endpointManager->RegisterEndpoint(m_ConfigRpcEndpoint);
@@ -73,18 +73,18 @@ int ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
 
 int ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
 {
-       JsonRpcRequest request;
+       RpcRequest request;
        request.SetMethod("config::FetchObjects");
 
        Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
-       GetEndpointManager()->SendUnicastRequest(m_ConfigRpcEndpoint, endpoint, request);
+       GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, endpoint, request);
 
        return 0;
 }
 
-JsonRpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
+RpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
 {
-       JsonRpcRequest msg;
+       RpcRequest msg;
        msg.SetMethod(method);
 
        Message params;
@@ -121,9 +121,9 @@ int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
                        if (!ShouldReplicateObject(object))
                                continue;
 
-                       JsonRpcRequest request = MakeObjectMessage(object, "config::ObjectCreated", true);
+                       RpcRequest request = MakeObjectMessage(object, "config::ObjectCreated", true);
 
-                       GetEndpointManager()->SendUnicastRequest(m_ConfigRpcEndpoint, client, request);
+                       GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
                }
        }
 
@@ -137,7 +137,7 @@ int ConfigRpcComponent::LocalObjectCommittedHandler(const EventArgs& ea)
        if (!ShouldReplicateObject(object))
                return 0;
 
-       GetEndpointManager()->SendMulticastRequest(m_ConfigRpcEndpoint,
+       GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
            MakeObjectMessage(object, "config::ObjectCreated", true));
 
        return 0;
@@ -150,7 +150,7 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
        if (!ShouldReplicateObject(object))
                return 0;
 
-       GetEndpointManager()->SendMulticastRequest(m_ConfigRpcEndpoint,
+       GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
            MakeObjectMessage(object, "config::ObjectRemoved", false));
 
        return 0;
@@ -158,7 +158,7 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
 
 int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
 {
-       JsonRpcRequest message = ea.Request;
+       RpcRequest message = ea.Request;
        bool was_null = false;
 
        Message params;
@@ -199,7 +199,7 @@ int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
 
 int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
 {
-       JsonRpcRequest message = ea.Request;
+       RpcRequest message = ea.Request;
        
        Message params;
        if (!message.GetParams(&params))
index 9c367f8866e8f30407657afe9313fc507cfde9fe..b91f646491dbd3bf69f25023e42702e5096ab68a 100644 (file)
@@ -38,7 +38,7 @@ private:
        int RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
        int RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
 
-       static JsonRpcRequest MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties);
+       static RpcRequest MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties);
 
        static bool ShouldReplicateObject(const ConfigObject::Ptr& object);
 public:
index 8fa5748762d05f872226af14f0c60a9d1654765d..560f16885f857cf8362599a53a1134fba10b6930 100644 (file)
@@ -37,9 +37,9 @@ string DemoComponent::GetName(void) const
 void DemoComponent::Start(void)
 {
        m_DemoEndpoint = make_shared<VirtualEndpoint>();
-       m_DemoEndpoint->RegisterMethodHandler("demo::HelloWorld",
+       m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
            bind_weak(&DemoComponent::HelloWorldRequestHandler, shared_from_this()));
-       m_DemoEndpoint->RegisterMethodSource("demo::HelloWorld");
+       m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
 
        EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
        endpointManager->RegisterEndpoint(m_DemoEndpoint);
@@ -73,11 +73,11 @@ int DemoComponent::DemoTimerHandler(const TimerEventArgs&)
 {
        Application::Log("Sending multicast 'hello world' message.");
 
-       JsonRpcRequest request;
+       RpcRequest request;
        request.SetMethod("demo::HelloWorld");
 
        EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
-       endpointManager->SendMulticastRequest(m_DemoEndpoint, request);
+       endpointManager->SendMulticastMessage(m_DemoEndpoint, request);
 
        return 0;
 }
index c6e738e1062efc11c1068966dee961ec942b335f..ce752a217a4fb9144fe69aad4f80586fab79e0f3 100644 (file)
@@ -38,15 +38,15 @@ void DiscoveryComponent::Start(void)
 {
        m_DiscoveryEndpoint = make_shared<VirtualEndpoint>();
 
-       m_DiscoveryEndpoint->RegisterMethodSource("discovery::RegisterComponent");
-       m_DiscoveryEndpoint->RegisterMethodHandler("discovery::RegisterComponent",
+       m_DiscoveryEndpoint->RegisterPublication("discovery::RegisterComponent");
+       m_DiscoveryEndpoint->RegisterTopicHandler("discovery::RegisterComponent",
                bind_weak(&DiscoveryComponent::RegisterComponentMessageHandler, shared_from_this()));
 
-       m_DiscoveryEndpoint->RegisterMethodSource("discovery::NewComponent");
-       m_DiscoveryEndpoint->RegisterMethodHandler("discovery::NewComponent",
+       m_DiscoveryEndpoint->RegisterPublication("discovery::NewComponent");
+       m_DiscoveryEndpoint->RegisterTopicHandler("discovery::NewComponent",
                bind_weak(&DiscoveryComponent::NewComponentMessageHandler, shared_from_this()));
 
-       m_DiscoveryEndpoint->RegisterMethodHandler("discovery::Welcome",
+       m_DiscoveryEndpoint->RegisterTopicHandler("discovery::Welcome",
                bind_weak(&DiscoveryComponent::WelcomeMessageHandler, shared_from_this()));
 
        GetEndpointManager()->ForEachEndpoint(bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
@@ -112,42 +112,16 @@ int DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
        neea.Endpoint->OnIdentityChanged += bind_weak(&DiscoveryComponent::NewIdentityHandler, shared_from_this());
 
        /* accept discovery::RegisterComponent messages from any endpoint */
-       neea.Endpoint->RegisterMethodSource("discovery::RegisterComponent");
+       neea.Endpoint->RegisterPublication("discovery::RegisterComponent");
 
        /* accept discovery::Welcome messages from any endpoint */
-       neea.Endpoint->RegisterMethodSource("discovery::Welcome");
+       neea.Endpoint->RegisterPublication("discovery::Welcome");
 
        return 0;
 }
 
 /**
- * Registers a new message sink for a component.
- *
- * @param nmea Event args for the new message sink.
- * @param info The component registration information.
- * @returns 0
- */
-int DiscoveryComponent::DiscoverySinkHandler(const NewMethodEventArgs& nmea, ComponentDiscoveryInfo::Ptr info) const
-{
-       info->SubscribedMethods.insert(nmea.Method);
-       return 0;
-}
-
-/**
- * Registers a new message source for a component.
- *
- * @param nmea Event args for the new message source.
- * @param info The component registration information.
- * @returns 0
- */
-int DiscoveryComponent::DiscoverySourceHandler(const NewMethodEventArgs& nmea, ComponentDiscoveryInfo::Ptr info) const
-{
-       info->PublishedMethods.insert(nmea.Method);
-       return 0;
-}
-
-/**
- * Registers message sinks/sources in the specified component information object.
+ * Registers message Subscriptions/sources in the specified component information object.
  *
  * @param neea Event arguments for the endpoint.
  * @param info Component information object.
@@ -155,8 +129,16 @@ int DiscoveryComponent::DiscoverySourceHandler(const NewMethodEventArgs& nmea, C
  */
 int DiscoveryComponent::DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const
 {
-       neea.Endpoint->ForEachMethodSink(bind(&DiscoveryComponent::DiscoverySinkHandler, this, _1, info));
-       neea.Endpoint->ForEachMethodSource(bind(&DiscoveryComponent::DiscoverySourceHandler, this, _1, info));
+       Endpoint::ConstTopicIterator i;
+
+       for (i = neea.Endpoint->BeginSubscriptions(); i != neea.Endpoint->EndSubscriptions(); i++) {
+               info->Subscriptions.insert(*i);
+       }
+
+       for (i = neea.Endpoint->BeginPublications(); i != neea.Endpoint->EndPublications(); i++) {
+               info->Publications.insert(*i);
+       }
+
        return 0;
 }
 
@@ -216,7 +198,7 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
 
        // we assume the other component _always_ wants
        // discovery::RegisterComponent messages from us
-       endpoint->RegisterMethodSink("discovery::RegisterComponent");
+       endpoint->RegisterSubscription("discovery::RegisterComponent");
 
        // send a discovery::RegisterComponent message, if the
        // other component is a broker this makes sure
@@ -227,7 +209,7 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
 
        // we assume the other component _always_ wants
        // discovery::NewComponent messages from us
-       endpoint->RegisterMethodSink("discovery::NewComponent");
+       endpoint->RegisterSubscription("discovery::NewComponent");
 
        // send discovery::NewComponent message for ourselves
        SendDiscoveryMessage("discovery::NewComponent", GetEndpointManager()->GetIdentity(), endpoint);
@@ -248,14 +230,14 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
                return 0;
        }
 
-       // register published/subscribed methods for this endpoint
+       // register published/subscribed topics for this endpoint
        ComponentDiscoveryInfo::Ptr info = ic->second;
        set<string>::iterator it;
-       for (it = info->PublishedMethods.begin(); it != info->PublishedMethods.end(); it++)
-               endpoint->RegisterMethodSource(*it);
+       for (it = info->Publications.begin(); it != info->Publications.end(); it++)
+               endpoint->RegisterPublication(*it);
 
-       for (it = info->SubscribedMethods.begin(); it != info->SubscribedMethods.end(); it++)
-               endpoint->RegisterMethodSink(*it);
+       for (it = info->Subscriptions.begin(); it != info->Subscriptions.end(); it++)
+               endpoint->RegisterSubscription(*it);
 
        FinishDiscoverySetup(endpoint);
 
@@ -288,7 +270,7 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
 
 /**
  * Finishes the welcome handshake for a new component
- * by registering message sinks/sources for the component
+ * by registering message Subscriptions/sources for the component
  * and sending a welcome message if necessary.
  *
  * @param endpoint The endpoint to set up.
@@ -300,10 +282,10 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
 
        // we assume the other component _always_ wants
        // discovery::Welcome messages from us
-       endpoint->RegisterMethodSink("discovery::Welcome");
-       JsonRpcRequest request;
+       endpoint->RegisterSubscription("discovery::Welcome");
+       RpcRequest request;
        request.SetMethod("discovery::Welcome");
-       GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, endpoint, request);
+       GetEndpointManager()->SendUnicastMessage(m_DiscoveryEndpoint, endpoint, request);
 
        endpoint->SetSentWelcome(true);
 
@@ -324,7 +306,7 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
  */
 void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, Endpoint::Ptr recipient)
 {
-       JsonRpcRequest request;
+       RpcRequest request;
        request.SetMethod(method);
        
        DiscoveryMessage params;
@@ -333,10 +315,10 @@ void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, En
        params.SetIdentity(identity);
 
        Message subscriptions;
-       params.SetSubscribes(subscriptions);
+       params.SetSubscriptions(subscriptions);
 
        Message publications;
-       params.SetProvides(publications);
+       params.SetPublications(publications);
 
        ComponentDiscoveryInfo::Ptr info;
 
@@ -349,16 +331,16 @@ void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, En
        }
 
        set<string>::iterator i;
-       for (i = info->PublishedMethods.begin(); i != info->PublishedMethods.end(); i++)
+       for (i = info->Publications.begin(); i != info->Publications.end(); i++)
                publications.AddUnnamedPropertyString(*i);
 
-       for (i = info->SubscribedMethods.begin(); i != info->SubscribedMethods.end(); i++)
+       for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
                subscriptions.AddUnnamedPropertyString(*i);
 
        if (recipient)
-               GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, recipient, request);
+               GetEndpointManager()->SendUnicastMessage(m_DiscoveryEndpoint, recipient, request);
        else
-               GetEndpointManager()->SendMulticastRequest(m_DiscoveryEndpoint, request);
+               GetEndpointManager()->SendMulticastMessage(m_DiscoveryEndpoint, request);
 }
 
 bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string messageType, string message)
@@ -419,26 +401,26 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
 
        Endpoint::Ptr endpoint = GetEndpointManager()->GetEndpointByIdentity(identity);
 
-       Message provides;
-       if (message.GetProvides(&provides)) {
+       Message publications;
+       if (message.GetPublications(&publications)) {
                DictionaryIterator i;
-               for (i = provides.GetDictionary()->Begin(); i != provides.GetDictionary()->End(); i++) {
-                       if (trusted || HasMessagePermission(roles, "publish", i->second)) {
-                               info->PublishedMethods.insert(i->second);
+               for (i = publications.GetDictionary()->Begin(); i != publications.GetDictionary()->End(); i++) {
+                       if (trusted || HasMessagePermission(roles, "publications", i->second)) {
+                               info->Publications.insert(i->second);
                                if (endpoint)
-                                       endpoint->RegisterMethodSource(i->second);
+                                       endpoint->RegisterPublication(i->second);
                        }
                }
        }
 
-       Message subscribes;
-       if (message.GetSubscribes(&subscribes)) {
+       Message subscriptions;
+       if (message.GetSubscriptions(&subscriptions)) {
                DictionaryIterator i;
-               for (i = subscribes.GetDictionary()->Begin(); i != subscribes.GetDictionary()->End(); i++) {
-                       if (trusted || HasMessagePermission(roles, "subscribe", i->second)) {
-                               info->SubscribedMethods.insert(i->second);
+               for (i = subscriptions.GetDictionary()->Begin(); i != subscriptions.GetDictionary()->End(); i++) {
+                       if (trusted || HasMessagePermission(roles, "subscriptions", i->second)) {
+                               info->Subscriptions.insert(i->second);
                                if (endpoint)
-                                       endpoint->RegisterMethodSink(i->second);
+                                       endpoint->RegisterSubscription(i->second);
                        }
                }
        }
index 049b916c4881ddb28f7e090d03ae62dd33f395da..ad7f6a0eaa3106c748dc6f9cc59af6f3c72d8168 100644 (file)
@@ -32,8 +32,8 @@ public:
        string Node;
        string Service;
 
-       set<string> SubscribedMethods;
-       set<string> PublishedMethods;
+       set<string> Subscriptions;
+       set<string> Publications;
 
        time_t LastSeen;
 };
@@ -60,8 +60,6 @@ private:
 
        int CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea);
        int DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const;
-       int DiscoverySinkHandler(const NewMethodEventArgs& nmea, ComponentDiscoveryInfo::Ptr info) const;
-       int DiscoverySourceHandler(const NewMethodEventArgs& nmea, ComponentDiscoveryInfo::Ptr info) const;
 
        int DiscoveryTimerHandler(const TimerEventArgs& tea);
 
index ad88e3b930520bb0f39548703852fd4a728da386..f5754092969e2d666ebef6655fcfd01282f41829 100644 (file)
@@ -41,24 +41,24 @@ public:
                SetPropertyString("service", value);
        }
 
-       inline bool GetSubscribes(Message *value) const
+       inline bool GetSubscriptions(Message *value) const
        {
-               return GetPropertyMessage("subscribes", value);
+               return GetPropertyMessage("subscriptions", value);
        }
 
-       inline void SetSubscribes(Message value)
+       inline void SetSubscriptions(Message value)
        {
-               SetPropertyMessage("subscribes", value);
+               SetPropertyMessage("subscriptions", value);
        }
 
-       inline bool GetProvides(Message *value) const
+       inline bool GetPublications(Message *value) const
        {
-               return GetPropertyMessage("provides", value);
+               return GetPropertyMessage("publications", value);
        }
 
-       inline void SetProvides(Message value)
+       inline void SetPublications(Message value)
        {
-               SetPropertyMessage("provides", value);
+               SetPropertyMessage("publications", value);
        }
 };
 
index 6b6a1bafb4bb58ac53c55a56da3c6eff72628531..679874d3ef5d386d821265a675ca1b22e54f2d01 100644 (file)
        },
        "role": {
                "broker": {
-                       "publish": [ "discovery::NewComponent" ]
+                       "publications": [ "discovery::NewComponent" ]
                },
                "demo": {
-                       "publish": [ "demo::*" ],
-                       "subscribe": [ "demo::*" ]
+                       "publications": [ "demo::*" ],
+                       "subscriptions": [ "demo::*" ]
                }
        }
 }
\ No newline at end of file
index c457b86da1aec6e57d1fe78b677a13e42a35cd70..b6e79c99aeb4f20fc567f215b0c3c46f3b709af6 100644 (file)
        },
        "role": {
                "broker": {
-                       "publish": [ "discovery::NewComponent" ]
+                       "publications": [ "discovery::NewComponent" ]
                },
                "demo": {
-                       "publish": [ "demo::*" ],
-                       "subscribe": [ "demo::*" ]
+                       "publications": [ "demo::*" ],
+                       "subscriptions": [ "demo::*" ]
                }
        }
 }
\ No newline at end of file
index c6af6127300b87f211bf3be4e53bbe4a6ceae40f..879a39f22c12dfe524df0285f33692835d319e3d 100644 (file)
        },
        "role": {
                "broker": {
-                       "publish": [ "discovery::NewComponent" ]
+                       "publications": [ "discovery::NewComponent" ]
                },
                "demo": {
-                       "publish": [ "demo::*" ],
-                       "subscribe": [ "demo::*" ]
+                       "publications": [ "demo::*" ],
+                       "subscriptions": [ "demo::*" ]
                }
        }
 }
\ No newline at end of file
index ada9056dee545f8a4f09f1dfeb05e57260276944..e00ffff94e9becfb9b8d2ce54792e43ec428a4f3 100644 (file)
 
 using namespace icinga;
 
+/**
+ * Constructor for the Endpoint class.
+ */
 Endpoint::Endpoint(void)
 {
        m_ReceivedWelcome = false;
        m_SentWelcome = false;
 }
 
+/**
+ * Retrieves the identity of this endpoint.
+ *
+ * @returns The identity of the endpoint.
+ */
 string Endpoint::GetIdentity(void) const
 {
        return m_Identity;
 }
 
+/**
+ * Sets the identity of this endpoint.
+ *
+ * @param identity The new identity of the endpoint.
+ */
 void Endpoint::SetIdentity(string identity)
 {
        m_Identity = identity;
@@ -41,126 +54,179 @@ void Endpoint::SetIdentity(string identity)
        OnIdentityChanged(ea);
 }
 
-bool Endpoint::HasIdentity(void) const
-{
-       return !m_Identity.empty();
-}
-
+/**
+ * Retrieves the endpoint manager this endpoint is registered with.
+ *
+ * @returns The EndpointManager object.
+ */
 EndpointManager::Ptr Endpoint::GetEndpointManager(void) const
 {
        return m_EndpointManager.lock();
 }
 
+/**
+ * Sets the endpoint manager this endpoint is registered with.
+ *
+ * @param manager The EndpointManager object.
+ */
 void Endpoint::SetEndpointManager(EndpointManager::WeakPtr manager)
 {
        m_EndpointManager = manager;
 }
 
-void Endpoint::RegisterMethodSink(string method)
-{
-       m_MethodSinks.insert(method);
-}
-
-void Endpoint::UnregisterMethodSink(string method)
-{
-       m_MethodSinks.erase(method);
-}
-
-bool Endpoint::IsMethodSink(string method) const
-{
-       return (m_MethodSinks.find(method) != m_MethodSinks.end());
-}
-
-void Endpoint::ForEachMethodSink(function<int (const NewMethodEventArgs&)> callback)
-{
-       for (set<string>::iterator i = m_MethodSinks.begin(); i != m_MethodSinks.end(); i++) {
-               NewMethodEventArgs nmea;
-               nmea.Source = shared_from_this();
-               nmea.Method = *i;
-               callback(nmea);
-       }
-}
-
-void Endpoint::RegisterMethodSource(string method)
+/**
+ * Registers a topic subscription for this endpoint.
+ *
+ * @param topic The name of the topic.
+ */
+void Endpoint::RegisterSubscription(string topic)
 {
-       m_MethodSources.insert(method);
+       m_Subscriptions.insert(topic);
 }
 
-void Endpoint::UnregisterMethodSource(string method)
+/**
+ * Removes a topic subscription from this endpoint.
+ *
+ * @param topic The name of the topic.
+ */
+void Endpoint::UnregisterSubscription(string topic)
 {
-       m_MethodSources.erase(method);
+       m_Subscriptions.erase(topic);
 }
 
-bool Endpoint::IsMethodSource(string method) const
+/**
+ * Checks whether the endpoint has a subscription for the specified topic.
+ *
+ * @param topic The name of the topic.
+ * @returns true if the endpoint is subscribed to the topic, false otherwise.
+ */
+bool Endpoint::HasSubscription(string topic) const
 {
-       return (m_MethodSources.find(method) != m_MethodSources.end());
+       return (m_Subscriptions.find(topic) != m_Subscriptions.end());
 }
 
-void Endpoint::ForEachMethodSource(function<int (const NewMethodEventArgs&)> callback)
+/**
+ * Registers a topic publication for this endpoint.
+ *
+ * @param topic The name of the topic.
+ */
+void Endpoint::RegisterPublication(string topic)
 {
-       for (set<string>::iterator i = m_MethodSources.begin(); i != m_MethodSources.end(); i++) {
-               NewMethodEventArgs nmea;
-               nmea.Source = shared_from_this();
-               nmea.Method = *i;
-               callback(nmea);
-       }
+       m_Publications.insert(topic);
 }
 
-void Endpoint::ClearMethodSinks(void)
+/**
+ * Removes a topic publication from this endpoint.
+ *
+ * @param topic The name of the topic.
+ */
+void Endpoint::UnregisterPublication(string topic)
 {
-       m_MethodSinks.clear();
+       m_Publications.erase(topic);
 }
 
-void Endpoint::ClearMethodSources(void)
+/**
+ * Checks whether the endpoint  has a publication for the specified topic.
+ *
+ * @param topic The name of the topic.
+ * @returns true if the endpoint is publishing this topic, false otherwise.
+ */
+bool Endpoint::HasPublication(string topic) const
 {
-       m_MethodSources.clear();
+       return (m_Publications.find(topic) != m_Publications.end());
 }
 
-int Endpoint::CountMethodSinks(void) const
+/**
+ * Removes all subscriptions for the endpoint.
+ */
+void Endpoint::ClearSubscriptions(void)
 {
-       return m_MethodSinks.size();
+       m_Subscriptions.clear();
 }
 
-int Endpoint::CountMethodSources(void) const
+/**
+ * Removes all publications for the endpoint.
+ */
+void Endpoint::ClearPublications(void)
 {
-       return m_MethodSources.size();
+       m_Publications.clear();
 }
 
-set<string>::const_iterator Endpoint::BeginSinks(void) const
+/**
+ * Returns the beginning of the subscriptions list.
+ *
+ * @returns An iterator that points to the first subscription.
+ */
+Endpoint::ConstTopicIterator Endpoint::BeginSubscriptions(void) const
 {
-       return m_MethodSinks.begin();
+       return m_Subscriptions.begin();
 }
 
-set<string>::const_iterator Endpoint::EndSinks(void) const
+/**
+ * Returns the end of the subscriptions list.
+ *
+ * @returns An iterator that points past the last subscription.
+ */
+Endpoint::ConstTopicIterator Endpoint::EndSubscriptions(void) const
 {
-       return m_MethodSinks.end();
+       return m_Subscriptions.end();
 }
 
-set<string>::const_iterator Endpoint::BeginSources(void) const
+/**
+ * Returns the beginning of the publications list.
+ *
+ * @returns An iterator that points to the first publication.
+ */
+Endpoint::ConstTopicIterator Endpoint::BeginPublications(void) const
 {
-       return m_MethodSources.begin();
+       return m_Publications.begin();
 }
 
-set<string>::const_iterator Endpoint::EndSources(void) const
+/**
+ * Returns the end of the publications list.
+ *
+ * @returns An iterator that points past the last publication.
+ */
+Endpoint::ConstTopicIterator Endpoint::EndPublications(void) const
 {
-       return m_MethodSources.end();
+       return m_Publications.end();
 }
 
+/**
+ * Sets whether a welcome message has been received from this endpoint.
+ *
+ * @param value Whether we've received a welcome message.
+ */
 void Endpoint::SetReceivedWelcome(bool value)
 {
        m_ReceivedWelcome = value;
 }
 
+/**
+ * Retrieves whether a welcome message has been received from this endpoint.
+ *
+ * @returns Whether we've received a welcome message.
+ */
 bool Endpoint::GetReceivedWelcome(void) const
 {
        return m_ReceivedWelcome;
 }
 
+/**
+ * Sets whether a welcome message has been sent to this endpoint.
+ *
+ * @param value Whether we've sent a welcome message.
+ */
 void Endpoint::SetSentWelcome(bool value)
 {
        m_SentWelcome = value;
 }
 
+/**
+ * Retrieves whether a welcome message has been sent to this endpoint.
+ *
+ * @returns Whether we've sent a welcome message.
+ */
 bool Endpoint::GetSentWelcome(void) const
 {
        return m_SentWelcome;
index 9aec18e5bce574aa035dc880bfb71c1bb6053380..71939675ad28f96d6c89caba6b305ad0b9179ee3 100644 (file)
@@ -25,33 +25,38 @@ namespace icinga
 
 class EndpointManager;
 
-struct I2_ICINGA_API NewMethodEventArgs : public EventArgs
-{
-       string Method;
-};
-
+/**
+ * An endpoint that can be used to send and receive messages.
+ */
 class I2_ICINGA_API Endpoint : public Object
 {
 private:
-       string m_Identity;
-       set<string> m_MethodSinks;
-       set<string> m_MethodSources;
-       bool m_ReceivedWelcome;
-       bool m_SentWelcome;
-
-       weak_ptr<EndpointManager> m_EndpointManager;
+       string m_Identity; /**< The identity of this endpoint. */
+       set<string> m_Subscriptions; /**< The topics this endpoint is
+                                         subscribed to. */
+       set<string> m_Publications; /**< The topics this endpoint is
+                                        publishing. */
+       bool m_ReceivedWelcome; /**< Have we received a welcome message
+                                    from this endpoint? */
+       bool m_SentWelcome; /**< Have we sent a welcome message to this
+                                endpoint? */
+
+       weak_ptr<EndpointManager> m_EndpointManager; /**< The endpoint manager
+                                                         this endpoint is
+                                                         registered with. */
 
 public:
        typedef shared_ptr<Endpoint> Ptr;
        typedef weak_ptr<Endpoint> WeakPtr;
 
+       typedef set<string>::const_iterator ConstTopicIterator;
+
        Endpoint(void);
 
        virtual string GetAddress(void) const = 0;
 
        string GetIdentity(void) const;
        void SetIdentity(string identity);
-       bool HasIdentity(void) const;
 
        void SetReceivedWelcome(bool value);
        bool GetReceivedWelcome(void) const;
@@ -62,39 +67,30 @@ public:
        shared_ptr<EndpointManager> GetEndpointManager(void) const;
        void SetEndpointManager(weak_ptr<EndpointManager> manager);
 
-       void RegisterMethodSink(string method);
-       void UnregisterMethodSink(string method);
-       bool IsMethodSink(string method) const;
+       void RegisterSubscription(string topic);
+       void UnregisterSubscription(string topic);
+       bool HasSubscription(string topic) const;
 
-       void RegisterMethodSource(string method);
-       void UnregisterMethodSource(string method);
-       bool IsMethodSource(string method) const;
+       void RegisterPublication(string topic);
+       void UnregisterPublication(string topic);
+       bool HasPublication(string topic) const;
 
        virtual bool IsLocal(void) const = 0;
        virtual bool IsConnected(void) const = 0;
 
-       virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message) = 0;
-       virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message) = 0;
+       virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message) = 0;
+       virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message) = 0;
 
        virtual void Stop(void) = 0;
 
-       Event<NewMethodEventArgs> OnNewMethodSink;
-       Event<NewMethodEventArgs> OnNewMethodSource;
-
-       void ForEachMethodSink(function<int (const NewMethodEventArgs&)> callback);
-       void ForEachMethodSource(function<int (const NewMethodEventArgs&)> callback);
-
-       void ClearMethodSinks(void);
-       void ClearMethodSources(void);
-
-       int CountMethodSinks(void) const;
-       int CountMethodSources(void) const;
+       void ClearSubscriptions(void);
+       void ClearPublications(void);
 
-       set<string>::const_iterator BeginSinks(void) const;
-       set<string>::const_iterator EndSinks(void) const;
+       ConstTopicIterator BeginSubscriptions(void) const;
+       ConstTopicIterator EndSubscriptions(void) const;
 
-       set<string>::const_iterator BeginSources(void) const;
-       set<string>::const_iterator EndSources(void) const;
+       ConstTopicIterator BeginPublications(void) const;
+       ConstTopicIterator EndPublications(void) const;
 
        Event<EventArgs> OnIdentityChanged;
        Event<EventArgs> OnSessionEstablished;
index 3a20120956fd24803a79adb98fa82da1d629d741..11f88e1c25b9bb824bd0f38f2b104e5a3422a5f2 100644 (file)
 
 using namespace icinga;
 
+/**
+ * Sets the identity of the endpoint manager. This identity is used when
+ * connecting to remote peers.
+ *
+ * @param identity The new identity.
+ */
 void EndpointManager::SetIdentity(string identity)
 {
        m_Identity = identity;
 }
 
+/**
+ * Retrieves the identity for the endpoint manager.
+ *
+ * @returns The identity.
+ */
 string EndpointManager::GetIdentity(void) const
 {
        return m_Identity;
 }
 
+/**
+ * Sets the SSL context that is used for remote connections.
+ *
+ * @param sslContext The new SSL context.
+ */
 void EndpointManager::SetSSLContext(shared_ptr<SSL_CTX> sslContext)
 {
        m_SSLContext = sslContext;
 }
 
+/**
+ * Retrieves the SSL context that is used for remote connections.
+ *
+ * @returns The SSL context.
+ */
 shared_ptr<SSL_CTX> EndpointManager::GetSSLContext(void) const
 {
        return m_SSLContext;
 }
 
+/**
+ * Creates a new JSON-RPC listener on the specified port.
+ *
+ * @param service The name of the service to listen on (@see getaddrinfo).
+ */
 void EndpointManager::AddListener(string service)
 {
        if (!GetSSLContext())
@@ -58,6 +84,12 @@ void EndpointManager::AddListener(string service)
        server->Start();
 }
 
+/**
+ * Creates a new JSON-RPC client and connects to the specified host and port.
+ *
+ * @param node The remote host (@see getaddrinfo).
+ * @param service The remote port (@see getaddrinfo).
+ */
 void EndpointManager::AddConnection(string node, string service)
 {
        stringstream s;
@@ -69,12 +101,22 @@ void EndpointManager::AddConnection(string node, string service)
        endpoint->Connect(node, service, m_SSLContext);
 }
 
+/**
+ * Registers a new JSON-RPC server with this endpoint manager.
+ *
+ * @param server The JSON-RPC server.
+ */
 void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
 {
        m_Servers.push_back(server);
        server->OnNewClient += bind_weak(&EndpointManager::NewClientHandler, shared_from_this());
 }
 
+/**
+ * Processes a new client connection.
+ *
+ * @param ncea Event arguments.
+ */
 int EndpointManager::NewClientHandler(const NewClientEventArgs& ncea)
 {
        string address = ncea.Client->GetPeerAddress();
@@ -87,6 +129,11 @@ int EndpointManager::NewClientHandler(const NewClientEventArgs& ncea)
        return 0;
 }
 
+/**
+ * Unregisters a JSON-RPC server.
+ *
+ * @param server The JSON-RPC server.
+ */
 void EndpointManager::UnregisterServer(JsonRpcServer::Ptr server)
 {
        m_Servers.erase(
@@ -95,6 +142,11 @@ void EndpointManager::UnregisterServer(JsonRpcServer::Ptr server)
        // TODO: unbind event
 }
 
+/**
+ * Registers a new endpoint with this endpoint manager.
+ *
+ * @param endpoint The new endpoint.
+ */
 void EndpointManager::RegisterEndpoint(Endpoint::Ptr endpoint)
 {
        if (!endpoint->IsLocal() && endpoint->GetIdentity() != "")
@@ -109,6 +161,11 @@ void EndpointManager::RegisterEndpoint(Endpoint::Ptr endpoint)
        OnNewEndpoint(neea);
 }
 
+/**
+ * Unregisters an endpoint.
+ *
+ * @param endpoint The endpoint.
+ */
 void EndpointManager::UnregisterEndpoint(Endpoint::Ptr endpoint)
 {
        m_Endpoints.erase(
@@ -116,48 +173,68 @@ void EndpointManager::UnregisterEndpoint(Endpoint::Ptr endpoint)
            m_Endpoints.end());
 }
 
-void EndpointManager::SendUnicastRequest(Endpoint::Ptr sender, Endpoint::Ptr recipient, const JsonRpcRequest& request, bool fromLocal)
+/**
+ * Sends a unicast message to the specified recipient.
+ *
+ * @param sender The sender of the message.
+ * @param recipient The recipient of the message.
+ * @param message The request.
+ */
+void EndpointManager::SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const Message& message)
 {
+       /* don't forward messages back to the sender */
        if (sender == recipient)
                return;
 
        /* don't forward messages between non-local endpoints */
-       if (!fromLocal && !recipient->IsLocal())
+       if (!sender->IsLocal() && !recipient->IsLocal())
                return;
 
-       string method;
-       if (!request.GetMethod(&method))
-               throw InvalidArgumentException("Missing 'method' parameter.");
-
-       if (recipient->IsMethodSink(method)) {
-               //Application::Log(sender->GetAddress() + " -> " + recipient->GetAddress() + ": " + method);
-               recipient->ProcessRequest(sender, request);
-       }
+       recipient->ProcessRequest(sender, message);
 }
 
-void EndpointManager::SendAnycastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal)
+/**
+ * Sends a message to exactly one recipient out of all recipients who have a
+ * subscription for the message's topic.
+ *
+ * @param sender The sender of the message.
+ * @param message The message.
+ */
+void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest& message)
 {
        throw NotImplementedException();
 }
 
-void EndpointManager::SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal)
+/**
+ * Sends a message to all recipients who have a subscription for the
+ * message's topic.
+ *
+ * @param sender The sender of the message.
+ * @param message The message.
+ */
+void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender, const RpcRequest& message)
 {
-#ifdef _DEBUG
        string id;
-       if (request.GetID(&id))
+       if (message.GetID(&id))
                throw InvalidArgumentException("Multicast requests must not have an ID.");
-#endif /* _DEBUG */
 
        string method;
-       if (!request.GetMethod(&method))
+       if (!message.GetMethod(&method))
                throw InvalidArgumentException("Message is missing the 'method' property.");
 
        for (vector<Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
        {
-               SendUnicastRequest(sender, *i, request, fromLocal);
+               Endpoint::Ptr recipient = *i;
+               if (recipient->HasSubscription(method))
+                       SendUnicastMessage(sender, recipient, message);
        }
 }
 
+/**
+ * Calls the specified callback function for each registered endpoint.
+ *
+ * @param callback The callback function.
+ */
 void EndpointManager::ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback)
 {
        NewEndpointEventArgs neea;
@@ -173,6 +250,11 @@ void EndpointManager::ForEachEndpoint(function<int (const NewEndpointEventArgs&)
        }
 }
 
+/**
+ * Retrieves an endpoint that has the specified identity.
+ *
+ * @param identity The identity of the endpoint.
+ */
 Endpoint::Ptr EndpointManager::GetEndpointByIdentity(string identity) const
 {
        vector<Endpoint::Ptr>::const_iterator i;
index b866a83f8f13d0b7c36960df93055154c7cf5433..816c1f9e01e619def8ab0ea301832bc84706aa6f 100644 (file)
 namespace icinga
 {
 
+/**
+ * Event arguments for the "new endpoint registered" event.
+ */
 struct I2_ICINGA_API NewEndpointEventArgs : public EventArgs
 {
-       icinga::Endpoint::Ptr Endpoint;
+       icinga::Endpoint::Ptr Endpoint; /**< The new endpoint. */
 };
 
+/**
+ * Forwards messages between endpoints.
+ */
 class I2_ICINGA_API EndpointManager : public Object
 {
        string m_Identity;
@@ -57,9 +63,9 @@ public:
        void RegisterEndpoint(Endpoint::Ptr endpoint);
        void UnregisterEndpoint(Endpoint::Ptr endpoint);
 
-       void SendUnicastRequest(Endpoint::Ptr sender, Endpoint::Ptr recipient, const JsonRpcRequest& request, bool fromLocal = true);
-       void SendAnycastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal = true);
-       void SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRequest& request, bool fromLocal = true);
+       void SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const Message& message);
+       void SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest& message);
+       void SendMulticastMessage(Endpoint::Ptr sender, const RpcRequest& message);
 
        void ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback);
 
index c515cade3854e8e2b9e29573a3f1bb2f6a306285..b029c9aa86ebe77d91c49313ad934d9acafd60f2 100644 (file)
 
 using namespace icinga;
 
+/**
+ * The entry point for the Icinga application.
+ *
+ * @param args Command-line arguments.
+ * @returns An exit status.
+ */
 int IcingaApplication::Main(const vector<string>& args)
 {
 #ifdef _WIN32
@@ -37,7 +43,7 @@ int IcingaApplication::Main(const vector<string>& args)
 #endif  /* _WIN32 */
 
        if (args.size() < 2) {
-               PrintUsage(args[0]);
+               cout << "Syntax: " << args[0] << " <config-file>" << endl;
                return EXIT_FAILURE;
        }
 
@@ -87,11 +93,11 @@ int IcingaApplication::Main(const vector<string>& args)
        return EXIT_SUCCESS;
 }
 
-void IcingaApplication::PrintUsage(const string& programPath)
-{
-       cout << "Syntax: " << programPath << " <config-file>" << endl;
-}
-
+/**
+ * Retrieves Icinga's endpoint manager.
+ *
+ * @returns The endpoint manager.
+ */
 EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
 {
        return m_EndpointManager;
index 9901b20b82f254ce98105ad6f724aa71a7132564..15f903e83dd688acf82a15f1d3f10a30bf57f025 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * The Icinga application.
+ */
 class I2_ICINGA_API IcingaApplication : public Application
 {
 private:
@@ -54,8 +57,6 @@ public:
 
        int Main(const vector<string>& args);
 
-       void PrintUsage(const string& programPath);
-
        EndpointManager::Ptr GetEndpointManager(void);
 
        void SetPrivateKeyFile(string privkey);
index 8275c65d8fa6efa045adee60977fb9ac708684a0..06745ac92eb677a6efb845c22e57205fb42720d4 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * A component that can be loaded into the Icinga application at run-time.
+ */
 class I2_ICINGA_API IcingaComponent : public Component
 {
 protected:
index 2c4421c167a6d4e3abefadd08da65fc2a415e3d6..9491c34972c31a3d548c8f56726364d62dd00520 100644 (file)
@@ -61,7 +61,7 @@ bool JsonRpcEndpoint::IsConnected(void) const
        return (bool)m_Client;
 }
 
-void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message)
+void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message)
 {
        if (IsConnected()) {
                string id;
@@ -75,7 +75,7 @@ void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest&
        }
 }
 
-void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message)
+void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message)
 {
        if (IsConnected())
                m_Client->SendMessage(message);
@@ -88,18 +88,18 @@ int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
 
        string method;
        if (message.GetPropertyString("method", &method)) {
-               if (!IsMethodSource(method))
+               if (!HasPublication(method))
                        return 0;
 
-               JsonRpcRequest request = message;
+               RpcRequest request = message;
 
                string id;
                if (request.GetID(&id))
-                       GetEndpointManager()->SendAnycastRequest(sender, request, false);
+                       GetEndpointManager()->SendAnycastMessage(sender, request);
                else
-                       GetEndpointManager()->SendMulticastRequest(sender, request, false);
+                       GetEndpointManager()->SendMulticastMessage(sender, request);
        } else {
-               JsonRpcResponse response = message;
+               RpcResponse response = message;
 
                // TODO: deal with response messages
                throw NotImplementedException();
@@ -114,12 +114,13 @@ int JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
 
        m_PendingCalls.clear();
 
-       // TODO: _only_ clear non-persistent method sources/sinks
-       // unregister ourselves if no persistent sources/sinks are left (use a timer for that, once we have a TTL property for the methods)
-       ClearMethodSinks();
-       ClearMethodSources();
+       // TODO: _only_ clear non-persistent publications/subscriptions
+       // unregister ourselves if no persistent publications/subscriptions are left (use a timer for that, once we have a TTL property for the topics)
+       ClearSubscriptions();
+       ClearPublications();
 
-       if (CountMethodSinks() == 0)
+       // remove the endpoint if there are no more subscriptions */
+       if (BeginSubscriptions() == EndSubscriptions())
                GetEndpointManager()->UnregisterEndpoint(static_pointer_cast<Endpoint>(shared_from_this()));
 
        m_Client.reset();
index 849ac1de8997c56fac53f848bd2e8dcb34bfc735..5bf74de71b3d3da9e368f85cca1b64f3e1e10c8d 100644 (file)
@@ -23,6 +23,9 @@
 namespace icinga
 {
 
+/**
+ * A JSON-RPC endpoint that can be used to communicate with a remote
+ * Icinga instance. */
 class I2_ICINGA_API JsonRpcEndpoint : public Endpoint
 {
 private:
@@ -52,8 +55,8 @@ public:
        virtual bool IsLocal(void) const;
        virtual bool IsConnected(void) const;
 
-       virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
-       virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);
+       virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message);
+       virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message);
 
        virtual void Stop(void);
 };
index 4bca79d42682e16241aead3482ab2c8180d922d0..d36426b09329b680f0d71440cb4dd8eefefa1eee 100644 (file)
@@ -38,31 +38,31 @@ bool VirtualEndpoint::IsConnected(void) const
        return true;
 }
 
-void VirtualEndpoint::RegisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
+void VirtualEndpoint::RegisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback)
 {
-       m_MethodHandlers[method] += callback;
+       m_TopicHandlers[topic] += callback;
 
-       RegisterMethodSink(method);
+       RegisterSubscription(topic);
 }
 
-void VirtualEndpoint::UnregisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
+void VirtualEndpoint::UnregisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback)
 {
        // TODO: implement
-       //m_MethodHandlers[method] -= callback;
-       //UnregisterMethodSink(method);
+       //m_TopicHandlers[method] -= callback;
+       //UnregisterMethodSubscription(method);
 
        throw NotImplementedException();
 }
 
-void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& request)
+void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& request)
 {
        string method;
        if (!request.GetMethod(&method))
                return;
 
-       map<string, Event<NewRequestEventArgs> >::iterator i = m_MethodHandlers.find(method);
+       map<string, Event<NewRequestEventArgs> >::iterator i = m_TopicHandlers.find(method);
 
-       if (i == m_MethodHandlers.end())
+       if (i == m_TopicHandlers.end())
                return;
 
        NewRequestEventArgs nrea;
@@ -72,7 +72,7 @@ void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest&
        i->second(nrea);
 }
 
-void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& response)
+void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const RpcResponse& response)
 {
        // TODO: figure out which request this response belongs to and notify the caller
        throw NotImplementedException();
index 173eef6be32d8815ffac4bc635f3cafd40c2e8ba..c7774d5560cd5a67927f521e6ccb81d3073cd164 100644 (file)
@@ -29,28 +29,31 @@ struct I2_ICINGA_API NewRequestEventArgs : public EventArgs
        typedef weak_ptr<NewRequestEventArgs> WeakPtr;
 
        Endpoint::Ptr Sender;
-       JsonRpcRequest Request;
+       RpcRequest Request;
 };
 
+/**
+ * A local endpoint.
+ */
 class I2_ICINGA_API VirtualEndpoint : public Endpoint
 {
 private:
-       map< string, Event<NewRequestEventArgs> > m_MethodHandlers;
+       map< string, Event<NewRequestEventArgs> > m_TopicHandlers;
 
 public:
        typedef shared_ptr<VirtualEndpoint> Ptr;
        typedef weak_ptr<VirtualEndpoint> WeakPtr;
 
-       void RegisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback);
-       void UnregisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback);
+       void RegisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback);
+       void UnregisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback);
 
        virtual string GetAddress(void) const;
 
        virtual bool IsLocal(void) const;
        virtual bool IsConnected(void) const;
 
-       virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
-       virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);
+       virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message);
+       virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message);
 
        virtual void Stop(void);
 };
index 3f1210a5afe9882385c9ed3c3e6b2e944ca76c91..fb2f02ff4c3ee75e346653b4051ef826c49d01ec 100644 (file)
@@ -8,16 +8,16 @@ libjsonrpc_la_SOURCES = \
        i2-jsonrpc.h \
        jsonrpcclient.cpp \
        jsonrpcclient.h \
-       jsonrpcrequest.cpp \
-       jsonrpcrequest.h \
-       jsonrpcresponse.cpp \
-       jsonrpcresponse.h \
        jsonrpcserver.cpp \
        jsonrpcserver.h \
        message.cpp \
        message.h \
        netstring.cpp \
-       netstring.h
+       netstring.h \
+       rpcrequest.cpp \
+       rpcrequest.h \
+       rpcresponse.cpp \
+       rpcresponse.h
 
 libjsonrpc_la_CXXFLAGS = \
        -DI2_JSONRPC_BUILD \
index 5ddc0e6020a62f6724d4e038e148b812f6c0e2a7..e5fffaf37d75d98e39ee77523586b93af1bcc884 100644 (file)
@@ -32,9 +32,9 @@
 #include "variant.h"
 #include "dictionary.h"
 #include "message.h"
+#include "rpcrequest.h"
+#include "rpcresponse.h"
 #include "netstring.h"
-#include "jsonrpcrequest.h"
-#include "jsonrpcresponse.h"
 #include "jsonrpcclient.h"
 #include "jsonrpcserver.h"
 
index 1eaa212b975eccd83de76ff2ff4f86cb9203fe92..a5464f8e59acc1e23e81d6b7c5b659a37053eabd 100644 (file)
   <ItemGroup>
     <ClInclude Include="i2-jsonrpc.h" />
     <ClInclude Include="jsonrpcclient.h" />
-    <ClInclude Include="jsonrpcrequest.h" />
-    <ClInclude Include="jsonrpcresponse.h" />
+    <ClInclude Include="rpcrequest.h" />
+    <ClInclude Include="rpcresponse.h" />
     <ClInclude Include="jsonrpcserver.h" />
     <ClInclude Include="message.h" />
     <ClInclude Include="netstring.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="jsonrpcclient.cpp" />
-    <ClCompile Include="jsonrpcrequest.cpp" />
-    <ClCompile Include="jsonrpcresponse.cpp" />
+    <ClCompile Include="rpcrequest.cpp" />
+    <ClCompile Include="rpcresponse.cpp" />
     <ClCompile Include="jsonrpcserver.cpp" />
     <ClCompile Include="message.cpp" />
     <ClCompile Include="netstring.cpp" />
index 6e33d294285c5e6a9d6ccffffcbf47b11f83f1e5..3b8eec49688b2a53077473ca9bcfe6dedf52fb05 100644 (file)
@@ -5,8 +5,8 @@
     <ClCompile Include="jsonrpcserver.cpp" />
     <ClCompile Include="message.cpp" />
     <ClCompile Include="netstring.cpp" />
-    <ClCompile Include="jsonrpcrequest.cpp" />
-    <ClCompile Include="jsonrpcresponse.cpp" />
+    <ClCompile Include="rpcrequest.cpp" />
+    <ClCompile Include="rpcresponse.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="i2-jsonrpc.h" />
@@ -14,7 +14,7 @@
     <ClInclude Include="jsonrpcserver.h" />
     <ClInclude Include="message.h" />
     <ClInclude Include="netstring.h" />
-    <ClInclude Include="jsonrpcrequest.h" />
-    <ClInclude Include="jsonrpcresponse.h" />
+    <ClInclude Include="rpcrequest.h" />
+    <ClInclude Include="rpcresponse.h" />
   </ItemGroup>
 </Project>
\ No newline at end of file
similarity index 90%
rename from jsonrpc/jsonrpcrequest.h
rename to jsonrpc/rpcrequest.h
index 90d1b9a15b797851cb3e70df3dc8bf7a96a01773..a7d11a898ab33562ba12fe565c60713b6a8371f4 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef JSONRPCREQUEST_H
-#define JSONRPCREQUEST_H
+#ifndef RpcRequest_H
+#define RpcRequest_H
 
 namespace icinga
 {
 
-class I2_JSONRPC_API JsonRpcRequest : public Message
+class I2_JSONRPC_API RpcRequest : public Message
 {
 
 public:
-       JsonRpcRequest(void) : Message() {
+       RpcRequest(void) : Message() {
                SetVersion("2.0");
        }
 
-       JsonRpcRequest(const Message& message) : Message(message) { }
+       RpcRequest(const Message& message) : Message(message) { }
 
        inline bool GetVersion(string *value) const
        {
@@ -76,4 +76,4 @@ public:
 
 }
 
-#endif /* JSONRPCREQUEST_H */
+#endif /* RpcRequest_H */
similarity index 90%
rename from jsonrpc/jsonrpcresponse.h
rename to jsonrpc/rpcresponse.h
index db255685888fd57e7b2a3d8ea7628cc8afa33d00..199a67445e0b57447e671abb3d43a013a2d39b08 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef JSONRPCRESPONSE_H
-#define JSONRPCRESPONSE_H
+#ifndef RpcResponse_H
+#define RpcResponse_H
 
 namespace icinga
 {
 
-class I2_JSONRPC_API JsonRpcResponse : public Message
+class I2_JSONRPC_API RpcResponse : public Message
 {
 public:
-       JsonRpcResponse(void) : Message() {
+       RpcResponse(void) : Message() {
                SetVersion("2.0");
        }
 
-       JsonRpcResponse(const Message& message) : Message(message) { }
+       RpcResponse(const Message& message) : Message(message) { }
 
        inline bool GetVersion(string *value) const
        {
@@ -75,4 +75,4 @@ public:
 
 }
 
-#endif /* JSONRPCRESPONSE_H */
+#endif /* RpcResponse_H */