using namespace icinga;
-void ConnectionManager::BindServer(JsonRpcServer::RefType server)
+void ConnectionManager::RegisterServer(JsonRpcServer::RefType server)
{
m_Servers.push_front(server);
server->OnNewClient.bind(bind_weak(&ConnectionManager::NewClientHandler, shared_from_this()));
}
-void ConnectionManager::UnbindServer(JsonRpcServer::RefType server)
+void ConnectionManager::UnregisterServer(JsonRpcServer::RefType server)
{
m_Servers.remove(server);
// TODO: unbind event
}
-void ConnectionManager::BindClient(JsonRpcClient::RefType client)
+void ConnectionManager::RegisterClient(JsonRpcClient::RefType client)
{
m_Clients.push_front(client);
client->OnNewMessage.bind(bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this()));
}
-void ConnectionManager::UnbindClient(JsonRpcClient::RefType client)
+void ConnectionManager::UnregisterClient(JsonRpcClient::RefType client)
{
m_Clients.remove(client);
// TODO: unbind event
int ConnectionManager::NewClientHandler(NewClientEventArgs::RefType ncea)
{
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(ncea->Client);
- BindClient(client);
+ RegisterClient(client);
return 0;
}
int ConnectionManager::CloseClientHandler(EventArgs::RefType ea)
{
- UnbindClient(static_pointer_cast<JsonRpcClient>(ea->Source));
+ UnregisterClient(static_pointer_cast<JsonRpcClient>(ea->Source));
return 0;
}
{
// TODO: implement
}
+
+void ConnectionManager::SendMessage(JsonRpcMessage::RefType message)
+{
+ /* TODO: filter messages based on event subscriptions */
+ for (list<JsonRpcClient::RefType>::iterator i = m_Clients.begin(); i != m_Clients.end(); i++)
+ {
+ JsonRpcClient::RefType client = *i;
+ client->SendMessage(message);
+ }
+}
typedef shared_ptr<ConnectionManager> RefType;
typedef weak_ptr<ConnectionManager> WeakRefType;
- void BindServer(JsonRpcServer::RefType server);
- void UnbindServer(JsonRpcServer::RefType server);
+ void RegisterServer(JsonRpcServer::RefType server);
+ void UnregisterServer(JsonRpcServer::RefType server);
- void BindClient(JsonRpcClient::RefType client);
- void UnbindClient(JsonRpcClient::RefType client);
+ void RegisterClient(JsonRpcClient::RefType client);
+ void UnregisterClient(JsonRpcClient::RefType client);
void RegisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function);
void UnregisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function);
+
+ void SendMessage(JsonRpcMessage::RefType message);
};
}
-#endif /* I2_CONNECTIONMANAGER_H */
\ No newline at end of file
+#endif /* I2_CONNECTIONMANAGER_H */
#include "jsonrpcserver.h"
#include "connectionmanager.h"
-#endif /* I2_JSONRPC_H */
\ No newline at end of file
+#endif /* I2_JSONRPC_H */
<PropertyGroup Label="Globals">
<ProjectGuid>{8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
- <RootNamespace>i2jsonrpc</RootNamespace>
+ <RootNamespace>icinga</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>Unicode</CharacterSet>
+ <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>Unicode</CharacterSet>
+ <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <IncludePath>$(MSBuildProjectDirectory)\..\base;$(IncludePath)</IncludePath>
- <LibraryPath>..\Debug;$(LibraryPath)</LibraryPath>
+ <IncludePath>$(ProjectDir)\..\base;$(IncludePath)</IncludePath>
+ <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <IncludePath>$(MSBuildProjectDirectory)\..\base;$(IncludePath)</IncludePath>
- <LibraryPath>..\Release;$(LibraryPath)</LibraryPath>
+ <IncludePath>$(ProjectDir)\..\base;$(IncludePath)</IncludePath>
+ <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
- <AdditionalDependencies>..\Debug\base.lib</AdditionalDependencies>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Lib>
- <AdditionalDependencies>..\Release\base.lib</AdditionalDependencies>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
return object;
}
+void JsonRpcMessage::SetParam(const string& name, const string& value)
+{
+}
+
+cJSON *JsonRpcMessage::GetParam(const string& name)
+{
+ cJSON *params = GetFieldObject("params");
+
+ if (params == NULL)
+ return NULL;
+
+ return cJSON_GetObjectItem(params, name.c_str());
+}
+
+bool JsonRpcMessage::GetParamString(const string name, string *value)
+{
+ cJSON *param = GetParam(name);
+
+ if (param == NULL || param->type != cJSON_String)
+ return false;
+
+ *value = param->valuestring;
+
+ return true;
+}
+
void JsonRpcMessage::ClearResult(void)
{
SetFieldObject("result", NULL);
void ClearParams(void);
cJSON *GetParams(void);
+ void SetParam(const string& name, const string& value);
+ cJSON *GetParam(const string& name);
+ bool GetParamString(const string name, string *value);
+
void ClearResult();
cJSON *GetResult(void);