mirror of https://github.com/Icinga/icinga2.git
Remove EventArgs struct.
This commit is contained in:
parent
10138c7ff8
commit
7753e229cc
|
@ -159,9 +159,6 @@ void Application::RunEventLoop(void)
|
||||||
else if (ready == 0)
|
else if (ready == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
EventArgs ea;
|
|
||||||
ea.Source = shared_from_this();
|
|
||||||
|
|
||||||
for (i = Socket::Sockets.begin();
|
for (i = Socket::Sockets.begin();
|
||||||
i != Socket::Sockets.end(); ) {
|
i != Socket::Sockets.end(); ) {
|
||||||
Socket::Ptr socket = i->lock();
|
Socket::Ptr socket = i->lock();
|
||||||
|
@ -178,15 +175,15 @@ void Application::RunEventLoop(void)
|
||||||
|
|
||||||
fd = socket->GetFD();
|
fd = socket->GetFD();
|
||||||
if (fd != INVALID_SOCKET && FD_ISSET(fd, &writefds))
|
if (fd != INVALID_SOCKET && FD_ISSET(fd, &writefds))
|
||||||
socket->OnWritable(ea);
|
socket->OnWritable(socket);
|
||||||
|
|
||||||
fd = socket->GetFD();
|
fd = socket->GetFD();
|
||||||
if (fd != INVALID_SOCKET && FD_ISSET(fd, &readfds))
|
if (fd != INVALID_SOCKET && FD_ISSET(fd, &readfds))
|
||||||
socket->OnReadable(ea);
|
socket->OnReadable(socket);
|
||||||
|
|
||||||
fd = socket->GetFD();
|
fd = socket->GetFD();
|
||||||
if (fd != INVALID_SOCKET && FD_ISSET(fd, &exceptfds))
|
if (fd != INVALID_SOCKET && FD_ISSET(fd, &exceptfds))
|
||||||
socket->OnException(ea);
|
socket->OnException(socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
<ClInclude Include="component.h" />
|
<ClInclude Include="component.h" />
|
||||||
<ClInclude Include="configobject.h" />
|
<ClInclude Include="configobject.h" />
|
||||||
<ClInclude Include="dictionary.h" />
|
<ClInclude Include="dictionary.h" />
|
||||||
<ClInclude Include="eventargs.h" />
|
|
||||||
<ClInclude Include="objectmap.h" />
|
<ClInclude Include="objectmap.h" />
|
||||||
<ClInclude Include="objectset.h" />
|
<ClInclude Include="objectset.h" />
|
||||||
<ClInclude Include="exception.h" />
|
<ClInclude Include="exception.h" />
|
||||||
|
|
|
@ -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 */
|
|
|
@ -145,7 +145,6 @@ using boost::function;
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
#include "eventargs.h"
|
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "fifo.h"
|
#include "fifo.h"
|
||||||
|
|
|
@ -43,9 +43,9 @@ public:
|
||||||
|
|
||||||
void Start(void)
|
void Start(void)
|
||||||
{
|
{
|
||||||
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectMap::ObjectAddedHandler, this, _1));
|
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectMap::ObjectAddedHandler, this, _2));
|
||||||
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _1));
|
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _2));
|
||||||
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _1));
|
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _2));
|
||||||
|
|
||||||
for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
||||||
AddObject(*it);
|
AddObject(*it);
|
||||||
|
@ -56,16 +56,12 @@ public:
|
||||||
return m_Objects.equal_range(key);
|
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);
|
Range range = GetRange(key);
|
||||||
|
|
||||||
for (Iterator it = range.first; it != range.second; it++) {
|
for (Iterator it = range.first; it != range.second; it++) {
|
||||||
ea.Target(*it);
|
callback(shared_from_this(), *it);
|
||||||
callback(ea);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,19 +101,19 @@ private:
|
||||||
AddObject(object);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,6 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename TValue>
|
|
||||||
struct ObjectSetEventArgs : public EventArgs
|
|
||||||
{
|
|
||||||
TValue Target;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename TValue>
|
template<typename TValue>
|
||||||
class ObjectSet : public Object
|
class ObjectSet : public Object
|
||||||
{
|
{
|
||||||
|
@ -49,25 +43,19 @@ public:
|
||||||
void Start(void)
|
void Start(void)
|
||||||
{
|
{
|
||||||
if (m_Parent) {
|
if (m_Parent) {
|
||||||
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
|
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
|
||||||
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
|
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
|
||||||
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _1));
|
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _2));
|
||||||
|
|
||||||
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
||||||
CheckObject(*it);
|
CheckObject(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddObject(const TValue& object)
|
void AddObject(const TValue& object)
|
||||||
{
|
{
|
||||||
m_Objects.insert(object);
|
m_Objects.insert(object);
|
||||||
|
OnObjectAdded(shared_from_this(), object);
|
||||||
ObjectSetEventArgs<TValue> ea;
|
|
||||||
ea.Source = shared_from_this();
|
|
||||||
ea.Target = object;
|
|
||||||
OnObjectAdded(ea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveObject(const TValue& object)
|
void RemoveObject(const TValue& object)
|
||||||
|
@ -76,11 +64,7 @@ public:
|
||||||
|
|
||||||
if (it != m_Objects.end()) {
|
if (it != m_Objects.end()) {
|
||||||
m_Objects.erase(it);
|
m_Objects.erase(it);
|
||||||
|
OnObjectRemoved(shared_from_this(), object);
|
||||||
ObjectSetEventArgs<TValue> ea;
|
|
||||||
ea.Source = shared_from_this();
|
|
||||||
ea.Target = object;
|
|
||||||
OnObjectRemoved(ea);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,17 +81,14 @@ public:
|
||||||
if (!Contains(object)) {
|
if (!Contains(object)) {
|
||||||
AddObject(object);
|
AddObject(object);
|
||||||
} else {
|
} else {
|
||||||
ObjectSetEventArgs<TValue> ea;
|
OnObjectCommitted(shared_from_this(), object);
|
||||||
ea.Source = shared_from_this();
|
|
||||||
ea.Target = object;
|
|
||||||
OnObjectCommitted(ea);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::signal<void (const ObjectSetEventArgs<TValue>&)> OnObjectAdded;
|
boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectAdded;
|
||||||
boost::signal<void (const ObjectSetEventArgs<TValue>&)> OnObjectCommitted;
|
boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectCommitted;
|
||||||
boost::signal<void (const ObjectSetEventArgs<TValue>&)> OnObjectRemoved;
|
boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectRemoved;
|
||||||
|
|
||||||
Iterator Begin(void)
|
Iterator Begin(void)
|
||||||
{
|
{
|
||||||
|
@ -119,14 +100,10 @@ public:
|
||||||
return m_Objects.end();
|
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++) {
|
for (Iterator it = Begin(); it != End(); it++) {
|
||||||
ea.Target(*it);
|
callback(shared_from_this(), *it);
|
||||||
callback(ea);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,14 +113,14 @@ private:
|
||||||
typename ObjectSet<TValue>::Ptr m_Parent;
|
typename ObjectSet<TValue>::Ptr m_Parent;
|
||||||
function<bool (const TValue&)> m_Predicate;
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ void Socket::Start(void)
|
||||||
{
|
{
|
||||||
assert(m_FD != INVALID_SOCKET);
|
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()));
|
Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
|
||||||
}
|
}
|
||||||
|
@ -125,9 +125,7 @@ void Socket::CloseInternal(bool from_dtor)
|
||||||
if (!from_dtor) {
|
if (!from_dtor) {
|
||||||
Stop();
|
Stop();
|
||||||
|
|
||||||
EventArgs ea;
|
OnClosed(shared_from_this());
|
||||||
ea.Source = shared_from_this();
|
|
||||||
OnClosed(ea);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +170,7 @@ int Socket::GetLastSocketError(void)
|
||||||
void Socket::HandleSocketError(const std::exception& ex)
|
void Socket::HandleSocketError(const std::exception& ex)
|
||||||
{
|
{
|
||||||
if (!OnError.empty()) {
|
if (!OnError.empty()) {
|
||||||
SocketErrorEventArgs sea(ex);
|
OnError(shared_from_this(), ex);
|
||||||
OnError(sea);
|
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,7 +183,7 @@ void Socket::HandleSocketError(const std::exception& ex)
|
||||||
*
|
*
|
||||||
* @param - Event arguments for the socket error.
|
* @param - Event arguments for the socket error.
|
||||||
*/
|
*/
|
||||||
void Socket::ExceptionEventHandler(const EventArgs&)
|
void Socket::ExceptionEventHandler(void)
|
||||||
{
|
{
|
||||||
HandleSocketError(SocketException(
|
HandleSocketError(SocketException(
|
||||||
"select() returned fd in except fdset", GetError()));
|
"select() returned fd in except fdset", GetError()));
|
||||||
|
|
|
@ -22,19 +22,6 @@
|
||||||
|
|
||||||
namespace icinga {
|
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.
|
* Base class for sockets.
|
||||||
*
|
*
|
||||||
|
@ -55,12 +42,12 @@ public:
|
||||||
void SetFD(SOCKET fd);
|
void SetFD(SOCKET fd);
|
||||||
SOCKET GetFD(void) const;
|
SOCKET GetFD(void) const;
|
||||||
|
|
||||||
boost::signal<void (const EventArgs&)> OnReadable;
|
boost::signal<void (const Object::Ptr&)> OnReadable;
|
||||||
boost::signal<void (const EventArgs&)> OnWritable;
|
boost::signal<void (const Object::Ptr&)> OnWritable;
|
||||||
boost::signal<void (const EventArgs&)> OnException;
|
boost::signal<void (const Object::Ptr&)> OnException;
|
||||||
|
|
||||||
boost::signal<void (const SocketErrorEventArgs&)> OnError;
|
boost::signal<void (const Object::Ptr&, const std::exception&)> OnError;
|
||||||
boost::signal<void (const EventArgs&)> OnClosed;
|
boost::signal<void (const Object::Ptr&)> OnClosed;
|
||||||
|
|
||||||
virtual bool WantsToRead(void) const;
|
virtual bool WantsToRead(void) const;
|
||||||
virtual bool WantsToWrite(void) const;
|
virtual bool WantsToWrite(void) const;
|
||||||
|
@ -85,7 +72,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
SOCKET m_FD; /**< The socket descriptor. */
|
SOCKET m_FD; /**< The socket descriptor. */
|
||||||
|
|
||||||
void ExceptionEventHandler(const EventArgs& ea);
|
void ExceptionEventHandler(void);
|
||||||
|
|
||||||
static string GetAddressFromSockaddr(sockaddr *address, socklen_t len);
|
static string GetAddressFromSockaddr(sockaddr *address, socklen_t len);
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,8 +51,8 @@ void TcpClient::Start(void)
|
||||||
{
|
{
|
||||||
TcpSocket::Start();
|
TcpSocket::Start();
|
||||||
|
|
||||||
OnReadable.connect(boost::bind(&TcpClient::ReadableEventHandler, this, _1));
|
OnReadable.connect(boost::bind(&TcpClient::ReadableEventHandler, this));
|
||||||
OnWritable.connect(boost::bind(&TcpClient::WritableEventHandler, this, _1));
|
OnWritable.connect(boost::bind(&TcpClient::WritableEventHandler, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,10 +136,8 @@ FIFO::Ptr TcpClient::GetRecvQueue(void)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes data that is available for this socket.
|
* Processes data that is available for this socket.
|
||||||
*
|
|
||||||
* @param - Event arguments.
|
|
||||||
*/
|
*/
|
||||||
void TcpClient::ReadableEventHandler(const EventArgs&)
|
void TcpClient::ReadableEventHandler(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -161,17 +159,13 @@ void TcpClient::ReadableEventHandler(const EventArgs&)
|
||||||
|
|
||||||
m_RecvQueue->Write(NULL, rc);
|
m_RecvQueue->Write(NULL, rc);
|
||||||
|
|
||||||
EventArgs dea;
|
OnDataAvailable(shared_from_this());
|
||||||
dea.Source = shared_from_this();
|
|
||||||
OnDataAvailable(dea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes data that can be written for this socket.
|
* Processes data that can be written for this socket.
|
||||||
*
|
|
||||||
* @param - Event arguments.
|
|
||||||
*/
|
*/
|
||||||
void TcpClient::WritableEventHandler(const EventArgs&)
|
void TcpClient::WritableEventHandler(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
virtual bool WantsToRead(void) const;
|
virtual bool WantsToRead(void) const;
|
||||||
virtual bool WantsToWrite(void) const;
|
virtual bool WantsToWrite(void) const;
|
||||||
|
|
||||||
boost::signal<void (const EventArgs&)> OnDataAvailable;
|
boost::signal<void (const Object::Ptr&)> OnDataAvailable;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TcpClientRole m_Role;
|
TcpClientRole m_Role;
|
||||||
|
@ -69,8 +69,8 @@ private:
|
||||||
FIFO::Ptr m_SendQueue;
|
FIFO::Ptr m_SendQueue;
|
||||||
FIFO::Ptr m_RecvQueue;
|
FIFO::Ptr m_RecvQueue;
|
||||||
|
|
||||||
virtual void ReadableEventHandler(const EventArgs& ea);
|
virtual void ReadableEventHandler(void);
|
||||||
virtual void WritableEventHandler(const EventArgs& ea);
|
virtual void WritableEventHandler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,7 +56,7 @@ void TcpServer::Start(void)
|
||||||
{
|
{
|
||||||
TcpSocket::Start();
|
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)
|
void TcpServer::Listen(void)
|
||||||
{
|
{
|
||||||
int rc = listen(GetFD(), SOMAXCONN);
|
if (listen(GetFD(), SOMAXCONN) < 0) {
|
||||||
|
|
||||||
if (rc < 0) {
|
|
||||||
HandleSocketError(SocketException(
|
HandleSocketError(SocketException(
|
||||||
"listen() failed", GetError()));
|
"listen() failed", GetError()));
|
||||||
return;
|
return;
|
||||||
|
@ -76,11 +74,8 @@ void TcpServer::Listen(void)
|
||||||
/**
|
/**
|
||||||
* Accepts a new client and creates a new client object for it
|
* Accepts a new client and creates a new client object for it
|
||||||
* using the client factory function.
|
* using the client factory function.
|
||||||
*
|
|
||||||
* @param - Event arguments.
|
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int TcpServer::ReadableEventHandler(const EventArgs&)
|
void TcpServer::ReadableEventHandler(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
sockaddr_storage addr;
|
sockaddr_storage addr;
|
||||||
|
@ -91,17 +86,14 @@ int TcpServer::ReadableEventHandler(const EventArgs&)
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
HandleSocketError(SocketException(
|
HandleSocketError(SocketException(
|
||||||
"accept() failed", GetError()));
|
"accept() failed", GetError()));
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewClientEventArgs nea;
|
TcpClient::Ptr client = m_ClientFactory();
|
||||||
nea.Source = shared_from_this();
|
client->SetFD(fd);
|
||||||
nea.Client = static_pointer_cast<TcpSocket>(m_ClientFactory());
|
client->Start();
|
||||||
nea.Client->SetFD(fd);
|
|
||||||
nea.Client->Start();
|
|
||||||
OnNewClient(nea);
|
|
||||||
|
|
||||||
return 0;
|
OnNewClient(shared_from_this(), client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,16 +23,6 @@
|
||||||
namespace icinga
|
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
|
* A TCP server that listens on a TCP port and accepts incoming
|
||||||
* client connections.
|
* client connections.
|
||||||
|
@ -54,12 +44,12 @@ public:
|
||||||
|
|
||||||
void Listen(void);
|
void Listen(void);
|
||||||
|
|
||||||
boost::signal<void (const NewClientEventArgs&)> OnNewClient;
|
boost::signal<void (const Object::Ptr&, const TcpClient::Ptr&)> OnNewClient;
|
||||||
|
|
||||||
virtual bool WantsToRead(void) const;
|
virtual bool WantsToRead(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int ReadableEventHandler(const EventArgs& ea);
|
void ReadableEventHandler(void);
|
||||||
|
|
||||||
function<TcpClient::Ptr()> m_ClientFactory;
|
function<TcpClient::Ptr()> m_ClientFactory;
|
||||||
};
|
};
|
||||||
|
|
|
@ -100,9 +100,7 @@ void Timer::CallExpiredTimers(void)
|
||||||
*/
|
*/
|
||||||
void Timer::Call(void)
|
void Timer::Call(void)
|
||||||
{
|
{
|
||||||
EventArgs tea;
|
OnTimerExpired(shared_from_this());
|
||||||
tea.Source = shared_from_this();
|
|
||||||
OnTimerExpired(tea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
|
|
||||||
void Reschedule(time_t next);
|
void Reschedule(time_t next);
|
||||||
|
|
||||||
boost::signal<void(const EventArgs&)> OnTimerExpired;
|
boost::signal<void(const Object::Ptr&)> OnTimerExpired;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
time_t m_Interval; /**< The interval of the timer. */
|
time_t m_Interval; /**< The interval of the timer. */
|
||||||
|
|
|
@ -105,10 +105,8 @@ void TlsClient::Start(void)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes data that is available for this socket.
|
* Processes data that is available for this socket.
|
||||||
*
|
|
||||||
* @param - Event arguments.
|
|
||||||
*/
|
*/
|
||||||
void TlsClient::ReadableEventHandler(const EventArgs&)
|
void TlsClient::ReadableEventHandler(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -138,17 +136,13 @@ void TlsClient::ReadableEventHandler(const EventArgs&)
|
||||||
|
|
||||||
GetRecvQueue()->Write(NULL, rc);
|
GetRecvQueue()->Write(NULL, rc);
|
||||||
|
|
||||||
EventArgs dea;
|
OnDataAvailable(shared_from_this());
|
||||||
dea.Source = shared_from_this();
|
|
||||||
OnDataAvailable(dea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes data that can be written for this socket.
|
* Processes data that can be written for this socket.
|
||||||
*
|
|
||||||
* @param - Event arguments.
|
|
||||||
*/
|
*/
|
||||||
void TlsClient::WritableEventHandler(const EventArgs&)
|
void TlsClient::WritableEventHandler(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -248,12 +242,9 @@ int TlsClient::SSLVerifyCertificate(int ok, X509_STORE_CTX *x509Context)
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
VerifyCertificateEventArgs vcea;
|
bool valid = false;
|
||||||
vcea.Source = client->shared_from_this();
|
shared_ptr<X509> x509Certificate = shared_ptr<X509>(x509Context->cert, &TlsClient::NullCertificateDeleter);
|
||||||
vcea.ValidCertificate = (ok != 0);
|
client->OnVerifyCertificate(client->shared_from_this(), valid, x509Context, x509Certificate);
|
||||||
vcea.Context = x509Context;
|
|
||||||
vcea.Certificate = shared_ptr<X509>(x509Context->cert, &TlsClient::NullCertificateDeleter);
|
|
||||||
client->OnVerifyCertificate(vcea);
|
|
||||||
|
|
||||||
return (int)vcea.ValidCertificate;
|
return valid ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,20 +23,6 @@
|
||||||
namespace icinga
|
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.
|
* A TLS client connection.
|
||||||
*
|
*
|
||||||
|
@ -55,7 +41,7 @@ public:
|
||||||
virtual bool WantsToRead(void) const;
|
virtual bool WantsToRead(void) const;
|
||||||
virtual bool WantsToWrite(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:
|
protected:
|
||||||
void HandleSSLError(void);
|
void HandleSSLError(void);
|
||||||
|
@ -70,8 +56,8 @@ private:
|
||||||
static int m_SSLIndex;
|
static int m_SSLIndex;
|
||||||
static bool m_SSLIndexInitialized;
|
static bool m_SSLIndexInitialized;
|
||||||
|
|
||||||
virtual void ReadableEventHandler(const EventArgs& ea);
|
virtual void ReadableEventHandler(void);
|
||||||
virtual void WritableEventHandler(const EventArgs& ea);
|
virtual void WritableEventHandler(void);
|
||||||
|
|
||||||
virtual void CloseInternal(bool from_dtor);
|
virtual void CloseInternal(bool from_dtor);
|
||||||
|
|
||||||
|
|
|
@ -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>
|
|
@ -30,11 +30,11 @@ void CheckerComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_CheckerEndpoint = boost::make_shared<VirtualEndpoint>();
|
m_CheckerEndpoint = boost::make_shared<VirtualEndpoint>();
|
||||||
m_CheckerEndpoint->RegisterTopicHandler("checker::AssignService",
|
m_CheckerEndpoint->RegisterTopicHandler("checker::AssignService",
|
||||||
boost::bind(&CheckerComponent::AssignServiceRequestHandler, this, _1));
|
boost::bind(&CheckerComponent::AssignServiceRequestHandler, this, _2, _3));
|
||||||
m_CheckerEndpoint->RegisterTopicHandler("checker::RevokeService",
|
m_CheckerEndpoint->RegisterTopicHandler("checker::RevokeService",
|
||||||
boost::bind(&CheckerComponent::RevokeServiceRequestHandler, this, _1));
|
boost::bind(&CheckerComponent::RevokeServiceRequestHandler, this, _2, _3));
|
||||||
m_CheckerEndpoint->RegisterTopicHandler("checker::ClearServices",
|
m_CheckerEndpoint->RegisterTopicHandler("checker::ClearServices",
|
||||||
boost::bind(&CheckerComponent::ClearServicesRequestHandler, this, _1));
|
boost::bind(&CheckerComponent::ClearServicesRequestHandler, this, _2, _3));
|
||||||
m_CheckerEndpoint->RegisterPublication("checker::CheckResult");
|
m_CheckerEndpoint->RegisterPublication("checker::CheckResult");
|
||||||
GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
|
GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
|
||||||
|
|
||||||
|
@ -90,10 +90,10 @@ void CheckerComponent::CheckTimerHandler(void)
|
||||||
m_CheckTimer->SetInterval(service.GetNextCheck() - now);
|
m_CheckTimer->SetInterval(service.GetNextCheck() - now);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nrea)
|
void CheckerComponent::AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
|
||||||
{
|
{
|
||||||
MessagePart params;
|
MessagePart params;
|
||||||
if (!nrea.Request.GetParams(¶ms))
|
if (!request.GetParams(¶ms))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MessagePart serviceMsg;
|
MessagePart serviceMsg;
|
||||||
|
@ -110,20 +110,20 @@ void CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nr
|
||||||
m_CheckTimer->Reschedule(0);
|
m_CheckTimer->Reschedule(0);
|
||||||
|
|
||||||
string id;
|
string id;
|
||||||
if (nrea.Request.GetID(&id)) {
|
if (request.GetID(&id)) {
|
||||||
ResponseMessage rm;
|
ResponseMessage rm;
|
||||||
rm.SetID(id);
|
rm.SetID(id);
|
||||||
|
|
||||||
MessagePart result;
|
MessagePart result;
|
||||||
rm.SetResult(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;
|
MessagePart params;
|
||||||
if (!nrea.Request.GetParams(¶ms))
|
if (!request.GetParams(¶ms))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
@ -148,29 +148,29 @@ void CheckerComponent::RevokeServiceRequestHandler(const NewRequestEventArgs& nr
|
||||||
Application::Log(LogInformation, "checker", "Revoked delegation for service '" + name + "'");
|
Application::Log(LogInformation, "checker", "Revoked delegation for service '" + name + "'");
|
||||||
|
|
||||||
string id;
|
string id;
|
||||||
if (nrea.Request.GetID(&id)) {
|
if (request.GetID(&id)) {
|
||||||
ResponseMessage rm;
|
ResponseMessage rm;
|
||||||
rm.SetID(id);
|
rm.SetID(id);
|
||||||
|
|
||||||
MessagePart result;
|
MessagePart result;
|
||||||
rm.SetResult(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.");
|
Application::Log(LogInformation, "checker", "Clearing service delegations.");
|
||||||
m_Services = ServiceQueue();
|
m_Services = ServiceQueue();
|
||||||
|
|
||||||
string id;
|
string id;
|
||||||
if (nrea.Request.GetID(&id)) {
|
if (request.GetID(&id)) {
|
||||||
ResponseMessage rm;
|
ResponseMessage rm;
|
||||||
rm.SetID(id);
|
rm.SetID(id);
|
||||||
|
|
||||||
MessagePart result;
|
MessagePart result;
|
||||||
rm.SetResult(result);
|
rm.SetResult(result);
|
||||||
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
|
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, sender, rm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,9 @@ private:
|
||||||
|
|
||||||
void CheckTimerHandler(void);
|
void CheckTimerHandler(void);
|
||||||
|
|
||||||
void AssignServiceRequestHandler(const NewRequestEventArgs& nrea);
|
void AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
void RevokeServiceRequestHandler(const NewRequestEventArgs& nrea);
|
void RevokeServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
void ClearServicesRequestHandler(const NewRequestEventArgs& nrea);
|
void ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,23 +35,23 @@ void ConfigRpcComponent::Start(void)
|
||||||
long configSource;
|
long configSource;
|
||||||
if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
|
if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
|
||||||
m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
|
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()->OnObjectAdded.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _2));
|
||||||
ConfigObject::GetAllObjects()->OnObjectCommitted.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
|
ConfigObject::GetAllObjects()->OnObjectCommitted.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _2));
|
||||||
ConfigObject::GetAllObjects()->OnObjectRemoved.connect(boost::bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _1));
|
ConfigObject::GetAllObjects()->OnObjectRemoved.connect(boost::bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _2));
|
||||||
|
|
||||||
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
|
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
|
||||||
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectRemoved");
|
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->RegisterPublication("config::FetchObjects");
|
||||||
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectCommitted",
|
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectCommitted",
|
||||||
boost::bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _1));
|
boost::bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _3));
|
||||||
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectRemoved",
|
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectRemoved",
|
||||||
boost::bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _1));
|
boost::bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _3));
|
||||||
|
|
||||||
endpointManager->RegisterEndpoint(m_ConfigRpcEndpoint);
|
endpointManager->RegisterEndpoint(m_ConfigRpcEndpoint);
|
||||||
}
|
}
|
||||||
|
@ -64,17 +64,17 @@ void ConfigRpcComponent::Stop(void)
|
||||||
mgr->UnregisterEndpoint(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;
|
RequestMessage request;
|
||||||
request.SetMethod("config::FetchObjects");
|
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);
|
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, endpoint, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +100,8 @@ bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
|
||||||
return (!object->IsLocal());
|
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();
|
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
|
||||||
|
|
||||||
for (ConfigObject::Set::Iterator ci = allObjects->Begin(); ci != allObjects->End(); ci++) {
|
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);
|
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))
|
if (!ShouldReplicateObject(object))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -128,10 +125,8 @@ void ConfigRpcComponent::LocalObjectCommittedHandler(const ObjectSetEventArgs<Co
|
||||||
MakeObjectMessage(object, "config::ObjectCreated", true));
|
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))
|
if (!ShouldReplicateObject(object))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -139,12 +134,10 @@ void ConfigRpcComponent::LocalObjectRemovedHandler(const ObjectSetEventArgs<Conf
|
||||||
MakeObjectMessage(object, "config::ObjectRemoved", false));
|
MakeObjectMessage(object, "config::ObjectRemoved", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
|
void ConfigRpcComponent::RemoteObjectCommittedHandler(const RequestMessage& request)
|
||||||
{
|
{
|
||||||
RequestMessage message = ea.Request;
|
|
||||||
|
|
||||||
MessagePart params;
|
MessagePart params;
|
||||||
if (!message.GetParams(¶ms))
|
if (!request.GetParams(¶ms))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
@ -169,12 +162,10 @@ void ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs&
|
||||||
object->Commit();
|
object->Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
|
void ConfigRpcComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
|
||||||
{
|
{
|
||||||
RequestMessage message = ea.Request;
|
|
||||||
|
|
||||||
MessagePart params;
|
MessagePart params;
|
||||||
if (!message.GetParams(¶ms))
|
if (!request.GetParams(¶ms))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
|
|
@ -36,15 +36,15 @@ public:
|
||||||
private:
|
private:
|
||||||
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
|
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
|
||||||
|
|
||||||
void NewEndpointHandler(const NewEndpointEventArgs& ea);
|
void NewEndpointHandler(const Endpoint::Ptr& endpoint);
|
||||||
void SessionEstablishedHandler(const EventArgs& ea);
|
void SessionEstablishedHandler(const Object::Ptr& source);
|
||||||
|
|
||||||
void LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void LocalObjectCommittedHandler(const ConfigObject::Ptr& object);
|
||||||
void LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void LocalObjectRemovedHandler(const ConfigObject::Ptr& object);
|
||||||
|
|
||||||
void FetchObjectsHandler(const NewRequestEventArgs& ea);
|
void FetchObjectsHandler(const Endpoint::Ptr& sender);
|
||||||
void RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
|
void RemoteObjectCommittedHandler(const RequestMessage& request);
|
||||||
void RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
|
void RemoteObjectRemovedHandler(const RequestMessage& request);
|
||||||
|
|
||||||
static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
|
static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
|
||||||
string method, bool includeProperties);
|
string method, bool includeProperties);
|
||||||
|
|
|
@ -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>
|
|
@ -29,9 +29,9 @@ string DelegationComponent::GetName(void) const
|
||||||
void DelegationComponent::Start(void)
|
void DelegationComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_AllServices = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
|
m_AllServices = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
|
||||||
m_AllServices->OnObjectAdded.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
|
m_AllServices->OnObjectAdded.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _2));
|
||||||
m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
|
m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _2));
|
||||||
m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::RemovedServiceHandler, this, _1));
|
m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::RemovedServiceHandler, this, _2));
|
||||||
m_AllServices->Start();
|
m_AllServices->Start();
|
||||||
|
|
||||||
m_DelegationTimer = boost::make_shared<Timer>();
|
m_DelegationTimer = boost::make_shared<Timer>();
|
||||||
|
@ -53,14 +53,14 @@ void DelegationComponent::Stop(void)
|
||||||
mgr->UnregisterEndpoint(m_DelegationEndpoint);
|
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)
|
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() + "'");
|
Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service->GetName() + "'");
|
||||||
|
|
||||||
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
|
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.");
|
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' timed out.");
|
||||||
} else {
|
} else {
|
||||||
service->SetTag("checker", nrea.Sender->GetIdentity());
|
service->SetTag("checker", sender->GetIdentity());
|
||||||
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' was successful.");
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,11 @@ private:
|
||||||
ConfigObject::Set::Ptr m_AllServices;
|
ConfigObject::Set::Ptr m_AllServices;
|
||||||
Timer::Ptr m_DelegationTimer;
|
Timer::Ptr m_DelegationTimer;
|
||||||
|
|
||||||
void NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void NewServiceHandler(const ConfigObject::Ptr& object);
|
||||||
void RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void RemovedServiceHandler(const ConfigObject::Ptr& object);
|
||||||
|
|
||||||
void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
|
void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
|
||||||
void RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
|
void RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
|
||||||
|
|
||||||
void DelegationTimerHandler(void);
|
void DelegationTimerHandler(void);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void DemoComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_DemoEndpoint = boost::make_shared<VirtualEndpoint>();
|
m_DemoEndpoint = boost::make_shared<VirtualEndpoint>();
|
||||||
m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
|
m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
|
||||||
boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _1));
|
boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2, _3));
|
||||||
m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
|
m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
|
||||||
GetEndpointManager()->RegisterEndpoint(m_DemoEndpoint);
|
GetEndpointManager()->RegisterEndpoint(m_DemoEndpoint);
|
||||||
|
|
||||||
|
@ -80,9 +80,9 @@ void DemoComponent::DemoTimerHandler(void)
|
||||||
/**
|
/**
|
||||||
* Processes demo::HelloWorld messages.
|
* 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);
|
EXPORT_COMPONENT(demo, DemoComponent);
|
||||||
|
|
|
@ -38,7 +38,7 @@ private:
|
||||||
VirtualEndpoint::Ptr m_DemoEndpoint;
|
VirtualEndpoint::Ptr m_DemoEndpoint;
|
||||||
|
|
||||||
void DemoTimerHandler(void);
|
void DemoTimerHandler(void);
|
||||||
void HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
|
void HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,17 +40,17 @@ void DiscoveryComponent::Start(void)
|
||||||
|
|
||||||
m_DiscoveryEndpoint->RegisterPublication("discovery::RegisterComponent");
|
m_DiscoveryEndpoint->RegisterPublication("discovery::RegisterComponent");
|
||||||
m_DiscoveryEndpoint->RegisterTopicHandler("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->RegisterPublication("discovery::NewComponent");
|
||||||
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::NewComponent",
|
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::NewComponent",
|
||||||
boost::bind(&DiscoveryComponent::NewComponentMessageHandler, this, _1));
|
boost::bind(&DiscoveryComponent::NewComponentMessageHandler, this, _3));
|
||||||
|
|
||||||
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::Welcome",
|
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()->ForEachEndpoint(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _2));
|
||||||
GetEndpointManager()->OnNewEndpoint.connect(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
|
GetEndpointManager()->OnNewEndpoint.connect(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _2));
|
||||||
|
|
||||||
GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
|
GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
|
||||||
|
|
||||||
|
@ -79,40 +79,39 @@ void DiscoveryComponent::Stop(void)
|
||||||
* Checks whether the specified endpoint is already connected
|
* Checks whether the specified endpoint is already connected
|
||||||
* and disconnects older endpoints.
|
* and disconnects older endpoints.
|
||||||
*
|
*
|
||||||
* @param endpoint The endpoint that is to be checked.
|
* @param self The endpoint that is to be checked.
|
||||||
* @param neea Event arguments for another endpoint.
|
* @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;
|
return;
|
||||||
|
|
||||||
if (!neea.Endpoint->IsConnected())
|
if (!other->IsConnected())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
|
if (self->GetIdentity() == other->GetIdentity()) {
|
||||||
Application::Log(LogWarning, "discovery", "Detected duplicate identity:" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
|
Application::Log(LogWarning, "discovery", "Detected duplicate identity:" + other->GetIdentity() + " - Disconnecting old endpoint.");
|
||||||
|
|
||||||
neea.Endpoint->Stop();
|
other->Stop();
|
||||||
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
|
GetEndpointManager()->UnregisterEndpoint(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers handlers for new endpoints.
|
* Registers handlers for new endpoints.
|
||||||
*
|
*
|
||||||
* @param neea Event arguments for the new endpoint.
|
* @param endpoint The endpoint.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
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 */
|
/* accept discovery::RegisterComponent messages from any endpoint */
|
||||||
neea.Endpoint->RegisterPublication("discovery::RegisterComponent");
|
endpoint->RegisterPublication("discovery::RegisterComponent");
|
||||||
|
|
||||||
/* accept discovery::Welcome messages from any endpoint */
|
/* 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.
|
* @param info Component information object.
|
||||||
* @return 0
|
* @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;
|
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);
|
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);
|
info->Publications.insert(*i);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +144,7 @@ bool DiscoveryComponent::GetComponentDiscoveryInfo(string component, ComponentDi
|
||||||
if (component == GetEndpointManager()->GetIdentity()) {
|
if (component == GetEndpointManager()->GetIdentity()) {
|
||||||
/* Build fake discovery info for ourselves */
|
/* Build fake discovery info for ourselves */
|
||||||
*info = boost::make_shared<ComponentDiscoveryInfo>();
|
*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)->LastSeen = 0;
|
||||||
(*info)->Node = GetIcingaApplication()->GetNode();
|
(*info)->Node = GetIcingaApplication()->GetNode();
|
||||||
|
@ -173,9 +170,9 @@ bool DiscoveryComponent::GetComponentDiscoveryInfo(string component, ComponentDi
|
||||||
* @param ea Event arguments for the component.
|
* @param ea Event arguments for the component.
|
||||||
* @returns 0
|
* @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();
|
string identity = endpoint->GetIdentity();
|
||||||
|
|
||||||
if (identity == GetEndpointManager()->GetIdentity()) {
|
if (identity == GetEndpointManager()->GetIdentity()) {
|
||||||
|
@ -187,7 +184,7 @@ void DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
|
||||||
return;
|
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
|
// we assume the other component _always_ wants
|
||||||
// discovery::RegisterComponent messages from us
|
// discovery::RegisterComponent messages from us
|
||||||
|
@ -241,20 +238,15 @@ void DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
|
||||||
* @param nrea Event arguments for the request.
|
* @param nrea Event arguments for the request.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
void DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
|
void DiscoveryComponent::WelcomeMessageHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
|
||||||
{
|
{
|
||||||
Endpoint::Ptr endpoint = nrea.Sender;
|
if (sender->HasReceivedWelcome())
|
||||||
|
|
||||||
if (endpoint->HasReceivedWelcome())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
endpoint->SetReceivedWelcome(true);
|
sender->SetReceivedWelcome(true);
|
||||||
|
|
||||||
if (endpoint->HasSentWelcome()) {
|
if (sender->HasSentWelcome())
|
||||||
EventArgs ea;
|
sender->OnSessionEstablished(sender);
|
||||||
ea.Source = endpoint;
|
|
||||||
endpoint->OnSessionEstablished(ea);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -264,7 +256,7 @@ void DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
|
||||||
*
|
*
|
||||||
* @param endpoint The endpoint to set up.
|
* @param endpoint The endpoint to set up.
|
||||||
*/
|
*/
|
||||||
void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
|
void DiscoveryComponent::FinishDiscoverySetup(const Endpoint::Ptr& endpoint)
|
||||||
{
|
{
|
||||||
if (endpoint->HasSentWelcome())
|
if (endpoint->HasSentWelcome())
|
||||||
return;
|
return;
|
||||||
|
@ -278,11 +270,8 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
|
||||||
|
|
||||||
endpoint->SetSentWelcome(true);
|
endpoint->SetSentWelcome(true);
|
||||||
|
|
||||||
if (endpoint->HasReceivedWelcome()) {
|
if (endpoint->HasReceivedWelcome())
|
||||||
EventArgs ea;
|
endpoint->OnSessionEstablished(endpoint);
|
||||||
ea.Source = endpoint;
|
|
||||||
endpoint->OnSessionEstablished(ea);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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 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.
|
* @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;
|
RequestMessage request;
|
||||||
request.SetMethod(method);
|
request.SetMethod(method);
|
||||||
|
@ -332,7 +321,7 @@ void DiscoveryComponent::SendDiscoveryMessage(string method, string identity, En
|
||||||
GetEndpointManager()->SendMulticastMessage(m_DiscoveryEndpoint, request);
|
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)
|
if (!roles)
|
||||||
return false;
|
return false;
|
||||||
|
@ -367,7 +356,7 @@ bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string mess
|
||||||
* @param message The discovery message.
|
* @param message The discovery message.
|
||||||
* @param trusted Whether the message comes from a trusted source (i.e. a broker).
|
* @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 */
|
/* ignore discovery messages that are about ourselves */
|
||||||
if (identity == GetEndpointManager()->GetIdentity())
|
if (identity == GetEndpointManager()->GetIdentity())
|
||||||
|
@ -438,10 +427,10 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
|
||||||
*
|
*
|
||||||
* @param nrea Event arguments for the request.
|
* @param nrea Event arguments for the request.
|
||||||
*/
|
*/
|
||||||
void DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& nrea)
|
void DiscoveryComponent::NewComponentMessageHandler(const RequestMessage& request)
|
||||||
{
|
{
|
||||||
DiscoveryMessage message;
|
DiscoveryMessage message;
|
||||||
nrea.Request.GetParams(&message);
|
request.GetParams(&message);
|
||||||
|
|
||||||
string identity;
|
string identity;
|
||||||
if (!message.GetIdentity(&identity))
|
if (!message.GetIdentity(&identity))
|
||||||
|
@ -455,11 +444,11 @@ void DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& n
|
||||||
*
|
*
|
||||||
* @param nrea Event arguments for the request.
|
* @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;
|
DiscoveryMessage message;
|
||||||
nrea.Request.GetParams(&message);
|
request.GetParams(&message);
|
||||||
ProcessDiscoveryMessage(nrea.Sender->GetIdentity(), message, false);
|
ProcessDiscoveryMessage(sender->GetIdentity(), message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,27 +56,27 @@ private:
|
||||||
map<string, ComponentDiscoveryInfo::Ptr> m_Components;
|
map<string, ComponentDiscoveryInfo::Ptr> m_Components;
|
||||||
Timer::Ptr m_DiscoveryTimer;
|
Timer::Ptr m_DiscoveryTimer;
|
||||||
|
|
||||||
void NewEndpointHandler(const NewEndpointEventArgs& neea);
|
void NewEndpointHandler(const Endpoint::Ptr& endpoint);
|
||||||
void NewIdentityHandler(const EventArgs& ea);
|
void NewIdentityHandler(const Object::Ptr& source);
|
||||||
|
|
||||||
void NewComponentMessageHandler(const NewRequestEventArgs& nrea);
|
void NewComponentMessageHandler(const RequestMessage& request);
|
||||||
void RegisterComponentMessageHandler(const NewRequestEventArgs& nrea);
|
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 SendDiscoveryMessage(const string& method, const string& identity, const Endpoint::Ptr& recipient);
|
||||||
void ProcessDiscoveryMessage(string identity, DiscoveryMessage message, bool trusted);
|
void ProcessDiscoveryMessage(const string& identity, const DiscoveryMessage& message, bool trusted);
|
||||||
|
|
||||||
bool GetComponentDiscoveryInfo(string component, ComponentDiscoveryInfo::Ptr *info) const;
|
bool GetComponentDiscoveryInfo(string component, ComponentDiscoveryInfo::Ptr *info) const;
|
||||||
|
|
||||||
void CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea);
|
void CheckExistingEndpoint(const Endpoint::Ptr& self, const Endpoint::Ptr& other);
|
||||||
void DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const;
|
void DiscoveryEndpointHandler(const Endpoint::Ptr& endpoint, const ComponentDiscoveryInfo::Ptr& info) const;
|
||||||
|
|
||||||
void DiscoveryTimerHandler(void);
|
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;
|
static const int RegistrationTTL = 300;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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>
|
|
@ -48,10 +48,7 @@ string Endpoint::GetIdentity(void) const
|
||||||
void Endpoint::SetIdentity(string identity)
|
void Endpoint::SetIdentity(string identity)
|
||||||
{
|
{
|
||||||
m_Identity = identity;
|
m_Identity = identity;
|
||||||
|
OnIdentityChanged(shared_from_this());
|
||||||
EventArgs ea;
|
|
||||||
ea.Source = shared_from_this();
|
|
||||||
OnIdentityChanged(ea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -79,8 +79,8 @@ public:
|
||||||
ConstTopicIterator BeginPublications(void) const;
|
ConstTopicIterator BeginPublications(void) const;
|
||||||
ConstTopicIterator EndPublications(void) const;
|
ConstTopicIterator EndPublications(void) const;
|
||||||
|
|
||||||
boost::signal<void (const EventArgs&)> OnIdentityChanged;
|
boost::signal<void (const Object::Ptr&)> OnIdentityChanged;
|
||||||
boost::signal<void (const EventArgs&)> OnSessionEstablished;
|
boost::signal<void (const Object::Ptr&)> OnSessionEstablished;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_Identity; /**< The identity of this endpoint. */
|
string m_Identity; /**< The identity of this endpoint. */
|
||||||
|
|
|
@ -110,7 +110,7 @@ void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
|
||||||
{
|
{
|
||||||
m_Servers.push_back(server);
|
m_Servers.push_back(server);
|
||||||
server->OnNewClient.connect(boost::bind(&EndpointManager::NewClientHandler,
|
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.
|
* @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 " + client->GetPeerAddress());
|
||||||
Application::Log(LogInformation, "icinga", "Accepted new client from " + address);
|
|
||||||
|
|
||||||
JsonRpcEndpoint::Ptr endpoint = boost::make_shared<JsonRpcEndpoint>();
|
JsonRpcEndpoint::Ptr endpoint = boost::make_shared<JsonRpcEndpoint>();
|
||||||
endpoint->SetClient(static_pointer_cast<JsonRpcClient>(ncea.Client));
|
endpoint->SetClient(static_pointer_cast<JsonRpcClient>(client));
|
||||||
RegisterEndpoint(endpoint);
|
RegisterEndpoint(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,10 +153,7 @@ void EndpointManager::RegisterEndpoint(Endpoint::Ptr endpoint)
|
||||||
endpoint->SetEndpointManager(static_pointer_cast<EndpointManager>(shared_from_this()));
|
endpoint->SetEndpointManager(static_pointer_cast<EndpointManager>(shared_from_this()));
|
||||||
m_Endpoints.push_back(endpoint);
|
m_Endpoints.push_back(endpoint);
|
||||||
|
|
||||||
NewEndpointEventArgs neea;
|
OnNewEndpoint(shared_from_this(), endpoint);
|
||||||
neea.Source = shared_from_this();
|
|
||||||
neea.Endpoint = endpoint;
|
|
||||||
OnNewEndpoint(neea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -257,18 +253,14 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
|
||||||
*
|
*
|
||||||
* @param callback The callback function.
|
* @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;
|
vector<Endpoint::Ptr>::iterator prev, i;
|
||||||
for (i = m_Endpoints.begin(); i != m_Endpoints.end(); ) {
|
for (i = m_Endpoints.begin(); i != m_Endpoints.end(); ) {
|
||||||
prev = i;
|
prev = i;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
neea.Endpoint = *prev;
|
callback(shared_from_this(), *prev);
|
||||||
callback(neea);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +282,7 @@ Endpoint::Ptr EndpointManager::GetEndpointByIdentity(string identity) const
|
||||||
|
|
||||||
void EndpointManager::SendAPIMessage(Endpoint::Ptr sender,
|
void EndpointManager::SendAPIMessage(Endpoint::Ptr sender,
|
||||||
RequestMessage& message,
|
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++;
|
m_NextMessageID++;
|
||||||
|
|
||||||
|
@ -345,12 +337,7 @@ void EndpointManager::RequestTimerHandler(void)
|
||||||
map<string, PendingRequest>::iterator it;
|
map<string, PendingRequest>::iterator it;
|
||||||
for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
|
for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
|
||||||
if (it->second.HasTimedOut()) {
|
if (it->second.HasTimedOut()) {
|
||||||
NewResponseEventArgs nrea;
|
it->second.Callback(shared_from_this(), Endpoint::Ptr(), it->second.Request, ResponseMessage(), true);
|
||||||
nrea.Request = it->second.Request;
|
|
||||||
nrea.Source = shared_from_this();
|
|
||||||
nrea.TimedOut = true;
|
|
||||||
|
|
||||||
it->second.Callback(nrea);
|
|
||||||
|
|
||||||
m_Requests.erase(it);
|
m_Requests.erase(it);
|
||||||
|
|
||||||
|
@ -373,14 +360,7 @@ void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const
|
||||||
if (it == m_Requests.end())
|
if (it == m_Requests.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NewResponseEventArgs nrea;
|
it->second.Callback(shared_from_this(), sender, it->second.Request, message, false);
|
||||||
nrea.Sender = sender;
|
|
||||||
nrea.Request = it->second.Request;
|
|
||||||
nrea.Response = message;
|
|
||||||
nrea.Source = shared_from_this();
|
|
||||||
nrea.TimedOut = false;
|
|
||||||
|
|
||||||
it->second.Callback(nrea);
|
|
||||||
|
|
||||||
m_Requests.erase(it);
|
m_Requests.erase(it);
|
||||||
RescheduleRequestTimer();
|
RescheduleRequestTimer();
|
||||||
|
|
|
@ -23,18 +23,6 @@
|
||||||
namespace icinga
|
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.
|
* Information about a pending API request.
|
||||||
*
|
*
|
||||||
|
@ -44,7 +32,7 @@ struct I2_ICINGA_API PendingRequest
|
||||||
{
|
{
|
||||||
time_t Timeout;
|
time_t Timeout;
|
||||||
RequestMessage Request;
|
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
|
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.
|
* Forwards messages between endpoints.
|
||||||
*
|
*
|
||||||
|
@ -97,15 +72,15 @@ public:
|
||||||
void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
|
void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
|
||||||
|
|
||||||
void SendAPIMessage(Endpoint::Ptr sender, 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 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;
|
Endpoint::Ptr GetEndpointByIdentity(string identity) const;
|
||||||
|
|
||||||
boost::signal<void (const NewEndpointEventArgs&)> OnNewEndpoint;
|
boost::signal<void (const Object::Ptr&, const Endpoint::Ptr&)> OnNewEndpoint;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_Identity;
|
string m_Identity;
|
||||||
|
@ -125,7 +100,7 @@ private:
|
||||||
void RescheduleRequestTimer(void);
|
void RescheduleRequestTimer(void);
|
||||||
void RequestTimerHandler(void);
|
void RequestTimerHandler(void);
|
||||||
|
|
||||||
void NewClientHandler(const NewClientEventArgs& ncea);
|
void NewClientHandler(const TcpClient::Ptr& client);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,9 @@ int IcingaApplication::Main(const vector<string>& args)
|
||||||
|
|
||||||
/* register handler for 'component' config objects */
|
/* register handler for 'component' config objects */
|
||||||
static ConfigObject::Set::Ptr componentObjects = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
|
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(boost::bind(&IcingaApplication::NewComponentHandler, this, _2));
|
||||||
componentObjects->OnObjectAdded.connect(NewComponentHandler);
|
componentObjects->OnObjectCommitted.connect(boost::bind(&IcingaApplication::NewComponentHandler, this, _2));
|
||||||
componentObjects->OnObjectCommitted.connect(NewComponentHandler);
|
componentObjects->OnObjectRemoved.connect(boost::bind(&IcingaApplication::DeletedComponentHandler, this, _2));
|
||||||
componentObjects->OnObjectRemoved.connect(boost::bind(&IcingaApplication::DeletedComponentHandler, this, _1));
|
|
||||||
componentObjects->Start();
|
componentObjects->Start();
|
||||||
|
|
||||||
/* load config file */
|
/* load config file */
|
||||||
|
@ -113,10 +112,8 @@ EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
|
||||||
return m_EndpointManager;
|
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 */
|
/* don't allow replicated config objects */
|
||||||
if (!object->IsLocal())
|
if (!object->IsLocal())
|
||||||
throw runtime_error("'component' objects must be 'local'");
|
throw runtime_error("'component' objects must be 'local'");
|
||||||
|
@ -133,10 +130,8 @@ void IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObjec
|
||||||
LoadComponent(path, object);
|
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());
|
Component::Ptr component = GetComponent(object->GetName());
|
||||||
UnregisterComponent(component);
|
UnregisterComponent(component);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,8 @@ private:
|
||||||
string m_Node;
|
string m_Node;
|
||||||
string m_Service;
|
string m_Service;
|
||||||
|
|
||||||
void NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void NewComponentHandler(const ConfigObject::Ptr& object);
|
||||||
void DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void DeletedComponentHandler(const ConfigObject::Ptr& object);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,10 @@ void JsonRpcEndpoint::Connect(string node, string service, shared_ptr<SSL_CTX> s
|
||||||
void JsonRpcEndpoint::SetClient(JsonRpcClient::Ptr client)
|
void JsonRpcEndpoint::SetClient(JsonRpcClient::Ptr client)
|
||||||
{
|
{
|
||||||
m_Client = client;
|
m_Client = client;
|
||||||
client->OnNewMessage.connect(boost::bind(&JsonRpcEndpoint::NewMessageHandler, this, _1));
|
client->OnNewMessage.connect(boost::bind(&JsonRpcEndpoint::NewMessageHandler, this, _2));
|
||||||
client->OnClosed.connect(boost::bind(&JsonRpcEndpoint::ClientClosedHandler, this, _1));
|
client->OnClosed.connect(boost::bind(&JsonRpcEndpoint::ClientClosedHandler, this));
|
||||||
client->OnError.connect(boost::bind(&JsonRpcEndpoint::ClientErrorHandler, this, _1));
|
client->OnError.connect(boost::bind(&JsonRpcEndpoint::ClientErrorHandler, this, _2));
|
||||||
client->OnVerifyCertificate.connect(boost::bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _1));
|
client->OnVerifyCertificate.connect(boost::bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _2, _4));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonRpcEndpoint::IsLocal(void) const
|
bool JsonRpcEndpoint::IsLocal(void) const
|
||||||
|
@ -80,9 +80,8 @@ void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessag
|
||||||
m_Client->SendMessage(message);
|
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());
|
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
|
||||||
|
|
||||||
if (ResponseMessage::IsResponseMessage(message)) {
|
if (ResponseMessage::IsResponseMessage(message)) {
|
||||||
|
@ -108,7 +107,7 @@ void JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
|
||||||
GetEndpointManager()->SendMulticastMessage(sender, request);
|
GetEndpointManager()->SendMulticastMessage(sender, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
|
void JsonRpcEndpoint::ClientClosedHandler(void)
|
||||||
{
|
{
|
||||||
Application::Log(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetIdentity());
|
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
|
// 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;
|
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());
|
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) {
|
if (certificate && valid) {
|
||||||
string identity = Utility::GetCertificateCN(ea.Certificate);
|
string identity = Utility::GetCertificateCN(certificate);
|
||||||
|
|
||||||
if (GetIdentity().empty() && !identity.empty())
|
if (GetIdentity().empty() && !identity.empty())
|
||||||
SetIdentity(identity);
|
SetIdentity(identity);
|
||||||
|
|
|
@ -58,10 +58,10 @@ private:
|
||||||
JsonRpcClient::Ptr m_Client;
|
JsonRpcClient::Ptr m_Client;
|
||||||
map<string, Endpoint::Ptr> m_PendingCalls;
|
map<string, Endpoint::Ptr> m_PendingCalls;
|
||||||
|
|
||||||
void NewMessageHandler(const NewMessageEventArgs& nmea);
|
void NewMessageHandler(const MessagePart& message);
|
||||||
void ClientClosedHandler(const EventArgs& ea);
|
void ClientClosedHandler(void);
|
||||||
void ClientErrorHandler(const SocketErrorEventArgs& ea);
|
void ClientErrorHandler(const std::exception& ex);
|
||||||
void VerifyCertificateHandler(const VerifyCertificateEventArgs& ea);
|
void VerifyCertificateHandler(bool& valid, const shared_ptr<X509>& certificate);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,15 @@ bool VirtualEndpoint::IsConnected(void) const
|
||||||
return true;
|
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);
|
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()) {
|
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));
|
m_TopicHandlers.insert(make_pair(topic, sig));
|
||||||
} else {
|
} else {
|
||||||
sig = it->second;
|
sig = it->second;
|
||||||
|
@ -57,7 +57,7 @@ void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const Ne
|
||||||
RegisterSubscription(topic);
|
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
|
// TODO: implement
|
||||||
//m_TopicHandlers[method] -= callback;
|
//m_TopicHandlers[method] -= callback;
|
||||||
|
@ -72,17 +72,13 @@ void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage&
|
||||||
if (!request.GetMethod(&method))
|
if (!request.GetMethod(&method))
|
||||||
return;
|
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);
|
it = m_TopicHandlers.find(method);
|
||||||
|
|
||||||
if (it == m_TopicHandlers.end())
|
if (it == m_TopicHandlers.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NewRequestEventArgs nrea;
|
(*it->second)(shared_from_this(), sender, request);
|
||||||
nrea.Source = shared_from_this();
|
|
||||||
nrea.Sender = sender;
|
|
||||||
nrea.Request = request;
|
|
||||||
(*it->second)(nrea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)
|
void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)
|
||||||
|
|
|
@ -23,17 +23,6 @@
|
||||||
namespace icinga
|
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.
|
* A local endpoint.
|
||||||
*
|
*
|
||||||
|
@ -45,8 +34,8 @@ public:
|
||||||
typedef shared_ptr<VirtualEndpoint> Ptr;
|
typedef shared_ptr<VirtualEndpoint> Ptr;
|
||||||
typedef weak_ptr<VirtualEndpoint> WeakPtr;
|
typedef weak_ptr<VirtualEndpoint> WeakPtr;
|
||||||
|
|
||||||
void RegisterTopicHandler(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 NewRequestEventArgs&)> callback);
|
void UnregisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback);
|
||||||
|
|
||||||
virtual string GetAddress(void) const;
|
virtual string GetAddress(void) const;
|
||||||
|
|
||||||
|
@ -59,7 +48,7 @@ public:
|
||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
|
||||||
private:
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,9 @@ using namespace icinga;
|
||||||
* @param sslContext SSL context for the TLS connection.
|
* @param sslContext SSL context for the TLS connection.
|
||||||
*/
|
*/
|
||||||
JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
||||||
: TlsClient(role, sslContext) { }
|
: TlsClient(role, sslContext)
|
||||||
|
|
||||||
void JsonRpcClient::Start(void)
|
|
||||||
{
|
{
|
||||||
TlsClient::Start();
|
OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this));
|
||||||
|
|
||||||
OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this, _1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,11 +45,8 @@ void JsonRpcClient::SendMessage(const MessagePart& message)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes inbound data.
|
* Processes inbound data.
|
||||||
*
|
|
||||||
* @param - Event arguments for the event.
|
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
void JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
void JsonRpcClient::DataAvailableHandler(void)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
try {
|
try {
|
||||||
|
@ -64,11 +57,7 @@ void JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
message = MessagePart(jsonString);
|
message = MessagePart(jsonString);
|
||||||
|
OnNewMessage(shared_from_this(), message);
|
||||||
NewMessageEventArgs nea;
|
|
||||||
nea.Source = shared_from_this();
|
|
||||||
nea.Message = message;
|
|
||||||
OnNewMessage(nea);
|
|
||||||
} catch (const Exception& ex) {
|
} catch (const Exception& ex) {
|
||||||
Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
|
Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
|
||||||
Close();
|
Close();
|
||||||
|
|
|
@ -23,16 +23,6 @@
|
||||||
namespace icinga
|
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.
|
* A JSON-RPC client.
|
||||||
*
|
*
|
||||||
|
@ -48,12 +38,10 @@ public:
|
||||||
|
|
||||||
void SendMessage(const MessagePart& message);
|
void SendMessage(const MessagePart& message);
|
||||||
|
|
||||||
virtual void Start(void);
|
boost::signal<void (const Object::Ptr&, const MessagePart&)> OnNewMessage;
|
||||||
|
|
||||||
boost::signal<void (const NewMessageEventArgs&)> OnNewMessage;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DataAvailableHandler(const EventArgs&);
|
void DataAvailableHandler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonRpcClient::Ptr JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
JsonRpcClient::Ptr JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
||||||
|
|
|
@ -82,12 +82,12 @@ bool Netstring::ReadStringFromFIFO(FIFO::Ptr fifo, string *str)
|
||||||
*/
|
*/
|
||||||
void Netstring::WriteStringToFIFO(FIFO::Ptr fifo, const string& str)
|
void Netstring::WriteStringToFIFO(FIFO::Ptr fifo, const string& str)
|
||||||
{
|
{
|
||||||
unsigned long len = str.size();
|
stringstream prefixbuf;
|
||||||
char strLength[50];
|
prefixbuf << str.size() << ":";
|
||||||
sprintf(strLength, "%lu:", (unsigned long)len);
|
|
||||||
|
|
||||||
fifo->Write(strLength, strlen(strLength));
|
string prefix = prefixbuf.str();
|
||||||
fifo->Write(str.c_str(), len);
|
fifo->Write(prefix.c_str(), prefix.size());
|
||||||
|
fifo->Write(str.c_str(), str.size());
|
||||||
|
|
||||||
fifo->Write(",", 1);
|
fifo->Write(",", 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue