]> granicus.if.org Git - icinga2/commitdiff
Moved ConnectionManager class to icinga subproject.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 4 Apr 2012 13:09:59 +0000 (15:09 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 4 Apr 2012 13:37:57 +0000 (15:37 +0200)
base/socket.cpp
icinga/Makefile.am
icinga/connectionmanager.cpp [moved from jsonrpc/connectionmanager.cpp with 80% similarity]
icinga/connectionmanager.h [moved from jsonrpc/connectionmanager.h with 89% similarity]
icinga/i2-icinga.h
icinga/icinga.vcxproj
jsonrpc/Makefile.am
jsonrpc/i2-jsonrpc.h
jsonrpc/jsonrpc.vcxproj

index 8c6b226000779c9fdb2f116b55a8924799df3a63..aba6d054c6a1b5225e3af500549fc4408d92ea0a 100644 (file)
@@ -100,8 +100,9 @@ int Socket::ExceptionEventHandler(EventArgs::Ptr ea)
                SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
                ea->Code = opt;
                ea->Message = FormatErrorCode(opt);
-               Close();
+               OnError(ea);
 
+               Close();
        }
 
        return 0;
index 849f877c54b345f2fa8e11227374ed13eb31e471..bd090f8cd61202cbbfd90455fc156c2d48f477c0 100644 (file)
@@ -5,6 +5,8 @@ bin_PROGRAMS =  \
        icinga
 
 icinga_SOURCES =  \
+       connectionmanager.cpp \
+       connectionmanager.h \
        icingaapplication.cpp \
        icingaapplication.h \
        i2-icinga.h
similarity index 80%
rename from jsonrpc/connectionmanager.cpp
rename to icinga/connectionmanager.cpp
index c9dd0ae59c95459db2179f0684b000c71a68cc3b..3688efffcdfb19e6cbfabb254922c789dd85d326 100644 (file)
@@ -1,7 +1,17 @@
-#include "i2-jsonrpc.h"
+#include "i2-icinga.h"
 
 using namespace icinga;
 
+void ConnectionManager::SetIdentity(string identity)
+{
+       m_Identity = identity;
+}
+
+string ConnectionManager::GetIdentity(void)
+{
+       return m_Identity;
+}
+
 void ConnectionManager::AddListener(unsigned short port)
 {
        JsonRpcServer::Ptr server = make_shared<JsonRpcServer>();
@@ -23,7 +33,6 @@ void ConnectionManager::AddConnection(string host, short port)
        client->Start();
 }
 
-
 void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
 {
        m_Servers.push_front(server);
@@ -41,6 +50,7 @@ void ConnectionManager::RegisterClient(JsonRpcClient::Ptr client)
        m_Clients.push_front(client);
        client->OnNewMessage += bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this());
        client->OnClosed += bind_weak(&ConnectionManager::CloseClientHandler, shared_from_this());
+       client->OnError += bind_weak(&ConnectionManager::ErrorClientHandler, shared_from_this());
 }
 
 void ConnectionManager::UnregisterClient(JsonRpcClient::Ptr client)
@@ -62,12 +72,21 @@ int ConnectionManager::CloseClientHandler(EventArgs::Ptr ea)
        JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->Source);
        UnregisterClient(client);
 
-       Timer::Ptr timer = make_shared<Timer>();
-       timer->SetInterval(30);
-       timer->SetUserArgs(ea);
-       timer->OnTimerExpired += bind_weak(&ConnectionManager::ReconnectClientHandler, shared_from_this());
-       timer->Start();
-       m_ReconnectTimers.push_front(timer);
+       if (client->GetPeerHost() != string()) {
+               Timer::Ptr timer = make_shared<Timer>();
+               timer->SetInterval(30);
+               timer->SetUserArgs(ea);
+               timer->OnTimerExpired += bind_weak(&ConnectionManager::ReconnectClientHandler, shared_from_this());
+               timer->Start();
+               m_ReconnectTimers.push_front(timer);
+       }
+
+       return 0;
+}
+
+int ConnectionManager::ErrorClientHandler(SocketErrorEventArgs::Ptr ea)
+{
+       cout << "Error occured for JSON-RPC socket: Code=" << ea->Code << "; Message=" << ea->Message << endl;
 
        return 0;
 }
similarity index 89%
rename from jsonrpc/connectionmanager.h
rename to icinga/connectionmanager.h
index fe3999e7ef6c8e57734a37d4d16699f825a25253..2cd2f2fd8d3566423262aff56f91211d5c6713f5 100644 (file)
@@ -10,9 +10,11 @@ class ConnectionManager : public Object
        list<JsonRpcClient::Ptr> m_Clients;
        map< string, event<NewMessageEventArgs::Ptr> > m_Methods;
        list<Timer::Ptr> m_ReconnectTimers;
+       string m_Identity;
 
        int NewClientHandler(NewClientEventArgs::Ptr ncea);
        int CloseClientHandler(EventArgs::Ptr ea);
+       int ErrorClientHandler(SocketErrorEventArgs::Ptr ea);
        int ReconnectClientHandler(TimerEventArgs::Ptr ea);
        int NewMessageHandler(NewMessageEventArgs::Ptr nmea);
 
@@ -25,6 +27,9 @@ public:
        typedef shared_ptr<ConnectionManager> Ptr;
        typedef weak_ptr<ConnectionManager> WeakPtr;
 
+       void SetIdentity(string identity);
+       string GetIdentity(void);
+
        void AddListener(unsigned short port);
        void AddConnection(string host, short port);
 
index fd61e6fca58560b9d74b7ac15a73a3270fa951b8..61d091e8a8d81e9bad1f30b3cd4f64ce2ca43fe8 100644 (file)
@@ -4,6 +4,7 @@
 #include <i2-base.h>
 #include <i2-jsonrpc.h>
 
+#include "connectionmanager.h"
 #include "icingaapplication.h"
 
 #endif /* I2ICINGA_H */
index e1b775aa52872159cad8706ab4c3927a736cd807..748c461201d231b138b60d040d236209a8c47d67 100644 (file)
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="connectionmanager.cpp" />
     <ClCompile Include="icingaapplication.cpp" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="connectionmanager.h" />
     <ClInclude Include="icingaapplication.h" />
     <ClInclude Include="i2-icinga.h" />
   </ItemGroup>
index a74d76e4abed819bb8c32ad908da2c332d440afb..7ec7558c20791a905e1ddd37ca1ca9fe45bf36fe 100644 (file)
@@ -7,8 +7,6 @@ noinst_LTLIBRARIES =  \
 libjsonrpc_la_SOURCES =  \
        cJSON.c \
        cJSON.h \
-       connectionmanager.cpp \
-       connectionmanager.h \
        i2-jsonrpc.h \
        jsonrpcclient.cpp \
        jsonrpcclient.h \
index dfbec61c2c73a4b1e231ce38ed61f1a52977211a..1a2b4311007e82d7a3bd0f69c42c7e0635a3fb9c 100644 (file)
@@ -9,6 +9,5 @@
 #include "jsonrpcmessage.h"
 #include "jsonrpcclient.h"
 #include "jsonrpcserver.h"
-#include "connectionmanager.h"
 
 #endif /* I2JSONRPC_H */
index ccb112e08e53d92323faaa8a83074f3759095546..2a321fab90b5adfb6d56fbb2da90093ce6725133 100644 (file)
@@ -12,7 +12,6 @@
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="cJSON.h" />
-    <ClInclude Include="connectionmanager.h" />
     <ClInclude Include="i2-jsonrpc.h" />
     <ClInclude Include="jsonrpcclient.h" />
     <ClInclude Include="jsonrpcmessage.h" />
@@ -21,7 +20,6 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="cJSON.c" />
-    <ClCompile Include="connectionmanager.cpp" />
     <ClCompile Include="jsonrpcclient.cpp" />
     <ClCompile Include="jsonrpcmessage.cpp" />
     <ClCompile Include="jsonrpcserver.cpp" />