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();
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);
}
}
}
<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" />
+++ /dev/null
-/******************************************************************************
- * 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 */
#include "exception.h"
#include "memory.h"
#include "variant.h"
-#include "eventargs.h"
#include "dictionary.h"
#include "timer.h"
#include "fifo.h"
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);
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);
}
}
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);
}
};
namespace icinga
{
-template<typename TValue>
-struct ObjectSetEventArgs : public EventArgs
-{
- TValue Target;
-};
-
template<typename TValue>
class ObjectSet : public Object
{
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)
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);
}
}
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)
{
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);
}
}
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);
}
};
{
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()));
}
if (!from_dtor) {
Stop();
- EventArgs ea;
- ea.Source = shared_from_this();
- OnClosed(ea);
+ OnClosed(shared_from_this());
}
}
void Socket::HandleSocketError(const std::exception& ex)
{
if (!OnError.empty()) {
- SocketErrorEventArgs sea(ex);
- OnError(sea);
+ OnError(shared_from_this(), ex);
Close();
} else {
*
* @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()));
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.
*
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;
private:
SOCKET m_FD; /**< The socket descriptor. */
- void ExceptionEventHandler(const EventArgs& ea);
+ void ExceptionEventHandler(void);
static string GetAddressFromSockaddr(sockaddr *address, socklen_t len);
};
{
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));
}
/**
/**
* Processes data that is available for this socket.
- *
- * @param - Event arguments.
*/
-void TcpClient::ReadableEventHandler(const EventArgs&)
+void TcpClient::ReadableEventHandler(void)
{
int rc;
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;
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;
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);
};
/**
{
TcpSocket::Start();
- OnReadable.connect(boost::bind(&TcpServer::ReadableEventHandler, this, _1));
+ OnReadable.connect(boost::bind(&TcpServer::ReadableEventHandler, this));
}
/**
*/
void TcpServer::Listen(void)
{
- int rc = listen(GetFD(), SOMAXCONN);
-
- if (rc < 0) {
+ if (listen(GetFD(), SOMAXCONN) < 0) {
HandleSocketError(SocketException(
"listen() failed", GetError()));
return;
/**
* 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;
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);
}
/**
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.
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;
};
*/
void Timer::Call(void)
{
- EventArgs tea;
- tea.Source = shared_from_this();
- OnTimerExpired(tea);
+ OnTimerExpired(shared_from_this());
}
/**
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. */
/**
* Processes data that is available for this socket.
- *
- * @param - Event arguments.
*/
-void TlsClient::ReadableEventHandler(const EventArgs&)
+void TlsClient::ReadableEventHandler(void)
{
int rc;
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;
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;
}
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.
*
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);
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);
--- /dev/null
+<?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>
\ No newline at end of file
{
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);
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(¶ms))
+ if (!request.GetParams(¶ms))
return;
MessagePart serviceMsg;
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(¶ms))
+ if (!request.GetParams(¶ms))
return;
string name;
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);
}
}
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);
};
}
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);
}
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);
}
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++) {
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;
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;
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(¶ms))
+ if (!request.GetParams(¶ms))
return;
string name;
object->Commit();
}
-void ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
+void ConfigRpcComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
{
- RequestMessage message = ea.Request;
-
MessagePart params;
- if (!message.GetParams(¶ms))
+ if (!request.GetParams(¶ms))
return;
string name;
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);
--- /dev/null
+<?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>
\ No newline at end of file
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>();
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)
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.");
}
}
}
-void DelegationComponent::RevokeServiceResponseHandler(const NewResponseEventArgs& nrea)
+void DelegationComponent::RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut)
{
}
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);
{
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);
/**
* 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);
VirtualEndpoint::Ptr m_DemoEndpoint;
void DemoTimerHandler(void);
- void HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
+ void HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
};
}
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);
* 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");
}
/**
* @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);
- }
}
/**
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();
* @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()) {
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
* @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);
}
/**
*
* @param endpoint The endpoint to set up.
*/
-void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
+void DiscoveryComponent::FinishDiscoverySetup(const Endpoint::Ptr& endpoint)
{
if (endpoint->HasSentWelcome())
return;
endpoint->SetSentWelcome(true);
- if (endpoint->HasReceivedWelcome()) {
- EventArgs ea;
- ea.Source = endpoint;
- endpoint->OnSessionEstablished(ea);
- }
+ if (endpoint->HasReceivedWelcome())
+ endpoint->OnSessionEstablished(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);
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;
* @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())
*
* @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))
*
* @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);
}
/**
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;
};
--- /dev/null
+<?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>
\ No newline at end of file
void Endpoint::SetIdentity(string identity)
{
m_Identity = identity;
-
- EventArgs ea;
- ea.Source = shared_from_this();
- OnIdentityChanged(ea);
+ OnIdentityChanged(shared_from_this());
}
/**
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. */
{
m_Servers.push_back(server);
server->OnNewClient.connect(boost::bind(&EndpointManager::NewClientHandler,
- this, _1));
+ this, _2));
}
/**
*
* @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);
}
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);
}
/**
*
* @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);
}
}
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++;
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);
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();
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.
*
{
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
{
}
};
-/**
- * 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.
*
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;
void RescheduleRequestTimer(void);
void RequestTimerHandler(void);
- void NewClientHandler(const NewClientEventArgs& ncea);
+ void NewClientHandler(const TcpClient::Ptr& client);
};
}
/* 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 */
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'");
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);
}
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);
};
}
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
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)) {
GetEndpointManager()->SendMulticastMessage(sender, request);
}
-void JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
+void JsonRpcEndpoint::ClientClosedHandler(void)
{
Application::Log(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetIdentity());
// 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);
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);
};
}
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;
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;
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)
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.
*
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;
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;
};
}
* @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));
}
/**
/**
* Processes inbound data.
- *
- * @param - Event arguments for the event.
- * @returns 0
*/
-void JsonRpcClient::DataAvailableHandler(const EventArgs&)
+void JsonRpcClient::DataAvailableHandler(void)
{
for (;;) {
try {
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();
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.
*
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);
*/
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);
}