mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 15:44:11 +02:00
Cleaned up message classes.
This commit is contained in:
parent
a4b0da505f
commit
b1256d9fe9
@ -14,9 +14,11 @@ ConfigHive::WeakPtr ConfigCollection::GetHive(void) const
|
|||||||
|
|
||||||
void ConfigCollection::AddObject(const ConfigObject::Ptr& object)
|
void ConfigCollection::AddObject(const ConfigObject::Ptr& object)
|
||||||
{
|
{
|
||||||
|
RemoveObject(object);
|
||||||
|
|
||||||
Objects[object->GetName()] = object;
|
Objects[object->GetName()] = object;
|
||||||
|
|
||||||
ConfigObjectEventArgs ea;
|
EventArgs ea;
|
||||||
ea.Source = object;
|
ea.Source = object;
|
||||||
OnObjectCreated(ea);
|
OnObjectCreated(ea);
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ void ConfigCollection::RemoveObject(const ConfigObject::Ptr& object)
|
|||||||
if (oi != Objects.end()) {
|
if (oi != Objects.end()) {
|
||||||
Objects.erase(oi);
|
Objects.erase(oi);
|
||||||
|
|
||||||
ConfigObjectEventArgs ea;
|
EventArgs ea;
|
||||||
ea.Source = object;
|
ea.Source = object;
|
||||||
OnObjectRemoved(ea);
|
OnObjectRemoved(ea);
|
||||||
|
|
||||||
@ -52,9 +54,9 @@ ConfigObject::Ptr ConfigCollection::GetObject(const string& name)
|
|||||||
return oi->second;
|
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++) {
|
for (ObjectIterator oi = Objects.begin(); oi != Objects.end(); oi++) {
|
||||||
ea.Source = oi->second;
|
ea.Source = oi->second;
|
||||||
|
@ -25,11 +25,11 @@ public:
|
|||||||
void RemoveObject(const ConfigObject::Ptr& object);
|
void RemoveObject(const ConfigObject::Ptr& object);
|
||||||
ConfigObject::Ptr GetObject(const string& name = string());
|
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<EventArgs> OnObjectCreated;
|
||||||
Event<ConfigObjectEventArgs> OnObjectRemoved;
|
Event<EventArgs> OnObjectRemoved;
|
||||||
Event<ConfigObjectEventArgs> OnPropertyChanged;
|
Event<DictionaryPropertyChangedEventArgs> OnPropertyChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ ConfigCollection::Ptr ConfigHive::GetCollection(const string& collection)
|
|||||||
return ci->second;
|
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);
|
CollectionIterator ci = Collections.find(type);
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ public:
|
|||||||
ConfigObject::Ptr GetObject(const string& collection, const string& name = string());
|
ConfigObject::Ptr GetObject(const string& collection, const string& name = string());
|
||||||
ConfigCollection::Ptr GetCollection(const string& collection);
|
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<EventArgs> OnObjectCreated;
|
||||||
Event<ConfigObjectEventArgs> OnObjectRemoved;
|
Event<EventArgs> OnObjectRemoved;
|
||||||
Event<ConfigObjectEventArgs> OnPropertyChanged;
|
Event<DictionaryPropertyChangedEventArgs> OnPropertyChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,11 @@ ConfigObject::ConfigObject(const string& type, const string& name)
|
|||||||
|
|
||||||
void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
|
void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
|
||||||
{
|
{
|
||||||
|
if (m_Hive.lock())
|
||||||
|
throw InvalidArgumentException();
|
||||||
|
|
||||||
m_Hive = hive;
|
m_Hive = hive;
|
||||||
|
OnPropertyChanged += bind_weak(&ConfigObject::PropertyChangedHandler, shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigHive::WeakPtr ConfigObject::GetHive(void) const
|
ConfigHive::WeakPtr ConfigObject::GetHive(void) const
|
||||||
@ -38,64 +42,13 @@ string ConfigObject::GetType(void) const
|
|||||||
return m_Type;
|
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();
|
ConfigHive::Ptr hive = m_Hive.lock();
|
||||||
if (hive) {
|
if (hive) {
|
||||||
ConfigObjectEventArgs ea;
|
hive->GetCollection(m_Type)->OnPropertyChanged(dpcea);
|
||||||
ea.Source = shared_from_this();
|
hive->OnPropertyChanged(dpcea);
|
||||||
ea.Property = name;
|
|
||||||
|
|
||||||
string oldValue;
|
|
||||||
if (GetProperty(name, &oldValue))
|
|
||||||
ea.OldValue = oldValue;
|
|
||||||
|
|
||||||
hive->GetCollection(m_Type)->OnPropertyChanged(ea);
|
|
||||||
hive->OnPropertyChanged(ea);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigObject::SetPropertyInteger(const string& name, int value)
|
return 0;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
@ -8,16 +8,7 @@ namespace icinga
|
|||||||
|
|
||||||
class ConfigHive;
|
class ConfigHive;
|
||||||
|
|
||||||
struct I2_BASE_API ConfigObjectEventArgs : public EventArgs
|
class I2_BASE_API ConfigObject : public Dictionary
|
||||||
{
|
|
||||||
typedef shared_ptr<ConfigObjectEventArgs> Ptr;
|
|
||||||
typedef weak_ptr<ConfigObjectEventArgs> WeakPtr;
|
|
||||||
|
|
||||||
string Property;
|
|
||||||
string OldValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
class I2_BASE_API ConfigObject : public Object
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
weak_ptr<ConfigHive> m_Hive;
|
weak_ptr<ConfigHive> m_Hive;
|
||||||
@ -25,6 +16,8 @@ private:
|
|||||||
string m_Name;
|
string m_Name;
|
||||||
string m_Type;
|
string m_Type;
|
||||||
|
|
||||||
|
int PropertyChangedHandler(const DictionaryPropertyChangedEventArgs dpcea);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<ConfigObject> Ptr;
|
typedef shared_ptr<ConfigObject> Ptr;
|
||||||
typedef weak_ptr<ConfigObject> WeakPtr;
|
typedef weak_ptr<ConfigObject> WeakPtr;
|
||||||
@ -42,14 +35,6 @@ public:
|
|||||||
|
|
||||||
void SetType(const string& type);
|
void SetType(const string& type);
|
||||||
string GetType(void) const;
|
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,62 +2,75 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
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())
|
if (i == m_Data.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*value = i->second;
|
*value = i->second;
|
||||||
|
|
||||||
return true;
|
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);
|
||||||
m_Data[key] = value;
|
|
||||||
|
Variant oldValue;
|
||||||
|
if (i != m_Data.end()) {
|
||||||
|
oldValue = i->second;
|
||||||
|
m_Data.erase(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dictionary::GetValueString(string key, string *value)
|
m_Data[key] = value;
|
||||||
|
|
||||||
|
DictionaryPropertyChangedEventArgs dpce;
|
||||||
|
dpce.Source = shared_from_this();
|
||||||
|
dpce.Property = key;
|
||||||
|
dpce.OldValue = oldValue;
|
||||||
|
dpce.NewValue = value;
|
||||||
|
OnPropertyChanged(dpce);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Dictionary::GetPropertyString(string key, string *value)
|
||||||
{
|
{
|
||||||
Variant data;
|
Variant data;
|
||||||
|
|
||||||
if (!GetValueVariant(key, &data))
|
if (!GetProperty(key, &data))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*value = static_cast<string>(data);
|
*value = static_cast<string>(data);
|
||||||
return true;
|
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;
|
Variant data;
|
||||||
|
|
||||||
if (!GetValueVariant(key, &data))
|
if (!GetProperty(key, &data))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*value = data;
|
*value = static_cast<long>(data);
|
||||||
return true;
|
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;
|
Dictionary::Ptr dictionary;
|
||||||
Variant data;
|
Variant data;
|
||||||
|
|
||||||
if (!GetValueVariant(key, &data))
|
if (!GetProperty(key, &data))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dictionary = dynamic_pointer_cast<Dictionary>(data.GetObject());
|
dictionary = dynamic_pointer_cast<Dictionary>(data.GetObject());
|
||||||
@ -70,25 +83,25 @@ bool Dictionary::GetValueDictionary(string key, Dictionary::Ptr *value)
|
|||||||
return true;
|
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;
|
Variant data;
|
||||||
|
|
||||||
if (!GetValueVariant(key, &data))
|
if (!GetProperty(key, &data))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*value = data;
|
*value = data;
|
||||||
return true;
|
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)
|
DictionaryIterator Dictionary::Begin(void)
|
||||||
|
@ -4,8 +4,16 @@
|
|||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
typedef map<string, Variant>::const_iterator ConstDictionaryIterator;
|
||||||
typedef map<string, Variant>::iterator DictionaryIterator;
|
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
|
class I2_BASE_API Dictionary : public Object
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -15,23 +23,25 @@ public:
|
|||||||
typedef shared_ptr<Dictionary> Ptr;
|
typedef shared_ptr<Dictionary> Ptr;
|
||||||
typedef weak_ptr<Dictionary> WeakPtr;
|
typedef weak_ptr<Dictionary> WeakPtr;
|
||||||
|
|
||||||
bool GetValueVariant(string key, Variant *value);
|
bool GetProperty(string key, Variant *value) const;
|
||||||
void SetValueVariant(string key, const Variant& value);
|
void SetProperty(string key, const Variant& value);
|
||||||
|
|
||||||
bool GetValueString(string key, string *value);
|
bool GetPropertyString(string key, string *value);
|
||||||
void SetValueString(string key, const string& value);
|
void SetPropertyString(string key, const string& value);
|
||||||
|
|
||||||
bool GetValueInteger(string key, long *value);
|
bool GetPropertyInteger(string key, long *value);
|
||||||
void SetValueInteger(string key, long value);
|
void SetPropertyInteger(string key, long value);
|
||||||
|
|
||||||
bool GetValueDictionary(string key, Dictionary::Ptr *value);
|
bool GetPropertyDictionary(string key, Dictionary::Ptr *value);
|
||||||
void SetValueDictionary(string key, const Dictionary::Ptr& value);
|
void SetPropertyDictionary(string key, const Dictionary::Ptr& value);
|
||||||
|
|
||||||
bool GetValueObject(string key, Object::Ptr *value);
|
bool GetPropertyObject(string key, Object::Ptr *value);
|
||||||
void SetValueObject(string key, const Object::Ptr& value);
|
void SetPropertyObject(string key, const Object::Ptr& value);
|
||||||
|
|
||||||
DictionaryIterator Begin(void);
|
DictionaryIterator Begin(void);
|
||||||
DictionaryIterator End(void);
|
DictionaryIterator End(void);
|
||||||
|
|
||||||
|
Event<DictionaryPropertyChangedEventArgs> OnPropertyChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,29 +2,20 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
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
|
void Variant::Convert(VariantType newType) const
|
||||||
{
|
{
|
||||||
if (newType == m_Type)
|
if (newType == m_Type)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (m_Type == VariantString && newType == VariantInteger) {
|
||||||
|
m_IntegerValue = strtol(m_StringValue.c_str(), NULL, 10);
|
||||||
|
m_Type = VariantInteger;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: convert variant data
|
// TODO: convert variant data
|
||||||
throw NotImplementedException();
|
throw InvalidArgumentException("Invalid variant conversion.");
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantType Variant::GetType(void) const
|
VariantType Variant::GetType(void) const
|
||||||
@ -53,6 +44,11 @@ Object::Ptr Variant::GetObject(void) const
|
|||||||
return m_ObjectValue;
|
return m_ObjectValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Variant::IsEmpty(void) const
|
||||||
|
{
|
||||||
|
return (m_Type == VariantEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
Variant::operator long(void) const
|
Variant::operator long(void) const
|
||||||
{
|
{
|
||||||
return GetInteger();
|
return GetInteger();
|
||||||
|
@ -24,10 +24,16 @@ private:
|
|||||||
void Convert(VariantType newType) const;
|
void Convert(VariantType newType) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Variant(void);
|
inline Variant::Variant(void) : m_Type(VariantEmpty) { }
|
||||||
Variant(long value);
|
|
||||||
Variant(string value);
|
inline Variant::Variant(long value) : m_Type(VariantInteger), m_IntegerValue(value) { }
|
||||||
Variant(Object::Ptr 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;
|
VariantType GetType(void) const;
|
||||||
|
|
||||||
@ -35,6 +41,8 @@ public:
|
|||||||
string GetString(void) const;
|
string GetString(void) const;
|
||||||
Object::Ptr GetObject(void) const;
|
Object::Ptr GetObject(void) const;
|
||||||
|
|
||||||
|
bool IsEmpty(void) const;
|
||||||
|
|
||||||
operator long(void) const;
|
operator long(void) const;
|
||||||
operator string(void) const;
|
operator string(void) const;
|
||||||
operator Object::Ptr(void) const;
|
operator Object::Ptr(void) const;
|
||||||
|
@ -16,8 +16,8 @@ void ConfigFileComponent::Start(void)
|
|||||||
FIFO::Ptr fifo = make_shared<FIFO>();
|
FIFO::Ptr fifo = make_shared<FIFO>();
|
||||||
|
|
||||||
string filename;
|
string filename;
|
||||||
if (!GetConfig()->GetProperty("configFilename", &filename))
|
if (!GetConfig()->GetPropertyString("configFilename", &filename))
|
||||||
throw ConfigParserException("Missing configFilename property");
|
throw InvalidArgumentException("Missing 'configFilename' property");
|
||||||
|
|
||||||
fp.open(filename.c_str(), ifstream::in);
|
fp.open(filename.c_str(), ifstream::in);
|
||||||
if (fp.fail())
|
if (fp.fail())
|
||||||
@ -61,7 +61,7 @@ void ConfigFileComponent::Start(void)
|
|||||||
|
|
||||||
string value = property->valuestring;
|
string value = property->valuestring;
|
||||||
|
|
||||||
cfgobj->SetProperty(key, value);
|
cfgobj->SetPropertyString(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
GetApplication()->GetConfigHive()->AddObject(cfgobj);
|
GetApplication()->GetConfigHive()->AddObject(cfgobj);
|
||||||
|
@ -21,7 +21,7 @@ void ConfigRpcComponent::Start(void)
|
|||||||
|
|
||||||
m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
|
m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
|
||||||
|
|
||||||
int configSource;
|
long configSource;
|
||||||
if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
|
if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
|
||||||
m_ConfigRpcEndpoint->RegisterMethodHandler("config::FetchObjects", bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
|
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;
|
Message params;
|
||||||
msg.SetParams(params);
|
msg.SetParams(params);
|
||||||
|
|
||||||
params.GetDictionary()->SetValueString("name", object->GetName());
|
params.GetDictionary()->SetPropertyString("name", object->GetName());
|
||||||
params.GetDictionary()->SetValueString("type", object->GetType());
|
params.GetDictionary()->SetPropertyString("type", object->GetType());
|
||||||
|
|
||||||
if (includeProperties) {
|
if (includeProperties) {
|
||||||
Message properties;
|
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++) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::LocalObjectCreatedHandler(const ConfigObjectEventArgs& ea)
|
int ConfigRpcComponent::LocalObjectCreatedHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||||
|
|
||||||
int replicate = 0;
|
long replicate = 0;
|
||||||
object->GetPropertyInteger("replicate", &replicate);
|
object->GetPropertyInteger("replicate", &replicate);
|
||||||
|
|
||||||
if (replicate) {
|
if (replicate) {
|
||||||
@ -128,11 +128,11 @@ int ConfigRpcComponent::LocalObjectCreatedHandler(const ConfigObjectEventArgs& e
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::LocalObjectRemovedHandler(const ConfigObjectEventArgs& ea)
|
int ConfigRpcComponent::LocalObjectRemovedHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||||
|
|
||||||
int replicate = 0;
|
long replicate = 0;
|
||||||
object->GetPropertyInteger("replicate", &replicate);
|
object->GetPropertyInteger("replicate", &replicate);
|
||||||
|
|
||||||
if (replicate) {
|
if (replicate) {
|
||||||
@ -143,11 +143,11 @@ int ConfigRpcComponent::LocalObjectRemovedHandler(const ConfigObjectEventArgs& e
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::LocalPropertyChangedHandler(const ConfigObjectEventArgs& ea)
|
int ConfigRpcComponent::LocalPropertyChangedHandler(const DictionaryPropertyChangedEventArgs& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||||
|
|
||||||
int replicate = 0;
|
long replicate = 0;
|
||||||
object->GetPropertyInteger("replicate", &replicate);
|
object->GetPropertyInteger("replicate", &replicate);
|
||||||
|
|
||||||
if (replicate) {
|
if (replicate) {
|
||||||
@ -156,12 +156,13 @@ int ConfigRpcComponent::LocalPropertyChangedHandler(const ConfigObjectEventArgs&
|
|||||||
msg.SetParams(params);
|
msg.SetParams(params);
|
||||||
|
|
||||||
Message properties;
|
Message properties;
|
||||||
params.GetDictionary()->SetValueDictionary("properties", properties.GetDictionary());
|
params.GetDictionary()->SetPropertyDictionary("properties", properties.GetDictionary());
|
||||||
|
|
||||||
string value;
|
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();
|
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
|
||||||
mgr->SendMulticastRequest(m_ConfigRpcEndpoint, msg);
|
mgr->SendMulticastRequest(m_ConfigRpcEndpoint, msg);
|
||||||
@ -180,11 +181,11 @@ int ConfigRpcComponent::RemoteObjectUpdatedHandler(const NewRequestEventArgs& ea
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
if (!params.GetDictionary()->GetValueString("name", &name))
|
if (!params.GetDictionary()->GetPropertyString("name", &name))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
string type;
|
string type;
|
||||||
if (!params.GetDictionary()->GetValueString("type", &type))
|
if (!params.GetDictionary()->GetPropertyString("type", &type))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
|
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
|
||||||
@ -196,11 +197,11 @@ int ConfigRpcComponent::RemoteObjectUpdatedHandler(const NewRequestEventArgs& ea
|
|||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr properties;
|
Dictionary::Ptr properties;
|
||||||
if (!params.GetDictionary()->GetValueDictionary("properties", &properties))
|
if (!params.GetDictionary()->GetPropertyDictionary("properties", &properties))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (DictionaryIterator i = properties->Begin(); i != properties->End(); i++) {
|
for (DictionaryIterator i = properties->Begin(); i != properties->End(); i++) {
|
||||||
object->SetProperty(i->first, i->second);
|
object->SetPropertyString(i->first, i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (was_null)
|
if (was_null)
|
||||||
@ -218,11 +219,11 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
if (!params.GetDictionary()->GetValueString("name", &name))
|
if (!params.GetDictionary()->GetPropertyString("name", &name))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
string type;
|
string type;
|
||||||
if (!params.GetDictionary()->GetValueString("type", &type))
|
if (!params.GetDictionary()->GetPropertyString("type", &type))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
|
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
|
||||||
|
@ -14,9 +14,9 @@ private:
|
|||||||
int NewEndpointHandler(const NewEndpointEventArgs& ea);
|
int NewEndpointHandler(const NewEndpointEventArgs& ea);
|
||||||
int WelcomeMessageHandler(const NewRequestEventArgs& ea);
|
int WelcomeMessageHandler(const NewRequestEventArgs& ea);
|
||||||
|
|
||||||
int LocalObjectCreatedHandler(const ConfigObjectEventArgs& ea);
|
int LocalObjectCreatedHandler(const EventArgs& ea);
|
||||||
int LocalObjectRemovedHandler(const ConfigObjectEventArgs& ea);
|
int LocalObjectRemovedHandler(const EventArgs& ea);
|
||||||
int LocalPropertyChangedHandler(const ConfigObjectEventArgs& ea);
|
int LocalPropertyChangedHandler(const DictionaryPropertyChangedEventArgs& ea);
|
||||||
|
|
||||||
int FetchObjectsHandler(const NewRequestEventArgs& ea);
|
int FetchObjectsHandler(const NewRequestEventArgs& ea);
|
||||||
int RemoteObjectUpdatedHandler(const NewRequestEventArgs& ea);
|
int RemoteObjectUpdatedHandler(const NewRequestEventArgs& ea);
|
||||||
|
@ -117,9 +117,9 @@ int EndpointManager::NewMethodSinkHandler(const NewMethodEventArgs& ea)
|
|||||||
request.SetVersion("2.0");
|
request.SetVersion("2.0");
|
||||||
request.SetMethod("message::Subscribe");
|
request.SetMethod("message::Subscribe");
|
||||||
|
|
||||||
Message params;
|
SubscriptionMessage subscriptionMessage;
|
||||||
params.GetDictionary()->SetValueString("method", ea.Method);
|
subscriptionMessage.SetMethod(ea.Method);
|
||||||
request.SetParams(params);
|
request.SetParams(subscriptionMessage);
|
||||||
|
|
||||||
SendMulticastRequest(sender, request);
|
SendMulticastRequest(sender, request);
|
||||||
|
|
||||||
@ -137,9 +137,9 @@ int EndpointManager::NewMethodSourceHandler(const NewMethodEventArgs& ea)
|
|||||||
request.SetVersion("2.0");
|
request.SetVersion("2.0");
|
||||||
request.SetMethod("message::Provide");
|
request.SetMethod("message::Provide");
|
||||||
|
|
||||||
Message params;
|
SubscriptionMessage subscriptionMessage;
|
||||||
params.GetDictionary()->SetValueString("method", ea.Method);
|
subscriptionMessage.SetMethod(ea.Method);
|
||||||
request.SetParams(params);
|
request.SetParams(subscriptionMessage);
|
||||||
|
|
||||||
SendMulticastRequest(sender, request);
|
SendMulticastRequest(sender, request);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||||||
|
|
||||||
ConfigCollection::Ptr componentCollection = GetConfigHive()->GetCollection("component");
|
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->OnObjectCreated += NewComponentHandler;
|
||||||
componentCollection->ForEachObject(NewComponentHandler);
|
componentCollection->ForEachObject(NewComponentHandler);
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||||||
|
|
||||||
ConfigCollection::Ptr listenerCollection = GetConfigHive()->GetCollection("rpclistener");
|
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->OnObjectCreated += NewRpcListenerHandler;
|
||||||
listenerCollection->ForEachObject(NewRpcListenerHandler);
|
listenerCollection->ForEachObject(NewRpcListenerHandler);
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||||||
|
|
||||||
ConfigCollection::Ptr connectionCollection = GetConfigHive()->GetCollection("rpcconnection");
|
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->OnObjectCreated += NewRpcConnectionHandler;
|
||||||
connectionCollection->ForEachObject(NewRpcConnectionHandler);
|
connectionCollection->ForEachObject(NewRpcConnectionHandler);
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||||||
RegisterComponent(subscriptionsComponent);
|
RegisterComponent(subscriptionsComponent);
|
||||||
|
|
||||||
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
|
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
|
||||||
fileComponentConfig->SetProperty("configFilename", args[1]);
|
fileComponentConfig->SetPropertyString("configFilename", args[1]);
|
||||||
fileComponentConfig->SetPropertyInteger("replicate", 0);
|
fileComponentConfig->SetPropertyInteger("replicate", 0);
|
||||||
GetConfigHive()->AddObject(fileComponentConfig);
|
GetConfigHive()->AddObject(fileComponentConfig);
|
||||||
|
|
||||||
@ -103,12 +103,12 @@ EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
|
|||||||
return m_EndpointManager;
|
return m_EndpointManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::NewComponentHandler(const ConfigObjectEventArgs& ea)
|
int IcingaApplication::NewComponentHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
string path;
|
string path;
|
||||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||||
|
|
||||||
if (!object->GetProperty("path", &path)) {
|
if (!object->GetPropertyString("path", &path)) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
path = object->GetName() + ".dll";
|
path = object->GetName() + ".dll";
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
@ -123,7 +123,7 @@ int IcingaApplication::NewComponentHandler(const ConfigObjectEventArgs& ea)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::DeletedComponentHandler(const ConfigObjectEventArgs& ea)
|
int IcingaApplication::DeletedComponentHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||||
Component::Ptr component = GetComponent(object->GetName());
|
Component::Ptr component = GetComponent(object->GetName());
|
||||||
@ -132,13 +132,19 @@ int IcingaApplication::DeletedComponentHandler(const ConfigObjectEventArgs& ea)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::NewRpcListenerHandler(const ConfigObjectEventArgs& ea)
|
int IcingaApplication::NewRpcListenerHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||||
int port;
|
long portValue;
|
||||||
|
unsigned short port;
|
||||||
|
|
||||||
if (!object->GetPropertyInteger("port", &port))
|
if (!object->GetPropertyInteger("port", &portValue))
|
||||||
throw Exception("Parameter 'port' is required for 'rpclistener' objects.");
|
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);
|
Log("Creating JSON-RPC listener on port %d", port);
|
||||||
|
|
||||||
@ -147,24 +153,30 @@ int IcingaApplication::NewRpcListenerHandler(const ConfigObjectEventArgs& ea)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::DeletedRpcListenerHandler(const ConfigObjectEventArgs& ea)
|
int IcingaApplication::DeletedRpcListenerHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
throw Exception("Unsupported operation.");
|
throw Exception("Unsupported operation.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::NewRpcConnectionHandler(const ConfigObjectEventArgs& ea)
|
int IcingaApplication::NewRpcConnectionHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
|
||||||
string hostname;
|
string hostname;
|
||||||
int port;
|
long portValue;
|
||||||
|
unsigned short port;
|
||||||
|
|
||||||
if (!object->GetProperty("hostname", &hostname))
|
if (!object->GetPropertyString("hostname", &hostname))
|
||||||
throw Exception("Parameter 'hostname' is required for 'rpcconnection' objects.");
|
throw InvalidArgumentException("Parameter 'hostname' is required for 'rpcconnection' objects.");
|
||||||
|
|
||||||
if (!object->GetPropertyInteger("port", &port))
|
if (!object->GetPropertyInteger("port", &portValue))
|
||||||
throw Exception("Parameter 'port' is required for 'rpcconnection' objects.");
|
throw InvalidArgumentException("Parameter 'port' is required for 'rpcconnection' objects.");
|
||||||
|
|
||||||
|
if (portValue < 0 || portValue > USHRT_MAX)
|
||||||
|
throw InvalidArgumentException("Parameter 'port' contains an invalid value.");
|
||||||
|
|
||||||
|
port = (unsigned short)portValue;
|
||||||
|
|
||||||
Log("Creating JSON-RPC connection to %s:%d", hostname.c_str(), port);
|
Log("Creating JSON-RPC connection to %s:%d", hostname.c_str(), port);
|
||||||
|
|
||||||
@ -173,7 +185,7 @@ int IcingaApplication::NewRpcConnectionHandler(const ConfigObjectEventArgs& ea)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::DeletedRpcConnectionHandler(const ConfigObjectEventArgs& ea)
|
int IcingaApplication::DeletedRpcConnectionHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
throw Exception("Unsupported operation.");
|
throw Exception("Unsupported operation.");
|
||||||
|
|
||||||
|
@ -11,14 +11,14 @@ private:
|
|||||||
Timer::Ptr m_TestTimer;
|
Timer::Ptr m_TestTimer;
|
||||||
VirtualEndpoint::Ptr m_TestEndpoint;
|
VirtualEndpoint::Ptr m_TestEndpoint;
|
||||||
|
|
||||||
int NewComponentHandler(const ConfigObjectEventArgs& ea);
|
int NewComponentHandler(const EventArgs& ea);
|
||||||
int DeletedComponentHandler(const ConfigObjectEventArgs& ea);
|
int DeletedComponentHandler(const EventArgs& ea);
|
||||||
|
|
||||||
int NewRpcListenerHandler(const ConfigObjectEventArgs& ea);
|
int NewRpcListenerHandler(const EventArgs& ea);
|
||||||
int DeletedRpcListenerHandler(const ConfigObjectEventArgs& ea);
|
int DeletedRpcListenerHandler(const EventArgs& ea);
|
||||||
|
|
||||||
int NewRpcConnectionHandler(const ConfigObjectEventArgs& ea);
|
int NewRpcConnectionHandler(const EventArgs& ea);
|
||||||
int DeletedRpcConnectionHandler(const ConfigObjectEventArgs& ea);
|
int DeletedRpcConnectionHandler(const EventArgs& ea);
|
||||||
|
|
||||||
int TestTimerHandler(const TimerEventArgs& tea);
|
int TestTimerHandler(const TimerEventArgs& tea);
|
||||||
public:
|
public:
|
||||||
|
@ -13,12 +13,12 @@ public:
|
|||||||
|
|
||||||
inline bool GetIdentity(string *value) const
|
inline bool GetIdentity(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("identity", value);
|
return GetPropertyString("identity", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetIdentity(const string& value)
|
inline void SetIdentity(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("identity", value);
|
SetPropertyString("identity", value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
|
|||||||
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
|
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
|
||||||
|
|
||||||
string method;
|
string method;
|
||||||
if (message.GetDictionary()->GetValueString("method", &method)) {
|
if (message.GetPropertyString("method", &method)) {
|
||||||
JsonRpcRequest request = message;
|
JsonRpcRequest request = message;
|
||||||
|
|
||||||
string id;
|
string id;
|
||||||
|
@ -40,9 +40,9 @@ int SubscriptionComponent::SyncSubscription(Endpoint::Ptr target, string type, c
|
|||||||
request.SetVersion("2.0");
|
request.SetVersion("2.0");
|
||||||
request.SetMethod(type);
|
request.SetMethod(type);
|
||||||
|
|
||||||
Message params;
|
SubscriptionMessage subscriptionMessage;
|
||||||
params.GetDictionary()->SetValueString("method", nmea.Method);
|
subscriptionMessage.SetMethod(nmea.Method);
|
||||||
request.SetParams(params);
|
request.SetParams(subscriptionMessage);
|
||||||
|
|
||||||
target->ProcessRequest(m_SubscriptionEndpoint, request);
|
target->ProcessRequest(m_SubscriptionEndpoint, request);
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ public:
|
|||||||
|
|
||||||
inline bool GetMethod(string *value) const
|
inline bool GetMethod(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("method", value);
|
return GetPropertyString("method", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetMethod(const string& value)
|
inline void SetMethod(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("method", value);
|
SetPropertyString("method", value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,49 +13,42 @@ public:
|
|||||||
|
|
||||||
inline bool GetVersion(string *value) const
|
inline bool GetVersion(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("jsonrpc", value);
|
return GetPropertyString("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetVersion(const string& value)
|
inline void SetVersion(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("jsonrpc", value);
|
SetPropertyString("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool GetMethod(string *value) const
|
inline bool GetMethod(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("method", value);
|
return GetPropertyString("method", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetMethod(const string& value)
|
inline void SetMethod(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("method", value);
|
SetPropertyString("method", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool GetParams(Message *value) const
|
inline bool GetParams(Message *value) const
|
||||||
{
|
{
|
||||||
Dictionary::Ptr dictionary;
|
return GetPropertyMessage("params", value);
|
||||||
|
|
||||||
if (!GetDictionary()->GetValueDictionary("params", &dictionary))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
*value = Message(dictionary);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetParams(const Message& value)
|
inline void SetParams(const Message& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueDictionary("params", value.GetDictionary());
|
SetPropertyMessage("params", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool GetID(string *value) const
|
inline bool GetID(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("id", value);
|
return GetPropertyString("id", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetID(const string& value)
|
inline void SetID(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("id", value);
|
SetPropertyString("id", value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,42 +12,42 @@ public:
|
|||||||
|
|
||||||
inline bool GetVersion(string *value) const
|
inline bool GetVersion(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("jsonrpc", value);
|
return GetPropertyString("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetJsonRpc(const string& value)
|
inline void SetJsonRpc(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("jsonrpc", value);
|
SetPropertyString("jsonrpc", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetResult(string *value) const
|
bool GetResult(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("result", value);
|
return GetPropertyString("result", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetResult(const string& value)
|
void SetResult(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("result", value);
|
SetPropertyString("result", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetError(string *value) const
|
bool GetError(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("error", value);
|
return GetPropertyString("error", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetError(const string& value)
|
void SetError(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("error", value);
|
SetPropertyString("error", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetID(string *value) const
|
bool GetID(string *value) const
|
||||||
{
|
{
|
||||||
return GetDictionary()->GetValueString("id", value);
|
return GetPropertyString("id", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetID(const string& value)
|
void SetID(const string& value)
|
||||||
{
|
{
|
||||||
GetDictionary()->SetValueString("id", value);
|
SetPropertyString("id", value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,3 +21,38 @@ Dictionary::Ptr Message::GetDictionary(void) const
|
|||||||
{
|
{
|
||||||
return m_Dictionary;
|
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()));
|
||||||
|
}
|
||||||
|
@ -15,6 +15,15 @@ public:
|
|||||||
Message(const Message& message);
|
Message(const Message& message);
|
||||||
|
|
||||||
Dictionary::Ptr GetDictionary(void) const;
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,13 @@ Dictionary::Ptr Netstring::GetDictionaryFromJson(json_t *json)
|
|||||||
for (cJSON *i = json->child; i != NULL; i = i->next) {
|
for (cJSON *i = json->child; i != NULL; i = i->next) {
|
||||||
switch (i->type) {
|
switch (i->type) {
|
||||||
case cJSON_Number:
|
case cJSON_Number:
|
||||||
dictionary->SetValueInteger(i->string, i->valueint);
|
dictionary->SetProperty(i->string, i->valueint);
|
||||||
break;
|
break;
|
||||||
case cJSON_String:
|
case cJSON_String:
|
||||||
dictionary->SetValueString(i->string, i->valuestring);
|
dictionary->SetProperty(i->string, i->valuestring);
|
||||||
break;
|
break;
|
||||||
case cJSON_Object:
|
case cJSON_Object:
|
||||||
dictionary->SetValueDictionary(i->string, GetDictionaryFromJson(i));
|
dictionary->SetProperty(i->string, GetDictionaryFromJson(i));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user