]> granicus.if.org Git - icinga2/commitdiff
Cleaned up code.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 17 May 2012 17:14:03 +0000 (19:14 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 17 May 2012 17:14:03 +0000 (19:14 +0200)
27 files changed:
Doxyfile
base/Makefile.am
base/application.cpp
base/base.vcxproj
base/configcollection.h
base/confighive.h
base/dictionary.cpp
base/dictionary.h
base/event.h [deleted file]
base/exception.cpp
base/exception.h
base/i2-base.h
base/socket.h
base/tcpclient.h
base/tcpserver.h
base/thread.cpp
base/thread.h
base/timer.h
base/tlsclient.h
components/discovery/discoverycomponent.cpp
icinga/endpoint.h
icinga/endpointmanager.h
icinga/virtualendpoint.cpp
icinga/virtualendpoint.h
jsonrpc/jsonrpcclient.cpp
jsonrpc/jsonrpcclient.h
jsonrpc/messagepart.cpp

index 4f8d9c93b3f90a456917fd2bf359760fa97fa911..eaadb283dfc959030af74cc5d764a8f207bccd3d 100644 (file)
--- a/Doxyfile
+++ b/Doxyfile
@@ -1469,7 +1469,7 @@ ENABLE_PREPROCESSING   = YES
 # compilation will be performed. Macro expansion can be done in a controlled
 # way by setting EXPAND_ONLY_PREDEF to YES.
 
-MACRO_EXPANSION        = NO
+MACRO_EXPANSION        = YES
 
 # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
 # then the macro expansion is limited to the macros specified with the
index f5520d9e68cbda0e5297e7c1e85fae18e27a2615..601d09d502f573fa876d6ca07673fd9d3dc68471 100644 (file)
@@ -21,7 +21,7 @@ libbase_la_SOURCES =  \
        delegate.h \
        dictionary.cpp \
        dictionary.h \
-       event.h \
+       observable.h \
        exception.cpp \
        exception.h \
        fifo.cpp \
index 11fc30fe5277dfee9156ca686f85191329eba411..de3054477d85165b7480713b457d5ac15713601b 100644 (file)
@@ -460,12 +460,12 @@ int Application::Run(int argc, char **argv)
        } else {
                try {
                        result = Main(m_Arguments);
-               } catch (const Exception& ex) {
+               } catch (const exception& ex) {
                        Application::Instance.reset();
 
                        Application::Log("---");
                        Application::Log("Exception: " + Utility::GetTypeName(ex));
-                       Application::Log("Message: " + ex.GetMessage());
+                       Application::Log("Message: " + string(ex.what()));
 
                        return EXIT_FAILURE;
                }
index 3710e309d13d07ed0da2ff90db36d82073525477..bdcca97adcdc008f186a4214771909c73009c8a6 100644 (file)
@@ -45,7 +45,7 @@
     <ClInclude Include="cxx11-compat.h" />
     <ClInclude Include="delegate.h" />
     <ClInclude Include="dictionary.h" />
-    <ClInclude Include="event.h" />
+    <ClInclude Include="observable.h" />
     <ClInclude Include="exception.h" />
     <ClInclude Include="fifo.h" />
     <ClInclude Include="i2-base.h" />
index 1846453c36336d8c20ff0378a6c702095fae5978..a37332ab1073d7749dc27be620e9744a6841e989 100644 (file)
@@ -50,8 +50,8 @@ public:
 
        void ForEachObject(function<int (const EventArgs&)> callback);
 
-       Event<EventArgs> OnObjectCommitted;
-       Event<EventArgs> OnObjectRemoved;
+       Observable<EventArgs> OnObjectCommitted;
+       Observable<EventArgs> OnObjectRemoved;
 };
 
 }
index c137cf6ca01934fb93110ffcf72d0fbd4344116f..0bb3b708a6311da491b32d4a908ccccc32fdd471 100644 (file)
@@ -45,8 +45,8 @@ public:
        void ForEachObject(const string& type,
            function<int (const EventArgs&)> callback);
 
-       Event<EventArgs> OnObjectCommitted;
-       Event<EventArgs> OnObjectRemoved;
+       Observable<EventArgs> OnObjectCommitted;
+       Observable<EventArgs> OnObjectRemoved;
 };
 
 }
index e8e62658059eeeea8b9d1c313398dcb687f58920..90d6c7c0608eaad36ab415e7ae0e81f8d7e9755c 100644 (file)
 
 using namespace icinga;
 
-/**
- * Retrieves a value from the dictionary.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetProperty(string key, Variant *value) const
-{
-       ConstDictionaryIterator i = m_Data.find(key);
-
-       if (i == m_Data.end())
-               return false;
-
-       *value = i->second;
-       return true;
-}
-
-/**
- * Sets a value in the dictionary.
- *
- * @param key The key.
- * @param value The value.
- */
-void Dictionary::SetProperty(string key, const Variant& value)
-{
-       DictionaryIterator i = m_Data.find(key);
-
-       Variant oldValue;
-       if (i != m_Data.end()) {
-               oldValue = i->second;
-               m_Data.erase(i);
-       }
-
-       m_Data[key] = value;
-}
-
-/**
- * Retrieves a value from the dictionary.
- *
- * @param key The key.
- * @param value Pointer to the value.
- * @returns true if the value was retrieved, false otherwise.
- */
-bool Dictionary::GetProperty(string key, Dictionary::Ptr *value) const
-{
-       Object::Ptr object;
-
-       if (!GetProperty(key, &object))
-               return false;
-
-       Dictionary::Ptr dictionary = dynamic_pointer_cast<Dictionary>(object);
-       if (!dictionary)
-               throw InvalidArgumentException();
-
-       *value = dictionary;
-       return true;
-}
-
 /**
  * Returns an iterator to the beginning of the dictionary.
  *
@@ -109,25 +50,3 @@ long Dictionary::GetLength(void) const
 {
        return m_Data.size();
 }
-
-/**
- * Adds an unnamed value to the dictionary.
- *
- * @param value The value.
- */
-void Dictionary::AddUnnamedProperty(const Variant& value)
-{
-       map<string, Variant>::const_iterator it;
-       string key;
-       long index = GetLength();
-       do {
-               stringstream s;
-               s << "_" << index;
-               index++;
-
-               key = s.str();
-               it = m_Data.find(key);
-       } while (it != m_Data.end());
-
-       m_Data[key] = value;
-}
index edfeda281cecf837f8f2b5d27be4bc89c3303a6a..ec8df24516d0187f46fc74d7ca9a8a7b1ba7290f 100644 (file)
@@ -38,29 +38,64 @@ public:
        typedef shared_ptr<Dictionary> Ptr;
        typedef weak_ptr<Dictionary> WeakPtr;
 
-       bool GetProperty(string key, Variant *value) const;
-       void SetProperty(string key, const Variant& value);
-
+       /**
+        * Retrieves a value from the dictionary.
+        *
+        * @param key The key.
+        * @param value Pointer to the value.
+        * @returns true if the value was retrieved, false otherwise.
+        */
        template<typename T>
        bool GetProperty(string key, T *value) const
        {
-               Variant data;
+               ConstDictionaryIterator i = m_Data.find(key);
 
-               if (!GetProperty(key, &data))
+               if (i == m_Data.end())
                        return false;
 
-               *value = data;
+               *value = i->second;
 
                return true;
        }
 
-       bool GetProperty(string key, Dictionary::Ptr *value) const;
+       /**
+        * Sets a value in the dictionary.
+        *
+        * @param key The key.
+        * @param value The value.
+        */
+       template<typename T>
+       void SetProperty(string key, const T& value)
+       {
+               m_Data[key] = value;
+       }
+
+       /**
+        * Adds an unnamed value to the dictionary.
+        *
+        * @param value The value.
+        */
+       template<typename T>
+       void AddUnnamedProperty(const T& value)
+       {
+               DictionaryIterator it;
+               string key;
+               long index = GetLength();
+               do {
+                       stringstream s;
+                       s << "_" << index;
+                       index++;
+
+                       key = s.str();
+                       it = m_Data.find(key);
+               } while (it != m_Data.end());
+
+               SetProperty(key, value);
+       }
 
        DictionaryIterator Begin(void);
        DictionaryIterator End(void);
 
-       void AddUnnamedProperty(const Variant& value);
-
        long GetLength(void) const;
 };
 
diff --git a/base/event.h b/base/event.h
deleted file mode 100644 (file)
index 430f7b0..0000000
+++ /dev/null
@@ -1,92 +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 EVENT_H
-#define EVENT_H
-
-namespace icinga
-{
-
-/**
- * Base class for event arguments.
- */
-struct I2_BASE_API EventArgs
-{
-       Object::Ptr Source; /**< The source of the event. */
-};
-
-/**
- * An observable event.
- */
-template<class TArgs>
-class Event
-{
-public:
-       typedef function<int (const TArgs&)> ObserverType;
-
-private:
-       vector<ObserverType> m_Observers;
-
-public:
-       /**
-        * Adds an observer to this event.
-        *
-        * @param rhs The delegate.
-        */
-       Event<TArgs>& operator +=(const ObserverType& rhs)
-       {
-               m_Observers.push_back(rhs);
-               return *this;
-       }
-
-       /**
-        * Removes an observer from this event.
-        *
-        * @param rhs The delegate.
-        */
-       Event<TArgs>& operator -=(const ObserverType& rhs)
-       {
-               m_Observers.erase(rhs);
-               return *this;
-       }
-
-       /**
-        * Invokes each observer function that is registered for this event. Any
-        * observer function which returns -1 is removed.
-        *
-        * @param args Event arguments.
-        */
-       void operator()(const TArgs& args)
-       {
-               typename vector<ObserverType>::iterator i;
-
-               for (i = m_Observers.begin(); i != m_Observers.end(); ) {
-                       int result = (*i)(args);
-
-                       if (result == -1)
-                               i = m_Observers.erase(i);
-                       else
-                               i++;
-               }
-       }
-};
-
-}
-
-#endif /* EVENT_H */
index 8a339f29edbc27563d414379915ce6566dd9a787..8f8af1ed3ff36788d83d0a5d213f9db03b6013d3 100644 (file)
@@ -33,7 +33,7 @@ Exception::Exception(void)
  *
  * @param message A message describing the exception.
  */
-Exception::Exception(const string& message)
+Exception::Exception(const char *message)
 {
        SetMessage(message);
 }
@@ -43,19 +43,32 @@ Exception::Exception(const string& message)
  *
  * @returns The description.
  */
-string Exception::GetMessage(void) const
+const char *Exception::GetMessage(void) const
 {
        return m_Message;
 }
 
+/**
+ * Retrieves the description for the exception.
+ *
+ * @returns The description.
+ */
+const char *Exception::what(void) const throw()
+{
+       return GetMessage();
+}
+
 /**
  * Sets the description for the exception.
  *
  * @param message The description.
  */
-void Exception::SetMessage(string message)
+void Exception::SetMessage(const char *message)
 {
-       m_Message = message;
+       if (m_Message)
+               delete m_Message;
+
+       m_Message = Memory::StrDup(message);
 }
 
 #ifdef _WIN32
index 21c8dd2e78e57149b3685b2b96ac816796cfbf26..9687b734126f6d02fb09482946c8c30e2d48ad16 100644 (file)
@@ -26,26 +26,29 @@ namespace icinga
 /**
  * Base class for all exceptions.
  */
-class I2_BASE_API Exception
+class I2_BASE_API Exception : exception
 {
 private:
-       string m_Message;
+       const char *m_Message;
 
 protected:
-       void SetMessage(string message);
+       void SetMessage(const char *message);
 
 public:
        Exception(void);
-       Exception(const string& message);
+       Exception(const char *message);
 
        /**
         * Destructor for the Exception class. Must be virtual for RTTI to work.
         */
        virtual ~Exception(void)
        {
+               delete m_Message;
        }
 
-       string GetMessage(void) const;
+       const char *GetMessage(void) const;
+
+       virtual const char *what(void) const throw();
 };
 
 #define DEFINE_EXCEPTION_CLASS(klass)                                  \
@@ -56,7 +59,7 @@ public:
                {                                                       \
                }                                                       \
                                                                        \
-               inline klass(const string& message)                     \
+               inline klass(const char *message)                       \
                    : Exception(message)                                \
                {                                                       \
                }                                                       \
@@ -64,6 +67,7 @@ public:
 
 DEFINE_EXCEPTION_CLASS(NotImplementedException);
 DEFINE_EXCEPTION_CLASS(InvalidArgumentException);
+DEFINE_EXCEPTION_CLASS(InvalidCastException);
 
 #ifdef _WIN32
 /**
@@ -80,7 +84,8 @@ public:
         */
        inline Win32Exception(const string& message, int errorCode)
        {
-               SetMessage(message + ": " + FormatErrorCode(errorCode));
+               string msg = message + ": " + FormatErrorCode(errorCode);
+               SetMessage(msg.c_str());
        }
 
        /**
@@ -107,7 +112,8 @@ public:
         */
        inline PosixException(const string& message, int errorCode)
        {
-               SetMessage(message + ": " + FormatErrorCode(errorCode));
+               string msg = message + ": " + FormatErrorCode(errorCode);
+               SetMessage(msg.c_str());
        }
 
        /**
@@ -133,7 +139,8 @@ public:
         */
        inline OpenSSLException(const string& message, int errorCode)
        {
-               SetMessage(message + ": " + FormatErrorCode(errorCode));
+               string msg = message + ": " + FormatErrorCode(errorCode);
+               SetMessage(msg.c_str());
        }
 
        /**
index 771708887ba9f487885cac47865d05b568d52df2..985565e89e21c22153fd9d579f227179b1bc49f3 100644 (file)
@@ -103,7 +103,7 @@ using namespace std::tr1::placeholders;
 #include "exception.h"
 #include "memory.h"
 #include "delegate.h"
-#include "event.h"
+#include "observable.h"
 #include "variant.h"
 #include "dictionary.h"
 #include "timer.h"
index ce6b77855b97c1c469ec50ad2ace0209bb6a61e0..a222913df7f86188a694f998705f98383f6f09af 100644 (file)
@@ -62,12 +62,12 @@ public:
        void SetFD(SOCKET fd);
        SOCKET GetFD(void) const;
 
-       Event<EventArgs> OnReadable;
-       Event<EventArgs> OnWritable;
-       Event<EventArgs> OnException;
+       Observable<EventArgs> OnReadable;
+       Observable<EventArgs> OnWritable;
+       Observable<EventArgs> OnException;
 
-       Event<SocketErrorEventArgs> OnError;
-       Event<EventArgs> OnClosed;
+       Observable<SocketErrorEventArgs> OnError;
+       Observable<EventArgs> OnClosed;
 
        virtual bool WantsToRead(void) const;
        virtual bool WantsToWrite(void) const;
index 5c36dfa336f9631464556e77cd945ea915eb75cc..de7ed375717f1fdb32f7a095729c00f85a55ea27 100644 (file)
@@ -64,7 +64,7 @@ public:
        virtual bool WantsToRead(void) const;
        virtual bool WantsToWrite(void) const;
 
-       Event<EventArgs> OnDataAvailable;
+       Observable<EventArgs> OnDataAvailable;
 };
 
 /**
index d9b30190d39c86b7562e98076d34a4288726b845..370cac0d626fc451cb614eb66c2d133f6cc3c4b0 100644 (file)
@@ -54,7 +54,7 @@ public:
 
        void Listen(void);
 
-       Event<NewClientEventArgs> OnNewClient;
+       Observable<NewClientEventArgs> OnNewClient;
 
        virtual bool WantsToRead(void) const;
 };
index 70c2fe2e94f3d762afadb5a03a51a62b15382843..611dbbfaf6b8cf2d22508c075c5de53e7fd748d9 100644 (file)
 
 using namespace icinga;
 
-typedef struct threadparam_s
-{
-       ThreadProc callback;
-       void *param;
-} threadparam_t;
-
 /**
  * Helper function that deals with OS-specific differences in the thread
  * proc's function signature.
@@ -34,16 +28,16 @@ typedef struct threadparam_s
 #ifdef _WIN32
 static DWORD WINAPI ThreadStartProc(LPVOID param)
 {
-       threadparam_t *tparam = (threadparam_t *)param;
-       tparam->callback(tparam->param);
+       ThreadParameters *tparam = (ThreadParameters *)param;
+       tparam->Callback(tparam->UserParams);
        delete tparam;
        return 0;
 }
 #else /* _WIN32 */
 static void *ThreadStartProc(void *param)
 {
-       threadparam_t *tparam = (threadparam_t *)param;
-       tparam->callback(tparam->param);
+       ThreadParameters *tparam = (ThreadParameters *)param;
+       tparam->Callback(tparam->UserParams);
        delete tparam;
        return NULL;
 }
@@ -55,13 +49,13 @@ static void *ThreadStartProc(void *param)
  */
 Thread::Thread(ThreadProc callback, void *param)
 {
-       threadparam_t *tparam = new threadparam_t();
+       ThreadParameters *tparam = new ThreadParameters();
 
        if (tparam == NULL)
                throw OutOfMemoryException("Out of memory");
 
-       tparam->callback = callback;
-       tparam->param = param;
+       tparam->Callback = callback;
+       tparam->UserParams = param;
 
 #ifdef _WIN32
        m_Thread = CreateThread(NULL, 0, ThreadStartProc, tparam, CREATE_SUSPENDED, NULL);
@@ -69,7 +63,8 @@ Thread::Thread(ThreadProc callback, void *param)
        if (m_Thread == NULL)
                throw Win32Exception("CreateThread failed.", GetLastError());
 #else /* _WIN32 */
-       pthread_create(&m_Thread, NULL, ThreadStartProc, &tparam);
+       if (pthread_create(&m_Thread, NULL, ThreadStartProc, &tparam) < 0)
+               throw PosixException("pthread_create failed.", errno);
 #endif /* _WIN32 */
 }
 
index cf6744a25e359fd1d838335265e351cc99bfbcf7..7f32370250342b139288bdb63b3b7a8283ed4f27 100644 (file)
@@ -25,6 +25,12 @@ namespace icinga
 
 typedef void (*ThreadProc)(void *);
 
+struct ThreadParameters
+{
+       ThreadProc Callback;
+       void *UserParams;
+};
+
 /**
  * A wrapper around OS-specific thread functionality.
  */
index 79f013d5380cea819e3840988801ac923118b583..17017a9f3bf36073ca006109dd29734d8d263d2f 100644 (file)
@@ -72,7 +72,7 @@ public:
 
        void Reschedule(time_t next);
 
-       Event<TimerEventArgs> OnTimerExpired;
+       Observable<TimerEventArgs> OnTimerExpired;
 };
 
 }
index bf76dbe16a8d318d6de5ffda9f826515e9a4d24d..cec54277c178c604033359e60ecd7a30e6ffef48 100644 (file)
@@ -73,7 +73,7 @@ public:
        virtual bool WantsToRead(void) const;
        virtual bool WantsToWrite(void) const;
 
-       Event<VerifyCertificateEventArgs> OnVerifyCertificate;
+       Observable<VerifyCertificateEventArgs> OnVerifyCertificate;
 };
 
 TCPClient::Ptr TLSClientFactory(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
index b1fa37277558fc130984140254e083227f4e60f8..0dade5e880dfc35608d23063e6bf7886cef7a15a 100644 (file)
@@ -357,10 +357,14 @@ bool DiscoveryComponent::HasMessagePermission(Dictionary::Ptr roles, string mess
                if (!role)
                        continue;
 
-               Dictionary::Ptr permissions;
-               if (!role->GetProperty(messageType, &permissions))
+               Object::Ptr object;
+               if (!role->GetProperty(messageType, &object))
                        continue;
 
+               Dictionary::Ptr permissions = dynamic_pointer_cast<Dictionary>(object);
+               if (!permissions)
+                       throw InvalidCastException();
+
                for (DictionaryIterator is = permissions->Begin(); is != permissions->End(); is++) {
                        if (Utility::Match(is->second.GetString(), message))
                                return true;
@@ -396,8 +400,15 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
 
        ConfigObject::Ptr endpointConfig = endpointCollection->GetObject(identity);
        Dictionary::Ptr roles;
-       if (endpointConfig)
-               endpointConfig->GetProperty("roles", &roles);
+       if (endpointConfig) {
+               Object::Ptr object;
+               if (endpointConfig->GetProperty("roles", &object)) {
+                       roles = dynamic_pointer_cast<Dictionary>(object);
+
+                       if (!roles)
+                               throw InvalidCastException();
+               }
+       }
 
        Endpoint::Ptr endpoint = GetEndpointManager()->GetEndpointByIdentity(identity);
 
index 71939675ad28f96d6c89caba6b305ad0b9179ee3..59f046c85c63654ee9f8d19f54ce490df21f55b0 100644 (file)
@@ -92,8 +92,8 @@ public:
        ConstTopicIterator BeginPublications(void) const;
        ConstTopicIterator EndPublications(void) const;
 
-       Event<EventArgs> OnIdentityChanged;
-       Event<EventArgs> OnSessionEstablished;
+       Observable<EventArgs> OnIdentityChanged;
+       Observable<EventArgs> OnSessionEstablished;
 };
 
 }
index d7cd71c224afbc67670540889c058df004d93fc8..f6e322638debbc82a7e8ade2f5d76bca5c59cb01 100644 (file)
@@ -71,7 +71,7 @@ public:
 
        Endpoint::Ptr GetEndpointByIdentity(string identity) const;
 
-       Event<NewEndpointEventArgs> OnNewEndpoint;
+       Observable<NewEndpointEventArgs> OnNewEndpoint;
 };
 
 }
index d36426b09329b680f0d71440cb4dd8eefefa1eee..48e48ab2a4f052be6b51a4c5f75dfe41ae29f860 100644 (file)
@@ -60,7 +60,7 @@ void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const RpcRequest& req
        if (!request.GetMethod(&method))
                return;
 
-       map<string, Event<NewRequestEventArgs> >::iterator i = m_TopicHandlers.find(method);
+       map<string, Observable<NewRequestEventArgs> >::iterator i = m_TopicHandlers.find(method);
 
        if (i == m_TopicHandlers.end())
                return;
index c7774d5560cd5a67927f521e6ccb81d3073cd164..5222502d5e2888c2990fb7f722188b86e92a0923 100644 (file)
@@ -38,7 +38,7 @@ struct I2_ICINGA_API NewRequestEventArgs : public EventArgs
 class I2_ICINGA_API VirtualEndpoint : public Endpoint
 {
 private:
-       map< string, Event<NewRequestEventArgs> > m_TopicHandlers;
+       map< string, Observable<NewRequestEventArgs> > m_TopicHandlers;
 
 public:
        typedef shared_ptr<VirtualEndpoint> Ptr;
index 42dafe9d89e5ecb63b0f492f0809032bf8222808..c240946ad7f0da497c0dea8d2038418ad530a4dc 100644 (file)
@@ -53,7 +53,7 @@ int JsonRpcClient::DataAvailableHandler(const EventArgs&)
                        nea.Message = message;
                        OnNewMessage(nea);
                } catch (const Exception& ex) {
-                       Application::Log("Exception while processing message from JSON-RPC client: " + ex.GetMessage());
+                       Application::Log("Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
                        Close();
 
                        return 1;
index 9f7d242ba221dc73572abbadece5d8617e5e2cd6..07aac91de90061beba02608541f14e7532c3777a 100644 (file)
@@ -46,7 +46,7 @@ public:
 
        virtual void Start(void);
 
-       Event<NewMessageEventArgs> OnNewMessage;
+       Observable<NewMessageEventArgs> OnNewMessage;
 };
 
 TCPClient::Ptr JsonRpcClientFactory(TCPClientRole role, shared_ptr<SSL_CTX> sslContext);
index bd14463267dc0b7885aade30603afde85ac7b8eb..de701dc3fa23588bf2b566a78d70247b54d99908 100644 (file)
@@ -130,10 +130,14 @@ Dictionary::Ptr MessagePart::GetDictionary(void) const
 
 bool MessagePart::GetProperty(string key, MessagePart *value) const
 {
-       Dictionary::Ptr dictionary;
-       if (!GetDictionary()->GetProperty(key, &dictionary))
+       Object::Ptr object;
+       if (GetDictionary()->GetProperty(key, &object))
                return false;
 
+       Dictionary::Ptr dictionary = dynamic_pointer_cast<Dictionary>(object);
+       if (!dictionary)
+               throw InvalidCastException();
+
        *value = MessagePart(dictionary);
        return true;
 }