void ConfigCollection::AddObject(const ConfigObject::Ptr& object)
{
+ RemoveObject(object);
+
Objects[object->GetName()] = object;
- ConfigObjectEventArgs ea;
+ EventArgs ea;
ea.Source = object;
OnObjectCreated(ea);
if (oi != Objects.end()) {
Objects.erase(oi);
- ConfigObjectEventArgs ea;
+ EventArgs ea;
ea.Source = object;
OnObjectRemoved(ea);
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;
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;
};
}
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);
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;
};
}
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
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;
}
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;
string m_Name;
string m_Type;
+ int PropertyChangedHandler(const DictionaryPropertyChangedEventArgs dpcea);
+
public:
typedef shared_ptr<ConfigObject> Ptr;
typedef weak_ptr<ConfigObject> WeakPtr;
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;
};
}
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());
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)
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:
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;
};
}
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
return m_ObjectValue;
}
+bool Variant::IsEmpty(void) const
+{
+ return (m_Type == VariantEmpty);
+}
+
Variant::operator long(void) const
{
return GetInteger();
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;
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;
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())
string value = property->valuestring;
- cfgobj->SetProperty(key, value);
+ cfgobj->SetPropertyString(key, value);
}
GetApplication()->GetConfigHive()->AddObject(cfgobj);
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()));
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);
}
}
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) {
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) {
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) {
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);
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();
}
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)
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();
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);
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);
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);
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);
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);
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);
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);
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 */
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());
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);
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);
return 0;
}
-int IcingaApplication::DeletedRpcConnectionHandler(const ConfigObjectEventArgs& ea)
+int IcingaApplication::DeletedRpcConnectionHandler(const EventArgs& ea)
{
throw Exception("Unsupported operation.");
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:
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);
}
};
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;
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);
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 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);
}
};
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);
}
};
{
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()));
+}
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);
};
}
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;