Moved ConnectionManager class to icinga subproject.

This commit is contained in:
Gunnar Beutner 2012-04-04 15:09:59 +02:00
parent 7657fc6bd1
commit 6a42ac0fe5
9 changed files with 39 additions and 14 deletions

View 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;

View File

@ -5,6 +5,8 @@ bin_PROGRAMS = \
icinga
icinga_SOURCES = \
connectionmanager.cpp \
connectionmanager.h \
icingaapplication.cpp \
icingaapplication.h \
i2-icinga.h

View 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;
}

View 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);

View File

@ -4,6 +4,7 @@
#include <i2-base.h>
#include <i2-jsonrpc.h>
#include "connectionmanager.h"
#include "icingaapplication.h"
#endif /* I2ICINGA_H */

View File

@ -81,9 +81,11 @@
</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>

View 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 \

View File

@ -9,6 +9,5 @@
#include "jsonrpcmessage.h"
#include "jsonrpcclient.h"
#include "jsonrpcserver.h"
#include "connectionmanager.h"
#endif /* I2JSONRPC_H */

View 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" />