mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
Moved ConnectionManager class to icinga subproject.
This commit is contained in:
parent
7657fc6bd1
commit
6a42ac0fe5
@ -100,8 +100,9 @@ int Socket::ExceptionEventHandler(EventArgs::Ptr ea)
|
|||||||
SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
|
SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
|
||||||
ea->Code = opt;
|
ea->Code = opt;
|
||||||
ea->Message = FormatErrorCode(opt);
|
ea->Message = FormatErrorCode(opt);
|
||||||
Close();
|
OnError(ea);
|
||||||
|
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -5,6 +5,8 @@ bin_PROGRAMS = \
|
|||||||
icinga
|
icinga
|
||||||
|
|
||||||
icinga_SOURCES = \
|
icinga_SOURCES = \
|
||||||
|
connectionmanager.cpp \
|
||||||
|
connectionmanager.h \
|
||||||
icingaapplication.cpp \
|
icingaapplication.cpp \
|
||||||
icingaapplication.h \
|
icingaapplication.h \
|
||||||
i2-icinga.h
|
i2-icinga.h
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
#include "i2-jsonrpc.h"
|
#include "i2-icinga.h"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
void ConnectionManager::SetIdentity(string identity)
|
||||||
|
{
|
||||||
|
m_Identity = identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
string ConnectionManager::GetIdentity(void)
|
||||||
|
{
|
||||||
|
return m_Identity;
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionManager::AddListener(unsigned short port)
|
void ConnectionManager::AddListener(unsigned short port)
|
||||||
{
|
{
|
||||||
JsonRpcServer::Ptr server = make_shared<JsonRpcServer>();
|
JsonRpcServer::Ptr server = make_shared<JsonRpcServer>();
|
||||||
@ -23,7 +33,6 @@ void ConnectionManager::AddConnection(string host, short port)
|
|||||||
client->Start();
|
client->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
|
void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
|
||||||
{
|
{
|
||||||
m_Servers.push_front(server);
|
m_Servers.push_front(server);
|
||||||
@ -41,6 +50,7 @@ void ConnectionManager::RegisterClient(JsonRpcClient::Ptr client)
|
|||||||
m_Clients.push_front(client);
|
m_Clients.push_front(client);
|
||||||
client->OnNewMessage += bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this());
|
client->OnNewMessage += bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this());
|
||||||
client->OnClosed += bind_weak(&ConnectionManager::CloseClientHandler, 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)
|
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);
|
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->Source);
|
||||||
UnregisterClient(client);
|
UnregisterClient(client);
|
||||||
|
|
||||||
|
if (client->GetPeerHost() != string()) {
|
||||||
Timer::Ptr timer = make_shared<Timer>();
|
Timer::Ptr timer = make_shared<Timer>();
|
||||||
timer->SetInterval(30);
|
timer->SetInterval(30);
|
||||||
timer->SetUserArgs(ea);
|
timer->SetUserArgs(ea);
|
||||||
timer->OnTimerExpired += bind_weak(&ConnectionManager::ReconnectClientHandler, shared_from_this());
|
timer->OnTimerExpired += bind_weak(&ConnectionManager::ReconnectClientHandler, shared_from_this());
|
||||||
timer->Start();
|
timer->Start();
|
||||||
m_ReconnectTimers.push_front(timer);
|
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;
|
return 0;
|
||||||
}
|
}
|
@ -10,9 +10,11 @@ class ConnectionManager : public Object
|
|||||||
list<JsonRpcClient::Ptr> m_Clients;
|
list<JsonRpcClient::Ptr> m_Clients;
|
||||||
map< string, event<NewMessageEventArgs::Ptr> > m_Methods;
|
map< string, event<NewMessageEventArgs::Ptr> > m_Methods;
|
||||||
list<Timer::Ptr> m_ReconnectTimers;
|
list<Timer::Ptr> m_ReconnectTimers;
|
||||||
|
string m_Identity;
|
||||||
|
|
||||||
int NewClientHandler(NewClientEventArgs::Ptr ncea);
|
int NewClientHandler(NewClientEventArgs::Ptr ncea);
|
||||||
int CloseClientHandler(EventArgs::Ptr ea);
|
int CloseClientHandler(EventArgs::Ptr ea);
|
||||||
|
int ErrorClientHandler(SocketErrorEventArgs::Ptr ea);
|
||||||
int ReconnectClientHandler(TimerEventArgs::Ptr ea);
|
int ReconnectClientHandler(TimerEventArgs::Ptr ea);
|
||||||
int NewMessageHandler(NewMessageEventArgs::Ptr nmea);
|
int NewMessageHandler(NewMessageEventArgs::Ptr nmea);
|
||||||
|
|
||||||
@ -25,6 +27,9 @@ public:
|
|||||||
typedef shared_ptr<ConnectionManager> Ptr;
|
typedef shared_ptr<ConnectionManager> Ptr;
|
||||||
typedef weak_ptr<ConnectionManager> WeakPtr;
|
typedef weak_ptr<ConnectionManager> WeakPtr;
|
||||||
|
|
||||||
|
void SetIdentity(string identity);
|
||||||
|
string GetIdentity(void);
|
||||||
|
|
||||||
void AddListener(unsigned short port);
|
void AddListener(unsigned short port);
|
||||||
void AddConnection(string host, short port);
|
void AddConnection(string host, short port);
|
||||||
|
|
@ -4,6 +4,7 @@
|
|||||||
#include <i2-base.h>
|
#include <i2-base.h>
|
||||||
#include <i2-jsonrpc.h>
|
#include <i2-jsonrpc.h>
|
||||||
|
|
||||||
|
#include "connectionmanager.h"
|
||||||
#include "icingaapplication.h"
|
#include "icingaapplication.h"
|
||||||
|
|
||||||
#endif /* I2ICINGA_H */
|
#endif /* I2ICINGA_H */
|
||||||
|
@ -81,9 +81,11 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="connectionmanager.cpp" />
|
||||||
<ClCompile Include="icingaapplication.cpp" />
|
<ClCompile Include="icingaapplication.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="connectionmanager.h" />
|
||||||
<ClInclude Include="icingaapplication.h" />
|
<ClInclude Include="icingaapplication.h" />
|
||||||
<ClInclude Include="i2-icinga.h" />
|
<ClInclude Include="i2-icinga.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -7,8 +7,6 @@ noinst_LTLIBRARIES = \
|
|||||||
libjsonrpc_la_SOURCES = \
|
libjsonrpc_la_SOURCES = \
|
||||||
cJSON.c \
|
cJSON.c \
|
||||||
cJSON.h \
|
cJSON.h \
|
||||||
connectionmanager.cpp \
|
|
||||||
connectionmanager.h \
|
|
||||||
i2-jsonrpc.h \
|
i2-jsonrpc.h \
|
||||||
jsonrpcclient.cpp \
|
jsonrpcclient.cpp \
|
||||||
jsonrpcclient.h \
|
jsonrpcclient.h \
|
||||||
|
@ -9,6 +9,5 @@
|
|||||||
#include "jsonrpcmessage.h"
|
#include "jsonrpcmessage.h"
|
||||||
#include "jsonrpcclient.h"
|
#include "jsonrpcclient.h"
|
||||||
#include "jsonrpcserver.h"
|
#include "jsonrpcserver.h"
|
||||||
#include "connectionmanager.h"
|
|
||||||
|
|
||||||
#endif /* I2JSONRPC_H */
|
#endif /* I2JSONRPC_H */
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="cJSON.h" />
|
<ClInclude Include="cJSON.h" />
|
||||||
<ClInclude Include="connectionmanager.h" />
|
|
||||||
<ClInclude Include="i2-jsonrpc.h" />
|
<ClInclude Include="i2-jsonrpc.h" />
|
||||||
<ClInclude Include="jsonrpcclient.h" />
|
<ClInclude Include="jsonrpcclient.h" />
|
||||||
<ClInclude Include="jsonrpcmessage.h" />
|
<ClInclude Include="jsonrpcmessage.h" />
|
||||||
@ -21,7 +20,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="cJSON.c" />
|
<ClCompile Include="cJSON.c" />
|
||||||
<ClCompile Include="connectionmanager.cpp" />
|
|
||||||
<ClCompile Include="jsonrpcclient.cpp" />
|
<ClCompile Include="jsonrpcclient.cpp" />
|
||||||
<ClCompile Include="jsonrpcmessage.cpp" />
|
<ClCompile Include="jsonrpcmessage.cpp" />
|
||||||
<ClCompile Include="jsonrpcserver.cpp" />
|
<ClCompile Include="jsonrpcserver.cpp" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user