mirror of https://github.com/Icinga/icinga2.git
43 lines
824 B
C++
43 lines
824 B
C++
#include "i2-jsonrpc.h"
|
|
|
|
using namespace icinga;
|
|
|
|
void JsonRpcClient::Start(void)
|
|
{
|
|
TCPClient::Start();
|
|
|
|
OnDataAvailable += bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this());
|
|
}
|
|
|
|
void JsonRpcClient::SendMessage(JsonRpcMessage::Ptr message)
|
|
{
|
|
Netstring::WriteJSONToFIFO(GetSendQueue(), message->GetJSON());
|
|
}
|
|
|
|
int JsonRpcClient::DataAvailableHandler(EventArgs::Ptr ea)
|
|
{
|
|
cJSON *json;
|
|
|
|
while (true) {
|
|
try {
|
|
json = Netstring::ReadJSONFromFIFO(GetRecvQueue());
|
|
} catch (const exception&) {
|
|
Close();
|
|
|
|
return 1;
|
|
}
|
|
|
|
if (json == NULL)
|
|
break;
|
|
|
|
JsonRpcMessage::Ptr msg = make_shared<JsonRpcMessage>();
|
|
msg->SetJSON(json);
|
|
NewMessageEventArgs::Ptr nea = make_shared<NewMessageEventArgs>();
|
|
nea->Source = shared_from_this();
|
|
nea->Message = msg;
|
|
OnNewMessage(nea);
|
|
}
|
|
|
|
return 0;
|
|
}
|