Remove EventArgs struct.

This commit is contained in:
Gunnar Beutner 2012-06-16 03:42:54 +02:00
parent 10138c7ff8
commit 7753e229cc
42 changed files with 321 additions and 494 deletions

View File

@ -159,9 +159,6 @@ void Application::RunEventLoop(void)
else if (ready == 0)
continue;
EventArgs ea;
ea.Source = shared_from_this();
for (i = Socket::Sockets.begin();
i != Socket::Sockets.end(); ) {
Socket::Ptr socket = i->lock();
@ -178,15 +175,15 @@ void Application::RunEventLoop(void)
fd = socket->GetFD();
if (fd != INVALID_SOCKET && FD_ISSET(fd, &writefds))
socket->OnWritable(ea);
socket->OnWritable(socket);
fd = socket->GetFD();
if (fd != INVALID_SOCKET && FD_ISSET(fd, &readfds))
socket->OnReadable(ea);
socket->OnReadable(socket);
fd = socket->GetFD();
if (fd != INVALID_SOCKET && FD_ISSET(fd, &exceptfds))
socket->OnException(ea);
socket->OnException(socket);
}
}
}

View File

@ -36,7 +36,6 @@
<ClInclude Include="component.h" />
<ClInclude Include="configobject.h" />
<ClInclude Include="dictionary.h" />
<ClInclude Include="eventargs.h" />
<ClInclude Include="objectmap.h" />
<ClInclude Include="objectset.h" />
<ClInclude Include="exception.h" />

View File

@ -1,38 +0,0 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#ifndef EVENTARGS_H
#define EVENTARGS_H
namespace icinga
{
/**
* Base class for event arguments.
*
* @ingroup base
*/
struct I2_BASE_API EventArgs
{
Object::Ptr Source; /**< The source of the event. */
};
}
#endif /* EVENTARGS_H */

View File

@ -145,7 +145,6 @@ using boost::function;
#include "exception.h"
#include "memory.h"
#include "variant.h"
#include "eventargs.h"
#include "dictionary.h"
#include "timer.h"
#include "fifo.h"

View File

@ -43,9 +43,9 @@ public:
void Start(void)
{
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectMap::ObjectAddedHandler, this, _1));
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _1));
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _1));
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectMap::ObjectAddedHandler, this, _2));
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _2));
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _2));
for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
AddObject(*it);
@ -56,16 +56,12 @@ public:
return m_Objects.equal_range(key);
}
void ForeachObject(TKey key, function<void (const ObjectSetEventArgs<TValue>&)> callback)
void ForeachObject(TKey key, function<void (const typename ObjectMap<TValue>::Ptr, const TValue&)> callback)
{
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
Range range = GetRange(key);
for (Iterator it = range.first; it != range.second; it++) {
ea.Target(*it);
callback(ea);
callback(shared_from_this(), *it);
}
}
@ -105,19 +101,19 @@ private:
AddObject(object);
}
void ObjectAddedHandler(const ObjectSetEventArgs<TValue>& ea)
void ObjectAddedHandler(const TValue& object)
{
AddObject(ea.Target);
AddObject(object);
}
void ObjectCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
void ObjectCommittedHandler(const TValue& object)
{
CheckObject(ea.Target);
CheckObject(object);
}
void ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
void ObjectRemovedHandler(const TValue& object)
{
RemoveObject(ea.Target);
RemoveObject(object);
}
};

View File

@ -23,12 +23,6 @@
namespace icinga
{
template<typename TValue>
struct ObjectSetEventArgs : public EventArgs
{
TValue Target;
};
template<typename TValue>
class ObjectSet : public Object
{
@ -49,25 +43,19 @@ public:
void Start(void)
{
if (m_Parent) {
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _1));
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _2));
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
CheckObject(*it);
}
}
}
void AddObject(const TValue& object)
{
m_Objects.insert(object);
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectAdded(ea);
OnObjectAdded(shared_from_this(), object);
}
void RemoveObject(const TValue& object)
@ -76,11 +64,7 @@ public:
if (it != m_Objects.end()) {
m_Objects.erase(it);
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectRemoved(ea);
OnObjectRemoved(shared_from_this(), object);
}
}
@ -97,17 +81,14 @@ public:
if (!Contains(object)) {
AddObject(object);
} else {
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
ea.Target = object;
OnObjectCommitted(ea);
OnObjectCommitted(shared_from_this(), object);
}
}
}
boost::signal<void (const ObjectSetEventArgs<TValue>&)> OnObjectAdded;
boost::signal<void (const ObjectSetEventArgs<TValue>&)> OnObjectCommitted;
boost::signal<void (const ObjectSetEventArgs<TValue>&)> OnObjectRemoved;
boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectAdded;
boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectCommitted;
boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectRemoved;
Iterator Begin(void)
{
@ -119,14 +100,10 @@ public:
return m_Objects.end();
}
void ForeachObject(function<void (const ObjectSetEventArgs<TValue>&)> callback)
void ForeachObject(function<void (const typename Object::Ptr&, const TValue&)> callback)
{
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
for (Iterator it = Begin(); it != End(); it++) {
ea.Target(*it);
callback(ea);
callback(shared_from_this(), *it);
}
}
@ -136,14 +113,14 @@ private:
typename ObjectSet<TValue>::Ptr m_Parent;
function<bool (const TValue&)> m_Predicate;
void ObjectAddedOrCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
void ObjectAddedOrCommittedHandler(const TValue& object)
{
CheckObject(ea.Target);
CheckObject(object);
}
void ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
void ObjectRemovedHandler(const TValue& object)
{
RemoveObject(ea.Target);
RemoveObject(object);
}
};

View File

@ -50,7 +50,7 @@ void Socket::Start(void)
{
assert(m_FD != INVALID_SOCKET);
OnException.connect(boost::bind(&Socket::ExceptionEventHandler, this, _1));
OnException.connect(boost::bind(&Socket::ExceptionEventHandler, this));
Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
}
@ -125,9 +125,7 @@ void Socket::CloseInternal(bool from_dtor)
if (!from_dtor) {
Stop();
EventArgs ea;
ea.Source = shared_from_this();
OnClosed(ea);
OnClosed(shared_from_this());
}
}
@ -172,8 +170,7 @@ int Socket::GetLastSocketError(void)
void Socket::HandleSocketError(const std::exception& ex)
{
if (!OnError.empty()) {
SocketErrorEventArgs sea(ex);
OnError(sea);
OnError(shared_from_this(), ex);
Close();
} else {
@ -186,7 +183,7 @@ void Socket::HandleSocketError(const std::exception& ex)
*
* @param - Event arguments for the socket error.
*/
void Socket::ExceptionEventHandler(const EventArgs&)
void Socket::ExceptionEventHandler(void)
{
HandleSocketError(SocketException(
"select() returned fd in except fdset", GetError()));

View File

@ -22,19 +22,6 @@
namespace icinga {
/**
* Event arguments for socket errors.
*
* @ingroup base
*/
struct I2_BASE_API SocketErrorEventArgs : public EventArgs
{
const std::exception& Exception;
SocketErrorEventArgs(const std::exception& ex)
: Exception(ex) { }
};
/**
* Base class for sockets.
*
@ -55,12 +42,12 @@ public:
void SetFD(SOCKET fd);
SOCKET GetFD(void) const;
boost::signal<void (const EventArgs&)> OnReadable;
boost::signal<void (const EventArgs&)> OnWritable;
boost::signal<void (const EventArgs&)> OnException;
boost::signal<void (const Object::Ptr&)> OnReadable;
boost::signal<void (const Object::Ptr&)> OnWritable;
boost::signal<void (const Object::Ptr&)> OnException;
boost::signal<void (const SocketErrorEventArgs&)> OnError;
boost::signal<void (const EventArgs&)> OnClosed;
boost::signal<void (const Object::Ptr&, const std::exception&)> OnError;
boost::signal<void (const Object::Ptr&)> OnClosed;
virtual bool WantsToRead(void) const;
virtual bool WantsToWrite(void) const;
@ -85,7 +72,7 @@ protected:
private:
SOCKET m_FD; /**< The socket descriptor. */
void ExceptionEventHandler(const EventArgs& ea);
void ExceptionEventHandler(void);
static string GetAddressFromSockaddr(sockaddr *address, socklen_t len);
};

View File

@ -51,8 +51,8 @@ void TcpClient::Start(void)
{
TcpSocket::Start();
OnReadable.connect(boost::bind(&TcpClient::ReadableEventHandler, this, _1));
OnWritable.connect(boost::bind(&TcpClient::WritableEventHandler, this, _1));
OnReadable.connect(boost::bind(&TcpClient::ReadableEventHandler, this));
OnWritable.connect(boost::bind(&TcpClient::WritableEventHandler, this));
}
/**
@ -136,10 +136,8 @@ FIFO::Ptr TcpClient::GetRecvQueue(void)
/**
* Processes data that is available for this socket.
*
* @param - Event arguments.
*/
void TcpClient::ReadableEventHandler(const EventArgs&)
void TcpClient::ReadableEventHandler(void)
{
int rc;
@ -161,17 +159,13 @@ void TcpClient::ReadableEventHandler(const EventArgs&)
m_RecvQueue->Write(NULL, rc);
EventArgs dea;
dea.Source = shared_from_this();
OnDataAvailable(dea);
OnDataAvailable(shared_from_this());
}
/**
* Processes data that can be written for this socket.
*
* @param - Event arguments.
*/
void TcpClient::WritableEventHandler(const EventArgs&)
void TcpClient::WritableEventHandler(void)
{
int rc;

View File

@ -61,7 +61,7 @@ public:
virtual bool WantsToRead(void) const;
virtual bool WantsToWrite(void) const;
boost::signal<void (const EventArgs&)> OnDataAvailable;
boost::signal<void (const Object::Ptr&)> OnDataAvailable;
private:
TcpClientRole m_Role;
@ -69,8 +69,8 @@ private:
FIFO::Ptr m_SendQueue;
FIFO::Ptr m_RecvQueue;
virtual void ReadableEventHandler(const EventArgs& ea);
virtual void WritableEventHandler(const EventArgs& ea);
virtual void ReadableEventHandler(void);
virtual void WritableEventHandler(void);
};
/**

View File

@ -56,7 +56,7 @@ void TcpServer::Start(void)
{
TcpSocket::Start();
OnReadable.connect(boost::bind(&TcpServer::ReadableEventHandler, this, _1));
OnReadable.connect(boost::bind(&TcpServer::ReadableEventHandler, this));
}
/**
@ -64,9 +64,7 @@ void TcpServer::Start(void)
*/
void TcpServer::Listen(void)
{
int rc = listen(GetFD(), SOMAXCONN);
if (rc < 0) {
if (listen(GetFD(), SOMAXCONN) < 0) {
HandleSocketError(SocketException(
"listen() failed", GetError()));
return;
@ -76,11 +74,8 @@ void TcpServer::Listen(void)
/**
* Accepts a new client and creates a new client object for it
* using the client factory function.
*
* @param - Event arguments.
* @returns 0
*/
int TcpServer::ReadableEventHandler(const EventArgs&)
void TcpServer::ReadableEventHandler(void)
{
int fd;
sockaddr_storage addr;
@ -91,17 +86,14 @@ int TcpServer::ReadableEventHandler(const EventArgs&)
if (fd < 0) {
HandleSocketError(SocketException(
"accept() failed", GetError()));
return 0;
return;
}
NewClientEventArgs nea;
nea.Source = shared_from_this();
nea.Client = static_pointer_cast<TcpSocket>(m_ClientFactory());
nea.Client->SetFD(fd);
nea.Client->Start();
OnNewClient(nea);
TcpClient::Ptr client = m_ClientFactory();
client->SetFD(fd);
client->Start();
return 0;
OnNewClient(shared_from_this(), client);
}
/**

View File

@ -23,16 +23,6 @@
namespace icinga
{
/**
* Event arguments for the "new client" event.
*
* @ingroup base
*/
struct I2_BASE_API NewClientEventArgs : public EventArgs
{
TcpSocket::Ptr Client; /**< The new client object. */
};
/**
* A TCP server that listens on a TCP port and accepts incoming
* client connections.
@ -54,12 +44,12 @@ public:
void Listen(void);
boost::signal<void (const NewClientEventArgs&)> OnNewClient;
boost::signal<void (const Object::Ptr&, const TcpClient::Ptr&)> OnNewClient;
virtual bool WantsToRead(void) const;
private:
int ReadableEventHandler(const EventArgs& ea);
void ReadableEventHandler(void);
function<TcpClient::Ptr()> m_ClientFactory;
};

View File

@ -100,9 +100,7 @@ void Timer::CallExpiredTimers(void)
*/
void Timer::Call(void)
{
EventArgs tea;
tea.Source = shared_from_this();
OnTimerExpired(tea);
OnTimerExpired(shared_from_this());
}
/**

View File

@ -52,7 +52,7 @@ public:
void Reschedule(time_t next);
boost::signal<void(const EventArgs&)> OnTimerExpired;
boost::signal<void(const Object::Ptr&)> OnTimerExpired;
private:
time_t m_Interval; /**< The interval of the timer. */

View File

@ -105,10 +105,8 @@ void TlsClient::Start(void)
/**
* Processes data that is available for this socket.
*
* @param - Event arguments.
*/
void TlsClient::ReadableEventHandler(const EventArgs&)
void TlsClient::ReadableEventHandler(void)
{
int rc;
@ -138,17 +136,13 @@ void TlsClient::ReadableEventHandler(const EventArgs&)
GetRecvQueue()->Write(NULL, rc);
EventArgs dea;
dea.Source = shared_from_this();
OnDataAvailable(dea);
OnDataAvailable(shared_from_this());
}
/**
* Processes data that can be written for this socket.
*
* @param - Event arguments.
*/
void TlsClient::WritableEventHandler(const EventArgs&)
void TlsClient::WritableEventHandler(void)
{
int rc;
@ -248,12 +242,9 @@ int TlsClient::SSLVerifyCertificate(int ok, X509_STORE_CTX *x509Context)
if (client == NULL)
return 0;
VerifyCertificateEventArgs vcea;
vcea.Source = client->shared_from_this();
vcea.ValidCertificate = (ok != 0);
vcea.Context = x509Context;
vcea.Certificate = shared_ptr<X509>(x509Context->cert, &TlsClient::NullCertificateDeleter);
client->OnVerifyCertificate(vcea);
bool valid = false;
shared_ptr<X509> x509Certificate = shared_ptr<X509>(x509Context->cert, &TlsClient::NullCertificateDeleter);
client->OnVerifyCertificate(client->shared_from_this(), valid, x509Context, x509Certificate);
return (int)vcea.ValidCertificate;
return valid ? 1 : 0;
}

View File

@ -23,20 +23,6 @@
namespace icinga
{
/**
* Event arguments for the "SSL certificate verification" event.
*
* @ingroup base
*/
struct I2_BASE_API VerifyCertificateEventArgs : public EventArgs
{
bool ValidCertificate; /**< Whether the certificate is valid, can be
changed by the event handler. */
X509_STORE_CTX *Context; /**< The X509 store context. */
shared_ptr<X509> Certificate; /**< The X509 certificate that should
ve verified. */
};
/**
* A TLS client connection.
*
@ -55,7 +41,7 @@ public:
virtual bool WantsToRead(void) const;
virtual bool WantsToWrite(void) const;
boost::signal<void (const VerifyCertificateEventArgs&)> OnVerifyCertificate;
boost::signal<void (const Object::Ptr&, bool&, X509_STORE_CTX *, const shared_ptr<X509>&)> OnVerifyCertificate;
protected:
void HandleSSLError(void);
@ -70,8 +56,8 @@ private:
static int m_SSLIndex;
static bool m_SSLIndexInitialized;
virtual void ReadableEventHandler(const EventArgs& ea);
virtual void WritableEventHandler(const EventArgs& ea);
virtual void ReadableEventHandler(void);
virtual void WritableEventHandler(void);
virtual void CloseInternal(bool from_dtor);

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Quelldateien">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Headerdateien">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="i2-checker.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="checkercomponent.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="checkercomponent.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -30,11 +30,11 @@ void CheckerComponent::Start(void)
{
m_CheckerEndpoint = boost::make_shared<VirtualEndpoint>();
m_CheckerEndpoint->RegisterTopicHandler("checker::AssignService",
boost::bind(&CheckerComponent::AssignServiceRequestHandler, this, _1));
boost::bind(&CheckerComponent::AssignServiceRequestHandler, this, _2, _3));
m_CheckerEndpoint->RegisterTopicHandler("checker::RevokeService",
boost::bind(&CheckerComponent::RevokeServiceRequestHandler, this, _1));
boost::bind(&CheckerComponent::RevokeServiceRequestHandler, this, _2, _3));
m_CheckerEndpoint->RegisterTopicHandler("checker::ClearServices",
boost::bind(&CheckerComponent::ClearServicesRequestHandler, this, _1));
boost::bind(&CheckerComponent::ClearServicesRequestHandler, this, _2, _3));
m_CheckerEndpoint->RegisterPublication("checker::CheckResult");
GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
@ -90,10 +90,10 @@ void CheckerComponent::CheckTimerHandler(void)
m_CheckTimer->SetInterval(service.GetNextCheck() - now);
}
void CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nrea)
void CheckerComponent::AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
{
MessagePart params;
if (!nrea.Request.GetParams(&params))
if (!request.GetParams(&params))
return;
MessagePart serviceMsg;
@ -110,20 +110,20 @@ void CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nr
m_CheckTimer->Reschedule(0);
string id;
if (nrea.Request.GetID(&id)) {
if (request.GetID(&id)) {
ResponseMessage rm;
rm.SetID(id);
MessagePart result;
rm.SetResult(result);
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, sender, rm);
}
}
void CheckerComponent::RevokeServiceRequestHandler(const NewRequestEventArgs& nrea)
void CheckerComponent::RevokeServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
{
MessagePart params;
if (!nrea.Request.GetParams(&params))
if (!request.GetParams(&params))
return;
string name;
@ -148,29 +148,29 @@ void CheckerComponent::RevokeServiceRequestHandler(const NewRequestEventArgs& nr
Application::Log(LogInformation, "checker", "Revoked delegation for service '" + name + "'");
string id;
if (nrea.Request.GetID(&id)) {
if (request.GetID(&id)) {
ResponseMessage rm;
rm.SetID(id);
MessagePart result;
rm.SetResult(result);
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, sender, rm);
}
}
void CheckerComponent::ClearServicesRequestHandler(const NewRequestEventArgs& nrea)
void CheckerComponent::ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
{
Application::Log(LogInformation, "checker", "Clearing service delegations.");
m_Services = ServiceQueue();
string id;
if (nrea.Request.GetID(&id)) {
if (request.GetID(&id)) {
ResponseMessage rm;
rm.SetID(id);
MessagePart result;
rm.SetResult(result);
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, sender, rm);
}
}

View File

@ -54,9 +54,9 @@ private:
void CheckTimerHandler(void);
void AssignServiceRequestHandler(const NewRequestEventArgs& nrea);
void RevokeServiceRequestHandler(const NewRequestEventArgs& nrea);
void ClearServicesRequestHandler(const NewRequestEventArgs& nrea);
void AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
void RevokeServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
void ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
};
}

View File

@ -35,23 +35,23 @@ void ConfigRpcComponent::Start(void)
long configSource;
if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
boost::bind(&ConfigRpcComponent::FetchObjectsHandler, this, _1));
boost::bind(&ConfigRpcComponent::FetchObjectsHandler, this, _2));
ConfigObject::GetAllObjects()->OnObjectAdded.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
ConfigObject::GetAllObjects()->OnObjectCommitted.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
ConfigObject::GetAllObjects()->OnObjectRemoved.connect(boost::bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _1));
ConfigObject::GetAllObjects()->OnObjectAdded.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _2));
ConfigObject::GetAllObjects()->OnObjectCommitted.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _2));
ConfigObject::GetAllObjects()->OnObjectRemoved.connect(boost::bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _2));
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectRemoved");
}
endpointManager->OnNewEndpoint.connect(boost::bind(&ConfigRpcComponent::NewEndpointHandler, this, _1));
endpointManager->OnNewEndpoint.connect(boost::bind(&ConfigRpcComponent::NewEndpointHandler, this, _2));
m_ConfigRpcEndpoint->RegisterPublication("config::FetchObjects");
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectCommitted",
boost::bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _1));
boost::bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _3));
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectRemoved",
boost::bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _1));
boost::bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _3));
endpointManager->RegisterEndpoint(m_ConfigRpcEndpoint);
}
@ -64,17 +64,17 @@ void ConfigRpcComponent::Stop(void)
mgr->UnregisterEndpoint(m_ConfigRpcEndpoint);
}
void ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
void ConfigRpcComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint)
{
ea.Endpoint->OnSessionEstablished.connect(boost::bind(&ConfigRpcComponent::SessionEstablishedHandler, this, _1));
endpoint->OnSessionEstablished.connect(boost::bind(&ConfigRpcComponent::SessionEstablishedHandler, this, _1));
}
void ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
void ConfigRpcComponent::SessionEstablishedHandler(const Object::Ptr& source)
{
RequestMessage request;
request.SetMethod("config::FetchObjects");
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(source);
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, endpoint, request);
}
@ -100,9 +100,8 @@ bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
return (!object->IsLocal());
}
void ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
void ConfigRpcComponent::FetchObjectsHandler(const Endpoint::Ptr& sender)
{
Endpoint::Ptr client = ea.Sender;
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
for (ConfigObject::Set::Iterator ci = allObjects->Begin(); ci != allObjects->End(); ci++) {
@ -113,14 +112,12 @@ void ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
RequestMessage request = MakeObjectMessage(object, "config::ObjectCreated", true);
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, sender, request);
}
}
void ConfigRpcComponent::LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
void ConfigRpcComponent::LocalObjectCommittedHandler(const ConfigObject::Ptr& object)
{
ConfigObject::Ptr object = ea.Target;
if (!ShouldReplicateObject(object))
return;
@ -128,10 +125,8 @@ void ConfigRpcComponent::LocalObjectCommittedHandler(const ObjectSetEventArgs<Co
MakeObjectMessage(object, "config::ObjectCreated", true));
}
void ConfigRpcComponent::LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
void ConfigRpcComponent::LocalObjectRemovedHandler(const ConfigObject::Ptr& object)
{
ConfigObject::Ptr object = ea.Target;
if (!ShouldReplicateObject(object))
return;
@ -139,12 +134,10 @@ void ConfigRpcComponent::LocalObjectRemovedHandler(const ObjectSetEventArgs<Conf
MakeObjectMessage(object, "config::ObjectRemoved", false));
}
void ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
void ConfigRpcComponent::RemoteObjectCommittedHandler(const RequestMessage& request)
{
RequestMessage message = ea.Request;
MessagePart params;
if (!message.GetParams(&params))
if (!request.GetParams(&params))
return;
string name;
@ -169,12 +162,10 @@ void ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
object->Commit();
}
void ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
void ConfigRpcComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
{
RequestMessage message = ea.Request;
MessagePart params;
if (!message.GetParams(&params))
if (!request.GetParams(&params))
return;
string name;

View File

@ -36,15 +36,15 @@ public:
private:
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
void NewEndpointHandler(const NewEndpointEventArgs& ea);
void SessionEstablishedHandler(const EventArgs& ea);
void NewEndpointHandler(const Endpoint::Ptr& endpoint);
void SessionEstablishedHandler(const Object::Ptr& source);
void LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
void LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
void LocalObjectCommittedHandler(const ConfigObject::Ptr& object);
void LocalObjectRemovedHandler(const ConfigObject::Ptr& object);
void FetchObjectsHandler(const NewRequestEventArgs& ea);
void RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
void RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
void FetchObjectsHandler(const Endpoint::Ptr& sender);
void RemoteObjectCommittedHandler(const RequestMessage& request);
void RemoteObjectRemovedHandler(const RequestMessage& request);
static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
string method, bool includeProperties);

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Quelldateien">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Headerdateien">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="delegationcomponent.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="delegationcomponent.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="i2-delegation.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -29,9 +29,9 @@ string DelegationComponent::GetName(void) const
void DelegationComponent::Start(void)
{
m_AllServices = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
m_AllServices->OnObjectAdded.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::RemovedServiceHandler, this, _1));
m_AllServices->OnObjectAdded.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _2));
m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _2));
m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::RemovedServiceHandler, this, _2));
m_AllServices->Start();
m_DelegationTimer = boost::make_shared<Timer>();
@ -53,14 +53,14 @@ void DelegationComponent::Stop(void)
mgr->UnregisterEndpoint(m_DelegationEndpoint);
}
void DelegationComponent::NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
void DelegationComponent::NewServiceHandler(const ConfigObject::Ptr& object)
{
AssignService(ea.Target);
AssignService(object);
}
void DelegationComponent::RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
void DelegationComponent::RemovedServiceHandler(const ConfigObject::Ptr& object)
{
RevokeService(ea.Target);
RevokeService(object);
}
void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
@ -75,15 +75,15 @@ void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service->GetName() + "'");
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _1));
boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _2, _5));
}
void DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea)
void DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut)
{
if (nrea.TimedOut) {
if (timedOut) {
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' timed out.");
} else {
service->SetTag("checker", nrea.Sender->GetIdentity());
service->SetTag("checker", sender->GetIdentity());
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' was successful.");
}
}
@ -93,7 +93,7 @@ void DelegationComponent::RevokeService(const ConfigObject::Ptr& service)
}
void DelegationComponent::RevokeServiceResponseHandler(const NewResponseEventArgs& nrea)
void DelegationComponent::RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut)
{
}

View File

@ -38,11 +38,11 @@ private:
ConfigObject::Set::Ptr m_AllServices;
Timer::Ptr m_DelegationTimer;
void NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
void RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
void NewServiceHandler(const ConfigObject::Ptr& object);
void RemovedServiceHandler(const ConfigObject::Ptr& object);
void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
void RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
void RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
void DelegationTimerHandler(void);

View File

@ -38,7 +38,7 @@ void DemoComponent::Start(void)
{
m_DemoEndpoint = boost::make_shared<VirtualEndpoint>();
m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _1));
boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2, _3));
m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
GetEndpointManager()->RegisterEndpoint(m_DemoEndpoint);
@ -80,9 +80,9 @@ void DemoComponent::DemoTimerHandler(void)
/**
* Processes demo::HelloWorld messages.
*/
void DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
{
Application::Log(LogInformation, "demo", "Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
Application::Log(LogInformation, "demo", "Got 'hello world' from address=" + sender->GetAddress() + ", identity=" + sender->GetIdentity());
}
EXPORT_COMPONENT(demo, DemoComponent);

View File

@ -38,7 +38,7 @@ private:
VirtualEndpoint::Ptr m_DemoEndpoint;
void DemoTimerHandler(void);
void HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
void HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
};
}

View File

@ -40,17 +40,17 @@ void DiscoveryComponent::Start(void)
m_DiscoveryEndpoint->RegisterPublication("discovery::RegisterComponent");
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::RegisterComponent",
boost::bind(&DiscoveryComponent::RegisterComponentMessageHandler, this, _1));
boost::bind(&DiscoveryComponent::RegisterComponentMessageHandler, this, _2, _3));
m_DiscoveryEndpoint->RegisterPublication("discovery::NewComponent");
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::NewComponent",
boost::bind(&DiscoveryComponent::NewComponentMessageHandler, this, _1));
boost::bind(&DiscoveryComponent::NewComponentMessageHandler, this, _3));
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::Welcome",
boost::bind(&DiscoveryComponent::WelcomeMessageHandler, this, _1));
boost::bind(&DiscoveryComponent::WelcomeMessageHandler, this, _2, _3));
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
GetEndpointManager()->OnNewEndpoint.connect(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _2));
GetEndpointManager()->OnNewEndpoint.connect(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _2));
GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
@ -79,40 +79,39 @@ void DiscoveryComponent::Stop(void)
* Checks whether the specified endpoint is already connected
* and disconnects older endpoints.
*
* @param endpoint The endpoint that is to be checked.
* @param neea Event arguments for another endpoint.
* @param self The endpoint that is to be checked.
* @param other The other endpoint.
*/
void DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea)
void DiscoveryComponent::CheckExistingEndpoint(const Endpoint::Ptr& self, const Endpoint::Ptr& other)
{
if (endpoint == neea.Endpoint)
if (self == other)
return;
if (!neea.Endpoint->IsConnected())
if (!other->IsConnected())
return;
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
Application::Log(LogWarning, "discovery", "Detected duplicate identity:" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
if (self->GetIdentity() == other->GetIdentity()) {
Application::Log(LogWarning, "discovery", "Detected duplicate identity:" + other->GetIdentity() + " - Disconnecting old endpoint.");
neea.Endpoint->Stop();
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
other->Stop();
GetEndpointManager()->UnregisterEndpoint(other);
}
}
/**
* Registers handlers for new endpoints.
*
* @param neea Event arguments for the new endpoint.
* @returns 0
* @param endpoint The endpoint.
*/
void DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
void DiscoveryComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint)
{
neea.Endpoint->OnIdentityChanged.connect(boost::bind(&DiscoveryComponent::NewIdentityHandler, this, _1));
endpoint->OnIdentityChanged.connect(boost::bind(&DiscoveryComponent::NewIdentityHandler, this, _1));
/* accept discovery::RegisterComponent messages from any endpoint */
neea.Endpoint->RegisterPublication("discovery::RegisterComponent");
endpoint->RegisterPublication("discovery::RegisterComponent");
/* accept discovery::Welcome messages from any endpoint */
neea.Endpoint->RegisterPublication("discovery::Welcome");
endpoint->RegisterPublication("discovery::Welcome");
}
/**
@ -122,17 +121,15 @@ void DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
* @param info Component information object.
* @return 0
*/
void DiscoveryComponent::DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const
void DiscoveryComponent::DiscoveryEndpointHandler(const Endpoint::Ptr& endpoint, const ComponentDiscoveryInfo::Ptr& info) const
{
Endpoint::ConstTopicIterator i;
for (i = neea.Endpoint->BeginSubscriptions(); i != neea.Endpoint->EndSubscriptions(); i++) {
for (i = endpoint->BeginSubscriptions(); i != endpoint->EndSubscriptions(); i++)
info->Subscriptions.insert(*i);
}
for (i = neea.Endpoint->BeginPublications(); i != neea.Endpoint->EndPublications(); i++) {
for (i = endpoint->BeginPublications(); i != endpoint->EndPublications(); i++)
info->Publications.insert(*i);
}
}
/**
@ -147,7 +144,7 @@ bool DiscoveryComponent::GetComponentDiscoveryInfo(string component, ComponentDi
if (component == GetEndpointManager()->GetIdentity()) {
/* Build fake discovery info for ourselves */
*info = boost::make_shared<ComponentDiscoveryInfo>();
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::DiscoveryEndpointHandler, this, _1, *info));
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::DiscoveryEndpointHandler, this, _2, *info));
(*info)->LastSeen = 0;
(*info)->Node = GetIcingaApplication()->GetNode();
@ -173,9 +170,9 @@ bool DiscoveryComponent::GetComponentDiscoveryInfo(string component, ComponentDi
* @param ea Event arguments for the component.
* @returns 0
*/
void DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
void DiscoveryComponent::NewIdentityHandler(const Object::Ptr& source)
{
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(source);
string identity = endpoint->GetIdentity();
if (identity == GetEndpointManager()->GetIdentity()) {
@ -187,7 +184,7 @@ void DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
return;
}
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::CheckExistingEndpoint, this, endpoint, _1));
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::CheckExistingEndpoint, this, endpoint, _2));
// we assume the other component _always_ wants
// discovery::RegisterComponent messages from us
@ -241,20 +238,15 @@ void DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
* @param nrea Event arguments for the request.
* @returns 0
*/
void DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
void DiscoveryComponent::WelcomeMessageHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
{
Endpoint::Ptr endpoint = nrea.Sender;
if (endpoint->HasReceivedWelcome())
if (sender->HasReceivedWelcome())
return;
endpoint->SetReceivedWelcome(true);
sender->SetReceivedWelcome(true);
if (endpoint->HasSentWelcome()) {
EventArgs ea;
ea.Source = endpoint;
endpoint->OnSessionEstablished(ea);
}
if (sender->HasSentWelcome())
sender->OnSessionEstablished(sender);
}
/**
@ -264,7 +256,7 @@ void DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
*
* @param endpoint The endpoint to set up.
*/
void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
void DiscoveryComponent::FinishDiscoverySetup(const Endpoint::Ptr& endpoint)
{
if (endpoint->HasSentWelcome())
return;
@ -278,11 +270,8 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
endpoint->SetSentWelcome(true);
if (endpoint->HasReceivedWelcome()) {
EventArgs ea;
ea.Source = endpoint;
endpoint->OnSessionEstablished(ea);
}
if (endpoint->HasReceivedWelcome())
endpoint->OnSessionEstablished(endpoint);
}
/**
@ -293,7 +282,7 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
* @param identity The identity of the component for which a message should be sent.
* @param recipient The recipient of the message. A multicast message is sent if this parameter is empty.
*/
void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, Endpoint::Ptr recipient)
void DiscoveryComponent::SendDiscoveryMessage(const string& method, const string& identity, const Endpoint::Ptr& recipient)
{
RequestMessage request;
request.SetMethod(method);
@ -332,7 +321,7 @@ void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, En
GetEndpointManager()->SendMulticastMessage(m_DiscoveryEndpoint, request);
}
bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string messageType, string message)
bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, const string& messageType, const string& message)
{
if (!roles)
return false;
@ -367,7 +356,7 @@ bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string mess
* @param message The discovery message.
* @param trusted Whether the message comes from a trusted source (i.e. a broker).
*/
void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessage message, bool trusted)
void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const DiscoveryMessage& message, bool trusted)
{
/* ignore discovery messages that are about ourselves */
if (identity == GetEndpointManager()->GetIdentity())
@ -438,10 +427,10 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
*
* @param nrea Event arguments for the request.
*/
void DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& nrea)
void DiscoveryComponent::NewComponentMessageHandler(const RequestMessage& request)
{
DiscoveryMessage message;
nrea.Request.GetParams(&message);
request.GetParams(&message);
string identity;
if (!message.GetIdentity(&identity))
@ -455,11 +444,11 @@ void DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& n
*
* @param nrea Event arguments for the request.
*/
void DiscoveryComponent::RegisterComponentMessageHandler(const NewRequestEventArgs& nrea)
void DiscoveryComponent::RegisterComponentMessageHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
{
DiscoveryMessage message;
nrea.Request.GetParams(&message);
ProcessDiscoveryMessage(nrea.Sender->GetIdentity(), message, false);
request.GetParams(&message);
ProcessDiscoveryMessage(sender->GetIdentity(), message, false);
}
/**

View File

@ -56,27 +56,27 @@ private:
map<string, ComponentDiscoveryInfo::Ptr> m_Components;
Timer::Ptr m_DiscoveryTimer;
void NewEndpointHandler(const NewEndpointEventArgs& neea);
void NewIdentityHandler(const EventArgs& ea);
void NewEndpointHandler(const Endpoint::Ptr& endpoint);
void NewIdentityHandler(const Object::Ptr& source);
void NewComponentMessageHandler(const NewRequestEventArgs& nrea);
void RegisterComponentMessageHandler(const NewRequestEventArgs& nrea);
void NewComponentMessageHandler(const RequestMessage& request);
void RegisterComponentMessageHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
void WelcomeMessageHandler(const NewRequestEventArgs& nrea);
void WelcomeMessageHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
void SendDiscoveryMessage(string method, string identity, Endpoint::Ptr recipient);
void ProcessDiscoveryMessage(string identity, DiscoveryMessage message, bool trusted);
void SendDiscoveryMessage(const string& method, const string& identity, const Endpoint::Ptr& recipient);
void ProcessDiscoveryMessage(const string& identity, const DiscoveryMessage& message, bool trusted);
bool GetComponentDiscoveryInfo(string component, ComponentDiscoveryInfo::Ptr *info) const;
void CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea);
void DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const;
void CheckExistingEndpoint(const Endpoint::Ptr& self, const Endpoint::Ptr& other);
void DiscoveryEndpointHandler(const Endpoint::Ptr& endpoint, const ComponentDiscoveryInfo::Ptr& info) const;
void DiscoveryTimerHandler(void);
void FinishDiscoverySetup(Endpoint::Ptr endpoint);
void FinishDiscoverySetup(const Endpoint::Ptr& endpoint);
bool HasMessagePermission(Dictionary::Ptr roles, string messageType, string message);
bool HasMessagePermission(const Dictionary::Ptr& roles, const string& messageType, const string& message);
static const int RegistrationTTL = 300;
};

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Quelldateien">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Headerdateien">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Ressourcendateien">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dyntest.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -48,10 +48,7 @@ string Endpoint::GetIdentity(void) const
void Endpoint::SetIdentity(string identity)
{
m_Identity = identity;
EventArgs ea;
ea.Source = shared_from_this();
OnIdentityChanged(ea);
OnIdentityChanged(shared_from_this());
}
/**

View File

@ -79,8 +79,8 @@ public:
ConstTopicIterator BeginPublications(void) const;
ConstTopicIterator EndPublications(void) const;
boost::signal<void (const EventArgs&)> OnIdentityChanged;
boost::signal<void (const EventArgs&)> OnSessionEstablished;
boost::signal<void (const Object::Ptr&)> OnIdentityChanged;
boost::signal<void (const Object::Ptr&)> OnSessionEstablished;
private:
string m_Identity; /**< The identity of this endpoint. */

View File

@ -110,7 +110,7 @@ void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
{
m_Servers.push_back(server);
server->OnNewClient.connect(boost::bind(&EndpointManager::NewClientHandler,
this, _1));
this, _2));
}
/**
@ -118,13 +118,12 @@ void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
*
* @param ncea Event arguments.
*/
void EndpointManager::NewClientHandler(const NewClientEventArgs& ncea)
void EndpointManager::NewClientHandler(const TcpClient::Ptr& client)
{
string address = ncea.Client->GetPeerAddress();
Application::Log(LogInformation, "icinga", "Accepted new client from " + address);
Application::Log(LogInformation, "icinga", "Accepted new client from " + client->GetPeerAddress());
JsonRpcEndpoint::Ptr endpoint = boost::make_shared<JsonRpcEndpoint>();
endpoint->SetClient(static_pointer_cast<JsonRpcClient>(ncea.Client));
endpoint->SetClient(static_pointer_cast<JsonRpcClient>(client));
RegisterEndpoint(endpoint);
}
@ -154,10 +153,7 @@ void EndpointManager::RegisterEndpoint(Endpoint::Ptr endpoint)
endpoint->SetEndpointManager(static_pointer_cast<EndpointManager>(shared_from_this()));
m_Endpoints.push_back(endpoint);
NewEndpointEventArgs neea;
neea.Source = shared_from_this();
neea.Endpoint = endpoint;
OnNewEndpoint(neea);
OnNewEndpoint(shared_from_this(), endpoint);
}
/**
@ -257,18 +253,14 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
*
* @param callback The callback function.
*/
void EndpointManager::ForEachEndpoint(function<void (const NewEndpointEventArgs&)> callback)
void EndpointManager::ForEachEndpoint(function<void (const Object::Ptr&, const Endpoint::Ptr&)> callback)
{
NewEndpointEventArgs neea;
neea.Source = shared_from_this();
vector<Endpoint::Ptr>::iterator prev, i;
for (i = m_Endpoints.begin(); i != m_Endpoints.end(); ) {
prev = i;
i++;
neea.Endpoint = *prev;
callback(neea);
callback(shared_from_this(), *prev);
}
}
@ -290,7 +282,7 @@ Endpoint::Ptr EndpointManager::GetEndpointByIdentity(string identity) const
void EndpointManager::SendAPIMessage(Endpoint::Ptr sender,
RequestMessage& message,
function<void(const NewResponseEventArgs&)> callback, time_t timeout)
function<void(const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, time_t timeout)
{
m_NextMessageID++;
@ -345,12 +337,7 @@ void EndpointManager::RequestTimerHandler(void)
map<string, PendingRequest>::iterator it;
for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
if (it->second.HasTimedOut()) {
NewResponseEventArgs nrea;
nrea.Request = it->second.Request;
nrea.Source = shared_from_this();
nrea.TimedOut = true;
it->second.Callback(nrea);
it->second.Callback(shared_from_this(), Endpoint::Ptr(), it->second.Request, ResponseMessage(), true);
m_Requests.erase(it);
@ -373,14 +360,7 @@ void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const
if (it == m_Requests.end())
return;
NewResponseEventArgs nrea;
nrea.Sender = sender;
nrea.Request = it->second.Request;
nrea.Response = message;
nrea.Source = shared_from_this();
nrea.TimedOut = false;
it->second.Callback(nrea);
it->second.Callback(shared_from_this(), sender, it->second.Request, message, false);
m_Requests.erase(it);
RescheduleRequestTimer();

View File

@ -23,18 +23,6 @@
namespace icinga
{
/**
* Event arguments for the "new endpoint registered" event.
*
* @ingroup icinga
*/
struct I2_ICINGA_API NewEndpointEventArgs : public EventArgs
{
icinga::Endpoint::Ptr Endpoint; /**< The new endpoint. */
};
struct NewResponseEventArgs;
/**
* Information about a pending API request.
*
@ -44,7 +32,7 @@ struct I2_ICINGA_API PendingRequest
{
time_t Timeout;
RequestMessage Request;
function<void(const NewResponseEventArgs&)> Callback;
function<void(const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> Callback;
bool HasTimedOut(void) const
{
@ -52,19 +40,6 @@ struct I2_ICINGA_API PendingRequest
}
};
/**
* Event arguments for the "new response" event.
*
* @ingroup icinga
*/
struct I2_ICINGA_API NewResponseEventArgs : public EventArgs
{
Endpoint::Ptr Sender;
RequestMessage Request;
ResponseMessage Response;
bool TimedOut;
};
/**
* Forwards messages between endpoints.
*
@ -97,15 +72,15 @@ public:
void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
void SendAPIMessage(Endpoint::Ptr sender, RequestMessage& message,
function<void(const NewResponseEventArgs&)> callback, time_t timeout = 10);
function<void(const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, time_t timeout = 10);
void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
void ForEachEndpoint(function<void (const NewEndpointEventArgs&)> callback);
void ForEachEndpoint(function<void (const Object::Ptr&, const Endpoint::Ptr&)> callback);
Endpoint::Ptr GetEndpointByIdentity(string identity) const;
boost::signal<void (const NewEndpointEventArgs&)> OnNewEndpoint;
boost::signal<void (const Object::Ptr&, const Endpoint::Ptr&)> OnNewEndpoint;
private:
string m_Identity;
@ -125,7 +100,7 @@ private:
void RescheduleRequestTimer(void);
void RequestTimerHandler(void);
void NewClientHandler(const NewClientEventArgs& ncea);
void NewClientHandler(const TcpClient::Ptr& client);
};
}

View File

@ -56,10 +56,9 @@ int IcingaApplication::Main(const vector<string>& args)
/* register handler for 'component' config objects */
static ConfigObject::Set::Ptr componentObjects = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
function<void (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = boost::bind(&IcingaApplication::NewComponentHandler, this, _1);
componentObjects->OnObjectAdded.connect(NewComponentHandler);
componentObjects->OnObjectCommitted.connect(NewComponentHandler);
componentObjects->OnObjectRemoved.connect(boost::bind(&IcingaApplication::DeletedComponentHandler, this, _1));
componentObjects->OnObjectAdded.connect(boost::bind(&IcingaApplication::NewComponentHandler, this, _2));
componentObjects->OnObjectCommitted.connect(boost::bind(&IcingaApplication::NewComponentHandler, this, _2));
componentObjects->OnObjectRemoved.connect(boost::bind(&IcingaApplication::DeletedComponentHandler, this, _2));
componentObjects->Start();
/* load config file */
@ -113,10 +112,8 @@ EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
return m_EndpointManager;
}
void IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
void IcingaApplication::NewComponentHandler(const ConfigObject::Ptr& object)
{
ConfigObject::Ptr object = ea.Target;
/* don't allow replicated config objects */
if (!object->IsLocal())
throw runtime_error("'component' objects must be 'local'");
@ -133,10 +130,8 @@ void IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObjec
LoadComponent(path, object);
}
void IcingaApplication::DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
void IcingaApplication::DeletedComponentHandler(const ConfigObject::Ptr& object)
{
ConfigObject::Ptr object = ea.Target;
Component::Ptr component = GetComponent(object->GetName());
UnregisterComponent(component);
}

View File

@ -53,8 +53,8 @@ private:
string m_Node;
string m_Service;
void NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
void DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
void NewComponentHandler(const ConfigObject::Ptr& object);
void DeletedComponentHandler(const ConfigObject::Ptr& object);
};
}

View File

@ -45,10 +45,10 @@ void JsonRpcEndpoint::Connect(string node, string service, shared_ptr<SSL_CTX> s
void JsonRpcEndpoint::SetClient(JsonRpcClient::Ptr client)
{
m_Client = client;
client->OnNewMessage.connect(boost::bind(&JsonRpcEndpoint::NewMessageHandler, this, _1));
client->OnClosed.connect(boost::bind(&JsonRpcEndpoint::ClientClosedHandler, this, _1));
client->OnError.connect(boost::bind(&JsonRpcEndpoint::ClientErrorHandler, this, _1));
client->OnVerifyCertificate.connect(boost::bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _1));
client->OnNewMessage.connect(boost::bind(&JsonRpcEndpoint::NewMessageHandler, this, _2));
client->OnClosed.connect(boost::bind(&JsonRpcEndpoint::ClientClosedHandler, this));
client->OnError.connect(boost::bind(&JsonRpcEndpoint::ClientErrorHandler, this, _2));
client->OnVerifyCertificate.connect(boost::bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _2, _4));
}
bool JsonRpcEndpoint::IsLocal(void) const
@ -80,9 +80,8 @@ void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessag
m_Client->SendMessage(message);
}
void JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
void JsonRpcEndpoint::NewMessageHandler(const MessagePart& message)
{
const MessagePart& message = nmea.Message;
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
if (ResponseMessage::IsResponseMessage(message)) {
@ -108,7 +107,7 @@ void JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
GetEndpointManager()->SendMulticastMessage(sender, request);
}
void JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
void JsonRpcEndpoint::ClientClosedHandler(void)
{
Application::Log(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetIdentity());
@ -130,18 +129,18 @@ void JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
// TODO: persist events, etc., for now we just disable the endpoint
}
void JsonRpcEndpoint::ClientErrorHandler(const SocketErrorEventArgs& ea)
void JsonRpcEndpoint::ClientErrorHandler(const std::exception& ex)
{
stringstream message;
message << "Error occured for JSON-RPC socket: Message=" << ea.Exception.what();
message << "Error occured for JSON-RPC socket: Message=" << ex.what();
Application::Log(LogWarning, "jsonrpc", message.str());
}
void JsonRpcEndpoint::VerifyCertificateHandler(const VerifyCertificateEventArgs& ea)
void JsonRpcEndpoint::VerifyCertificateHandler(bool& valid, const shared_ptr<X509>& certificate)
{
if (ea.Certificate && ea.ValidCertificate) {
string identity = Utility::GetCertificateCN(ea.Certificate);
if (certificate && valid) {
string identity = Utility::GetCertificateCN(certificate);
if (GetIdentity().empty() && !identity.empty())
SetIdentity(identity);

View File

@ -58,10 +58,10 @@ private:
JsonRpcClient::Ptr m_Client;
map<string, Endpoint::Ptr> m_PendingCalls;
void NewMessageHandler(const NewMessageEventArgs& nmea);
void ClientClosedHandler(const EventArgs& ea);
void ClientErrorHandler(const SocketErrorEventArgs& ea);
void VerifyCertificateHandler(const VerifyCertificateEventArgs& ea);
void NewMessageHandler(const MessagePart& message);
void ClientClosedHandler(void);
void ClientErrorHandler(const std::exception& ex);
void VerifyCertificateHandler(bool& valid, const shared_ptr<X509>& certificate);
};
}

View File

@ -38,15 +38,15 @@ bool VirtualEndpoint::IsConnected(void) const
return true;
}
void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback)
void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
{
map<string, shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > >::iterator it;
map<string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
it = m_TopicHandlers.find(topic);
shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > sig;
shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > sig;
if (it == m_TopicHandlers.end()) {
sig = boost::make_shared<boost::signal<void (const NewRequestEventArgs&)> >();
sig = boost::make_shared<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> >();
m_TopicHandlers.insert(make_pair(topic, sig));
} else {
sig = it->second;
@ -57,7 +57,7 @@ void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const Ne
RegisterSubscription(topic);
}
void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback)
void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
{
// TODO: implement
//m_TopicHandlers[method] -= callback;
@ -72,17 +72,13 @@ void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage&
if (!request.GetMethod(&method))
return;
map<string, shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > >::iterator it;
map<string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
it = m_TopicHandlers.find(method);
if (it == m_TopicHandlers.end())
return;
NewRequestEventArgs nrea;
nrea.Source = shared_from_this();
nrea.Sender = sender;
nrea.Request = request;
(*it->second)(nrea);
(*it->second)(shared_from_this(), sender, request);
}
void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)

View File

@ -23,17 +23,6 @@
namespace icinga
{
/**
* Event arguments for the "new request" event.
*
* @ingroup icinga
*/
struct I2_ICINGA_API NewRequestEventArgs : public EventArgs
{
Endpoint::Ptr Sender;
RequestMessage Request;
};
/**
* A local endpoint.
*
@ -45,8 +34,8 @@ public:
typedef shared_ptr<VirtualEndpoint> Ptr;
typedef weak_ptr<VirtualEndpoint> WeakPtr;
void RegisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback);
void UnregisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback);
void RegisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback);
void UnregisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback);
virtual string GetAddress(void) const;
@ -59,7 +48,7 @@ public:
virtual void Stop(void);
private:
map< string, shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > > m_TopicHandlers;
map< string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > > m_TopicHandlers;
};
}

View File

@ -28,13 +28,9 @@ using namespace icinga;
* @param sslContext SSL context for the TLS connection.
*/
JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
: TlsClient(role, sslContext) { }
void JsonRpcClient::Start(void)
: TlsClient(role, sslContext)
{
TlsClient::Start();
OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this, _1));
OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this));
}
/**
@ -49,11 +45,8 @@ void JsonRpcClient::SendMessage(const MessagePart& message)
/**
* Processes inbound data.
*
* @param - Event arguments for the event.
* @returns 0
*/
void JsonRpcClient::DataAvailableHandler(const EventArgs&)
void JsonRpcClient::DataAvailableHandler(void)
{
for (;;) {
try {
@ -64,11 +57,7 @@ void JsonRpcClient::DataAvailableHandler(const EventArgs&)
return;
message = MessagePart(jsonString);
NewMessageEventArgs nea;
nea.Source = shared_from_this();
nea.Message = message;
OnNewMessage(nea);
OnNewMessage(shared_from_this(), message);
} catch (const Exception& ex) {
Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
Close();

View File

@ -23,16 +23,6 @@
namespace icinga
{
/**
* Event arguments for the "new message" event.
*
* @ingroup jsonrpc
*/
struct I2_JSONRPC_API NewMessageEventArgs : public EventArgs
{
icinga::MessagePart Message;
};
/**
* A JSON-RPC client.
*
@ -48,12 +38,10 @@ public:
void SendMessage(const MessagePart& message);
virtual void Start(void);
boost::signal<void (const NewMessageEventArgs&)> OnNewMessage;
boost::signal<void (const Object::Ptr&, const MessagePart&)> OnNewMessage;
private:
void DataAvailableHandler(const EventArgs&);
void DataAvailableHandler(void);
};
JsonRpcClient::Ptr JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);

View File

@ -82,12 +82,12 @@ bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str)
*/
void Netstring::WriteStringToFIFO(FIFO::Ptr fifo, const string& str)
{
unsigned long len = str.size();
char strLength[50];
sprintf(strLength, "%lu:", (unsigned long)len);
stringstream prefixbuf;
prefixbuf << str.size() << ":";
fifo->Write(strLength, strlen(strLength));
fifo->Write(str.c_str(), len);
string prefix = prefixbuf.str();
fifo->Write(prefix.c_str(), prefix.size());
fifo->Write(str.c_str(), str.size());
fifo->Write(",", 1);
}