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