]> granicus.if.org Git - icinga2/commitdiff
Win32: added handler for Ctrl-C
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 21 May 2012 10:53:38 +0000 (12:53 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 21 May 2012 10:54:28 +0000 (12:54 +0200)
Removed unused code from the Component class
Added accessor function for Application::Instance

32 files changed:
Doxyfile.in
base/application.cpp
base/application.h
base/component.cpp
base/component.h
base/confighive.cpp
base/confighive.h
base/object.h
base/socket.cpp
base/timer.cpp
components/configfile/configfilecomponent.cpp
components/configrpc/configrpccomponent.cpp
components/configrpc/configrpccomponent.h
components/demo/democomponent.cpp
components/discovery/discoverycomponent.cpp
icinga/endpoint.h
icinga/endpointmanager.cpp
icinga/endpointmanager.h
icinga/icingacomponent.cpp
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/messagepart.cpp
jsonrpc/requestmessage.cpp [moved from jsonrpc/rpcrequest.cpp with 100% similarity]
jsonrpc/requestmessage.h [moved from jsonrpc/rpcrequest.h with 90% similarity]
jsonrpc/responsemessage.cpp [moved from jsonrpc/rpcresponse.cpp with 100% similarity]
jsonrpc/responsemessage.h [moved from jsonrpc/rpcresponse.h with 90% similarity]

index 6cfe8cf368e1ce9d3144d5bdcbd367e968b6d558..914126ca6b9ffd99c917e88cf41de7fc1ac47a71 100644 (file)
@@ -1210,7 +1210,7 @@ SERVER_BASED_SEARCH    = NO
 # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
 # generate Latex output.
 
-GENERATE_LATEX         = NO
+GENERATE_LATEX         = YES
 
 # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
 # If a relative path is entered the value of OUTPUT_DIRECTORY will be
index 5ed95f8956b3af7ff265213e2d323e3134d1ede5..a25279f2d7e9ab0e6687107da1bc29639af8fb9d 100644 (file)
@@ -25,7 +25,7 @@
 
 using namespace icinga;
 
-Application::Ptr I2_EXPORT Application::Instance;
+Application::Ptr I2_EXPORT Application::m_Instance;
 
 /**
  * Constructor for the Application class.
@@ -74,6 +74,16 @@ Application::~Application(void)
 #endif /* _WIN32 */
 }
 
+/**
+ * Retrieves a pointer to the application singleton object.
+ *
+ * @returns The application object.
+ */
+Application::Ptr Application::GetInstance(void)
+{
+       return m_Instance;
+}
+
 /**
  * Processes events for registered sockets and timers and calls whatever
  * handlers have been set up for these events.
@@ -246,7 +256,6 @@ Component::Ptr Application::LoadComponent(const string& path,
  */
 void Application::RegisterComponent(Component::Ptr component)
 {
-       component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
        m_Components[component->GetName()] = component;
 
        component->Start();
@@ -418,13 +427,24 @@ void Application::SigIntHandler(int signum)
 {
        assert(signum == SIGINT);
 
-       Application::Instance->Shutdown();
+       Application::GetInstance()->Shutdown();
 
        struct sigaction sa;
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = SIG_DFL;
        sigaction(SIGINT, &sa, NULL);
 }
+#else /* _WIN32 */
+/**
+ * Console control handler. Prepares the application for cleanly
+ * shutting down during the next execution of the event loop.
+ */
+BOOL WINAPI Application::CtrlHandler(DWORD type)
+{
+       Application::GetInstance()->Shutdown();
+       SetConsoleCtrlHandler(NULL, FALSE);
+       return TRUE;
+}
 #endif /* _WIN32 */
 
 /**
@@ -438,17 +458,19 @@ int Application::Run(int argc, char **argv)
 {
        int result;
 
-       assert(!Application::Instance);
-       Application::Instance = static_pointer_cast<Application>(shared_from_this());
+       assert(!Application::m_Instance);
+       Application::m_Instance = static_pointer_cast<Application>(shared_from_this());
 
 #ifndef _WIN32
        struct sigaction sa;
        memset(&sa, 0, sizeof(sa));
-       sa.sa_handler = Application::SigIntHandler;
+       sa.sa_handler = &Application::SigIntHandler;
        sigaction(SIGINT, &sa, NULL);
 
        sa.sa_handler = SIG_IGN;
        sigaction(SIGPIPE, &sa, NULL);
+#else
+       SetConsoleCtrlHandler(&Application::CtrlHandler, TRUE);
 #endif /* _WIN32 */
 
        m_Arguments.clear();
@@ -458,12 +480,12 @@ int Application::Run(int argc, char **argv)
        if (IsDebugging()) {
                result = Main(m_Arguments);
 
-               Application::Instance.reset();
+               Application::m_Instance.reset();
        } else {
                try {
                        result = Main(m_Arguments);
                } catch (const exception& ex) {
-                       Application::Instance.reset();
+                       Application::m_Instance.reset();
 
                        Application::Log("---");
                        Application::Log("Exception: " + Utility::GetTypeName(ex));
index d6d364548b36b96fd2857f7c364768de2e1c88dd..c3ed3a8467281cd81cd1a5dbe80a093f41ad2dea 100644 (file)
@@ -32,7 +32,13 @@ DEFINE_EXCEPTION_CLASS(ComponentLoadException);
  * @ingroup base
  */
 class I2_BASE_API Application : public Object {
+public:
+       typedef shared_ptr<Application> Ptr;
+       typedef weak_ptr<Application> WeakPtr;
+
 private:
+       static Application::Ptr m_Instance;
+
        bool m_ShuttingDown; /**< Whether the application is in the process of
                                  shutting down. */
        ConfigHive::Ptr m_ConfigHive; /**< The application's configuration. */
@@ -43,6 +49,8 @@ private:
 
 #ifndef _WIN32
        static void SigIntHandler(int signum);
+#else /* _WIN32 */
+       static BOOL WINAPI CtrlHandler(DWORD type);
 #endif /* _WIN32 */
 
 protected:
@@ -50,14 +58,11 @@ protected:
        string GetExeDirectory(void) const;
 
 public:
-       typedef shared_ptr<Application> Ptr;
-       typedef weak_ptr<Application> WeakPtr;
-
-       static Application::Ptr Instance;
-
        Application(void);
        ~Application(void);
 
+       static Application::Ptr GetInstance(void);
+
        int Run(int argc, char **argv);
 
        virtual int Main(const vector<string>& args) = 0;
index bdacff5e70f600fb4a267d2f849dbc04014ba751..dcea19ef71a59b1fed5a0df76c740055457e2345 100644 (file)
 
 using namespace icinga;
 
-/**
- * Sets the application this component belongs to.
- *
- * @param application The application.
- */
-void Component::SetApplication(const Application::WeakPtr& application)
-{
-       m_Application = application;
-}
-
-/**
- * Retrieves the application this component belongs to.
- *
- * @returns The application.
- */
-Application::Ptr Component::GetApplication(void) const
-{
-       return m_Application.lock();
-}
-
 /**
  * Sets the configuration for this component.
  *
index f70fff74bf4f0e3a1278355e4529403b232ce80e..b2d22237742e8cbb36ad4169b7c2de604e4ba4f2 100644 (file)
@@ -32,16 +32,12 @@ namespace icinga
 class I2_BASE_API Component : public Object
 {
 private:
-       Application::WeakPtr m_Application;
        ConfigObject::Ptr m_Config;
 
 public:
        typedef shared_ptr<Component> Ptr;
        typedef weak_ptr<Component> WeakPtr;
 
-       void SetApplication(const Application::WeakPtr& application);
-       Application::Ptr GetApplication(void) const;
-
        void SetConfig(const ConfigObject::Ptr& componentConfig);
        ConfigObject::Ptr GetConfig(void) const;
 
index 004c7dbf239864dd33eb1313fe24285d90bfc55a..37a4e6330adca80a6e92f057eb4de3e3a3e27495 100644 (file)
@@ -78,6 +78,7 @@ ConfigCollection::Ptr ConfigHive::GetCollection(const string& collection)
 /**
  * Invokes the specified callback for each object contained in this hive.
  *
+ * @param type The config object type.
  * @param callback The callback.
  */
 void ConfigHive::ForEachObject(const string& type,
index 57e38486968e8791c16140c6b2ac86aeb7ce6bd0..ac473205a6ed70fa5f1b88cfcd487d3c36ebcf4a 100644 (file)
@@ -40,9 +40,9 @@ public:
 
        void AddObject(const ConfigObject::Ptr& object);
        void RemoveObject(const ConfigObject::Ptr& object);
-       ConfigObject::Ptr GetObject(const string& collection,
+       ConfigObject::Ptr GetObject(const string& type,
            const string& name = string());
-       ConfigCollection::Ptr GetCollection(const string& collection);
+       ConfigCollection::Ptr GetCollection(const string& type);
 
        void ForEachObject(const string& type,
            function<int (const EventArgs&)> callback);
index 5405a616b3a0cc6a7e0d7c9299df760b02b48582..dcfb925efb03cc5c65352a41c57784f659f7d02c 100644 (file)
@@ -44,15 +44,24 @@ public:
        typedef weak_ptr<Object> WeakPtr;
 };
 
+/**
+ * Compares a weak pointer with a raw pointer.
+ */
 template<class T>
-struct weak_ptr_eq_raw
+struct WeakPtrEqual
 {
 private:
        const void *m_Ref;
 
 public:
-       weak_ptr_eq_raw(const void *ref) : m_Ref(ref) { }
+       WeakPtrEqual(const void *ref) : m_Ref(ref) { }
 
+       /**
+        * Compares the two pointers.
+        *
+        * @param wref The weak pointer.
+        * @returns true if the pointers point to the same object, false otherwise.
+        */
        bool operator()(const weak_ptr<T>& wref) const
        {
                return (wref.lock().get() == (const T *)m_Ref);
index b04f33737758da5830bb29550ea1b4b7f168e1d8..e5b697cc8f9815d9ab5177afa5783ad60fcab671 100644 (file)
@@ -60,7 +60,7 @@ void Socket::Start(void)
  */
 void Socket::Stop(void)
 {
-       Sockets.remove_if(weak_ptr_eq_raw<Socket>(this));
+       Sockets.remove_if(WeakPtrEqual<Socket>(this));
 }
 
 /**
index 0ff6833f10f01e9c93314001bde66266a7c4171c..9143314c71e8610b120f8b52f12cb4d05874b1df 100644 (file)
@@ -161,7 +161,7 @@ void Timer::Start(void)
  */
 void Timer::Stop(void)
 {
-       Timers.remove_if(weak_ptr_eq_raw<Timer>(this));
+       Timers.remove_if(WeakPtrEqual<Timer>(this));
 }
 
 /**
index d939b68ccdc7914c515cccafe96a3151c89e1877..08b52233eb1401abb9721c73d63044d747ea4d90 100644 (file)
@@ -42,7 +42,7 @@ void ConfigFileComponent::Start(void)
        if (fp.fail())
                throw ConfigParserException("Could not open config file");
        
-       GetApplication()->Log("Reading config file: " + filename);
+       GetIcingaApplication()->Log("Reading config file: " + filename);
 
        while (!fp.eof()) {
                size_t bufferSize = 1024;
@@ -93,7 +93,7 @@ void ConfigFileComponent::Start(void)
                                }
                        }
 
-                       GetApplication()->GetConfigHive()->AddObject(cfgobj);
+                       GetConfigHive()->AddObject(cfgobj);
                }
        }
 
index d59467a6eceaecfc1ec31b4aad32aaa810afca28..91c7767d3268c06efa2fc6f0b88f22ee4a928265 100644 (file)
@@ -73,7 +73,7 @@ int ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
 
 int ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
 {
-       RpcRequest request;
+       RequestMessage request;
        request.SetMethod("config::FetchObjects");
 
        Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
@@ -82,9 +82,9 @@ int ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
        return 0;
 }
 
-RpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
+RequestMessage ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
 {
-       RpcRequest msg;
+       RequestMessage msg;
        msg.SetMethod(method);
 
        MessagePart params;
@@ -121,7 +121,7 @@ int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
                        if (!ShouldReplicateObject(object))
                                continue;
 
-                       RpcRequest request = MakeObjectMessage(object, "config::ObjectCreated", true);
+                       RequestMessage request = MakeObjectMessage(object, "config::ObjectCreated", true);
 
                        GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
                }
@@ -158,7 +158,7 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
 
 int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
 {
-       RpcRequest message = ea.Request;
+       RequestMessage message = ea.Request;
        bool was_null = false;
 
        MessagePart params;
@@ -199,7 +199,7 @@ int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
 
 int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
 {
-       RpcRequest message = ea.Request;
+       RequestMessage message = ea.Request;
        
        MessagePart params;
        if (!message.GetParams(&params))
index a7fb6d6fc465b6aeb4a9ffe688e307ee5dc5f8cc..a7a0eda4eb49b022952b0f375a8bf92a2962298a 100644 (file)
@@ -41,7 +41,7 @@ private:
        int RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
        int RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
 
-       static RpcRequest MakeObjectMessage(const ConfigObject::Ptr& object,
+       static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
            string method, bool includeProperties);
 
        static bool ShouldReplicateObject(const ConfigObject::Ptr& object);
index 560f16885f857cf8362599a53a1134fba10b6930..2d9ff238579e11d48d328e47fcfae9d8c4fd937e 100644 (file)
@@ -73,7 +73,7 @@ int DemoComponent::DemoTimerHandler(const TimerEventArgs&)
 {
        Application::Log("Sending multicast 'hello world' message.");
 
-       RpcRequest request;
+       RequestMessage request;
        request.SetMethod("demo::HelloWorld");
 
        EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
index 0dade5e880dfc35608d23063e6bf7886cef7a15a..3ceb622113ebc1aaef81d9434ffeee22e7b59a57 100644 (file)
@@ -283,7 +283,7 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
        // we assume the other component _always_ wants
        // discovery::Welcome messages from us
        endpoint->RegisterSubscription("discovery::Welcome");
-       RpcRequest request;
+       RequestMessage request;
        request.SetMethod("discovery::Welcome");
        GetEndpointManager()->SendUnicastMessage(m_DiscoveryEndpoint, endpoint, request);
 
@@ -306,7 +306,7 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
  */
 void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, Endpoint::Ptr recipient)
 {
-       RpcRequest request;
+       RequestMessage request;
        request.SetMethod(method);
        
        DiscoveryMessage params;
@@ -348,7 +348,7 @@ bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string mess
        if (!roles)
                return false;
 
-       ConfigHive::Ptr configHive = GetApplication()->GetConfigHive();
+       ConfigHive::Ptr configHive = GetConfigHive();
        ConfigCollection::Ptr roleCollection = configHive->GetCollection("role");
 
        for (DictionaryIterator ip = roles->Begin(); ip != roles->End(); ip++) {
@@ -395,7 +395,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
        message.GetNode(&info->Node);
        message.GetService(&info->Service);
 
-       ConfigHive::Ptr configHive = GetApplication()->GetConfigHive();
+       ConfigHive::Ptr configHive = GetConfigHive();
        ConfigCollection::Ptr endpointCollection = configHive->GetCollection("endpoint");
 
        ConfigObject::Ptr endpointConfig = endpointCollection->GetObject(identity);
@@ -526,7 +526,7 @@ int DiscoveryComponent::DiscoveryTimerHandler(const TimerEventArgs& tea)
        time(&now);
 
        /* check whether we have to reconnect to one of our upstream endpoints */
-       ConfigCollection::Ptr endpointCollection = GetApplication()->GetConfigHive()->GetCollection("endpoint");
+       ConfigCollection::Ptr endpointCollection = GetConfigHive()->GetCollection("endpoint");
        endpointCollection->ForEachObject(bind(&DiscoveryComponent::EndpointConfigHandler, this, _1));
 
        map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
index f0fe409f9e2c7802939b36b990657812fb231a0d..2558891d864116e04cec95f434e52219a17734ba 100644 (file)
@@ -80,8 +80,8 @@ public:
        virtual bool IsLocal(void) const = 0;
        virtual bool IsConnected(void) const = 0;
 
-       virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message) = 0;
-       virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message) = 0;
+       virtual void ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message) = 0;
+       virtual void ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message) = 0;
 
        virtual void Stop(void) = 0;
 
index 612e0ca304a6810d94d0ef0bf01d65c90c0c9272..2b59db4f4d072dab5d57e11b78a346576537c28f 100644 (file)
@@ -203,7 +203,7 @@ void EndpointManager::SendUnicastMessage(Endpoint::Ptr sender,
  * @param message The message.
  */
 void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
-    const RpcRequest& message)
+    const RequestMessage& message)
 {
        throw NotImplementedException();
 }
@@ -216,7 +216,7 @@ void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
  * @param message The message.
  */
 void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
-    const RpcRequest& message)
+    const RequestMessage& message)
 {
        string id;
        if (message.GetID(&id))
index 204579b4d5d564124eabb11b255dcf8f0eb07a5c..0fc4eab91288eecc3d73ff4d270fd04dd75eafe8 100644 (file)
@@ -68,8 +68,8 @@ public:
        void UnregisterEndpoint(Endpoint::Ptr endpoint);
 
        void SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const MessagePart& message);
-       void SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest& message);
-       void SendMulticastMessage(Endpoint::Ptr sender, const RpcRequest& message);
+       void SendAnycastMessage(Endpoint::Ptr sender, const RequestMessage& message);
+       void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
 
        void ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback);
 
index 67f0838eed637cbf242a47eee5a6ff5089e3c113..8e711336adbc81fbcddc7bf36ce4e2742bc63aba 100644 (file)
@@ -23,7 +23,8 @@ using namespace icinga;
 
 IcingaApplication::Ptr IcingaComponent::GetIcingaApplication(void) const
 {
-       return static_pointer_cast<IcingaApplication>(GetApplication());
+       Application::Ptr application = Application::GetInstance();
+       return static_pointer_cast<IcingaApplication>(application);
 }
 
 EndpointManager::Ptr IcingaComponent::GetEndpointManager(void) const
index ec1682b7bea887742c854488a4e4cd71a628d8d6..6608bed7ef9b8b9df0269f35598eb0a565297399 100644 (file)
@@ -61,7 +61,7 @@ bool JsonRpcEndpoint::IsConnected(void) const
        return (bool)m_Client;
 }
 
-void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message)
+void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message)
 {
        if (IsConnected()) {
                string id;
@@ -75,7 +75,7 @@ void JsonRpcEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& mes
        }
 }
 
-void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message)
+void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message)
 {
        if (IsConnected())
                m_Client->SendMessage(message);
@@ -91,7 +91,7 @@ int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
                if (!HasPublication(method))
                        return 0;
 
-               RpcRequest request = message;
+               RequestMessage request = message;
 
                string id;
                if (request.GetID(&id))
@@ -99,7 +99,7 @@ int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
                else
                        GetEndpointManager()->SendMulticastMessage(sender, request);
        } else {
-               RpcResponse response = message;
+               ResponseMessage response = message;
 
                // TODO: deal with response messages
                throw NotImplementedException();
index 17fa2b44d34a0a7d5f5b2e827e6eb1241d880cf5..e2221bdeab0ae35dfa8ebdb2c554c56b2b2b0b9c 100644 (file)
@@ -58,8 +58,8 @@ public:
        virtual bool IsLocal(void) const;
        virtual bool IsConnected(void) const;
 
-       virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message);
-       virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message);
+       virtual void ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message);
+       virtual void ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message);
 
        virtual void Stop(void);
 };
index 48e48ab2a4f052be6b51a4c5f75dfe41ae29f860..be8b0c28bbef141871102c3da1490cfda9ca8c87 100644 (file)
@@ -54,7 +54,7 @@ void VirtualEndpoint::UnregisterTopicHandler(string topic, function<int (const N
        throw NotImplementedException();
 }
 
-void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& request)
+void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage& request)
 {
        string method;
        if (!request.GetMethod(&method))
@@ -72,7 +72,7 @@ void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& req
        i->second(nrea);
 }
 
-void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const RpcResponse& response)
+void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)
 {
        // TODO: figure out which request this response belongs to and notify the caller
        throw NotImplementedException();
index 281bf708c7aeec49eb799443113c825059abacb9..9947131de4e5f7371d8f1e3ad60a90801f2d40b6 100644 (file)
@@ -31,7 +31,7 @@ namespace icinga
 struct I2_ICINGA_API NewRequestEventArgs : public EventArgs
 {
        Endpoint::Ptr Sender;
-       RpcRequest Request;
+       RequestMessage Request;
 };
 
 /**
@@ -56,8 +56,8 @@ public:
        virtual bool IsLocal(void) const;
        virtual bool IsConnected(void) const;
 
-       virtual void ProcessRequest(Endpoint::Ptr sender, const RpcRequest& message);
-       virtual void ProcessResponse(Endpoint::Ptr sender, const RpcResponse& message);
+       virtual void ProcessRequest(Endpoint::Ptr sender, const RequestMessage& message);
+       virtual void ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& message);
 
        virtual void Stop(void);
 };
index 92784b9c560e89098a0428416a4e1e35d61cb96f..ffa2fe50b3491b3bb94d131cf6fdf3b3ad009d5b 100644 (file)
@@ -14,10 +14,10 @@ libjsonrpc_la_SOURCES = \
        messagepart.h \
        netstring.cpp \
        netstring.h \
-       rpcrequest.cpp \
-       rpcrequest.h \
-       rpcresponse.cpp \
-       rpcresponse.h
+       requestmessage.cpp \
+       requestmessage.h \
+       responsemessage.cpp \
+       responsemessage.h
 
 libjsonrpc_la_CXXFLAGS = \
        -DI2_JSONRPC_BUILD \
index 1fdd52d83779fcab0bbfa34f7dcc08fccb66ad24..e7fcc15b56912dbe0dd8549a197d23ab56bdea53 100644 (file)
@@ -37,8 +37,8 @@
 #endif /* I2_JSONRPC_BUILD */
 
 #include "messagepart.h"
-#include "rpcrequest.h"
-#include "rpcresponse.h"
+#include "requestmessage.h"
+#include "responsemessage.h"
 #include "netstring.h"
 #include "jsonrpcclient.h"
 #include "jsonrpcserver.h"
index 152a68dc8e9590144e0457c9557ca3db2f798e8a..9cd579651f817efeb296cfedba1146db0d22de7f 100644 (file)
   <ItemGroup>
     <ClInclude Include="i2-jsonrpc.h" />
     <ClInclude Include="jsonrpcclient.h" />
-    <ClInclude Include="rpcrequest.h" />
-    <ClInclude Include="rpcresponse.h" />
+    <ClInclude Include="requestmessage.h" />
+    <ClInclude Include="responsemessage.h" />
     <ClInclude Include="jsonrpcserver.h" />
     <ClInclude Include="messagepart.h" />
     <ClInclude Include="netstring.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="jsonrpcclient.cpp" />
-    <ClCompile Include="rpcrequest.cpp" />
-    <ClCompile Include="rpcresponse.cpp" />
+    <ClCompile Include="requestmessage.cpp" />
+    <ClCompile Include="responsemessage.cpp" />
     <ClCompile Include="jsonrpcserver.cpp" />
     <ClCompile Include="messagepart.cpp" />
     <ClCompile Include="netstring.cpp" />
index 233af4920c61cc45be24376fdc60f357ad17bf38..055198b6c102b7bc171aa201a620208000369644 100644 (file)
@@ -4,17 +4,17 @@
     <ClCompile Include="jsonrpcclient.cpp" />
     <ClCompile Include="jsonrpcserver.cpp" />
     <ClCompile Include="netstring.cpp" />
-    <ClCompile Include="rpcrequest.cpp" />
-    <ClCompile Include="rpcresponse.cpp" />
     <ClCompile Include="messagepart.cpp" />
+    <ClCompile Include="requestmessage.cpp" />
+    <ClCompile Include="responsemessage.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="i2-jsonrpc.h" />
     <ClInclude Include="jsonrpcclient.h" />
     <ClInclude Include="jsonrpcserver.h" />
     <ClInclude Include="netstring.h" />
-    <ClInclude Include="rpcrequest.h" />
-    <ClInclude Include="rpcresponse.h" />
     <ClInclude Include="messagepart.h" />
+    <ClInclude Include="requestmessage.h" />
+    <ClInclude Include="responsemessage.h" />
   </ItemGroup>
 </Project>
\ No newline at end of file
index 15330d05087707399ad8c25a627c49c38a439807..fa6bafb01bc727131fd34aa42eb33f216103788c 100644 (file)
@@ -145,11 +145,10 @@ string MessagePart::ToJsonString(void) const
        char *jsonString;
        string result;
 
-#ifdef _DEBUG
-       jsonString = cJSON_Print(json);
-#else /* _DEBUG */
-       jsonString = cJSON_PrintUnformatted(json);
-#endif /* _DEBUG */
+       if (!Application::GetInstance()->IsDebugging())
+               jsonString = cJSON_Print(json);
+       else
+               jsonString = cJSON_PrintUnformatted(json);
 
        cJSON_Delete(json);
 
similarity index 90%
rename from jsonrpc/rpcrequest.h
rename to jsonrpc/requestmessage.h
index b53463f6ee97280fb5c61e0d2ec923ace47856a6..868e2c8bc75518a33466a587a9d1c0351129361a 100644 (file)
@@ -17,8 +17,8 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef RPCREQUEST_H
-#define RPCREQUEST_H
+#ifndef REQUESTMESSAGE_H
+#define REQUESTMESSAGE_H
 
 namespace icinga
 {
@@ -28,22 +28,22 @@ namespace icinga
  *
  * @ingroup jsonrpc
  */
-class I2_JSONRPC_API RpcRequest : public MessagePart
+class I2_JSONRPC_API RequestMessage : public MessagePart
 {
 public:
        /**
-        * Constructor for the RpcRequest class.
+        * Constructor for the RequestMessage class.
         */
-       RpcRequest(void) : MessagePart() {
+       RequestMessage(void) : MessagePart() {
                SetVersion("2.0");
        }
 
        /**
-        * Copy-constructor for the RpcRequest class.
+        * Copy-constructor for the RequestMessage class.
         *
         * @param message The message that is to be copied.
         */
-       RpcRequest(const MessagePart& message) : MessagePart(message) { }
+       RequestMessage(const MessagePart& message) : MessagePart(message) { }
 
        /**
         * Retrieves the version of the JSON-RPC protocol.
@@ -132,4 +132,4 @@ public:
 
 }
 
-#endif /* RPCREQUEST_H */
+#endif /* REQUESTMESSAGE_H */
similarity index 90%
rename from jsonrpc/rpcresponse.h
rename to jsonrpc/responsemessage.h
index 24bb2311eed79719665a4f1c109d59b8ef1d4a47..785c5c0bf3bcc138ff7bc2962904732d6d71a605 100644 (file)
@@ -17,8 +17,8 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef RPCRESPONSE_H
-#define RPCRESPONSE_H
+#ifndef RESPONSEMESSAGE_H
+#define RESPONSEMESSAGE_H
 
 namespace icinga
 {
@@ -28,22 +28,22 @@ namespace icinga
  *
  * @ingroup jsonrpc
  */
-class I2_JSONRPC_API RpcResponse : public MessagePart
+class I2_JSONRPC_API ResponseMessage : public MessagePart
 {
 public:
        /**
-        * Constructor for the RpcResponse class.
+        * Constructor for the ResponseMessage class.
         */
-       RpcResponse(void) : MessagePart() {
+       ResponseMessage(void) : MessagePart() {
                SetVersion("2.0");
        }
 
        /**
-        * Copy-constructor for the RpcResponse class.
+        * Copy-constructor for the ResponseMessage class.
         *
         * @param message The message that should be copied.
         */
-       RpcResponse(const MessagePart& message) : MessagePart(message) { }
+       ResponseMessage(const MessagePart& message) : MessagePart(message) { }
 
        /**
         * Retrieves the version of the JSON-RPC protocol.
@@ -132,4 +132,4 @@ public:
 
 }
 
-#endif /* RPCRESPONSE_H */
+#endif /* RESPONSEMESSAGE_H */