mirror of https://github.com/Icinga/icinga2.git
Refactored event handling.
This commit is contained in:
parent
7c5d29bbc9
commit
3da08ca9b6
|
@ -44,7 +44,6 @@ libbase_la_SOURCES = \
|
|||
win32.h
|
||||
|
||||
libbase_la_LIBADD=$(LIBLTDL)
|
||||
libbase_la_LDFLAGS=-pthread
|
||||
|
||||
AM_CFLAGS=$(LTDLINCL)
|
||||
AM_CXXFLAGS=$(LTDLINCL)
|
||||
|
|
16
base/event.h
16
base/event.h
|
@ -22,16 +22,28 @@ private:
|
|||
list<DelegateType> m_Delegates;
|
||||
|
||||
public:
|
||||
void bind(const DelegateType& delegate)
|
||||
void hook(const DelegateType& delegate)
|
||||
{
|
||||
m_Delegates.push_front(delegate);
|
||||
}
|
||||
|
||||
void unbind(const DelegateType& delegate)
|
||||
void unhook(const DelegateType& delegate)
|
||||
{
|
||||
m_Delegates.remove(delegate);
|
||||
}
|
||||
|
||||
event<TArgs>& operator +=(const DelegateType& rhs)
|
||||
{
|
||||
hook(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
event<TArgs>& operator -=(const DelegateType& rhs)
|
||||
{
|
||||
unhook(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void operator()(const TArgs& args)
|
||||
{
|
||||
typename list<DelegateType>::iterator prev, i;
|
||||
|
|
|
@ -12,11 +12,8 @@ void TCPClient::Start(void)
|
|||
{
|
||||
TCPSocket::Start();
|
||||
|
||||
function<int (EventArgs::Ptr)> rd = bind_weak(&TCPClient::ReadableEventHandler, shared_from_this());
|
||||
OnReadable.bind(rd);
|
||||
|
||||
function<int (EventArgs::Ptr)> wd = bind_weak(&TCPClient::WritableEventHandler, shared_from_this());
|
||||
OnWritable.bind(wd);
|
||||
OnReadable += bind_weak(&TCPClient::ReadableEventHandler, shared_from_this());
|
||||
OnWritable += bind_weak(&TCPClient::WritableEventHandler, shared_from_this());
|
||||
}
|
||||
|
||||
FIFO::Ptr TCPClient::GetSendQueue(void)
|
||||
|
|
|
@ -21,8 +21,7 @@ void TCPServer::Start(void)
|
|||
{
|
||||
TCPSocket::Start();
|
||||
|
||||
function<int (EventArgs::Ptr)> dr = bind_weak(&TCPServer::ReadableEventHandler, shared_from_this());
|
||||
OnReadable.bind(dr);
|
||||
OnReadable += bind_weak(&TCPServer::ReadableEventHandler, shared_from_this());
|
||||
}
|
||||
|
||||
void TCPServer::Listen(void)
|
||||
|
|
|
@ -10,5 +10,5 @@ libconfigrpccomponent_la_SOURCES = \
|
|||
|
||||
libconfigrpccomponent_la_CXXFLAGS = -I${top_srcdir}/base -I${top_srcdir}/jsonrpc -I${top_srcdir}/icinga
|
||||
|
||||
libconfigrpccomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined
|
||||
libconfigrpccomponent_la_LDFLAGS = -module -version-info 0:0:0 -no-undefined -pthread
|
||||
libconfigrpccomponent_la_LIBADD = ${top_builddir}/base/libbase.la ${top_builddir}/jsonrpc/libjsonrpc.la
|
||||
|
|
|
@ -23,9 +23,9 @@ void ConfigRpcComponent::Start(void)
|
|||
if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
|
||||
connectionManager->RegisterMethod("config::FetchObjects", bind_weak(&ConfigRpcComponent::FetchObjectsHandler, shared_from_this()));
|
||||
|
||||
configHive->OnObjectCreated.bind(bind_weak(&ConfigRpcComponent::LocalObjectCreatedHandler, shared_from_this()));
|
||||
configHive->OnObjectRemoved.bind(bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this()));
|
||||
configHive->OnPropertyChanged.bind(bind_weak(&ConfigRpcComponent::LocalPropertyChangedHandler, shared_from_this()));
|
||||
configHive->OnObjectCreated += bind_weak(&ConfigRpcComponent::LocalObjectCreatedHandler, shared_from_this());
|
||||
configHive->OnObjectRemoved += bind_weak(&ConfigRpcComponent::LocalObjectRemovedHandler, shared_from_this());
|
||||
configHive->OnPropertyChanged += bind_weak(&ConfigRpcComponent::LocalPropertyChangedHandler, shared_from_this());
|
||||
}
|
||||
|
||||
connectionManager->RegisterMethod("config::ObjectCreated", bind_weak(&ConfigRpcComponent::RemoteObjectCreatedHandler, shared_from_this()));
|
||||
|
|
|
@ -30,8 +30,8 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||
string componentDirectory = GetExeDirectory() + "/../lib/icinga";
|
||||
AddComponentSearchDir(componentDirectory);
|
||||
|
||||
GetConfigHive()->OnObjectCreated.bind(bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this()));
|
||||
GetConfigHive()->OnObjectRemoved.bind(bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this()));
|
||||
GetConfigHive()->OnObjectCreated += bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this());
|
||||
GetConfigHive()->OnObjectRemoved += bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this());
|
||||
|
||||
ConfigObject::Ptr fileComponentConfig = new_object<ConfigObject>();
|
||||
fileComponentConfig->SetName("configfilecomponent");
|
||||
|
|
|
@ -5,7 +5,7 @@ using namespace icinga;
|
|||
void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
|
||||
{
|
||||
m_Servers.push_front(server);
|
||||
server->OnNewClient.bind(bind_weak(&ConnectionManager::NewClientHandler, shared_from_this()));
|
||||
server->OnNewClient += bind_weak(&ConnectionManager::NewClientHandler, shared_from_this());
|
||||
}
|
||||
|
||||
void ConnectionManager::UnregisterServer(JsonRpcServer::Ptr server)
|
||||
|
@ -17,7 +17,7 @@ void ConnectionManager::UnregisterServer(JsonRpcServer::Ptr server)
|
|||
void ConnectionManager::RegisterClient(JsonRpcClient::Ptr client)
|
||||
{
|
||||
m_Clients.push_front(client);
|
||||
client->OnNewMessage.bind(bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this()));
|
||||
client->OnNewMessage += bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this());
|
||||
}
|
||||
|
||||
void ConnectionManager::UnregisterClient(JsonRpcClient::Ptr client)
|
||||
|
@ -74,7 +74,7 @@ void ConnectionManager::RegisterMethod(string method, function<int (NewMessageEv
|
|||
i = m_Methods.find(method);
|
||||
}
|
||||
|
||||
i->second.bind(callback);
|
||||
i->second += callback;
|
||||
}
|
||||
|
||||
void ConnectionManager::UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> function)
|
||||
|
|
|
@ -6,7 +6,7 @@ void JsonRpcClient::Start(void)
|
|||
{
|
||||
TCPClient::Start();
|
||||
|
||||
OnDataAvailable.bind(bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this()));
|
||||
OnDataAvailable += bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this());
|
||||
}
|
||||
|
||||
void JsonRpcClient::SendMessage(JsonRpcMessage::Ptr message)
|
||||
|
|
Loading…
Reference in New Issue