]> granicus.if.org Git - icinga2/commitdiff
Cleaned up JSON-RPC API.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 31 Mar 2012 14:01:31 +0000 (16:01 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 31 Mar 2012 14:01:31 +0000 (16:01 +0200)
jsonrpc/connectionmanager.cpp
jsonrpc/connectionmanager.h
jsonrpc/i2-jsonrpc.h
jsonrpc/jsonrpc.vcxproj
jsonrpc/jsonrpcmessage.cpp
jsonrpc/jsonrpcmessage.h

index 3d23299c959318c1f6a657e1e1fd7a865f069540..5d1e336fc148f034ab8938e39ac6887b9c66377d 100644 (file)
@@ -2,25 +2,25 @@
 
 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
@@ -29,14 +29,14 @@ void ConnectionManager::UnbindClient(JsonRpcClient::RefType client)
 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;
 }
@@ -81,3 +81,13 @@ void ConnectionManager::UnregisterMethod(string method, function<int (NewMessage
 {
        // 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);
+       }
+}
index 13e8ca03fea0a52e6ce00e45da1c4329840160bc..f92b802b8f529b021935e904bc1da89ca5c91b53 100644 (file)
@@ -20,16 +20,18 @@ public:
        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 */
index 127cffd8d708c118f47c7eeb37d70bb682a23bb2..a25d58ce0128dda7f763ec1c98bd24e7d4081e87 100644 (file)
@@ -11,4 +11,4 @@
 #include "jsonrpcserver.h"
 #include "connectionmanager.h"
 
-#endif /* I2_JSONRPC_H */
\ No newline at end of file
+#endif /* I2_JSONRPC_H */
index 9b1f7f626b0967c0bd58e69874e382af3e2c6697..ccb112e08e53d92323faaa8a83074f3759095546 100644 (file)
   <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>
@@ -75,7 +75,8 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
     </Link>
     <Lib>
-      <AdditionalDependencies>..\Debug\base.lib</AdditionalDependencies>
+      <AdditionalDependencies>
+      </AdditionalDependencies>
     </Lib>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -95,7 +96,8 @@
       <OptimizeReferences>true</OptimizeReferences>
     </Link>
     <Lib>
-      <AdditionalDependencies>..\Release\base.lib</AdditionalDependencies>
+      <AdditionalDependencies>
+      </AdditionalDependencies>
     </Lib>
   </ItemDefinitionGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
index 81a7d89453eb20a905fb954a5cc033d3ebe26739..a5fbeb55e309a286c1bd2b3638bc5bd2ae9874d7 100644 (file)
@@ -113,6 +113,32 @@ cJSON *JsonRpcMessage::GetParams(void)
        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);
index ca5f6d7c0c701e145802dd4bc860b79b16949944..1f63d553cc947ae5e4db14aefa5c56949e40d3e9 100644 (file)
@@ -40,6 +40,10 @@ public:
        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);