]> granicus.if.org Git - icinga2/commitdiff
Cleaned up message classes.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 20 Apr 2012 11:49:04 +0000 (13:49 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 20 Apr 2012 11:51:39 +0000 (13:51 +0200)
25 files changed:
base/configcollection.cpp
base/configcollection.h
base/confighive.cpp
base/confighive.h
base/configobject.cpp
base/configobject.h
base/dictionary.cpp
base/dictionary.h
base/variant.cpp
base/variant.h
components/configfile/configfilecomponent.cpp
components/configrpc/configrpccomponent.cpp
components/configrpc/configrpccomponent.h
icinga/endpointmanager.cpp
icinga/icingaapplication.cpp
icinga/icingaapplication.h
icinga/identitymessage.h
icinga/jsonrpcendpoint.cpp
icinga/subscriptioncomponent.cpp
icinga/subscriptionmessage.h
jsonrpc/jsonrpcrequest.h
jsonrpc/jsonrpcresponse.h
jsonrpc/message.cpp
jsonrpc/message.h
jsonrpc/netstring.cpp

index a1d24fe06f0cd02e77f6f473fa87339c29d36284..aecca6de122c95570931729062b099771a69fbc4 100644 (file)
@@ -14,9 +14,11 @@ ConfigHive::WeakPtr ConfigCollection::GetHive(void) const
 
 void ConfigCollection::AddObject(const ConfigObject::Ptr& object)
 {
+       RemoveObject(object);
+
        Objects[object->GetName()] = object;
 
-       ConfigObjectEventArgs ea;
+       EventArgs ea;
        ea.Source = object;
        OnObjectCreated(ea);
 
@@ -32,7 +34,7 @@ void ConfigCollection::RemoveObject(const ConfigObject::Ptr& object)
        if (oi != Objects.end()) {
                Objects.erase(oi);
 
-               ConfigObjectEventArgs ea;
+               EventArgs ea;
                ea.Source = object;
                OnObjectRemoved(ea);
 
@@ -52,9 +54,9 @@ ConfigObject::Ptr ConfigCollection::GetObject(const string& name)
        return oi->second;
 }
 
-void ConfigCollection::ForEachObject(function<int (const ConfigObjectEventArgs&)> callback)
+void ConfigCollection::ForEachObject(function<int (const EventArgs&)> callback)
 {
-       ConfigObjectEventArgs ea;
+       EventArgs ea;
 
        for (ObjectIterator oi = Objects.begin(); oi != Objects.end(); oi++) {
                ea.Source = oi->second;
index be252c37577334b58356df10efb4b491cf41e921..dfcb3c84be8f7e11e7209bae168415008c4d2c00 100644 (file)
@@ -25,11 +25,11 @@ public:
        void RemoveObject(const ConfigObject::Ptr& object);
        ConfigObject::Ptr GetObject(const string& name = string());
 
-       void ForEachObject(function<int (const ConfigObjectEventArgs&)> callback);
+       void ForEachObject(function<int (const EventArgs&)> callback);
 
-       Event<ConfigObjectEventArgs> OnObjectCreated;
-       Event<ConfigObjectEventArgs> OnObjectRemoved;
-       Event<ConfigObjectEventArgs> OnPropertyChanged;
+       Event<EventArgs> OnObjectCreated;
+       Event<EventArgs> OnObjectRemoved;
+       Event<DictionaryPropertyChangedEventArgs> OnPropertyChanged;
 };
 
 }
index 81623b77c7603dc55f94bdc6f84cb0a263945e80..fb43ce3af0efb5d2b2c7fb161d8141663c92b19e 100644 (file)
@@ -30,7 +30,7 @@ ConfigCollection::Ptr ConfigHive::GetCollection(const string& collection)
        return ci->second;
 }
 
-void ConfigHive::ForEachObject(const string& type, function<int (const ConfigObjectEventArgs&)> callback)
+void ConfigHive::ForEachObject(const string& type, function<int (const EventArgs&)> callback)
 {
        CollectionIterator ci = Collections.find(type);
 
index f2d78e3cc5f0fa3587ae3610cafaf90376d19792..a8654cbd0bdddfa009cc4be49c105dfe7429ce42 100644 (file)
@@ -18,11 +18,11 @@ public:
        ConfigObject::Ptr GetObject(const string& collection, const string& name = string());
        ConfigCollection::Ptr GetCollection(const string& collection);
 
-       void ForEachObject(const string& type, function<int (const ConfigObjectEventArgs&)> callback);
+       void ForEachObject(const string& type, function<int (const EventArgs&)> callback);
 
-       Event<ConfigObjectEventArgs> OnObjectCreated;
-       Event<ConfigObjectEventArgs> OnObjectRemoved;
-       Event<ConfigObjectEventArgs> OnPropertyChanged;
+       Event<EventArgs> OnObjectCreated;
+       Event<EventArgs> OnObjectRemoved;
+       Event<DictionaryPropertyChangedEventArgs> OnPropertyChanged;
 };
 
 }
index 9f779a7cd05a29fcc6d8781f62e1fe91a33963f3..e0800dd1b600f39de8716400a9c93307a977716f 100644 (file)
@@ -10,7 +10,11 @@ ConfigObject::ConfigObject(const string& type, const string& name)
 
 void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
 {
+       if (m_Hive.lock())
+               throw InvalidArgumentException();
+
        m_Hive = hive;
+       OnPropertyChanged += bind_weak(&ConfigObject::PropertyChangedHandler, shared_from_this());
 }
 
 ConfigHive::WeakPtr ConfigObject::GetHive(void) const
@@ -38,64 +42,13 @@ string ConfigObject::GetType(void) const
        return m_Type;
 }
 
-void ConfigObject::SetProperty(const string& name, const string& value)
+int ConfigObject::PropertyChangedHandler(const DictionaryPropertyChangedEventArgs dpcea)
 {
-       Properties[name] = value;
-
        ConfigHive::Ptr hive = m_Hive.lock();
        if (hive) {
-               ConfigObjectEventArgs ea;
-               ea.Source = shared_from_this();
-               ea.Property = name;
-
-               string oldValue;
-               if (GetProperty(name, &oldValue))
-                       ea.OldValue = oldValue;
-
-               hive->GetCollection(m_Type)->OnPropertyChanged(ea);
-               hive->OnPropertyChanged(ea);
+               hive->GetCollection(m_Type)->OnPropertyChanged(dpcea);
+               hive->OnPropertyChanged(dpcea);
        }
-}
-
-void ConfigObject::SetPropertyInteger(const string& name, int value)
-{
-       char valueString[20];
-       sprintf(valueString, "%d", value);
-
-       SetProperty(name, string(valueString));
-}
-
-void ConfigObject::SetPropertyDouble(const string& name, double value)
-{
-       char valueString[20];
-       sprintf(valueString, "%f", value);
-
-       SetProperty(name, string(valueString));
-}
-
-bool ConfigObject::GetProperty(const string& name, string *value) const
-{
-       map<string, string>::const_iterator vi = Properties.find(name);
-       if (vi == Properties.end())
-               return false;
-       *value = vi->second;
-       return true;
-}
 
-bool ConfigObject::GetPropertyInteger(const string& name, int *value) const
-{
-       string stringValue;
-       if (!GetProperty(name, &stringValue))
-               return false;
-       *value = strtol(stringValue.c_str(), NULL, 10);
-       return true;
-}
-
-bool ConfigObject::GetPropertyDouble(const string& name, double *value) const
-{
-       string stringValue;
-       if (!GetProperty(name, &stringValue))
-               return false;
-       *value = strtod(stringValue.c_str(), NULL);
-       return true;
+       return 0;
 }
index a084b5b47b080c42bcae8d9d01f37f20f9649bda..84ac0e40ba728708df68e2bff22d599da2e2057d 100644 (file)
@@ -8,16 +8,7 @@ namespace icinga
 
 class ConfigHive;
 
-struct I2_BASE_API ConfigObjectEventArgs : public EventArgs
-{
-       typedef shared_ptr<ConfigObjectEventArgs> Ptr;
-       typedef weak_ptr<ConfigObjectEventArgs> WeakPtr;
-
-       string Property;
-       string OldValue;
-};
-
-class I2_BASE_API ConfigObject : public Object
+class I2_BASE_API ConfigObject : public Dictionary
 {
 private:
        weak_ptr<ConfigHive> m_Hive;
@@ -25,6 +16,8 @@ private:
        string m_Name;
        string m_Type;
 
+       int PropertyChangedHandler(const DictionaryPropertyChangedEventArgs dpcea);
+
 public:
        typedef shared_ptr<ConfigObject> Ptr;
        typedef weak_ptr<ConfigObject> WeakPtr;
@@ -42,14 +35,6 @@ public:
 
        void SetType(const string& type);
        string GetType(void) const;
-
-       void SetProperty(const string& name, const string& value);
-       void SetPropertyInteger(const string& name, int value);
-       void SetPropertyDouble(const string& name, double value);
-
-       bool GetProperty(const string& name, string *value) const;
-       bool GetPropertyInteger(const string& name, int *value) const;
-       bool GetPropertyDouble(const string& name, double *value) const;
 };
 
 }
index 1f69feb27e81968762648bbd0a4fb94efd1e1f52..965278519b285edfbd3b44a3168cfe74b0fca3a7 100644 (file)
@@ -2,62 +2,75 @@
 
 using namespace icinga;
 
-bool Dictionary::GetValueVariant(string key, Variant *value)
+bool Dictionary::GetProperty(string key, Variant *value) const
 {
-       DictionaryIterator i = m_Data.find(key);
+       ConstDictionaryIterator i = m_Data.find(key);
 
        if (i == m_Data.end())
                return false;
 
        *value = i->second;
-
        return true;
 }
 
-void Dictionary::SetValueVariant(string key, const Variant& value)
+void Dictionary::SetProperty(string key, const Variant& value)
 {
-       m_Data.erase(key);
+       DictionaryIterator i = m_Data.find(key);
+
+       Variant oldValue;
+       if (i != m_Data.end()) {
+               oldValue = i->second;
+               m_Data.erase(i);
+       }
+
        m_Data[key] = value;
+
+       DictionaryPropertyChangedEventArgs dpce;
+       dpce.Source = shared_from_this();
+       dpce.Property = key;
+       dpce.OldValue = oldValue;
+       dpce.NewValue = value;
+       OnPropertyChanged(dpce);
 }
 
-bool Dictionary::GetValueString(string key, string *value)
+bool Dictionary::GetPropertyString(string key, string *value)
 {
        Variant data;
 
-       if (!GetValueVariant(key, &data))
+       if (!GetProperty(key, &data))
                return false;
 
        *value = static_cast<string>(data);
        return true;
 }
 
-void Dictionary::SetValueString(string key, const string& value)
+void Dictionary::SetPropertyString(string key, const string& value)
 {
-       SetValueVariant(key, Variant(value));
+       SetProperty(key, Variant(value));
 }
 
-bool Dictionary::GetValueInteger(string key, long *value)
+bool Dictionary::GetPropertyInteger(string key, long *value)
 {
        Variant data;
 
-       if (!GetValueVariant(key, &data))
+       if (!GetProperty(key, &data))
                return false;
 
-       *value = data;
+       *value = static_cast<long>(data);
        return true;
 }
 
-void Dictionary::SetValueInteger(string key, long value)
+void Dictionary::SetPropertyInteger(string key, long value)
 {
-       SetValueVariant(key, Variant(value));
+       SetProperty(key, Variant(value));
 }
 
-bool Dictionary::GetValueDictionary(string key, Dictionary::Ptr *value)
+bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
 {
        Dictionary::Ptr dictionary;
        Variant data;
 
-       if (!GetValueVariant(key, &data))
+       if (!GetProperty(key, &data))
                return false;
 
        dictionary = dynamic_pointer_cast<Dictionary>(data.GetObject());
@@ -70,25 +83,25 @@ bool Dictionary::GetValueDictionary(string key, Dictionary::Ptr *value)
        return true;
 }
 
-void Dictionary::SetValueDictionary(string key, const Dictionary::Ptr& value)
+void Dictionary::SetPropertyDictionary(string key, const Dictionary::Ptr& value)
 {
-       SetValueVariant(key, Variant(value));
+       SetProperty(key, Variant(value));
 }
 
-bool Dictionary::GetValueObject(string key, Object::Ptr *value)
+bool Dictionary::GetPropertyObject(string key, Object::Ptr *value)
 {
        Variant data;
 
-       if (!GetValueVariant(key, &data))
+       if (!GetProperty(key, &data))
                return false;
 
        *value = data;
        return true;
 }
 
-void Dictionary::SetValueObject(string key, const Object::Ptr& value)
+void Dictionary::SetPropertyObject(string key, const Object::Ptr& value)
 {
-       SetValueVariant(key, Variant(value));
+       SetProperty(key, Variant(value));
 }
 
 DictionaryIterator Dictionary::Begin(void)
index 6f062ee08dc08a9fb2695a64ace527b67a28aa58..127f9d6a6c5a67e00f8cb264940619223b37564d 100644 (file)
@@ -4,8 +4,16 @@
 namespace icinga
 {
 
+typedef map<string, Variant>::const_iterator ConstDictionaryIterator;
 typedef map<string, Variant>::iterator DictionaryIterator;
 
+struct I2_BASE_API DictionaryPropertyChangedEventArgs : public EventArgs
+{
+       string Property;
+       Variant OldValue;
+       Variant NewValue;
+};
+
 class I2_BASE_API Dictionary : public Object
 {
 private:
@@ -15,23 +23,25 @@ public:
        typedef shared_ptr<Dictionary> Ptr;
        typedef weak_ptr<Dictionary> WeakPtr;
 
-       bool GetValueVariant(string key, Variant *value);
-       void SetValueVariant(string key, const Variant& value);
+       bool GetProperty(string key, Variant *value) const;
+       void SetProperty(string key, const Variant& value);
 
-       bool GetValueString(string key, string *value);
-       void SetValueString(string key, const string& value);
+       bool GetPropertyString(string key, string *value);
+       void SetPropertyString(string key, const string& value);
 
-       bool GetValueInteger(string key, long *value);
-       void SetValueInteger(string key, long value);
+       bool GetPropertyInteger(string key, long *value);
+       void SetPropertyInteger(string key, long value);
 
-       bool GetValueDictionary(string key, Dictionary::Ptr *value);
-       void SetValueDictionary(string key, const Dictionary::Ptr& value);
+       bool GetPropertyDictionary(string key, Dictionary::Ptr *value);
+       void SetPropertyDictionary(string key, const Dictionary::Ptr& value);
 
-       bool GetValueObject(string key, Object::Ptr *value);
-       void SetValueObject(string key, const Object::Ptr& value);
+       bool GetPropertyObject(string key, Object::Ptr *value);
+       void SetPropertyObject(string key, const Object::Ptr& value);
 
        DictionaryIterator Begin(void);
        DictionaryIterator End(void);
+
+       Event<DictionaryPropertyChangedEventArgs> OnPropertyChanged;
 };
 
 }
index d1ab9bd1897762afa68298b06e126107a1bd84e6..95a030e1b7e7e930a0a35e51eddb1f50e2ef694b 100644 (file)
@@ -2,29 +2,20 @@
 
 using namespace icinga;
 
-Variant::Variant(void) : m_Type(VariantEmpty)
-{      
-}
-
-Variant::Variant(long value) : m_Type(VariantInteger), m_IntegerValue(value)
-{
-}
-
-Variant::Variant(string value) : m_Type(VariantString), m_StringValue(value)
-{
-}
-
-Variant::Variant(Object::Ptr value) : m_Type(VariantObject), m_ObjectValue(value)
-{
-}
-
 void Variant::Convert(VariantType newType) const
 {
        if (newType == m_Type)
                return;
 
+       if (m_Type == VariantString && newType == VariantInteger) {
+               m_IntegerValue = strtol(m_StringValue.c_str(), NULL, 10);
+               m_Type = VariantInteger;
+
+               return;
+       }
+
        // TODO: convert variant data
-       throw NotImplementedException();
+       throw InvalidArgumentException("Invalid variant conversion.");
 }
 
 VariantType Variant::GetType(void) const
@@ -53,6 +44,11 @@ Object::Ptr Variant::GetObject(void) const
        return m_ObjectValue;
 }
 
+bool Variant::IsEmpty(void) const
+{
+       return (m_Type == VariantEmpty);
+}
+
 Variant::operator long(void) const
 {
        return GetInteger();
index ef44260e3f764cb93e401b676148ce16e48fc633..0608258666b2ffa4a8f522fba568d5e49d13462f 100644 (file)
@@ -24,10 +24,16 @@ private:
        void Convert(VariantType newType) const;
 
 public:
-       Variant(void);
-       Variant(long value);
-       Variant(string value);
-       Variant(Object::Ptr value);
+       inline Variant::Variant(void) : m_Type(VariantEmpty) { }
+
+       inline Variant::Variant(long value) : m_Type(VariantInteger), m_IntegerValue(value) { }
+
+       inline Variant::Variant(const char *value) : m_Type(VariantString), m_StringValue(string(value)) { }
+
+       inline Variant::Variant(string value) : m_Type(VariantString), m_StringValue(value) { }
+
+       template<typename T>
+       Variant(const shared_ptr<T>& value) : m_Type(VariantObject), m_ObjectValue(value) { }
 
        VariantType GetType(void) const;
 
@@ -35,6 +41,8 @@ public:
        string GetString(void) const;
        Object::Ptr GetObject(void) const;
 
+       bool IsEmpty(void) const;
+
        operator long(void) const;
        operator string(void) const;
        operator Object::Ptr(void) const;
index 3c1b7b4d496b9abd8af61b973e701c7ec359ea4d..bbd40758342bece64b25a38a841ceee73ba68b8e 100644 (file)
@@ -16,8 +16,8 @@ void ConfigFileComponent::Start(void)
        FIFO::Ptr fifo = make_shared<FIFO>();
 
        string filename;
-       if (!GetConfig()->GetProperty("configFilename", &filename))
-               throw ConfigParserException("Missing configFilename property");
+       if (!GetConfig()->GetPropertyString("configFilename", &filename))
+               throw InvalidArgumentException("Missing 'configFilename' property");
 
        fp.open(filename.c_str(), ifstream::in);
        if (fp.fail())
@@ -61,7 +61,7 @@ void ConfigFileComponent::Start(void)
 
                                string value = property->valuestring;
 
-                               cfgobj->SetProperty(key, value);
+                               cfgobj->SetPropertyString(key, value);
                        }
 
                        GetApplication()->GetConfigHive()->AddObject(cfgobj);
index 29a6cf9842e712a9a3b3a89003c5f4f5e8526233..4ed2a43f9b4215d1dad3e4f56c7ebdafb60d5c96 100644 (file)
@@ -21,7 +21,7 @@ void ConfigRpcComponent::Start(void)
 
        m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
 
-       int configSource;
+       long configSource;
        if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
                m_ConfigRpcEndpoint->RegisterMethodHandler("config::FetchObjects", bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
 
@@ -82,15 +82,15 @@ JsonRpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& ob
        Message params;
        msg.SetParams(params);
 
-       params.GetDictionary()->SetValueString("name", object->GetName());
-       params.GetDictionary()->SetValueString("type", object->GetType());
+       params.GetDictionary()->SetPropertyString("name", object->GetName());
+       params.GetDictionary()->SetPropertyString("type", object->GetType());
 
        if (includeProperties) {
                Message properties;
-               params.GetDictionary()->SetValueDictionary("properties", properties.GetDictionary());
+               params.GetDictionary()->SetPropertyDictionary("properties", properties.GetDictionary());
 
                for (ConfigObject::ParameterIterator pi = object->Properties.begin(); pi != object->Properties.end(); pi++) {
-                       properties.GetDictionary()->SetValueString(pi->first, pi->second);
+                       properties.GetDictionary()->SetPropertyString(pi->first, pi->second);
                }
        }
 
@@ -113,11 +113,11 @@ int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
        return 0;
 }
 
-int ConfigRpcComponent::LocalObjectCreatedHandler(const ConfigObjectEventArgs& ea)
+int ConfigRpcComponent::LocalObjectCreatedHandler(const EventArgs& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        
-       int replicate = 0;
+       long replicate = 0;
        object->GetPropertyInteger("replicate", &replicate);
 
        if (replicate) {
@@ -128,11 +128,11 @@ int ConfigRpcComponent::LocalObjectCreatedHandler(const ConfigObjectEventArgs& e
        return 0;
 }
 
-int ConfigRpcComponent::LocalObjectRemovedHandler(const ConfigObjectEventArgs& ea)
+int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        
-       int replicate = 0;
+       long replicate = 0;
        object->GetPropertyInteger("replicate", &replicate);
 
        if (replicate) {
@@ -143,11 +143,11 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(const ConfigObjectEventArgs& e
        return 0;
 }
 
-int ConfigRpcComponent::LocalPropertyChangedHandler(const ConfigObjectEventArgs& ea)
+int ConfigRpcComponent::LocalPropertyChangedHandler(const DictionaryPropertyChangedEventArgs& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        
-       int replicate = 0;
+       long replicate = 0;
        object->GetPropertyInteger("replicate", &replicate);
 
        if (replicate) {
@@ -156,12 +156,13 @@ int ConfigRpcComponent::LocalPropertyChangedHandler(const ConfigObjectEventArgs&
                msg.SetParams(params);
 
                Message properties;
-               params.GetDictionary()->SetValueDictionary("properties", properties.GetDictionary());
+               params.GetDictionary()->SetPropertyDictionary("properties", properties.GetDictionary());
 
                string value;
-               object->GetProperty(ea.Property, &value);
+               if (!object->GetPropertyString(ea.Property, &value))
+                       return 0;
 
-               properties.GetDictionary()->SetValueString(ea.Property, value);
+               properties.GetDictionary()->SetPropertyString(ea.Property, value);
 
                EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
                mgr->SendMulticastRequest(m_ConfigRpcEndpoint, msg);
@@ -180,11 +181,11 @@ int ConfigRpcComponent::RemoteObjectUpdatedHandler(const NewRequestEventArgs& ea
                return 0;
 
        string name;
-       if (!params.GetDictionary()->GetValueString("name", &name))
+       if (!params.GetDictionary()->GetPropertyString("name", &name))
                return 0;
 
        string type;
-       if (!params.GetDictionary()->GetValueString("type", &type))
+       if (!params.GetDictionary()->GetPropertyString("type", &type))
                return 0;
 
        ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
@@ -196,11 +197,11 @@ int ConfigRpcComponent::RemoteObjectUpdatedHandler(const NewRequestEventArgs& ea
        }
 
        Dictionary::Ptr properties;
-       if (!params.GetDictionary()->GetValueDictionary("properties", &properties))
+       if (!params.GetDictionary()->GetPropertyDictionary("properties", &properties))
                return 0;
 
        for (DictionaryIterator i = properties->Begin(); i != properties->End(); i++) {
-               object->SetProperty(i->first, i->second);
+               object->SetPropertyString(i->first, i->second);
        }
 
        if (was_null)
@@ -218,11 +219,11 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
                return 0;
 
        string name;
-       if (!params.GetDictionary()->GetValueString("name", &name))
+       if (!params.GetDictionary()->GetPropertyString("name", &name))
                return 0;
 
        string type;
-       if (!params.GetDictionary()->GetValueString("type", &type))
+       if (!params.GetDictionary()->GetPropertyString("type", &type))
                return 0;
 
        ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
index 92b00b2430bc8ae63b05789fe27fb217f82b81fe..05274a5292916d1a7e7bf487e240c4c112b3817c 100644 (file)
@@ -14,9 +14,9 @@ private:
        int NewEndpointHandler(const NewEndpointEventArgs& ea);
        int WelcomeMessageHandler(const NewRequestEventArgs& ea);
 
-       int LocalObjectCreatedHandler(const ConfigObjectEventArgs& ea);
-       int LocalObjectRemovedHandler(const ConfigObjectEventArgs& ea);
-       int LocalPropertyChangedHandler(const ConfigObjectEventArgs& ea);
+       int LocalObjectCreatedHandler(const EventArgs& ea);
+       int LocalObjectRemovedHandler(const EventArgs& ea);
+       int LocalPropertyChangedHandler(const DictionaryPropertyChangedEventArgs& ea);
 
        int FetchObjectsHandler(const NewRequestEventArgs& ea);
        int RemoteObjectUpdatedHandler(const NewRequestEventArgs& ea);
index 8d543a02022029132cc63e23cdfbbfe479e86c5d..a3d8d798befd5e352c2993f955d7f77dd4d5b2db 100644 (file)
@@ -117,9 +117,9 @@ int EndpointManager::NewMethodSinkHandler(const NewMethodEventArgs& ea)
        request.SetVersion("2.0");
        request.SetMethod("message::Subscribe");
 
-       Message params;
-       params.GetDictionary()->SetValueString("method", ea.Method);
-       request.SetParams(params);
+       SubscriptionMessage subscriptionMessage;
+       subscriptionMessage.SetMethod(ea.Method);
+       request.SetParams(subscriptionMessage);
 
        SendMulticastRequest(sender, request);
 
@@ -137,9 +137,9 @@ int EndpointManager::NewMethodSourceHandler(const NewMethodEventArgs& ea)
        request.SetVersion("2.0");
        request.SetMethod("message::Provide");
 
-       Message params;
-       params.GetDictionary()->SetValueString("method", ea.Method);
-       request.SetParams(params);
+       SubscriptionMessage subscriptionMessage;
+       subscriptionMessage.SetMethod(ea.Method);
+       request.SetParams(subscriptionMessage);
 
        SendMulticastRequest(sender, request);
 
index e2fdd9fc2143d97d67a879acb2aff8bbab6dcc8f..c44f389ce4d041a5da9ae7249b485274caa5473c 100644 (file)
@@ -32,7 +32,7 @@ int IcingaApplication::Main(const vector<string>& args)
 
        ConfigCollection::Ptr componentCollection = GetConfigHive()->GetCollection("component");
 
-       function<int (const ConfigObjectEventArgs&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
+       function<int (const EventArgs&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
        componentCollection->OnObjectCreated += NewComponentHandler;
        componentCollection->ForEachObject(NewComponentHandler);
 
@@ -40,7 +40,7 @@ int IcingaApplication::Main(const vector<string>& args)
 
        ConfigCollection::Ptr listenerCollection = GetConfigHive()->GetCollection("rpclistener");
 
-       function<int (const ConfigObjectEventArgs&)> NewRpcListenerHandler = bind_weak(&IcingaApplication::NewRpcListenerHandler, shared_from_this());
+       function<int (const EventArgs&)> NewRpcListenerHandler = bind_weak(&IcingaApplication::NewRpcListenerHandler, shared_from_this());
        listenerCollection->OnObjectCreated += NewRpcListenerHandler;
        listenerCollection->ForEachObject(NewRpcListenerHandler);
 
@@ -48,7 +48,7 @@ int IcingaApplication::Main(const vector<string>& args)
 
        ConfigCollection::Ptr connectionCollection = GetConfigHive()->GetCollection("rpcconnection");
 
-       function<int (const ConfigObjectEventArgs&)> NewRpcConnectionHandler = bind_weak(&IcingaApplication::NewRpcConnectionHandler, shared_from_this());
+       function<int (const EventArgs&)> NewRpcConnectionHandler = bind_weak(&IcingaApplication::NewRpcConnectionHandler, shared_from_this());
        connectionCollection->OnObjectCreated += NewRpcConnectionHandler;
        connectionCollection->ForEachObject(NewRpcConnectionHandler);
 
@@ -58,7 +58,7 @@ int IcingaApplication::Main(const vector<string>& args)
        RegisterComponent(subscriptionsComponent);
 
        ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
-       fileComponentConfig->SetProperty("configFilename", args[1]);
+       fileComponentConfig->SetPropertyString("configFilename", args[1]);
        fileComponentConfig->SetPropertyInteger("replicate", 0);
        GetConfigHive()->AddObject(fileComponentConfig);
 
@@ -103,12 +103,12 @@ EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
        return m_EndpointManager;
 }
 
-int IcingaApplication::NewComponentHandler(const ConfigObjectEventArgs& ea)
+int IcingaApplication::NewComponentHandler(const EventArgs& ea)
 {
        string path;
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
-               
-       if (!object->GetProperty("path", &path)) {
+       
+       if (!object->GetPropertyString("path", &path)) {
 #ifdef _WIN32
                path = object->GetName() + ".dll";
 #else /* _WIN32 */
@@ -123,7 +123,7 @@ int IcingaApplication::NewComponentHandler(const ConfigObjectEventArgs& ea)
        return 0;
 }
 
-int IcingaApplication::DeletedComponentHandler(const ConfigObjectEventArgs& ea)
+int IcingaApplication::DeletedComponentHandler(const EventArgs& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        Component::Ptr component = GetComponent(object->GetName());
@@ -132,13 +132,19 @@ int IcingaApplication::DeletedComponentHandler(const ConfigObjectEventArgs& ea)
        return 0;
 }
 
-int IcingaApplication::NewRpcListenerHandler(const ConfigObjectEventArgs& ea)
+int IcingaApplication::NewRpcListenerHandler(const EventArgs& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
-       int port;
+       long portValue;
+       unsigned short port;
 
-       if (!object->GetPropertyInteger("port", &port))
-               throw Exception("Parameter 'port' is required for 'rpclistener' objects.");
+       if (!object->GetPropertyInteger("port", &portValue))
+               throw InvalidArgumentException("Parameter 'port' is required for 'rpclistener' objects.");
+
+       if (portValue < 0 || portValue > USHRT_MAX)
+               throw InvalidArgumentException("Parameter 'port' contains an invalid value.");
+
+       port = (unsigned short)portValue;
 
        Log("Creating JSON-RPC listener on port %d", port);
 
@@ -147,24 +153,30 @@ int IcingaApplication::NewRpcListenerHandler(const ConfigObjectEventArgs& ea)
        return 0;
 }
 
-int IcingaApplication::DeletedRpcListenerHandler(const ConfigObjectEventArgs& ea)
+int IcingaApplication::DeletedRpcListenerHandler(const EventArgs& ea)
 {
        throw Exception("Unsupported operation.");
 
        return 0;
 }
 
-int IcingaApplication::NewRpcConnectionHandler(const ConfigObjectEventArgs& ea)
+int IcingaApplication::NewRpcConnectionHandler(const EventArgs& ea)
 {
        ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
        string hostname;
-       int port;
+       long portValue;
+       unsigned short port;
+
+       if (!object->GetPropertyString("hostname", &hostname))
+               throw InvalidArgumentException("Parameter 'hostname' is required for 'rpcconnection' objects.");
+
+       if (!object->GetPropertyInteger("port", &portValue))
+               throw InvalidArgumentException("Parameter 'port' is required for 'rpcconnection' objects.");
 
-       if (!object->GetProperty("hostname", &hostname))
-               throw Exception("Parameter 'hostname' is required for 'rpcconnection' objects.");
+       if (portValue < 0 || portValue > USHRT_MAX)
+               throw InvalidArgumentException("Parameter 'port' contains an invalid value.");
 
-       if (!object->GetPropertyInteger("port", &port))
-               throw Exception("Parameter 'port' is required for 'rpcconnection' objects.");
+       port = (unsigned short)portValue;
 
        Log("Creating JSON-RPC connection to %s:%d", hostname.c_str(), port);
 
@@ -173,7 +185,7 @@ int IcingaApplication::NewRpcConnectionHandler(const ConfigObjectEventArgs& ea)
        return 0;
 }
 
-int IcingaApplication::DeletedRpcConnectionHandler(const ConfigObjectEventArgs& ea)
+int IcingaApplication::DeletedRpcConnectionHandler(const EventArgs& ea)
 {
        throw Exception("Unsupported operation.");
 
index 7c46296c22f65b65fd7ebdb6603534b933a5f697..6d86e55d40ac2eaaffa6a13bd755598f5ef369e1 100644 (file)
@@ -11,14 +11,14 @@ private:
        Timer::Ptr m_TestTimer;
        VirtualEndpoint::Ptr m_TestEndpoint;
 
-       int NewComponentHandler(const ConfigObjectEventArgs& ea);
-       int DeletedComponentHandler(const ConfigObjectEventArgs& ea);
+       int NewComponentHandler(const EventArgs& ea);
+       int DeletedComponentHandler(const EventArgs& ea);
 
-       int NewRpcListenerHandler(const ConfigObjectEventArgs& ea);
-       int DeletedRpcListenerHandler(const ConfigObjectEventArgs& ea);
+       int NewRpcListenerHandler(const EventArgs& ea);
+       int DeletedRpcListenerHandler(const EventArgs& ea);
 
-       int NewRpcConnectionHandler(const ConfigObjectEventArgs& ea);
-       int DeletedRpcConnectionHandler(const ConfigObjectEventArgs& ea);
+       int NewRpcConnectionHandler(const EventArgs& ea);
+       int DeletedRpcConnectionHandler(const EventArgs& ea);
 
        int TestTimerHandler(const TimerEventArgs& tea);
 public:
index 714e26f3ada2036fce4edf2693d15d1812611628..2d2567d41c26a6542d4a0af6e10ee8617f6ac70e 100644 (file)
@@ -13,12 +13,12 @@ public:
 
        inline bool GetIdentity(string *value) const
        {
-               return GetDictionary()->GetValueString("identity", value);
+               return GetPropertyString("identity", value);
        }
 
        inline void SetIdentity(const string& value)
        {
-               GetDictionary()->SetValueString("identity", value);
+               SetPropertyString("identity", value);
        }
 };
 
index 6e58c64c1f3075466c1084664fca4a9f777c33f3..057da887be0258df6e9851a8c74a0c46138611a9 100644 (file)
@@ -71,7 +71,7 @@ int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
        Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
 
        string method;
-       if (message.GetDictionary()->GetValueString("method", &method)) {
+       if (message.GetPropertyString("method", &method)) {
                JsonRpcRequest request = message;
 
                string id;
index f614afc6b48032b14542bd3d64b60c998cecccf7..f87ef71e9e9e5c245f21955c620020d872f2e27a 100644 (file)
@@ -40,9 +40,9 @@ int SubscriptionComponent::SyncSubscription(Endpoint::Ptr target, string type, c
        request.SetVersion("2.0");
        request.SetMethod(type);
 
-       Message params;
-       params.GetDictionary()->SetValueString("method", nmea.Method);
-       request.SetParams(params);
+       SubscriptionMessage subscriptionMessage;
+       subscriptionMessage.SetMethod(nmea.Method);
+       request.SetParams(subscriptionMessage);
 
        target->ProcessRequest(m_SubscriptionEndpoint, request);
 
index 5e56e1a66825a02b1d327b4c86c46d32ff77f4ed..98464f04e0cb6e14d060400de1aad8fa5f5994f0 100644 (file)
@@ -13,12 +13,12 @@ public:
 
        inline bool GetMethod(string *value) const
        {
-               return GetDictionary()->GetValueString("method", value);
+               return GetPropertyString("method", value);
        }
 
        inline void SetMethod(const string& value)
        {
-               GetDictionary()->SetValueString("method", value);
+               SetPropertyString("method", value);
        }
 };
 
index d9d1df7697e45a5cdf8450060c75398186684cab..45362d9e7a7ae03552b8ed48eeafbd913208852a 100644 (file)
@@ -13,49 +13,42 @@ public:
 
        inline bool GetVersion(string *value) const
        {
-               return GetDictionary()->GetValueString("jsonrpc", value);
+               return GetPropertyString("jsonrpc", value);
        }
 
        inline void SetVersion(const string& value)
        {
-               GetDictionary()->SetValueString("jsonrpc", value);
+               SetPropertyString("jsonrpc", value);
        }
 
        inline bool GetMethod(string *value) const
        {
-               return GetDictionary()->GetValueString("method", value);
+               return GetPropertyString("method", value);
        }
 
        inline void SetMethod(const string& value)
        {
-               GetDictionary()->SetValueString("method", value);
+               SetPropertyString("method", value);
        }
 
        inline bool GetParams(Message *value) const
        {
-               Dictionary::Ptr dictionary;
-
-               if (!GetDictionary()->GetValueDictionary("params", &dictionary))
-                       return false;
-
-               *value = Message(dictionary);
-
-               return true;
+               return GetPropertyMessage("params", value);
        }
 
        inline void SetParams(const Message& value)
        {
-               GetDictionary()->SetValueDictionary("params", value.GetDictionary());
+               SetPropertyMessage("params", value);
        }
 
        inline bool GetID(string *value) const
        {
-               return GetDictionary()->GetValueString("id", value);
+               return GetPropertyString("id", value);
        }
 
        inline void SetID(const string& value)
        {
-               GetDictionary()->SetValueString("id", value);
+               SetPropertyString("id", value);
        }
 };
 
index aed6ff38adef64073dc9328d88ee3af7684d42d5..ab001b973e839eab34e2e9fdcfdf2926d74c9281 100644 (file)
@@ -12,42 +12,42 @@ public:
 
        inline bool GetVersion(string *value) const
        {
-               return GetDictionary()->GetValueString("jsonrpc", value);
+               return GetPropertyString("jsonrpc", value);
        }
 
        inline void SetJsonRpc(const string& value)
        {
-               GetDictionary()->SetValueString("jsonrpc", value);
+               SetPropertyString("jsonrpc", value);
        }
 
        bool GetResult(string *value) const
        {
-               return GetDictionary()->GetValueString("result", value);
+               return GetPropertyString("result", value);
        }
 
        void SetResult(const string& value)
        {
-               GetDictionary()->SetValueString("result", value);
+               SetPropertyString("result", value);
        }
 
        bool GetError(string *value) const
        {
-               return GetDictionary()->GetValueString("error", value);
+               return GetPropertyString("error", value);
        }
 
        void SetError(const string& value)
        {
-               GetDictionary()->SetValueString("error", value);
+               SetPropertyString("error", value);
        }
 
        bool GetID(string *value) const
        {
-               return GetDictionary()->GetValueString("id", value);
+               return GetPropertyString("id", value);
        }
 
        void SetID(const string& value)
        {
-               GetDictionary()->SetValueString("id", value);
+               SetPropertyString("id", value);
        }
 };
 
index 2b23caa93c45a3020869e1e790f1b3bcd4580d21..d7786af21611a7b95cd2fdaeb5ad5e1de4a01d68 100644 (file)
@@ -21,3 +21,38 @@ Dictionary::Ptr Message::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
+{
+       Dictionary::Ptr dictionary;
+       if (!GetDictionary()->GetPropertyDictionary(key, &dictionary))
+               return false;
+
+       *value = Message(dictionary);
+       return true;
+}
+
+void Message::SetPropertyString(string key, const string& value)
+{
+       GetDictionary()->SetProperty(key, value);
+}
+
+void Message::SetPropertyInteger(string key, long value)
+{
+       GetDictionary()->SetProperty(key, value);
+}
+
+void Message::SetPropertyMessage(string key, const Message& value)
+{
+       GetDictionary()->SetProperty(key, Variant(value.GetDictionary()));
+}
index 589de15c0f97bd9dbdcf4379a70a6a70b2810a10..a48e84fd64468d9fa26f2482991e8bbccfcc822a 100644 (file)
@@ -15,6 +15,15 @@ public:
        Message(const Message& message);
 
        Dictionary::Ptr GetDictionary(void) const;
+
+       bool GetPropertyString(string key, string *value) const;
+       void SetPropertyString(string key, const string& value);
+
+       bool GetPropertyInteger(string key, long *value) const;
+       void SetPropertyInteger(string key, long value);
+
+       bool GetPropertyMessage(string key, Message *value) const;
+       void SetPropertyMessage(string key, const Message& value);
 };
 
 }
index 85347cc0ef82ccdc88eaae7d921f2970809cb980..dd3e0e76f283993e34a22e81919e1a166fbc891c 100644 (file)
@@ -11,13 +11,13 @@ Dictionary::Ptr Netstring::GetDictionaryFromJson(json_t *json)
        for (cJSON *i = json->child; i != NULL; i = i->next) {
                switch (i->type) {
                        case cJSON_Number:
-                               dictionary->SetValueInteger(i->string, i->valueint);
+                               dictionary->SetProperty(i->string, i->valueint);
                                break;
                        case cJSON_String:
-                               dictionary->SetValueString(i->string, i->valuestring);
+                               dictionary->SetProperty(i->string, i->valuestring);
                                break;
                        case cJSON_Object:
-                               dictionary->SetValueDictionary(i->string, GetDictionaryFromJson(i));
+                               dictionary->SetProperty(i->string, GetDictionaryFromJson(i));
                                break;
                        default:
                                break;