]> granicus.if.org Git - icinga2/commitdiff
Cleaned up Dictionary/Message classes.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 16 May 2012 09:30:54 +0000 (11:30 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 16 May 2012 09:30:54 +0000 (11:30 +0200)
23 files changed:
base/application.cpp
base/application.h
base/dictionary.cpp
base/dictionary.h
base/variant.h
components/configfile/configfilecomponent.cpp
components/configrpc/configrpccomponent.cpp
components/discovery/discoverycomponent.cpp
components/discovery/discoverymessage.h
icinga/endpointmanager.cpp
icinga/endpointmanager.h
icinga/icingaapplication.cpp
icinga/jsonrpcendpoint.cpp
jsonrpc/Makefile.am
jsonrpc/i2-jsonrpc.h
jsonrpc/jsonrpc.vcxproj
jsonrpc/jsonrpc.vcxproj.filters
jsonrpc/jsonrpcclient.cpp
jsonrpc/jsonrpcclient.h
jsonrpc/messagepart.cpp [moved from jsonrpc/message.cpp with 69% similarity]
jsonrpc/messagepart.h [moved from jsonrpc/message.h with 67% similarity]
jsonrpc/rpcrequest.h
jsonrpc/rpcresponse.h

index d854169f9cfb81240460fa95670c1c96f924f5dd..11fc30fe5277dfee9156ca686f85191329eba411 100644 (file)
@@ -372,7 +372,7 @@ string Application::GetExeDirectory(void) const
 #else /* _WIN32 */
        char FullExePath[MAXPATHLEN];
 
-       GetModuleFileName(NULL, FullExePath, MAXPATHLEN);
+       GetModuleFileName(NULL, FullExePath, sizeof(FullExePath));
 
        PathRemoveFileSpec(FullExePath);
 
index f2ddff47669c3cb502c5f56d6723f20796de3c00..1bec711942a8cf25b8483a892d8ace104ea875fe 100644 (file)
@@ -31,11 +31,13 @@ DEFINE_EXCEPTION_CLASS(ComponentLoadException);
  */
 class I2_BASE_API Application : public Object {
 private:
-       bool m_ShuttingDown;
-       ConfigHive::Ptr m_ConfigHive;
-       map< string, shared_ptr<Component> > m_Components;
-       vector<string> m_Arguments;
-       bool m_Debugging;
+       bool m_ShuttingDown; /**< Whether the application is in the process of
+                                 shutting down. */
+       ConfigHive::Ptr m_ConfigHive; /**< The application's configuration. */
+       map< string, shared_ptr<Component> > m_Components; /**< Components that
+                                       were loaded by the application. */
+       vector<string> m_Arguments; /**< Command-line arguments */
+       bool m_Debugging; /**< Whether debugging is enabled. */
 
 protected:
        void RunEventLoop(void);
index 0a6bc1dd811d349e0a28fcc6969531a91bdc1246..e8e62658059eeeea8b9d1c313398dcb687f58920 100644 (file)
@@ -59,128 +59,27 @@ void Dictionary::SetProperty(string key, const Variant& value)
 }
 
 /**
- * Retrieves a value from the dictionary and converts it to a string.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetPropertyString(string key, string *value)
-{
-       Variant data;
-
-       if (!GetProperty(key, &data))
-               return false;
-
-       *value = static_cast<string>(data);
-       return true;
-}
-
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyString(string key, const string& value)
-{
-       SetProperty(key, Variant(value));
-}
-
-/**
- * Retrieves a value from the dictionary and converts it to an integer.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetPropertyInteger(string key, long *value)
-{
-       Variant data;
-
-       if (!GetProperty(key, &data))
-               return false;
-
-       *value = static_cast<long>(data);
-       return true;
-}
-
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyInteger(string key, long value)
-{
-       SetProperty(key, Variant(value));
-}
-
-/**
- * Retrieves a value from the dictionary and converts it to a dictionary.
+ * Retrieves a value from the dictionary.
  *
  * @param key The key.
  * @param value Pointer to the value.
  * @returns true if the value was retrieved, false otherwise.
  */
-bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
+bool Dictionary::GetProperty(string key, Dictionary::Ptr *value) const
 {
-       Dictionary::Ptr dictionary;
-       Variant data;
+       Object::Ptr object;
 
-       if (!GetProperty(key, &data))
+       if (!GetProperty(key, &object))
                return false;
 
-       dictionary = dynamic_pointer_cast<Dictionary>(data.GetObject());
-
-       if (dictionary == NULL)
-               throw InvalidArgumentException("Property is not a dictionary.");
+       Dictionary::Ptr dictionary = dynamic_pointer_cast<Dictionary>(object);
+       if (!dictionary)
+               throw InvalidArgumentException();
 
        *value = dictionary;
-
-       return true;
-}
-
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyDictionary(string key, const Dictionary::Ptr& value)
-{
-       SetProperty(key, Variant(value));
-}
-
-/**
- * Retrieves a value from the dictionary and converts it to an object.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetPropertyObject(string key, Object::Ptr *value)
-{
-       Variant data;
-
-       if (!GetProperty(key, &data))
-               return false;
-
-       *value = data;
        return true;
 }
 
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyObject(string key, const Object::Ptr& value)
-{
-       SetProperty(key, Variant(value));
-}
-
 /**
  * Returns an iterator to the beginning of the dictionary.
  *
@@ -232,43 +131,3 @@ void Dictionary::AddUnnamedProperty(const Variant& value)
 
        m_Data[key] = value;
 }
-
-/**
- * Adds an unnamed value to the dictionary.
- *
- * @param value The value.
- */
-void Dictionary::AddUnnamedPropertyString(const string& value)
-{
-       AddUnnamedProperty(Variant(value));
-}
-
-/**
- * Adds an unnamed value to the dictionary.
- *
- * @param value The value.
- */
-void Dictionary::AddUnnamedPropertyInteger(long value)
-{
-       AddUnnamedProperty(Variant(value));
-}
-
-/**
- * Adds an unnamed value to the dictionary.
- *
- * @param value The value.
- */
-void Dictionary::AddUnnamedPropertyDictionary(const Dictionary::Ptr& value)
-{
-       AddUnnamedProperty(Variant(value));
-}
-
-/**
- * Adds an unnamed value to the dictionary.
- *
- * @param value The value.
- */
-void Dictionary::AddUnnamedPropertyObject(const Object::Ptr& value)
-{
-       AddUnnamedProperty(Variant(value));
-}
index 01cb14d9712dd2911e000ffed30e0e57377169c2..edfeda281cecf837f8f2b5d27be4bc89c3303a6a 100644 (file)
@@ -41,26 +41,25 @@ public:
        bool GetProperty(string key, Variant *value) const;
        void SetProperty(string key, const Variant& value);
 
-       bool GetPropertyString(string key, string *value);
-       void SetPropertyString(string key, const string& value);
+       template<typename T>
+       bool GetProperty(string key, T *value) const
+       {
+               Variant data;
 
-       bool GetPropertyInteger(string key, long *value);
-       void SetPropertyInteger(string key, long value);
+               if (!GetProperty(key, &data))
+                       return false;
 
-       bool GetPropertyDictionary(string key, Dictionary::Ptr *value);
-       void SetPropertyDictionary(string key, const Dictionary::Ptr& value);
+               *value = data;
 
-       bool GetPropertyObject(string key, Object::Ptr *value);
-       void SetPropertyObject(string key, const Object::Ptr& value);
+               return true;
+       }
+
+       bool GetProperty(string key, Dictionary::Ptr *value) const;
 
        DictionaryIterator Begin(void);
        DictionaryIterator End(void);
 
        void AddUnnamedProperty(const Variant& value);
-       void AddUnnamedPropertyString(const string& value);
-       void AddUnnamedPropertyInteger(long value);
-       void AddUnnamedPropertyDictionary(const Dictionary::Ptr& value);
-       void AddUnnamedPropertyObject(const Object::Ptr& value);
 
        long GetLength(void) const;
 };
index b1b047127c15940eaec7353580e1f8804930c3b2..3f10b722eb9abc72ac2fd1a14449552d7911027e 100644 (file)
@@ -54,6 +54,9 @@ private:
 public:
        inline Variant(void) : m_Type(VariantEmpty) { }
 
+       inline Variant(int value)
+           : m_Type(VariantInteger), m_IntegerValue(value) { }
+
        inline Variant(long value)
            : m_Type(VariantInteger), m_IntegerValue(value) { }
 
index 59fb080dacb825abce58731b97214d51e0709569..d939b68ccdc7914c515cccafe96a3151c89e1877 100644 (file)
@@ -35,7 +35,7 @@ void ConfigFileComponent::Start(void)
        FIFO::Ptr fifo = make_shared<FIFO>();
 
        string filename;
-       if (!GetConfig()->GetPropertyString("configFilename", &filename))
+       if (!GetConfig()->GetProperty("configFilename", &filename))
                throw InvalidArgumentException("Missing 'configFilename' property");
 
        fp.open(filename.c_str(), ifstream::in);
@@ -78,7 +78,7 @@ void ConfigFileComponent::Start(void)
                                if (property->type == cJSON_String) {
                                        string value = property->valuestring;
 
-                                       cfgobj->SetPropertyString(key, value);
+                                       cfgobj->SetProperty(key, value);
                                } else if (property->type == cJSON_Array) {
                                        Dictionary::Ptr items = make_shared<Dictionary>();
 
@@ -86,10 +86,10 @@ void ConfigFileComponent::Start(void)
                                                if (item->type != cJSON_String)
                                                        continue;
 
-                                               items->AddUnnamedPropertyString(item->valuestring);
+                                               items->AddUnnamedProperty(item->valuestring);
                                        }
 
-                                       cfgobj->SetPropertyDictionary(key, items);
+                                       cfgobj->SetProperty(key, items);
                                }
                        }
 
index 1569ef072d80dcfddaedb7559931c7f80c0bb5a0..d59467a6eceaecfc1ec31b4aad32aaa810afca28 100644 (file)
@@ -34,7 +34,7 @@ void ConfigRpcComponent::Start(void)
        m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
 
        long configSource;
-       if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
+       if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
                m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
                    bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
 
@@ -87,14 +87,14 @@ RpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object
        RpcRequest msg;
        msg.SetMethod(method);
 
-       Message params;
+       MessagePart params;
        msg.SetParams(params);
 
-       params.GetDictionary()->SetPropertyString("name", object->GetName());
-       params.GetDictionary()->SetPropertyString("type", object->GetType());
+       params.SetProperty("name", object->GetName());
+       params.SetProperty("type", object->GetType());
 
        if (includeProperties)
-               params.SetPropertyMessage("properties", Message(object));
+               params.SetProperty("properties", object);
 
        return msg;
 }
@@ -102,7 +102,7 @@ RpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object
 bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
 {
        long replicate;
-       if (!object->GetPropertyInteger("replicate", &replicate))
+       if (!object->GetProperty("replicate", &replicate))
                return true;
        return (replicate != 0);
 }
@@ -161,16 +161,16 @@ int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
        RpcRequest message = ea.Request;
        bool was_null = false;
 
-       Message params;
+       MessagePart params;
        if (!message.GetParams(&params))
                return 0;
 
        string name;
-       if (!params.GetDictionary()->GetPropertyString("name", &name))
+       if (!params.GetProperty("name", &name))
                return 0;
 
        string type;
-       if (!params.GetDictionary()->GetPropertyString("type", &type))
+       if (!params.GetProperty("type", &type))
                return 0;
 
        ConfigHive::Ptr configHive = GetConfigHive();
@@ -181,12 +181,12 @@ int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
                object = make_shared<ConfigObject>(type, name);
        }
 
-       Dictionary::Ptr properties;
-       if (!params.GetDictionary()->GetPropertyDictionary("properties", &properties))
+       MessagePart properties;
+       if (!params.GetProperty("properties", &properties))
                return 0;
 
-       for (DictionaryIterator i = properties->Begin(); i != properties->End(); i++) {
-               object->SetPropertyString(i->first, i->second);
+       for (DictionaryIterator i = properties.Begin(); i != properties.End(); i++) {
+               object->SetProperty(i->first, i->second);
        }
 
        if (was_null) {
@@ -201,16 +201,16 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
 {
        RpcRequest message = ea.Request;
        
-       Message params;
+       MessagePart params;
        if (!message.GetParams(&params))
                return 0;
 
        string name;
-       if (!params.GetDictionary()->GetPropertyString("name", &name))
+       if (!params.GetProperty("name", &name))
                return 0;
 
        string type;
-       if (!params.GetDictionary()->GetPropertyString("type", &type))
+       if (!params.GetProperty("type", &type))
                return 0;
 
        ConfigHive::Ptr configHive = GetConfigHive();
index ce752a217a4fb9144fe69aad4f80586fab79e0f3..b1fa37277558fc130984140254e083227f4e60f8 100644 (file)
@@ -314,12 +314,6 @@ void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, En
 
        params.SetIdentity(identity);
 
-       Message subscriptions;
-       params.SetSubscriptions(subscriptions);
-
-       Message publications;
-       params.SetPublications(publications);
-
        ComponentDiscoveryInfo::Ptr info;
 
        if (!GetComponentDiscoveryInfo(identity, &info))
@@ -331,11 +325,17 @@ void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, En
        }
 
        set<string>::iterator i;
+       MessagePart subscriptions;
+       for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
+               subscriptions.AddUnnamedProperty(*i);
+
+       params.SetSubscriptions(subscriptions);
+
+       MessagePart publications;
        for (i = info->Publications.begin(); i != info->Publications.end(); i++)
-               publications.AddUnnamedPropertyString(*i);
+               publications.AddUnnamedProperty(*i);
 
-       for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
-               subscriptions.AddUnnamedPropertyString(*i);
+       params.SetPublications(publications);
 
        if (recipient)
                GetEndpointManager()->SendUnicastMessage(m_DiscoveryEndpoint, recipient, request);
@@ -358,7 +358,7 @@ bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string mess
                        continue;
 
                Dictionary::Ptr permissions;
-               if (!role->GetPropertyDictionary(messageType, &permissions))
+               if (!role->GetProperty(messageType, &permissions))
                        continue;
 
                for (DictionaryIterator is = permissions->Begin(); is != permissions->End(); is++) {
@@ -397,14 +397,14 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
        ConfigObject::Ptr endpointConfig = endpointCollection->GetObject(identity);
        Dictionary::Ptr roles;
        if (endpointConfig)
-               endpointConfig->GetPropertyDictionary("roles", &roles);
+               endpointConfig->GetProperty("roles", &roles);
 
        Endpoint::Ptr endpoint = GetEndpointManager()->GetEndpointByIdentity(identity);
 
-       Message publications;
+       MessagePart publications;
        if (message.GetPublications(&publications)) {
                DictionaryIterator i;
-               for (i = publications.GetDictionary()->Begin(); i != publications.GetDictionary()->End(); i++) {
+               for (i = publications.Begin(); i != publications.End(); i++) {
                        if (trusted || HasMessagePermission(roles, "publications", i->second)) {
                                info->Publications.insert(i->second);
                                if (endpoint)
@@ -413,10 +413,10 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
                }
        }
 
-       Message subscriptions;
+       MessagePart subscriptions;
        if (message.GetSubscriptions(&subscriptions)) {
                DictionaryIterator i;
-               for (i = subscriptions.GetDictionary()->Begin(); i != subscriptions.GetDictionary()->End(); i++) {
+               for (i = subscriptions.Begin(); i != subscriptions.End(); i++) {
                        if (trusted || HasMessagePermission(roles, "subscriptions", i->second)) {
                                info->Subscriptions.insert(i->second);
                                if (endpoint)
@@ -492,7 +492,7 @@ int DiscoveryComponent::EndpointConfigHandler(const EventArgs& ea)
                return 0;
 
        string node, service;
-       if (object->GetPropertyString("node", &node) && object->GetPropertyString("service", &service)) {
+       if (object->GetProperty("node", &node) && object->GetProperty("service", &service)) {
                /* reconnect to this endpoint */
                endpointManager->AddConnection(node, service);
        }
index f5754092969e2d666ebef6655fcfd01282f41829..6390f530d767aa29a6bafa976e86ed90719900b7 100644 (file)
@@ -4,61 +4,61 @@
 namespace icinga
 {
 
-class DiscoveryMessage : public Message
+class DiscoveryMessage : public MessagePart
 {
 
 public:
-       DiscoveryMessage(void) : Message() { }
-       DiscoveryMessage(const Message& message) : Message(message) { }
+       DiscoveryMessage(void) : MessagePart() { }
+       DiscoveryMessage(const MessagePart& message) : MessagePart(message) { }
 
        inline bool GetIdentity(string *value) const
        {
-               return GetPropertyString("identity", value);
+               return GetProperty("identity", value);
        }
 
        inline void SetIdentity(const string& value)
        {
-               SetPropertyString("identity", value);
+               SetProperty("identity", value);
        }
 
        inline bool GetNode(string *value) const
        {
-               return GetPropertyString("node", value);
+               return GetProperty("node", value);
        }
 
        inline void SetNode(const string& value)
        {
-               SetPropertyString("node", value);
+               SetProperty("node", value);
        }
 
        inline bool GetService(string *value) const
        {
-               return GetPropertyString("service", value);
+               return GetProperty("service", value);
        }
 
        inline void SetService(const string& value)
        {
-               SetPropertyString("service", value);
+               SetProperty("service", value);
        }
 
-       inline bool GetSubscriptions(Message *value) const
+       inline bool GetSubscriptions(MessagePart *value) const
        {
-               return GetPropertyMessage("subscriptions", value);
+               return GetProperty("subscriptions", value);
        }
 
-       inline void SetSubscriptions(Message value)
+       inline void SetSubscriptions(MessagePart value)
        {
-               SetPropertyMessage("subscriptions", value);
+               SetProperty("subscriptions", value);
        }
 
-       inline bool GetPublications(Message *value) const
+       inline bool GetPublications(MessagePart *value) const
        {
-               return GetPropertyMessage("publications", value);
+               return GetProperty("publications", value);
        }
 
-       inline void SetPublications(Message value)
+       inline void SetPublications(MessagePart value)
        {
-               SetPropertyMessage("publications", value);
+               SetProperty("publications", value);
        }
 };
 
index 11f88e1c25b9bb824bd0f38f2b104e5a3422a5f2..bb2736199f98026afacdcc869d6248b62f48651c 100644 (file)
@@ -109,7 +109,8 @@ void EndpointManager::AddConnection(string node, string service)
 void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
 {
        m_Servers.push_back(server);
-       server->OnNewClient += bind_weak(&EndpointManager::NewClientHandler, shared_from_this());
+       server->OnNewClient += bind_weak(&EndpointManager::NewClientHandler,
+           shared_from_this());
 }
 
 /**
@@ -180,7 +181,8 @@ void EndpointManager::UnregisterEndpoint(Endpoint::Ptr endpoint)
  * @param recipient The recipient of the message.
  * @param message The request.
  */
-void EndpointManager::SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const Message& message)
+void EndpointManager::SendUnicastMessage(Endpoint::Ptr sender,
+    Endpoint::Ptr recipient, const MessagePart& message)
 {
        /* don't forward messages back to the sender */
        if (sender == recipient)
@@ -200,7 +202,8 @@ void EndpointManager::SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr rec
  * @param sender The sender of the message.
  * @param message The message.
  */
-void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest& message)
+void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
+    const RpcRequest& message)
 {
        throw NotImplementedException();
 }
@@ -212,7 +215,8 @@ void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest&
  * @param sender The sender of the message.
  * @param message The message.
  */
-void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender, const RpcRequest& message)
+void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
+    const RpcRequest& message)
 {
        string id;
        if (message.GetID(&id))
index 816c1f9e01e619def8ab0ea301832bc84706aa6f..d7cd71c224afbc67670540889c058df004d93fc8 100644 (file)
@@ -63,7 +63,7 @@ public:
        void RegisterEndpoint(Endpoint::Ptr endpoint);
        void UnregisterEndpoint(Endpoint::Ptr endpoint);
 
-       void SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const Message& message);
+       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);
 
index b029c9aa86ebe77d91c49313ad934d9acafd60f2..a1ed1e4ee3e25d0cba515dd2000cd514ddbc307f 100644 (file)
@@ -68,8 +68,8 @@ int IcingaApplication::Main(const vector<string>& args)
 
        /* load config file */
        ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
-       fileComponentConfig->SetPropertyString("configFilename", args[1]);
-       fileComponentConfig->SetPropertyInteger("replicate", 0);
+       fileComponentConfig->SetProperty("configFilename", args[1]);
+       fileComponentConfig->SetProperty("replicate", 0);
        GetConfigHive()->AddObject(fileComponentConfig);
 
        if (!GetPrivateKeyFile().empty() && !GetPublicKeyFile().empty() && !GetCAKeyFile().empty()) {
@@ -112,7 +112,7 @@ int IcingaApplication::NewComponentHandler(const EventArgs& ea)
                return 0;
 
        string path;
-       if (!object->GetPropertyString("path", &path)) {
+       if (!object->GetProperty("path", &path)) {
 #ifdef _WIN32
                path = object->GetName() + ".dll";
 #else /* _WIN32 */
@@ -144,23 +144,23 @@ int IcingaApplication::NewIcingaConfigHandler(const EventArgs& ea)
                return 0;
 
        string privkey;
-       if (object->GetPropertyString("privkey", &privkey))
+       if (object->GetProperty("privkey", &privkey))
                SetPrivateKeyFile(privkey);
 
        string pubkey;
-       if (object->GetPropertyString("pubkey", &pubkey))
+       if (object->GetProperty("pubkey", &pubkey))
                SetPublicKeyFile(pubkey);
 
        string cakey;
-       if (object->GetPropertyString("cakey", &cakey))
+       if (object->GetProperty("cakey", &cakey))
                SetCAKeyFile(cakey);
 
        string node;
-       if (object->GetPropertyString("node", &node))
+       if (object->GetProperty("node", &node))
                SetNode(node);
 
        string service;
-       if (object->GetPropertyString("service", &service))
+       if (object->GetProperty("service", &service))
                SetService(service);
 
        return 0;
index 9491c34972c31a3d548c8f56726364d62dd00520..ec1682b7bea887742c854488a4e4cd71a628d8d6 100644 (file)
@@ -83,11 +83,11 @@ void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const RpcResponse& m
 
 int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
 {
-       const Message& message = nmea.Message;
+       const MessagePart& message = nmea.Message;
        Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
 
        string method;
-       if (message.GetPropertyString("method", &method)) {
+       if (message.GetProperty("method", &method)) {
                if (!HasPublication(method))
                        return 0;
 
index fb2f02ff4c3ee75e346653b4051ef826c49d01ec..92784b9c560e89098a0428416a4e1e35d61cb96f 100644 (file)
@@ -10,8 +10,8 @@ libjsonrpc_la_SOURCES = \
        jsonrpcclient.h \
        jsonrpcserver.cpp \
        jsonrpcserver.h \
-       message.cpp \
-       message.h \
+       messagepart.cpp \
+       messagepart.h \
        netstring.cpp \
        netstring.h \
        rpcrequest.cpp \
index e5fffaf37d75d98e39ee77523586b93af1bcc884..8a47c1d7b3a0690c6e2c306b7adf6eb6ac3b3901 100644 (file)
@@ -29,9 +29,7 @@
 #      define I2_JSONRPC_API I2_IMPORT
 #endif /* I2_JSONRPC_BUILD */
 
-#include "variant.h"
-#include "dictionary.h"
-#include "message.h"
+#include "messagepart.h"
 #include "rpcrequest.h"
 #include "rpcresponse.h"
 #include "netstring.h"
index a5464f8e59acc1e23e81d6b7c5b659a37053eabd..152a68dc8e9590144e0457c9557ca3db2f798e8a 100644 (file)
@@ -16,7 +16,7 @@
     <ClInclude Include="rpcrequest.h" />
     <ClInclude Include="rpcresponse.h" />
     <ClInclude Include="jsonrpcserver.h" />
-    <ClInclude Include="message.h" />
+    <ClInclude Include="messagepart.h" />
     <ClInclude Include="netstring.h" />
   </ItemGroup>
   <ItemGroup>
@@ -24,7 +24,7 @@
     <ClCompile Include="rpcrequest.cpp" />
     <ClCompile Include="rpcresponse.cpp" />
     <ClCompile Include="jsonrpcserver.cpp" />
-    <ClCompile Include="message.cpp" />
+    <ClCompile Include="messagepart.cpp" />
     <ClCompile Include="netstring.cpp" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
index 3b8eec49688b2a53077473ca9bcfe6dedf52fb05..233af4920c61cc45be24376fdc60f357ad17bf38 100644 (file)
@@ -3,18 +3,18 @@
   <ItemGroup>
     <ClCompile Include="jsonrpcclient.cpp" />
     <ClCompile Include="jsonrpcserver.cpp" />
-    <ClCompile Include="message.cpp" />
     <ClCompile Include="netstring.cpp" />
     <ClCompile Include="rpcrequest.cpp" />
     <ClCompile Include="rpcresponse.cpp" />
+    <ClCompile Include="messagepart.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="i2-jsonrpc.h" />
     <ClInclude Include="jsonrpcclient.h" />
     <ClInclude Include="jsonrpcserver.h" />
-    <ClInclude Include="message.h" />
     <ClInclude Include="netstring.h" />
     <ClInclude Include="rpcrequest.h" />
     <ClInclude Include="rpcresponse.h" />
+    <ClInclude Include="messagepart.h" />
   </ItemGroup>
 </Project>
\ No newline at end of file
index 0f12adf6e93b4a3e37876af2aa7dcb4377db01b2..42dafe9d89e5ecb63b0f492f0809032bf8222808 100644 (file)
@@ -31,7 +31,7 @@ void JsonRpcClient::Start(void)
        OnDataAvailable += bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this());
 }
 
-void JsonRpcClient::SendMessage(const Message& message)
+void JsonRpcClient::SendMessage(const MessagePart& message)
 {
        Netstring::WriteStringToFIFO(GetSendQueue(), message.ToJsonString());
 }
@@ -41,12 +41,12 @@ int JsonRpcClient::DataAvailableHandler(const EventArgs&)
        for (;;) {
                try {
                        string jsonString;
-                       Message message;
+                       MessagePart message;
 
                        if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
                                break;
 
-                       message = Message(jsonString);
+                       message = MessagePart(jsonString);
 
                        NewMessageEventArgs nea;
                        nea.Source = shared_from_this();
index 21cef5eac9857bbf123d9c30c7d4d2380d35c567..9f7d242ba221dc73572abbadece5d8617e5e2cd6 100644 (file)
@@ -28,7 +28,7 @@ struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs
        typedef shared_ptr<NewMessageEventArgs> Ptr;
        typedef weak_ptr<NewMessageEventArgs> WeakPtr;
 
-       icinga::Message Message;
+       icinga::MessagePart Message;
 };
 
 class I2_JSONRPC_API JsonRpcClient : public TLSClient
@@ -42,7 +42,7 @@ public:
 
        JsonRpcClient(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
 
-       void SendMessage(const Message& message);
+       void SendMessage(const MessagePart& message);
 
        virtual void Start(void);
 
similarity index 69%
rename from jsonrpc/message.cpp
rename to jsonrpc/messagepart.cpp
index f25ff7ec7c616428859b4e16512381b8e5f6885b..bd14463267dc0b7885aade30603afde85ac7b8eb 100644 (file)
 
 using namespace icinga;
 
-Message::Message(void)
+MessagePart::MessagePart(void)
 {
        m_Dictionary = make_shared<Dictionary>();
 }
 
-Message::Message(string jsonString)
+MessagePart::MessagePart(string jsonString)
 {
        json_t *json = cJSON_Parse(jsonString.c_str());
 
@@ -39,17 +39,17 @@ Message::Message(string jsonString)
        cJSON_Delete(json);
 }
 
-Message::Message(const Dictionary::Ptr& dictionary)
+MessagePart::MessagePart(const Dictionary::Ptr& dictionary)
 {
        m_Dictionary = dictionary;
 }
 
-Message::Message(const Message& message)
+MessagePart::MessagePart(const MessagePart& message)
 {
        m_Dictionary = message.GetDictionary();
 }
 
-Dictionary::Ptr Message::GetDictionaryFromJson(json_t *json)
+Dictionary::Ptr MessagePart::GetDictionaryFromJson(json_t *json)
 {
        Dictionary::Ptr dictionary = make_shared<Dictionary>();
 
@@ -72,7 +72,7 @@ Dictionary::Ptr Message::GetDictionaryFromJson(json_t *json)
        return dictionary;
 }
 
-json_t *Message::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
+json_t *MessagePart::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
 {
        cJSON *json;
        string valueString;
@@ -102,7 +102,7 @@ json_t *Message::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
        return json;
 }
 
-string Message::ToJsonString(void) const
+string MessagePart::ToJsonString(void) const
 {
        json_t *json = GetJsonFromDictionary(m_Dictionary);
        char *jsonString;
@@ -123,57 +123,42 @@ string Message::ToJsonString(void) const
        return result;
 }
 
-Dictionary::Ptr Message::GetDictionary(void) const
+Dictionary::Ptr MessagePart::GetDictionary(void) const
 {
        return m_Dictionary;
 }
 
-bool Message::GetPropertyString(string key, string *value) const
-{
-       return GetDictionary()->GetPropertyString(key, value);
-}
-
-bool Message::GetPropertyInteger(string key, long *value) const
-{
-       return GetDictionary()->GetPropertyInteger(key, value);
-}
-
-bool Message::GetPropertyMessage(string key, Message *value) const
+bool MessagePart::GetProperty(string key, MessagePart *value) const
 {
        Dictionary::Ptr dictionary;
-       if (!GetDictionary()->GetPropertyDictionary(key, &dictionary))
+       if (!GetDictionary()->GetProperty(key, &dictionary))
                return false;
 
-       *value = Message(dictionary);
+       *value = MessagePart(dictionary);
        return true;
 }
 
-void Message::SetPropertyString(string key, const string& value)
-{
-       GetDictionary()->SetProperty(key, value);
-}
-
-void Message::SetPropertyInteger(string key, long value)
+void MessagePart::SetProperty(string key, const MessagePart& value)
 {
-       GetDictionary()->SetProperty(key, value);
+       GetDictionary()->SetProperty(key, value.GetDictionary());
 }
 
-void Message::SetPropertyMessage(string key, const Message& value)
+void MessagePart::AddUnnamedProperty(const MessagePart& value)
 {
-       GetDictionary()->SetProperty(key, Variant(value.GetDictionary()));
+       GetDictionary()->AddUnnamedProperty(value.GetDictionary());
 }
 
-void Message::AddUnnamedPropertyString(const string& value)
+DictionaryIterator MessagePart::Begin(void)
 {
-       GetDictionary()->AddUnnamedPropertyString(value);
+       return GetDictionary()->Begin();
 }
 
-void Message::AddUnnamedPropertyInteger(long value)
+DictionaryIterator MessagePart::End(void)
 {
-       GetDictionary()->AddUnnamedPropertyInteger(value);
+       return GetDictionary()->End();
 }
 
-void Message::AddUnnamedPropertyMessage(const Message& value)
+MessagePart::operator Dictionary::Ptr(void)
 {
-       GetDictionary()->AddUnnamedPropertyDictionary(value.GetDictionary());
+       return GetDictionary();
 }
similarity index 67%
rename from jsonrpc/message.h
rename to jsonrpc/messagepart.h
index ddca1dcf8a780c0cc7739356e7287f5060922f85..37517f51450ee803d18e17787e3fa916ef301ce9 100644 (file)
@@ -17,8 +17,8 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef MESSAGE_H
-#define MESSAGE_H
+#ifndef MESSAGEPART_H
+#define MESSAGEPART_H
 
 struct cJSON;
 
@@ -27,7 +27,7 @@ namespace icinga
 
 typedef ::cJSON json_t;
 
-class I2_JSONRPC_API Message
+class I2_JSONRPC_API MessagePart
 {
 private:
        Dictionary::Ptr m_Dictionary;
@@ -36,29 +36,44 @@ private:
        static json_t *GetJsonFromDictionary(const Dictionary::Ptr& dictionary);
 
 public:
-       Message(void);
-       Message(string json);
-       Message(const Dictionary::Ptr& dictionary);
-       Message(const Message& message);
+       MessagePart(void);
+       MessagePart(string json);
+       MessagePart(const Dictionary::Ptr& dictionary);
+       MessagePart(const MessagePart& message);
 
        string ToJsonString(void) const;
 
        Dictionary::Ptr GetDictionary(void) const;
 
-       bool GetPropertyString(string key, string *value) const;
-       void SetPropertyString(string key, const string& value);
+       template<typename T>
+       bool GetProperty(string key, T *value) const
+       {
+               return GetDictionary()->GetProperty(key, value);
+       }
 
-       bool GetPropertyInteger(string key, long *value) const;
-       void SetPropertyInteger(string key, long value);
+       template<typename T>
+       void SetProperty(string key, const T& value)
+       {
+               GetDictionary()->SetProperty(key, value);
+       }
 
-       bool GetPropertyMessage(string key, Message *value) const;
-       void SetPropertyMessage(string key, const Message& value);
+       bool GetProperty(string key, MessagePart *value) const;
+       void SetProperty(string key, const MessagePart& value);
 
-       void AddUnnamedPropertyString(const string& value);
-       void AddUnnamedPropertyInteger(long value);
-       void AddUnnamedPropertyMessage(const Message& value);
+       template<typename T>
+       void AddUnnamedProperty(const T& value)
+       {
+               GetDictionary()->AddUnnamedProperty(value);
+       }
+
+       void AddUnnamedProperty(const MessagePart& value);
+
+       DictionaryIterator Begin(void);
+       DictionaryIterator End(void);
+
+       operator Dictionary::Ptr(void);
 };
 
 }
 
-#endif /* MESSAGE_H */
+#endif /* MESSAGEPART_H */
index a7d11a898ab33562ba12fe565c60713b6a8371f4..901353285d10c924ac7f2a0fb9cfcca32c1e761b 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef RpcRequest_H
-#define RpcRequest_H
+#ifndef RPCREQUEST_H
+#define RPCREQUEST_H
 
 namespace icinga
 {
 
-class I2_JSONRPC_API RpcRequest : public Message
+class I2_JSONRPC_API RpcRequest : public MessagePart
 {
 
 public:
-       RpcRequest(void) : Message() {
+       RpcRequest(void) : MessagePart() {
                SetVersion("2.0");
        }
 
-       RpcRequest(const Message& message) : Message(message) { }
+       RpcRequest(const MessagePart& message) : MessagePart(message) { }
 
        inline bool GetVersion(string *value) const
        {
-               return GetPropertyString("jsonrpc", value);
+               return GetProperty("jsonrpc", value);
        }
 
        inline void SetVersion(const string& value)
        {
-               SetPropertyString("jsonrpc", value);
+               SetProperty("jsonrpc", value);
        }
 
        inline bool GetMethod(string *value) const
        {
-               return GetPropertyString("method", value);
+               return GetProperty("method", value);
        }
 
        inline void SetMethod(const string& value)
        {
-               SetPropertyString("method", value);
+               SetProperty("method", value);
        }
 
-       inline bool GetParams(Message *value) const
+       inline bool GetParams(MessagePart *value) const
        {
-               return GetPropertyMessage("params", value);
+               return GetProperty("params", value);
        }
 
-       inline void SetParams(const Message& value)
+       inline void SetParams(const MessagePart& value)
        {
-               SetPropertyMessage("params", value);
+               SetProperty("params", value);
        }
 
        inline bool GetID(string *value) const
        {
-               return GetPropertyString("id", value);
+               return GetProperty("id", value);
        }
 
        inline void SetID(const string& value)
        {
-               SetPropertyString("id", value);
+               SetProperty("id", value);
        }
 };
 
 }
 
-#endif /* RpcRequest_H */
+#endif /* RPCREQUEST_H */
index 199a67445e0b57447e671abb3d43a013a2d39b08..6d444d3d4cc89e63623be756ff82673267162a11 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef RpcResponse_H
-#define RpcResponse_H
+#ifndef RPCRESPONSE_H
+#define RPCRESPONSE_H
 
 namespace icinga
 {
 
-class I2_JSONRPC_API RpcResponse : public Message
+class I2_JSONRPC_API RpcResponse : public MessagePart
 {
 public:
-       RpcResponse(void) : Message() {
+       RpcResponse(void) : MessagePart() {
                SetVersion("2.0");
        }
 
-       RpcResponse(const Message& message) : Message(message) { }
+       RpcResponse(const MessagePart& message) : MessagePart(message) { }
 
        inline bool GetVersion(string *value) const
        {
-               return GetPropertyString("jsonrpc", value);
+               return GetProperty("jsonrpc", value);
        }
 
        inline void SetVersion(const string& value)
        {
-               SetPropertyString("jsonrpc", value);
+               SetProperty("jsonrpc", value);
        }
 
        bool GetResult(string *value) const
        {
-               return GetPropertyString("result", value);
+               return GetProperty("result", value);
        }
 
        void SetResult(const string& value)
        {
-               SetPropertyString("result", value);
+               SetProperty("result", value);
        }
 
        bool GetError(string *value) const
        {
-               return GetPropertyString("error", value);
+               return GetProperty("error", value);
        }
 
        void SetError(const string& value)
        {
-               SetPropertyString("error", value);
+               SetProperty("error", value);
        }
 
        bool GetID(string *value) const
        {
-               return GetPropertyString("id", value);
+               return GetProperty("id", value);
        }
 
        void SetID(const string& value)
        {
-               SetPropertyString("id", value);
+               SetProperty("id", value);
        }
 };
 
 }
 
-#endif /* RpcResponse_H */
+#endif /* RPCRESPONSE_H */