SocketErrorEventArgs::Ptr ea = make_shared<SocketErrorEventArgs>();
ea->Code = opt;
ea->Message = FormatErrorCode(opt);
- Close();
+ OnError(ea);
+ Close();
}
return 0;
icinga
icinga_SOURCES = \
+ connectionmanager.cpp \
+ connectionmanager.h \
icingaapplication.cpp \
icingaapplication.h \
i2-icinga.h
-#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>();
client->Start();
}
-
void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
{
m_Servers.push_front(server);
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)
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;
}
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);
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);
#include <i2-base.h>
#include <i2-jsonrpc.h>
+#include "connectionmanager.h"
#include "icingaapplication.h"
#endif /* I2ICINGA_H */
</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>
libjsonrpc_la_SOURCES = \
cJSON.c \
cJSON.h \
- connectionmanager.cpp \
- connectionmanager.h \
i2-jsonrpc.h \
jsonrpcclient.cpp \
jsonrpcclient.h \
#include "jsonrpcmessage.h"
#include "jsonrpcclient.h"
#include "jsonrpcserver.h"
-#include "connectionmanager.h"
#endif /* I2JSONRPC_H */
</ItemGroup>
<ItemGroup>
<ClInclude Include="cJSON.h" />
- <ClInclude Include="connectionmanager.h" />
<ClInclude Include="i2-jsonrpc.h" />
<ClInclude Include="jsonrpcclient.h" />
<ClInclude Include="jsonrpcmessage.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cJSON.c" />
- <ClCompile Include="connectionmanager.cpp" />
<ClCompile Include="jsonrpcclient.cpp" />
<ClCompile Include="jsonrpcmessage.cpp" />
<ClCompile Include="jsonrpcserver.cpp" />