mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 15:14:07 +02:00
Cleaned up JSON-RPC API.
This commit is contained in:
parent
4388f20d64
commit
3158767ac6
@ -2,25 +2,25 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
void ConnectionManager::BindServer(JsonRpcServer::RefType server)
|
void ConnectionManager::RegisterServer(JsonRpcServer::RefType server)
|
||||||
{
|
{
|
||||||
m_Servers.push_front(server);
|
m_Servers.push_front(server);
|
||||||
server->OnNewClient.bind(bind_weak(&ConnectionManager::NewClientHandler, shared_from_this()));
|
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);
|
m_Servers.remove(server);
|
||||||
// TODO: unbind event
|
// TODO: unbind event
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionManager::BindClient(JsonRpcClient::RefType client)
|
void ConnectionManager::RegisterClient(JsonRpcClient::RefType client)
|
||||||
{
|
{
|
||||||
m_Clients.push_front(client);
|
m_Clients.push_front(client);
|
||||||
client->OnNewMessage.bind(bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this()));
|
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);
|
m_Clients.remove(client);
|
||||||
// TODO: unbind event
|
// TODO: unbind event
|
||||||
@ -29,14 +29,14 @@ void ConnectionManager::UnbindClient(JsonRpcClient::RefType client)
|
|||||||
int ConnectionManager::NewClientHandler(NewClientEventArgs::RefType ncea)
|
int ConnectionManager::NewClientHandler(NewClientEventArgs::RefType ncea)
|
||||||
{
|
{
|
||||||
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(ncea->Client);
|
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(ncea->Client);
|
||||||
BindClient(client);
|
RegisterClient(client);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConnectionManager::CloseClientHandler(EventArgs::RefType ea)
|
int ConnectionManager::CloseClientHandler(EventArgs::RefType ea)
|
||||||
{
|
{
|
||||||
UnbindClient(static_pointer_cast<JsonRpcClient>(ea->Source));
|
UnregisterClient(static_pointer_cast<JsonRpcClient>(ea->Source));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -81,3 +81,13 @@ void ConnectionManager::UnregisterMethod(string method, function<int (NewMessage
|
|||||||
{
|
{
|
||||||
// TODO: implement
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,16 +20,18 @@ public:
|
|||||||
typedef shared_ptr<ConnectionManager> RefType;
|
typedef shared_ptr<ConnectionManager> RefType;
|
||||||
typedef weak_ptr<ConnectionManager> WeakRefType;
|
typedef weak_ptr<ConnectionManager> WeakRefType;
|
||||||
|
|
||||||
void BindServer(JsonRpcServer::RefType server);
|
void RegisterServer(JsonRpcServer::RefType server);
|
||||||
void UnbindServer(JsonRpcServer::RefType server);
|
void UnregisterServer(JsonRpcServer::RefType server);
|
||||||
|
|
||||||
void BindClient(JsonRpcClient::RefType client);
|
void RegisterClient(JsonRpcClient::RefType client);
|
||||||
void UnbindClient(JsonRpcClient::RefType client);
|
void UnregisterClient(JsonRpcClient::RefType client);
|
||||||
|
|
||||||
void RegisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function);
|
void RegisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function);
|
||||||
void UnregisterMethod(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 */
|
#endif /* I2_CONNECTIONMANAGER_H */
|
||||||
|
@ -11,4 +11,4 @@
|
|||||||
#include "jsonrpcserver.h"
|
#include "jsonrpcserver.h"
|
||||||
#include "connectionmanager.h"
|
#include "connectionmanager.h"
|
||||||
|
|
||||||
#endif /* I2_JSONRPC_H */
|
#endif /* I2_JSONRPC_H */
|
||||||
|
@ -30,19 +30,19 @@
|
|||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}</ProjectGuid>
|
<ProjectGuid>{8DD52FAC-ECEE-48C2-B266-E7C47ED485F8}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>i2jsonrpc</RootNamespace>
|
<RootNamespace>icinga</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
@ -55,12 +55,12 @@
|
|||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<IncludePath>$(MSBuildProjectDirectory)\..\base;$(IncludePath)</IncludePath>
|
<IncludePath>$(ProjectDir)\..\base;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>..\Debug;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<IncludePath>$(MSBuildProjectDirectory)\..\base;$(IncludePath)</IncludePath>
|
<IncludePath>$(ProjectDir)\..\base;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>..\Release;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@ -75,7 +75,8 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalDependencies>..\Debug\base.lib</AdditionalDependencies>
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@ -95,7 +96,8 @@
|
|||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalDependencies>..\Release\base.lib</AdditionalDependencies>
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
@ -113,6 +113,32 @@ cJSON *JsonRpcMessage::GetParams(void)
|
|||||||
return object;
|
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)
|
void JsonRpcMessage::ClearResult(void)
|
||||||
{
|
{
|
||||||
SetFieldObject("result", NULL);
|
SetFieldObject("result", NULL);
|
||||||
|
@ -40,6 +40,10 @@ public:
|
|||||||
void ClearParams(void);
|
void ClearParams(void);
|
||||||
cJSON *GetParams(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();
|
void ClearResult();
|
||||||
cJSON *GetResult(void);
|
cJSON *GetResult(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user