]> granicus.if.org Git - icinga2/commitdiff
Refactored event handling.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Apr 2012 09:13:17 +0000 (11:13 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Apr 2012 09:13:17 +0000 (11:13 +0200)
base/Makefile.am
base/event.h
base/tcpclient.cpp
base/tcpserver.cpp
configrpccomponent/Makefile.am
configrpccomponent/configrpccomponent.cpp
icinga/icingaapplication.cpp
jsonrpc/connectionmanager.cpp
jsonrpc/jsonrpcclient.cpp

index a9b83c8fbb0789d790368ed75ce5aa426bc009c9..c8f50b60281b1b78a3a34506111d11bc0a13a5fb 100644 (file)
@@ -44,7 +44,6 @@ libbase_la_SOURCES =  \
        win32.h
 
 libbase_la_LIBADD=$(LIBLTDL)
-libbase_la_LDFLAGS=-pthread
 
 AM_CFLAGS=$(LTDLINCL)
 AM_CXXFLAGS=$(LTDLINCL)
index 5dd048dece35ab769b03a8f17796a90e7bd71cc0..60d9ecf1974d5758b4d88e2937b260a22908ee64 100644 (file)
@@ -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;
index 1d1e80a9fce17fe00c7bc9031f9d4c91f4d64418..bdcca575a48dbf3321647eda35062c17e4ca5c53 100644 (file)
@@ -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)
index c94e64cda51c99b4f952c9a41cabfbfda3ce2e86..4c8e5b6b13095c8cfad48fccb00fedf1ebcfb388 100644 (file)
@@ -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)
index 06bbf3d256566fedd5e625fbd95d5eb7df50ff6c..f76aec842dace3c3ce35c503defe35ec3f6a7a8d 100644 (file)
@@ -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
index d767d6d2692cba200247c49c3bf9c573f81accc3..20a42550238e26673cf8b214aaabe1ecc90c9485 100644 (file)
@@ -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()));
index 2f85e65a3c301d7bcb29f412ce0e5909b6634942..f882d7027cee397bd38db0b7e2ef220387a71943 100644 (file)
@@ -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");
index 803b5d70a15f3523f2260a400d045294aecd4c22..67151bef0349f9133fa603614b4376dca1809307 100644 (file)
@@ -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)
index 52cf3d75cce60a383a5c97f654e9ef2aea955561..34db54c0759f9a650ee3d81bb3b2b365046a4dee 100644 (file)
@@ -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)