#else /* _WIN32 */
char FullExePath[MAXPATHLEN];
- GetModuleFileName(NULL, FullExePath, MAXPATHLEN);
+ GetModuleFileName(NULL, FullExePath, sizeof(FullExePath));
PathRemoveFileSpec(FullExePath);
*/
class I2_BASE_API Application : public Object {
private:
- bool m_ShuttingDown;
- ConfigHive::Ptr m_ConfigHive;
- map< string, shared_ptr<Component> > m_Components;
- vector<string> m_Arguments;
- bool m_Debugging;
+ bool m_ShuttingDown; /**< Whether the application is in the process of
+ shutting down. */
+ ConfigHive::Ptr m_ConfigHive; /**< The application's configuration. */
+ map< string, shared_ptr<Component> > m_Components; /**< Components that
+ were loaded by the application. */
+ vector<string> m_Arguments; /**< Command-line arguments */
+ bool m_Debugging; /**< Whether debugging is enabled. */
protected:
void RunEventLoop(void);
}
/**
- * Retrieves a value from the dictionary and converts it to a string.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetPropertyString(string key, string *value)
-{
- Variant data;
-
- if (!GetProperty(key, &data))
- return false;
-
- *value = static_cast<string>(data);
- return true;
-}
-
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyString(string key, const string& value)
-{
- SetProperty(key, Variant(value));
-}
-
-/**
- * Retrieves a value from the dictionary and converts it to an integer.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetPropertyInteger(string key, long *value)
-{
- Variant data;
-
- if (!GetProperty(key, &data))
- return false;
-
- *value = static_cast<long>(data);
- return true;
-}
-
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyInteger(string key, long value)
-{
- SetProperty(key, Variant(value));
-}
-
-/**
- * Retrieves a value from the dictionary and converts it to a dictionary.
+ * Retrieves a value from the dictionary.
*
* @param key The key.
* @param value Pointer to the value.
* @returns true if the value was retrieved, false otherwise.
*/
-bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
+bool Dictionary::GetProperty(string key, Dictionary::Ptr *value) const
{
- Dictionary::Ptr dictionary;
- Variant data;
+ Object::Ptr object;
- if (!GetProperty(key, &data))
+ if (!GetProperty(key, &object))
return false;
- dictionary = dynamic_pointer_cast<Dictionary>(data.GetObject());
-
- if (dictionary == NULL)
- throw InvalidArgumentException("Property is not a dictionary.");
+ Dictionary::Ptr dictionary = dynamic_pointer_cast<Dictionary>(object);
+ if (!dictionary)
+ throw InvalidArgumentException();
*value = dictionary;
-
- return true;
-}
-
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyDictionary(string key, const Dictionary::Ptr& value)
-{
- SetProperty(key, Variant(value));
-}
-
-/**
- * Retrieves a value from the dictionary and converts it to an object.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetPropertyObject(string key, Object::Ptr *value)
-{
- Variant data;
-
- if (!GetProperty(key, &data))
- return false;
-
- *value = data;
return true;
}
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetPropertyObject(string key, const Object::Ptr& value)
-{
- SetProperty(key, Variant(value));
-}
-
/**
* Returns an iterator to the beginning of the dictionary.
*
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));
-}
bool GetProperty(string key, Variant *value) const;
void SetProperty(string key, const Variant& value);
- bool GetPropertyString(string key, string *value);
- void SetPropertyString(string key, const string& value);
+ template<typename T>
+ bool GetProperty(string key, T *value) const
+ {
+ Variant data;
- bool GetPropertyInteger(string key, long *value);
- void SetPropertyInteger(string key, long value);
+ if (!GetProperty(key, &data))
+ return false;
- bool GetPropertyDictionary(string key, Dictionary::Ptr *value);
- void SetPropertyDictionary(string key, const Dictionary::Ptr& value);
+ *value = data;
- bool GetPropertyObject(string key, Object::Ptr *value);
- void SetPropertyObject(string key, const Object::Ptr& value);
+ return true;
+ }
+
+ bool GetProperty(string key, Dictionary::Ptr *value) const;
DictionaryIterator Begin(void);
DictionaryIterator End(void);
void AddUnnamedProperty(const Variant& value);
- void AddUnnamedPropertyString(const string& value);
- void AddUnnamedPropertyInteger(long value);
- void AddUnnamedPropertyDictionary(const Dictionary::Ptr& value);
- void AddUnnamedPropertyObject(const Object::Ptr& value);
long GetLength(void) const;
};
public:
inline Variant(void) : m_Type(VariantEmpty) { }
+ inline Variant(int value)
+ : m_Type(VariantInteger), m_IntegerValue(value) { }
+
inline Variant(long value)
: m_Type(VariantInteger), m_IntegerValue(value) { }
FIFO::Ptr fifo = make_shared<FIFO>();
string filename;
- if (!GetConfig()->GetPropertyString("configFilename", &filename))
+ if (!GetConfig()->GetProperty("configFilename", &filename))
throw InvalidArgumentException("Missing 'configFilename' property");
fp.open(filename.c_str(), ifstream::in);
if (property->type == cJSON_String) {
string value = property->valuestring;
- cfgobj->SetPropertyString(key, value);
+ cfgobj->SetProperty(key, value);
} else if (property->type == cJSON_Array) {
Dictionary::Ptr items = make_shared<Dictionary>();
if (item->type != cJSON_String)
continue;
- items->AddUnnamedPropertyString(item->valuestring);
+ items->AddUnnamedProperty(item->valuestring);
}
- cfgobj->SetPropertyDictionary(key, items);
+ cfgobj->SetProperty(key, items);
}
}
m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
long configSource;
- if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
+ if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
RpcRequest msg;
msg.SetMethod(method);
- Message params;
+ MessagePart params;
msg.SetParams(params);
- params.GetDictionary()->SetPropertyString("name", object->GetName());
- params.GetDictionary()->SetPropertyString("type", object->GetType());
+ params.SetProperty("name", object->GetName());
+ params.SetProperty("type", object->GetType());
if (includeProperties)
- params.SetPropertyMessage("properties", Message(object));
+ params.SetProperty("properties", object);
return msg;
}
bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
{
long replicate;
- if (!object->GetPropertyInteger("replicate", &replicate))
+ if (!object->GetProperty("replicate", &replicate))
return true;
return (replicate != 0);
}
RpcRequest message = ea.Request;
bool was_null = false;
- Message params;
+ MessagePart params;
if (!message.GetParams(¶ms))
return 0;
string name;
- if (!params.GetDictionary()->GetPropertyString("name", &name))
+ if (!params.GetProperty("name", &name))
return 0;
string type;
- if (!params.GetDictionary()->GetPropertyString("type", &type))
+ if (!params.GetProperty("type", &type))
return 0;
ConfigHive::Ptr configHive = GetConfigHive();
object = make_shared<ConfigObject>(type, name);
}
- Dictionary::Ptr properties;
- if (!params.GetDictionary()->GetPropertyDictionary("properties", &properties))
+ MessagePart properties;
+ if (!params.GetProperty("properties", &properties))
return 0;
- for (DictionaryIterator i = properties->Begin(); i != properties->End(); i++) {
- object->SetPropertyString(i->first, i->second);
+ for (DictionaryIterator i = properties.Begin(); i != properties.End(); i++) {
+ object->SetProperty(i->first, i->second);
}
if (was_null) {
{
RpcRequest message = ea.Request;
- Message params;
+ MessagePart params;
if (!message.GetParams(¶ms))
return 0;
string name;
- if (!params.GetDictionary()->GetPropertyString("name", &name))
+ if (!params.GetProperty("name", &name))
return 0;
string type;
- if (!params.GetDictionary()->GetPropertyString("type", &type))
+ if (!params.GetProperty("type", &type))
return 0;
ConfigHive::Ptr configHive = GetConfigHive();
params.SetIdentity(identity);
- Message subscriptions;
- params.SetSubscriptions(subscriptions);
-
- Message publications;
- params.SetPublications(publications);
-
ComponentDiscoveryInfo::Ptr info;
if (!GetComponentDiscoveryInfo(identity, &info))
}
set<string>::iterator i;
+ MessagePart subscriptions;
+ for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
+ subscriptions.AddUnnamedProperty(*i);
+
+ params.SetSubscriptions(subscriptions);
+
+ MessagePart publications;
for (i = info->Publications.begin(); i != info->Publications.end(); i++)
- publications.AddUnnamedPropertyString(*i);
+ publications.AddUnnamedProperty(*i);
- for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
- subscriptions.AddUnnamedPropertyString(*i);
+ params.SetPublications(publications);
if (recipient)
GetEndpointManager()->SendUnicastMessage(m_DiscoveryEndpoint, recipient, request);
continue;
Dictionary::Ptr permissions;
- if (!role->GetPropertyDictionary(messageType, &permissions))
+ if (!role->GetProperty(messageType, &permissions))
continue;
for (DictionaryIterator is = permissions->Begin(); is != permissions->End(); is++) {
ConfigObject::Ptr endpointConfig = endpointCollection->GetObject(identity);
Dictionary::Ptr roles;
if (endpointConfig)
- endpointConfig->GetPropertyDictionary("roles", &roles);
+ endpointConfig->GetProperty("roles", &roles);
Endpoint::Ptr endpoint = GetEndpointManager()->GetEndpointByIdentity(identity);
- Message publications;
+ MessagePart publications;
if (message.GetPublications(&publications)) {
DictionaryIterator i;
- for (i = publications.GetDictionary()->Begin(); i != publications.GetDictionary()->End(); i++) {
+ for (i = publications.Begin(); i != publications.End(); i++) {
if (trusted || HasMessagePermission(roles, "publications", i->second)) {
info->Publications.insert(i->second);
if (endpoint)
}
}
- Message subscriptions;
+ MessagePart subscriptions;
if (message.GetSubscriptions(&subscriptions)) {
DictionaryIterator i;
- for (i = subscriptions.GetDictionary()->Begin(); i != subscriptions.GetDictionary()->End(); i++) {
+ for (i = subscriptions.Begin(); i != subscriptions.End(); i++) {
if (trusted || HasMessagePermission(roles, "subscriptions", i->second)) {
info->Subscriptions.insert(i->second);
if (endpoint)
return 0;
string node, service;
- if (object->GetPropertyString("node", &node) && object->GetPropertyString("service", &service)) {
+ if (object->GetProperty("node", &node) && object->GetProperty("service", &service)) {
/* reconnect to this endpoint */
endpointManager->AddConnection(node, service);
}
namespace icinga
{
-class DiscoveryMessage : public Message
+class DiscoveryMessage : public MessagePart
{
public:
- DiscoveryMessage(void) : Message() { }
- DiscoveryMessage(const Message& message) : Message(message) { }
+ DiscoveryMessage(void) : MessagePart() { }
+ DiscoveryMessage(const MessagePart& message) : MessagePart(message) { }
inline bool GetIdentity(string *value) const
{
- return GetPropertyString("identity", value);
+ return GetProperty("identity", value);
}
inline void SetIdentity(const string& value)
{
- SetPropertyString("identity", value);
+ SetProperty("identity", value);
}
inline bool GetNode(string *value) const
{
- return GetPropertyString("node", value);
+ return GetProperty("node", value);
}
inline void SetNode(const string& value)
{
- SetPropertyString("node", value);
+ SetProperty("node", value);
}
inline bool GetService(string *value) const
{
- return GetPropertyString("service", value);
+ return GetProperty("service", value);
}
inline void SetService(const string& value)
{
- SetPropertyString("service", value);
+ SetProperty("service", value);
}
- inline bool GetSubscriptions(Message *value) const
+ inline bool GetSubscriptions(MessagePart *value) const
{
- return GetPropertyMessage("subscriptions", value);
+ return GetProperty("subscriptions", value);
}
- inline void SetSubscriptions(Message value)
+ inline void SetSubscriptions(MessagePart value)
{
- SetPropertyMessage("subscriptions", value);
+ SetProperty("subscriptions", value);
}
- inline bool GetPublications(Message *value) const
+ inline bool GetPublications(MessagePart *value) const
{
- return GetPropertyMessage("publications", value);
+ return GetProperty("publications", value);
}
- inline void SetPublications(Message value)
+ inline void SetPublications(MessagePart value)
{
- SetPropertyMessage("publications", value);
+ SetProperty("publications", value);
}
};
void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
{
m_Servers.push_back(server);
- server->OnNewClient += bind_weak(&EndpointManager::NewClientHandler, shared_from_this());
+ server->OnNewClient += bind_weak(&EndpointManager::NewClientHandler,
+ shared_from_this());
}
/**
* @param recipient The recipient of the message.
* @param message The request.
*/
-void EndpointManager::SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const Message& message)
+void EndpointManager::SendUnicastMessage(Endpoint::Ptr sender,
+ Endpoint::Ptr recipient, const MessagePart& message)
{
/* don't forward messages back to the sender */
if (sender == recipient)
* @param sender The sender of the message.
* @param message The message.
*/
-void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest& message)
+void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
+ const RpcRequest& message)
{
throw NotImplementedException();
}
* @param sender The sender of the message.
* @param message The message.
*/
-void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender, const RpcRequest& message)
+void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
+ const RpcRequest& message)
{
string id;
if (message.GetID(&id))
void RegisterEndpoint(Endpoint::Ptr endpoint);
void UnregisterEndpoint(Endpoint::Ptr endpoint);
- void SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const Message& message);
+ void SendUnicastMessage(Endpoint::Ptr sender, Endpoint::Ptr recipient, const MessagePart& message);
void SendAnycastMessage(Endpoint::Ptr sender, const RpcRequest& message);
void SendMulticastMessage(Endpoint::Ptr sender, const RpcRequest& message);
/* load config file */
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
- fileComponentConfig->SetPropertyString("configFilename", args[1]);
- fileComponentConfig->SetPropertyInteger("replicate", 0);
+ fileComponentConfig->SetProperty("configFilename", args[1]);
+ fileComponentConfig->SetProperty("replicate", 0);
GetConfigHive()->AddObject(fileComponentConfig);
if (!GetPrivateKeyFile().empty() && !GetPublicKeyFile().empty() && !GetCAKeyFile().empty()) {
return 0;
string path;
- if (!object->GetPropertyString("path", &path)) {
+ if (!object->GetProperty("path", &path)) {
#ifdef _WIN32
path = object->GetName() + ".dll";
#else /* _WIN32 */
return 0;
string privkey;
- if (object->GetPropertyString("privkey", &privkey))
+ if (object->GetProperty("privkey", &privkey))
SetPrivateKeyFile(privkey);
string pubkey;
- if (object->GetPropertyString("pubkey", &pubkey))
+ if (object->GetProperty("pubkey", &pubkey))
SetPublicKeyFile(pubkey);
string cakey;
- if (object->GetPropertyString("cakey", &cakey))
+ if (object->GetProperty("cakey", &cakey))
SetCAKeyFile(cakey);
string node;
- if (object->GetPropertyString("node", &node))
+ if (object->GetProperty("node", &node))
SetNode(node);
string service;
- if (object->GetPropertyString("service", &service))
+ if (object->GetProperty("service", &service))
SetService(service);
return 0;
int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
{
- const Message& message = nmea.Message;
+ const MessagePart& message = nmea.Message;
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
string method;
- if (message.GetPropertyString("method", &method)) {
+ if (message.GetProperty("method", &method)) {
if (!HasPublication(method))
return 0;
jsonrpcclient.h \
jsonrpcserver.cpp \
jsonrpcserver.h \
- message.cpp \
- message.h \
+ messagepart.cpp \
+ messagepart.h \
netstring.cpp \
netstring.h \
rpcrequest.cpp \
# define I2_JSONRPC_API I2_IMPORT
#endif /* I2_JSONRPC_BUILD */
-#include "variant.h"
-#include "dictionary.h"
-#include "message.h"
+#include "messagepart.h"
#include "rpcrequest.h"
#include "rpcresponse.h"
#include "netstring.h"
<ClInclude Include="rpcrequest.h" />
<ClInclude Include="rpcresponse.h" />
<ClInclude Include="jsonrpcserver.h" />
- <ClInclude Include="message.h" />
+ <ClInclude Include="messagepart.h" />
<ClInclude Include="netstring.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="rpcrequest.cpp" />
<ClCompile Include="rpcresponse.cpp" />
<ClCompile Include="jsonrpcserver.cpp" />
- <ClCompile Include="message.cpp" />
+ <ClCompile Include="messagepart.cpp" />
<ClCompile Include="netstring.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ItemGroup>
<ClCompile Include="jsonrpcclient.cpp" />
<ClCompile Include="jsonrpcserver.cpp" />
- <ClCompile Include="message.cpp" />
<ClCompile Include="netstring.cpp" />
<ClCompile Include="rpcrequest.cpp" />
<ClCompile Include="rpcresponse.cpp" />
+ <ClCompile Include="messagepart.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="i2-jsonrpc.h" />
<ClInclude Include="jsonrpcclient.h" />
<ClInclude Include="jsonrpcserver.h" />
- <ClInclude Include="message.h" />
<ClInclude Include="netstring.h" />
<ClInclude Include="rpcrequest.h" />
<ClInclude Include="rpcresponse.h" />
+ <ClInclude Include="messagepart.h" />
</ItemGroup>
</Project>
\ No newline at end of file
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());
}
for (;;) {
try {
string jsonString;
- Message message;
+ MessagePart message;
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
break;
- message = Message(jsonString);
+ message = MessagePart(jsonString);
NewMessageEventArgs nea;
nea.Source = shared_from_this();
typedef shared_ptr<NewMessageEventArgs> Ptr;
typedef weak_ptr<NewMessageEventArgs> WeakPtr;
- icinga::Message Message;
+ icinga::MessagePart Message;
};
class I2_JSONRPC_API JsonRpcClient : public TLSClient
JsonRpcClient(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
- void SendMessage(const Message& message);
+ void SendMessage(const MessagePart& message);
virtual void Start(void);
using namespace icinga;
-Message::Message(void)
+MessagePart::MessagePart(void)
{
m_Dictionary = make_shared<Dictionary>();
}
-Message::Message(string jsonString)
+MessagePart::MessagePart(string jsonString)
{
json_t *json = cJSON_Parse(jsonString.c_str());
cJSON_Delete(json);
}
-Message::Message(const Dictionary::Ptr& dictionary)
+MessagePart::MessagePart(const Dictionary::Ptr& dictionary)
{
m_Dictionary = dictionary;
}
-Message::Message(const Message& message)
+MessagePart::MessagePart(const MessagePart& message)
{
m_Dictionary = message.GetDictionary();
}
-Dictionary::Ptr Message::GetDictionaryFromJson(json_t *json)
+Dictionary::Ptr MessagePart::GetDictionaryFromJson(json_t *json)
{
Dictionary::Ptr dictionary = make_shared<Dictionary>();
return dictionary;
}
-json_t *Message::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
+json_t *MessagePart::GetJsonFromDictionary(const Dictionary::Ptr& dictionary)
{
cJSON *json;
string valueString;
return json;
}
-string Message::ToJsonString(void) const
+string MessagePart::ToJsonString(void) const
{
json_t *json = GetJsonFromDictionary(m_Dictionary);
char *jsonString;
return result;
}
-Dictionary::Ptr Message::GetDictionary(void) const
+Dictionary::Ptr MessagePart::GetDictionary(void) const
{
return m_Dictionary;
}
-bool Message::GetPropertyString(string key, string *value) const
-{
- return GetDictionary()->GetPropertyString(key, value);
-}
-
-bool Message::GetPropertyInteger(string key, long *value) const
-{
- return GetDictionary()->GetPropertyInteger(key, value);
-}
-
-bool Message::GetPropertyMessage(string key, Message *value) const
+bool MessagePart::GetProperty(string key, MessagePart *value) const
{
Dictionary::Ptr dictionary;
- if (!GetDictionary()->GetPropertyDictionary(key, &dictionary))
+ if (!GetDictionary()->GetProperty(key, &dictionary))
return false;
- *value = Message(dictionary);
+ *value = MessagePart(dictionary);
return true;
}
-void Message::SetPropertyString(string key, const string& value)
-{
- GetDictionary()->SetProperty(key, value);
-}
-
-void Message::SetPropertyInteger(string key, long value)
+void MessagePart::SetProperty(string key, const MessagePart& value)
{
- GetDictionary()->SetProperty(key, value);
+ GetDictionary()->SetProperty(key, value.GetDictionary());
}
-void Message::SetPropertyMessage(string key, const Message& value)
+void MessagePart::AddUnnamedProperty(const MessagePart& value)
{
- GetDictionary()->SetProperty(key, Variant(value.GetDictionary()));
+ GetDictionary()->AddUnnamedProperty(value.GetDictionary());
}
-void Message::AddUnnamedPropertyString(const string& value)
+DictionaryIterator MessagePart::Begin(void)
{
- GetDictionary()->AddUnnamedPropertyString(value);
+ return GetDictionary()->Begin();
}
-void Message::AddUnnamedPropertyInteger(long value)
+DictionaryIterator MessagePart::End(void)
{
- GetDictionary()->AddUnnamedPropertyInteger(value);
+ return GetDictionary()->End();
}
-void Message::AddUnnamedPropertyMessage(const Message& value)
+MessagePart::operator Dictionary::Ptr(void)
{
- GetDictionary()->AddUnnamedPropertyDictionary(value.GetDictionary());
+ return GetDictionary();
}
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#ifndef MESSAGE_H
-#define MESSAGE_H
+#ifndef MESSAGEPART_H
+#define MESSAGEPART_H
struct cJSON;
typedef ::cJSON json_t;
-class I2_JSONRPC_API Message
+class I2_JSONRPC_API MessagePart
{
private:
Dictionary::Ptr m_Dictionary;
static json_t *GetJsonFromDictionary(const Dictionary::Ptr& dictionary);
public:
- Message(void);
- Message(string json);
- Message(const Dictionary::Ptr& dictionary);
- Message(const Message& message);
+ MessagePart(void);
+ MessagePart(string json);
+ MessagePart(const Dictionary::Ptr& dictionary);
+ MessagePart(const MessagePart& message);
string ToJsonString(void) const;
Dictionary::Ptr GetDictionary(void) const;
- bool GetPropertyString(string key, string *value) const;
- void SetPropertyString(string key, const string& value);
+ template<typename T>
+ bool GetProperty(string key, T *value) const
+ {
+ return GetDictionary()->GetProperty(key, value);
+ }
- bool GetPropertyInteger(string key, long *value) const;
- void SetPropertyInteger(string key, long value);
+ template<typename T>
+ void SetProperty(string key, const T& value)
+ {
+ GetDictionary()->SetProperty(key, value);
+ }
- bool GetPropertyMessage(string key, Message *value) const;
- void SetPropertyMessage(string key, const Message& value);
+ bool GetProperty(string key, MessagePart *value) const;
+ void SetProperty(string key, const MessagePart& value);
- void AddUnnamedPropertyString(const string& value);
- void AddUnnamedPropertyInteger(long value);
- void AddUnnamedPropertyMessage(const Message& value);
+ template<typename T>
+ void AddUnnamedProperty(const T& value)
+ {
+ GetDictionary()->AddUnnamedProperty(value);
+ }
+
+ void AddUnnamedProperty(const MessagePart& value);
+
+ DictionaryIterator Begin(void);
+ DictionaryIterator End(void);
+
+ operator Dictionary::Ptr(void);
};
}
-#endif /* MESSAGE_H */
+#endif /* MESSAGEPART_H */
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#ifndef RpcRequest_H
-#define RpcRequest_H
+#ifndef RPCREQUEST_H
+#define RPCREQUEST_H
namespace icinga
{
-class I2_JSONRPC_API RpcRequest : public Message
+class I2_JSONRPC_API RpcRequest : public MessagePart
{
public:
- RpcRequest(void) : Message() {
+ RpcRequest(void) : MessagePart() {
SetVersion("2.0");
}
- RpcRequest(const Message& message) : Message(message) { }
+ RpcRequest(const MessagePart& message) : MessagePart(message) { }
inline bool GetVersion(string *value) const
{
- return GetPropertyString("jsonrpc", value);
+ return GetProperty("jsonrpc", value);
}
inline void SetVersion(const string& value)
{
- SetPropertyString("jsonrpc", value);
+ SetProperty("jsonrpc", value);
}
inline bool GetMethod(string *value) const
{
- return GetPropertyString("method", value);
+ return GetProperty("method", value);
}
inline void SetMethod(const string& value)
{
- SetPropertyString("method", value);
+ SetProperty("method", value);
}
- inline bool GetParams(Message *value) const
+ inline bool GetParams(MessagePart *value) const
{
- return GetPropertyMessage("params", value);
+ return GetProperty("params", value);
}
- inline void SetParams(const Message& value)
+ inline void SetParams(const MessagePart& value)
{
- SetPropertyMessage("params", value);
+ SetProperty("params", value);
}
inline bool GetID(string *value) const
{
- return GetPropertyString("id", value);
+ return GetProperty("id", value);
}
inline void SetID(const string& value)
{
- SetPropertyString("id", value);
+ SetProperty("id", value);
}
};
}
-#endif /* RpcRequest_H */
+#endif /* RPCREQUEST_H */
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#ifndef RpcResponse_H
-#define RpcResponse_H
+#ifndef RPCRESPONSE_H
+#define RPCRESPONSE_H
namespace icinga
{
-class I2_JSONRPC_API RpcResponse : public Message
+class I2_JSONRPC_API RpcResponse : public MessagePart
{
public:
- RpcResponse(void) : Message() {
+ RpcResponse(void) : MessagePart() {
SetVersion("2.0");
}
- RpcResponse(const Message& message) : Message(message) { }
+ RpcResponse(const MessagePart& message) : MessagePart(message) { }
inline bool GetVersion(string *value) const
{
- return GetPropertyString("jsonrpc", value);
+ return GetProperty("jsonrpc", value);
}
inline void SetVersion(const string& value)
{
- SetPropertyString("jsonrpc", value);
+ SetProperty("jsonrpc", value);
}
bool GetResult(string *value) const
{
- return GetPropertyString("result", value);
+ return GetProperty("result", value);
}
void SetResult(const string& value)
{
- SetPropertyString("result", value);
+ SetProperty("result", value);
}
bool GetError(string *value) const
{
- return GetPropertyString("error", value);
+ return GetProperty("error", value);
}
void SetError(const string& value)
{
- SetPropertyString("error", value);
+ SetProperty("error", value);
}
bool GetID(string *value) const
{
- return GetPropertyString("id", value);
+ return GetProperty("id", value);
}
void SetID(const string& value)
{
- SetPropertyString("id", value);
+ SetProperty("id", value);
}
};
}
-#endif /* RpcResponse_H */
+#endif /* RPCRESPONSE_H */