]> granicus.if.org Git - icinga2/commitdiff
Use specific types (rather than Object::Ptr) for event handlers.
authorGunnar Beutner <gunnar@beutner.name>
Sat, 16 Jun 2012 11:06:06 +0000 (13:06 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Sat, 16 Jun 2012 11:09:17 +0000 (13:09 +0200)
31 files changed:
base/application.cpp
base/configobject.cpp
base/object.cpp
base/object.h
base/objectmap.h
base/objectset.h
base/socket.cpp
base/socket.h
base/tcpclient.cpp
base/tcpclient.h
base/tcpserver.cpp
base/tcpserver.h
base/timer.cpp
base/timer.h
base/tlsclient.cpp
base/tlsclient.h
components/configrpc/configrpccomponent.cpp
components/configrpc/configrpccomponent.h
components/discovery/discoverycomponent.cpp
components/discovery/discoverycomponent.h
dyn/configitem.cpp
icinga/endpoint.cpp
icinga/endpoint.h
icinga/endpointmanager.cpp
icinga/endpointmanager.h
icinga/jsonrpcendpoint.cpp
icinga/virtualendpoint.cpp
icinga/virtualendpoint.h
jsonrpc/jsonrpcclient.cpp
jsonrpc/jsonrpcclient.h
third-party/mmatch/mmatch.c

index 88c12a372891f1825b4a6d78913e7d70a56dcfb6..4ffe0e4f00535230c6bd7bb793b92b23645fd7f0 100644 (file)
@@ -465,7 +465,7 @@ int Application::Run(int argc, char **argv)
        int result;
 
        assert(!Application::m_Instance);
-       Application::m_Instance = static_pointer_cast<Application>(shared_from_this());
+       Application::m_Instance = GetSelf();
 
 #ifndef _WIN32
        struct sigaction sa;
index da273b4477c46a79d5d05d4e3fa9e2de38354d54..49b7e529fc6bf07d1f129add63b4cb011bf80f79 100644 (file)
@@ -90,14 +90,14 @@ bool ConfigObject::IsAbstract(void) const
 void ConfigObject::Commit(void)
 {
        ConfigObject::Ptr dobj = GetObject(GetType(), GetName());
-       ConfigObject::Ptr self = static_pointer_cast<ConfigObject>(shared_from_this());
+       ConfigObject::Ptr self = GetSelf();
        assert(!dobj || dobj == self);
        m_Container->CheckObject(self);
 }
 
 void ConfigObject::Unregister(void)
 {
-       ConfigObject::Ptr self = static_pointer_cast<ConfigObject>(shared_from_this());
+       ConfigObject::Ptr self = GetSelf();
        m_Container->RemoveObject(self);
 }
 
index 9e38f7e0f77d0d2e784caa3732b1e89f90ae2df8..924cc984236b4d917d997d5e4f0873e14a5f5dbe 100644 (file)
@@ -44,7 +44,7 @@ Object::~Object(void)
  */
 void Object::Hold(void)
 {
-       m_HeldObjects.push_back(shared_from_this());
+       m_HeldObjects.push_back(GetSelf());
 }
 
 /**
@@ -55,3 +55,7 @@ void Object::ClearHeldObjects(void)
        m_HeldObjects.clear();
 }
 
+SharedPtrHolder Object::GetSelf(void)
+{
+       return SharedPtrHolder(shared_from_this());
+}
index 573c4dc9771aef687529406e8938d899d3b8efb3..ca8170e3391011e04ff4dd7dd21ec5344b0e1b11 100644 (file)
@@ -23,6 +23,8 @@
 namespace icinga
 {
 
+class SharedPtrHolder;
+
 /**
  * Base class for all heap-allocated objects. At least one of its methods
  * has to be virtual for RTTI to work.
@@ -43,6 +45,8 @@ protected:
 
        void Hold(void);
 
+       SharedPtrHolder GetSelf(void);
+
 private:
        Object(const Object& other);
        Object operator=(const Object& rhs);
@@ -50,6 +54,39 @@ private:
        static vector<Object::Ptr> m_HeldObjects;
 };
 
+/**
+ * Holds a shared pointer and provides support for implicit upcasts.
+ */
+class SharedPtrHolder
+{
+public:
+       explicit SharedPtrHolder(const shared_ptr<Object>& object)
+               : m_Object(object)
+       { }
+
+       template<typename T>
+       operator shared_ptr<T>(void) const
+       {
+#ifdef _DEBUG
+               shared_ptr<T> other = dynamic_pointer_cast<T>(m_Object);
+               assert(other);
+#else /* _DEBUG */
+               shared_ptr<T> other = static_pointer_cast<T>(m_Object);
+#endif /* _DEBUG */
+
+               return other;
+       }
+
+       template<typename T>
+       operator weak_ptr<T>(void) const
+       {
+               return static_cast<shared_ptr<T> >(*this);
+       }
+
+private:
+       shared_ptr<Object> m_Object;
+};
+
 /**
  * Compares a weak pointer with a raw pointer.
  */
index 9a6cc04b0bd78b0e89ff6a60383b23ec9ac4f27c..df9e14da03301adfdb9174dc4b7b143e4a172dbe 100644 (file)
@@ -61,7 +61,7 @@ public:
                Range range = GetRange(key);
 
                for (Iterator it = range.first; it != range.second; it++) {
-                       callback(shared_from_this(), *it);
+                       callback(GetSelf(), *it);
                }
        }
 
index 394045610b1eb265888700366834c75ec48c2809..8441428f952da9da53b79771dc9f4c4d59532985 100644 (file)
@@ -55,7 +55,7 @@ public:
        void AddObject(const TValue& object)
        {
                m_Objects.insert(object);
-               OnObjectAdded(shared_from_this(), object);
+               OnObjectAdded(GetSelf(), object);
        }
 
        void RemoveObject(const TValue& object)
@@ -64,7 +64,7 @@ public:
 
                if (it != m_Objects.end()) {
                        m_Objects.erase(it);
-                       OnObjectRemoved(shared_from_this(), object);
+                       OnObjectRemoved(GetSelf(), object);
                }
        }
 
@@ -81,14 +81,14 @@ public:
                        if (!Contains(object)) {
                                AddObject(object);
                        } else {
-                               OnObjectCommitted(shared_from_this(), object);
+                               OnObjectCommitted(GetSelf(), object);
                        }
                }
        }
 
-       boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectAdded;
-       boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectCommitted;
-       boost::signal<void (const Object::Ptr&, const TValue&)> OnObjectRemoved;
+       boost::signal<void (const typename ObjectSet<TValue>::Ptr&, const TValue&)> OnObjectAdded;
+       boost::signal<void (const typename ObjectSet<TValue>::Ptr&, const TValue&)> OnObjectCommitted;
+       boost::signal<void (const typename ObjectSet<TValue>::Ptr&, const TValue&)> OnObjectRemoved;
 
        Iterator Begin(void)
        {
@@ -103,7 +103,7 @@ public:
        void ForeachObject(function<void (const typename Object::Ptr&, const TValue&)> callback)
        {
                for (Iterator it = Begin(); it != End(); it++) {
-                       callback(shared_from_this(), *it);
+                       callback(GetSelf(), *it);
                }
        }
 
index 6701342dd85a939dad0cc09b8c15e4f8f2a2d1dc..f1f1815d20512f9586eaf65134161243e82b2355 100644 (file)
@@ -52,7 +52,7 @@ void Socket::Start(void)
 
        OnException.connect(boost::bind(&Socket::ExceptionEventHandler, this));
 
-       Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
+       Sockets.push_back(GetSelf());
 }
 
 /**
@@ -125,7 +125,7 @@ void Socket::CloseInternal(bool from_dtor)
        if (!from_dtor) {
                Stop();
 
-               OnClosed(shared_from_this());
+               OnClosed(GetSelf());
        }
 }
 
@@ -170,7 +170,7 @@ int Socket::GetLastSocketError(void)
 void Socket::HandleSocketError(const std::exception& ex)
 {
        if (!OnError.empty()) {
-               OnError(shared_from_this(), ex);
+               OnError(GetSelf(), ex);
 
                Close();
        } else {
index 0fe6316f25ade02e583d895a9c92fdc2140ee8d3..aa920d44d4d77282da0fefef65ab061afda00d7c 100644 (file)
@@ -42,12 +42,12 @@ public:
        void SetFD(SOCKET fd);
        SOCKET GetFD(void) const;
 
-       boost::signal<void (const Object::Ptr&)> OnReadable;
-       boost::signal<void (const Object::Ptr&)> OnWritable;
-       boost::signal<void (const Object::Ptr&)> OnException;
+       boost::signal<void (const Socket::Ptr&)> OnReadable;
+       boost::signal<void (const Socket::Ptr&)> OnWritable;
+       boost::signal<void (const Socket::Ptr&)> OnException;
 
-       boost::signal<void (const Object::Ptr&, const std::exception&)> OnError;
-       boost::signal<void (const Object::Ptr&)> OnClosed;
+       boost::signal<void (const Socket::Ptr&, const std::exception&)> OnError;
+       boost::signal<void (const Socket::Ptr&)> OnClosed;
 
        virtual bool WantsToRead(void) const;
        virtual bool WantsToWrite(void) const;
index 1363ef308f4c93cb37e750297484e6642f2016bc..43b54987f56bd10b78b03a58ecfb646caa8a8070 100644 (file)
@@ -159,7 +159,7 @@ void TcpClient::ReadableEventHandler(void)
 
        m_RecvQueue->Write(NULL, rc);
 
-       OnDataAvailable(shared_from_this());
+       OnDataAvailable(GetSelf());
 }
 
 /**
index 2afd01942cccea3f9f251212b36191e8cf7a0d89..970696d89dbc6380747f17122cd5216d5e47b708 100644 (file)
@@ -61,7 +61,7 @@ public:
        virtual bool WantsToRead(void) const;
        virtual bool WantsToWrite(void) const;
 
-       boost::signal<void (const Object::Ptr&)> OnDataAvailable;
+       boost::signal<void (const TcpClient::Ptr&)> OnDataAvailable;
 
 private:
        TcpClientRole m_Role;
index 876bb91688321114f7046343cd83c7908cef45a7..fb559667b41044e7a13900f09d247d65d4ae28f4 100644 (file)
@@ -93,7 +93,7 @@ void TcpServer::ReadableEventHandler(void)
        client->SetFD(fd);
        client->Start();
 
-       OnNewClient(shared_from_this(), client);
+       OnNewClient(GetSelf(), client);
 }
 
 /**
index 62b59d65f9c308c0f409b5d7f35a09ad835f8aff..247f66a787e25f999b52e1ca7fa8c9edf112a527 100644 (file)
@@ -44,7 +44,7 @@ public:
 
        void Listen(void);
 
-       boost::signal<void (const Object::Ptr&, const TcpClient::Ptr&)> OnNewClient;
+       boost::signal<void (const TcpServer::Ptr&, const TcpClient::Ptr&)> OnNewClient;
 
        virtual bool WantsToRead(void) const;
 
index 9d404af34610a5a71ef2915f8180c00552f9e028..9159abe908a534345fbd0db7dc102239d0a32bf1 100644 (file)
@@ -100,7 +100,7 @@ void Timer::CallExpiredTimers(void)
  */
 void Timer::Call(void)
 {
-       OnTimerExpired(shared_from_this());
+       OnTimerExpired(GetSelf());
 }
 
 /**
@@ -130,7 +130,7 @@ void Timer::Start(void)
 {
        Stop();
 
-       Timers.push_back(static_pointer_cast<Timer>(shared_from_this()));
+       Timers.push_back(GetSelf());
 
        Reschedule(time(NULL) + m_Interval);
 }
index c9ea4db0b8170ee0b6dbe86635669c3dd3ce2e76..1c00b4ad481a60de3425df28a9c04ce61ee66fb8 100644 (file)
@@ -52,7 +52,7 @@ public:
 
        void Reschedule(time_t next);
 
-       boost::signal<void(const Object::Ptr&)> OnTimerExpired;
+       boost::signal<void(const Timer::Ptr&)> OnTimerExpired;
 
 private:
        time_t m_Interval; /**< The interval of the timer. */
index 065730745dae69eaa46548ec51aadda2e80a0e30..3c5dde6b5c322eba9ae482b8482adebdea0a67a8 100644 (file)
@@ -136,7 +136,7 @@ void TlsClient::ReadableEventHandler(void)
 
        GetRecvQueue()->Write(NULL, rc);
 
-       OnDataAvailable(shared_from_this());
+       OnDataAvailable(GetSelf());
 }
 
 /**
@@ -244,7 +244,7 @@ int TlsClient::SSLVerifyCertificate(int ok, X509_STORE_CTX *x509Context)
 
        bool valid = false;
        shared_ptr<X509> x509Certificate = shared_ptr<X509>(x509Context->cert, &TlsClient::NullCertificateDeleter);
-       client->OnVerifyCertificate(client->shared_from_this(), valid, x509Context, x509Certificate);
+       client->OnVerifyCertificate(client->GetSelf(), valid, x509Context, x509Certificate);
 
        return valid ? 1 : 0;
 }
index 0968fbff0bad70720b4143e95e2113b84457702a..b983f619c65b01901487e9eb992600c4db44a34d 100644 (file)
@@ -41,7 +41,7 @@ public:
        virtual bool WantsToRead(void) const;
        virtual bool WantsToWrite(void) const;
 
-       boost::signal<void (const Object::Ptr&, bool&, X509_STORE_CTX *, const shared_ptr<X509>&)> OnVerifyCertificate;
+       boost::signal<void (const TlsClient::Ptr&, bool&, X509_STORE_CTX *, const shared_ptr<X509>&)> OnVerifyCertificate;
 
 protected:
        void HandleSSLError(void);
index a3ba0e0e33bacd08286a299fd1fa9d82befe236e..c93f67d0047a15b42b3d7b0b5bd26d61beb1f91c 100644 (file)
@@ -69,12 +69,11 @@ void ConfigRpcComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint)
        endpoint->OnSessionEstablished.connect(boost::bind(&ConfigRpcComponent::SessionEstablishedHandler, this, _1));
 }
 
-void ConfigRpcComponent::SessionEstablishedHandler(const Object::Ptr& source)
+void ConfigRpcComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoint)
 {
        RequestMessage request;
        request.SetMethod("config::FetchObjects");
 
-       Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(source);
        GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, endpoint, request);
 }
 
index 696f6e01c085777a6166da96891ce0c25a60a083..ed73370f7cc1cc7cc54890fc581014085f90d317 100644 (file)
@@ -37,7 +37,7 @@ private:
        VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
 
        void NewEndpointHandler(const Endpoint::Ptr& endpoint);
-       void SessionEstablishedHandler(const Object::Ptr& source);
+       void SessionEstablishedHandler(const Endpoint::Ptr& endpoint);
 
        void LocalObjectCommittedHandler(const ConfigObject::Ptr& object);
        void LocalObjectRemovedHandler(const ConfigObject::Ptr& object);
index 78df88da7469287c59ad0cd18304ccb64c8a5f55..dd86f7da60066e405b6119721e03ab45ebe157c6 100644 (file)
@@ -170,9 +170,8 @@ bool DiscoveryComponent::GetComponentDiscoveryInfo(string component, ComponentDi
  * @param ea Event arguments for the component.
  * @returns 0
  */
-void DiscoveryComponent::NewIdentityHandler(const Object::Ptr& source)
+void DiscoveryComponent::NewIdentityHandler(const Endpoint::Ptr& endpoint)
 {
-       Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(source);
        string identity = endpoint->GetIdentity();
 
        if (identity == GetEndpointManager()->GetIdentity()) {
index 39172f96ff869d31b60d32917a3281e487db5fac..3cb7d86925b7388f0712f40709d0fbaa2395a598 100644 (file)
@@ -57,7 +57,7 @@ private:
        Timer::Ptr m_DiscoveryTimer;
 
        void NewEndpointHandler(const Endpoint::Ptr& endpoint);
-       void NewIdentityHandler(const Object::Ptr& source);
+       void NewIdentityHandler(const Endpoint::Ptr& endpoint);
 
        void NewComponentMessageHandler(const RequestMessage& request);
        void RegisterComponentMessageHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
index 24dde96c6a778ecc1f0462e07b35dd6a40129c4e..96ab331f24a762c18a2a11eb8184c87e6b5a3e28 100644 (file)
@@ -128,7 +128,7 @@ void ConfigItem::Commit(void)
                dobj->Commit();
 
        ConfigItem::Ptr ci = GetObject(GetType(), GetName());
-       ConfigItem::Ptr self = static_pointer_cast<ConfigItem>(shared_from_this());
+       ConfigItem::Ptr self = GetSelf();
        if (ci && ci != self) {
                ci->m_ConfigObject.reset();
                GetAllObjects()->RemoveObject(ci);
@@ -140,8 +140,7 @@ void ConfigItem::Unregister(void)
 {
        // TODO: unregister associated ConfigObject
 
-       ConfigItem::Ptr self = static_pointer_cast<ConfigItem>(shared_from_this());
-       GetAllObjects()->RemoveObject(self);
+       GetAllObjects()->RemoveObject(GetSelf());
 }
 
 ConfigItem::Ptr ConfigItem::GetObject(const string& type, const string& name)
index 980693137d5c31d00be4e65324a7db1ae59d8acf..3d2ab177fed5823203e226a849c9983f569bbc3d 100644 (file)
@@ -48,7 +48,7 @@ string Endpoint::GetIdentity(void) const
 void Endpoint::SetIdentity(string identity)
 {
        m_Identity = identity;
-       OnIdentityChanged(shared_from_this());
+       OnIdentityChanged(GetSelf());
 }
 
 /**
index 46848cd28f249ce352ce560728deb8c131c7f7bf..2f14b31162f430c0c6325f1b03b8b35621cb9579 100644 (file)
@@ -79,8 +79,8 @@ public:
        ConstTopicIterator BeginPublications(void) const;
        ConstTopicIterator EndPublications(void) const;
 
-       boost::signal<void (const Object::Ptr&)> OnIdentityChanged;
-       boost::signal<void (const Object::Ptr&)> OnSessionEstablished;
+       boost::signal<void (const Endpoint::Ptr&)> OnIdentityChanged;
+       boost::signal<void (const Endpoint::Ptr&)> OnSessionEstablished;
 
 private:
        string m_Identity; /**< The identity of this endpoint. */
index c3b11d59a4d5c32617e311b72246785cde439f7d..b95f88a2ba6c38e0e98eec9537a897c60119c412 100644 (file)
@@ -150,10 +150,10 @@ void EndpointManager::RegisterEndpoint(Endpoint::Ptr endpoint)
        if (!endpoint->IsLocal() && endpoint->GetIdentity() != "")
                throw invalid_argument("Identity must be empty.");
 
-       endpoint->SetEndpointManager(static_pointer_cast<EndpointManager>(shared_from_this()));
+       endpoint->SetEndpointManager(GetSelf());
        m_Endpoints.push_back(endpoint);
 
-       OnNewEndpoint(shared_from_this(), endpoint);
+       OnNewEndpoint(GetSelf(), endpoint);
 }
 
 /**
@@ -253,14 +253,14 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
  *
  * @param callback The callback function.
  */
-void EndpointManager::ForEachEndpoint(function<void (const Object::Ptr&, const Endpoint::Ptr&)> callback)
+void EndpointManager::ForEachEndpoint(function<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> callback)
 {
        vector<Endpoint::Ptr>::iterator prev, i;
        for (i = m_Endpoints.begin(); i != m_Endpoints.end(); ) {
                prev = i;
                i++;
 
-               callback(shared_from_this(), *prev);
+               callback(GetSelf(), *prev);
        }
 }
 
@@ -282,7 +282,7 @@ Endpoint::Ptr EndpointManager::GetEndpointByIdentity(string identity) const
 
 void EndpointManager::SendAPIMessage(Endpoint::Ptr sender,
     RequestMessage& message,
-    function<void(const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, time_t timeout)
+    function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, time_t timeout)
 {
        m_NextMessageID++;
 
@@ -337,7 +337,7 @@ void EndpointManager::RequestTimerHandler(void)
        map<string, PendingRequest>::iterator it;
        for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
                if (it->second.HasTimedOut()) {
-                       it->second.Callback(shared_from_this(), Endpoint::Ptr(), it->second.Request, ResponseMessage(), true);
+                       it->second.Callback(GetSelf(), Endpoint::Ptr(), it->second.Request, ResponseMessage(), true);
 
                        m_Requests.erase(it);
 
@@ -360,7 +360,7 @@ void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const
        if (it == m_Requests.end())
                return;
 
-       it->second.Callback(shared_from_this(), sender, it->second.Request, message, false);
+       it->second.Callback(GetSelf(), sender, it->second.Request, message, false);
 
        m_Requests.erase(it);
        RescheduleRequestTimer();
index 7c31740b44415c7c4408c5b06df8f8ae26b44de7..d91128315e9aaf51438453e3a8f1225d1f50005b 100644 (file)
 namespace icinga
 {
 
-/**
- * Information about a pending API request.
- *
- * @ingroup icinga
- */
-struct I2_ICINGA_API PendingRequest
-{
-       time_t Timeout;
-       RequestMessage Request;
-       function<void(const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> Callback;
-
-       bool HasTimedOut(void) const
-       {
-               return time(NULL) > Timeout;
-       }
-};
-
 /**
  * Forwards messages between endpoints.
  *
@@ -72,15 +55,15 @@ public:
        void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
 
        void SendAPIMessage(Endpoint::Ptr sender, RequestMessage& message,
-           function<void(const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, time_t timeout = 10);
+           function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, time_t timeout = 10);
 
        void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
 
-       void ForEachEndpoint(function<void (const Object::Ptr&, const Endpoint::Ptr&)> callback);
+       void ForEachEndpoint(function<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> callback);
 
        Endpoint::Ptr GetEndpointByIdentity(string identity) const;
 
-       boost::signal<void (const Object::Ptr&, const Endpoint::Ptr&)> OnNewEndpoint;
+       boost::signal<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> OnNewEndpoint;
 
 private:
        string m_Identity;
@@ -89,6 +72,23 @@ private:
        vector<JsonRpcServer::Ptr> m_Servers;
        vector<Endpoint::Ptr> m_Endpoints;
 
+       /**
+        * Information about a pending API request.
+        *
+        * @ingroup icinga
+        */
+       struct I2_ICINGA_API PendingRequest
+       {
+               time_t Timeout;
+               RequestMessage Request;
+               function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> Callback;
+
+               bool HasTimedOut(void) const
+               {
+                       return time(NULL) > Timeout;
+               }
+       };
+
        long m_NextMessageID;
        map<string, PendingRequest> m_Requests;
        Timer::Ptr m_RequestTimer;
index a9dfc1f7304206996a7bb1071dcbfa20d034d203..87fd61a7daf09ce739c4c0b9270a1fa6a5eaafbc 100644 (file)
@@ -82,7 +82,7 @@ void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessag
 
 void JsonRpcEndpoint::NewMessageHandler(const MessagePart& message)
 {
-       Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
+       Endpoint::Ptr sender = GetSelf();
 
        if (ResponseMessage::IsResponseMessage(message)) {
                /* rather than routing the message to the right virtual
@@ -121,7 +121,7 @@ void JsonRpcEndpoint::ClientClosedHandler(void)
        // remove the endpoint if there are no more subscriptions */
        if (BeginSubscriptions() == EndSubscriptions()) {
                Hold();
-               GetEndpointManager()->UnregisterEndpoint(static_pointer_cast<Endpoint>(shared_from_this()));
+               GetEndpointManager()->UnregisterEndpoint(GetSelf());
        }
 
        m_Client.reset();
index 02ff52efeedb5a98ceabdbbe6e31fd4a71ac87a1..be3f3295851906229b47940823c01ea492bc88bc 100644 (file)
@@ -38,15 +38,15 @@ bool VirtualEndpoint::IsConnected(void) const
        return true;
 }
 
-void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
+void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
 {
-       map<string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
+       map<string, shared_ptr<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
        it = m_TopicHandlers.find(topic);
 
-       shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > sig;
+       shared_ptr<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > sig;
 
        if (it == m_TopicHandlers.end()) {
-               sig = boost::make_shared<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> >();
+               sig = boost::make_shared<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> >();
                m_TopicHandlers.insert(make_pair(topic, sig));
        } else {
                sig = it->second;
@@ -57,7 +57,7 @@ void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const Ob
        RegisterSubscription(topic);
 }
 
-void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
+void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback)
 {
        // TODO: implement
        //m_TopicHandlers[method] -= callback;
@@ -72,13 +72,13 @@ void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RequestMessage&
        if (!request.GetMethod(&method))
                return;
 
-       map<string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
+       map<string, shared_ptr<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > >::iterator it;
        it = m_TopicHandlers.find(method);
 
        if (it == m_TopicHandlers.end())
                return;
 
-       (*it->second)(shared_from_this(), sender, request);
+       (*it->second)(GetSelf(), sender, request);
 }
 
 void VirtualEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessage& response)
index 4da70c053769a9f6fd34f39ae0263d94653a8713..ddc080c27d7ec8caad3635e6755c6a9caa3ae668 100644 (file)
@@ -34,8 +34,8 @@ public:
        typedef shared_ptr<VirtualEndpoint> Ptr;
        typedef weak_ptr<VirtualEndpoint> WeakPtr;
 
-       void RegisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback);
-       void UnregisterTopicHandler(string topic, function<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback);
+       void RegisterTopicHandler(string topic, function<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback);
+       void UnregisterTopicHandler(string topic, function<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> callback);
 
        virtual string GetAddress(void) const;
 
@@ -48,7 +48,7 @@ public:
        virtual void Stop(void);
 
 private:
-       map< string, shared_ptr<boost::signal<void (const Object::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > > m_TopicHandlers;
+       map< string, shared_ptr<boost::signal<void (const VirtualEndpoint::Ptr&, const Endpoint::Ptr, const RequestMessage&)> > > m_TopicHandlers;
 };
 
 }
index e35e76f08f3143944a59eaa433a3a7dff2b45206..c95b049b119b40ea6a26b0ce31eac2141050a61d 100644 (file)
@@ -57,7 +57,7 @@ void JsonRpcClient::DataAvailableHandler(void)
                                return;
 
                        message = MessagePart(jsonString);
-                       OnNewMessage(shared_from_this(), message);
+                       OnNewMessage(GetSelf(), message);
                } catch (const Exception& ex) {
                        Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
                        Close();
index a8f96288445b93a282f588927bfff8026288d6f8..00a16ada1de18e2a203ad4289d301ef18ccb64dc 100644 (file)
@@ -38,7 +38,7 @@ public:
 
        void SendMessage(const MessagePart& message);
 
-       boost::signal<void (const Object::Ptr&, const MessagePart&)> OnNewMessage;
+       boost::signal<void (const JsonRpcClient::Ptr&, const MessagePart&)> OnNewMessage;
 
 private:
        void DataAvailableHandler(void);
index 704f33abf6c852be323cee93d27885e966e690b7..e6fb1093f2584aaaa6e3df281af8c22e0bef9112 100644 (file)
@@ -301,6 +301,6 @@ char *collapse(char *pattern)
     }
     while (*m++);
   };
-  return mask;
+  return pattern;
 }