[PATCH 3/4] [mama] C++ Topic callback wrappers


Ian Bell <IBell@...>
 

From b904d9f1cf6a3e7318a7eb002c985b572322eae4 Mon Sep 17 00:00:00 2001

Message-Id: <b904d9f1cf6a3e7318a7eb002c985b572322eae4.1348732807.git.ibell@...>

In-Reply-To: <b3579c20edd49597fd58e530be463611e61515f0.1348732807.git.ibell@...>

References: <b3579c20edd49597fd58e530be463611e61515f0.1348732807.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Thu, 27 Sep 2012 08:57:51 +0100

Subject: [PATCH 3/4] [mama] C++ Topic callback wrappers

 

Added C++ Toic callback classes

 

Signed-off-by: Ian Bell <ibell@...>

---

mama/c_cpp/src/cpp/MamaTransport.cpp    |   81 ++++++++++++++++++++++++++++++-

mama/c_cpp/src/cpp/mama/MamaTransport.h |   35 +++++++++++++

2 files changed, 115 insertions(+), 1 deletion(-)

 

diff --git a/mama/c_cpp/src/cpp/MamaTransport.cpp b/mama/c_cpp/src/cpp/MamaTransport.cpp

index 62716c3..a6823cd 100644

--- a/mama/c_cpp/src/cpp/MamaTransport.cpp

+++ b/mama/c_cpp/src/cpp/MamaTransport.cpp

@@ -35,6 +35,7 @@ namespace Wombat

         void  setSymbolMap       (const MamaSymbolMap*  map);

         const MamaSymbolMap*     getSymbolMap () const;

+        MamaTransportTopicEventCallback*    myTopicEventCallback;

         MamaTransportCallback*   mCallback;

         const MamaSymbolMap*     mMap;

         bool                     mDeleteCTransport;

@@ -56,6 +57,29 @@ namespace Wombat

     extern "C"

     {

+        void MAMACALLTYPE transportTopicEventCb (mamaTransport tport,

+                                            mamaTransportTopicEvent event,

+                                            const char* topic,

+                                            const void* platformInfo,

+                                            void* closure)

+    {

+        MamaTransport* transport = static_cast<MamaTransport*> (closure);

+

+        switch (event)

+        {

+            case MAMA_TRANSPORT_TOPIC_SUBSCRIBED:

+            transport->mPimpl->myTopicEventCallback->onTopicSubscribe (transport, topic, platformInfo);

+            return;

+            case MAMA_TRANSPORT_TOPIC_UNSUBSCRIBED:

+            transport->mPimpl->myTopicEventCallback->onTopicUnsubscribe (transport, topic, platformInfo);

+            return;

+            default:

+            return;

+        }

+    }

+    }

+    extern "C"

+    {

         void MAMACALLTYPE transportCb (mamaTransport       tport,

                           mamaTransportEvent  ev,

                           short               cause,

@@ -99,6 +123,47 @@ namespace Wombat

         }

     }

+    class TransportTopicTestCallback : public MamaTransportTopicEventCallback

+    {

+    public:

+        TransportTopicTestCallback ( MamaTransportTopicEventCallback* ucallback)

+        {

+            usercallback = ucallback;

+        }

+       

+        virtual ~TransportTopicTestCallback() {}

+

+        void onTopicSubscribe (MamaTransport* tport,

+                               const char* topic,

+                               const void* platformInfo)

+        {

+            try

+            {

+                usercallback->onTopicSubscribe(tport, topic, platformInfo);

+            }

+            catch (...)

+            {

+                fprintf(stderr, "MamaTransportTopicEventCallback onTopicSubscribe, EXCEPTION CAUGHT\n");

+            }   

+        }

+       

+        void onTopicUnsubscribe (MamaTransport* tport,

+                                 const char* topic,

+                                 const void* platformInfo)

+        {

+            try

+            {

+                usercallback->onTopicUnsubscribe(tport, topic, platformInfo);

+            }

+            catch (...)

+            {

+                fprintf(stderr, "MAMATransportTopicEventCallback onTopicUnsubscribe, EXCEPTION CAUGHT\n");

+            }

+        }

+    private:

+      MamaTransportTopicEventCallback* usercallback; 

+

+    };

     class TransportTestCallback : public MamaTransportCallback

     {

     public:

@@ -337,6 +402,19 @@ namespace Wombat

         return quality;

     }

+    void MamaTransport::setTransportTopicCallback (MamaTransportTopicEventCallback* callback)

+    {

+        if (mamaInternal_getCatchCallbackExceptions())

+        {

+            mPimpl->myTopicEventCallback = new TransportTopicTestCallback (callback);

+        }

+        else

+        {

+            mPimpl->myTopicEventCallback = callback;

+        }

+        mamaTry (mamaTransport_setTransportTopicCallback (

+                    mTransport, transportTopicEventCb, this));

+    }

     void MamaTransport::setTransportCallback (MamaTransportCallback* callback)

     {

                   if (mamaInternal_getCatchCallbackExceptions ())

@@ -364,7 +442,8 @@ namespace Wombat

     }

     MamaTransport::MamaTransportImpl::MamaTransportImpl ()

-        : mCallback         (NULL)

+        : myTopicEventCallback  (NULL)

+        , mCallback             (NULL)

         , mMap              (NULL)

         , mDeleteCTransport (true)

     {

diff --git a/mama/c_cpp/src/cpp/mama/MamaTransport.h b/mama/c_cpp/src/cpp/mama/MamaTransport.h

index 95426b3..7022495 100644

--- a/mama/c_cpp/src/cpp/mama/MamaTransport.h

+++ b/mama/c_cpp/src/cpp/mama/MamaTransport.h

@@ -33,6 +33,36 @@ namespace Wombat

     class MamaServerConnection;

     /**

+    * TransportTopicEvent callback

+    */

+

+    class MAMACPPExpDLL MamaTransportTopicEventCallback

+    {

+    public:

+                             virtual ~MamaTransportTopicEventCallback()

+        {

+        };

+        /**

+         * Invoked when a topic is subscribed to.

+         */

+

+        virtual void onTopicSubscribe (MamaTransport* transport,

+                                       const char* topic,

+                                       const void* platformInfo)

+        {

+            return;

+        }

+

+        virtual void onTopicUnsubscribe (MamaTransport* transport,

+                                         const char* topic,

+                                         const void* platformInfo)

+        {

+            return;

+        }

+

+    };

+

+    /**

      * Transport callback.

      */

     class MAMACPPExpDLL MamaTransportCallback

@@ -281,6 +311,11 @@ namespace Wombat

             mamaThrottleInstance instance = MAMA_THROTTLE_DEFAULT);

         /**

+         * Set the transport topic callback

+         */

+

+        void setTransportTopicCallback (MamaTransportTopicEventCallback* callback);

+        /**

          * Set the transport callback.

          */

         void setTransportCallback (

--

1.7.9.5

 




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


Glenn McClements <gmcclements@...>
 

Ian,
What is the purpose of the TransportTopicTestCallback class here?

Glenn 

From: Ian Bell <ibell@...>
Date: Thu, 27 Sep 2012 08:02:32 +0000
To: "openmama-dev@..." <openmama-dev@...>
Subject: [Openmama-dev] [PATCH 3/4] [mama] C++ Topic callback wrappers

From b904d9f1cf6a3e7318a7eb002c985b572322eae4 Mon Sep 17 00:00:00 2001

Message-Id: <b904d9f1cf6a3e7318a7eb002c985b572322eae4.1348732807.git.ibell@...>

In-Reply-To: <b3579c20edd49597fd58e530be463611e61515f0.1348732807.git.ibell@...>

References: <b3579c20edd49597fd58e530be463611e61515f0.1348732807.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Thu, 27 Sep 2012 08:57:51 +0100

Subject: [PATCH 3/4] [mama] C++ Topic callback wrappers

 

Added C++ Toic callback classes

 

Signed-off-by: Ian Bell <ibell@...>

---

mama/c_cpp/src/cpp/MamaTransport.cpp    |   81 ++++++++++++++++++++++++++++++-

mama/c_cpp/src/cpp/mama/MamaTransport.h |   35 +++++++++++++

2 files changed, 115 insertions(+), 1 deletion(-)

 

diff --git a/mama/c_cpp/src/cpp/MamaTransport.cpp b/mama/c_cpp/src/cpp/MamaTransport.cpp

index 62716c3..a6823cd 100644

--- a/mama/c_cpp/src/cpp/MamaTransport.cpp

+++ b/mama/c_cpp/src/cpp/MamaTransport.cpp

@@ -35,6 +35,7 @@ namespace Wombat

         void  setSymbolMap       (const MamaSymbolMap*  map);

         const MamaSymbolMap*     getSymbolMap () const;

+        MamaTransportTopicEventCallback*    myTopicEventCallback;

         MamaTransportCallback*   mCallback;

         const MamaSymbolMap*     mMap;

         bool                     mDeleteCTransport;

@@ -56,6 +57,29 @@ namespace Wombat

     extern "C"

     {

+        void MAMACALLTYPE transportTopicEventCb (mamaTransport tport,

+                                            mamaTransportTopicEvent event,

+                                            const char* topic,

+                                            const void* platformInfo,

+                                            void* closure)

+    {

+        MamaTransport* transport = static_cast<MamaTransport*> (closure);

+

+        switch (event)

+        {

+            case MAMA_TRANSPORT_TOPIC_SUBSCRIBED:

+            transport->mPimpl->myTopicEventCallback->onTopicSubscribe (transport, topic, platformInfo);

+            return;

+            case MAMA_TRANSPORT_TOPIC_UNSUBSCRIBED:

+            transport->mPimpl->myTopicEventCallback->onTopicUnsubscribe (transport, topic, platformInfo);

+            return;

+            default:

+            return;

+        }

+    }

+    }

+    extern "C"

+    {

         void MAMACALLTYPE transportCb (mamaTransport       tport,

                           mamaTransportEvent  ev,

                           short               cause,

@@ -99,6 +123,47 @@ namespace Wombat

         }

     }

+    class TransportTopicTestCallback : public MamaTransportTopicEventCallback

+    {

+    public:

+        TransportTopicTestCallback ( MamaTransportTopicEventCallback* ucallback)

+        {

+            usercallback = ucallback;

+        }

+       

+        virtual ~TransportTopicTestCallback() {}

+

+        void onTopicSubscribe (MamaTransport* tport,

+                               const char* topic,

+                               const void* platformInfo)

+        {

+            try

+            {

+                usercallback->onTopicSubscribe(tport, topic, platformInfo);

+            }

+            catch (...)

+            {

+                fprintf(stderr, "MamaTransportTopicEventCallback onTopicSubscribe, EXCEPTION CAUGHT\n");

+            }   

+        }

+       

+        void onTopicUnsubscribe (MamaTransport* tport,

+                                 const char* topic,

+                                 const void* platformInfo)

+        {

+            try

+            {

+                usercallback->onTopicUnsubscribe(tport, topic, platformInfo);

+            }

+            catch (...)

+            {

+                fprintf(stderr, "MAMATransportTopicEventCallback onTopicUnsubscribe, EXCEPTION CAUGHT\n");

+            }

+        }

+    private:

+      MamaTransportTopicEventCallback* usercallback; 

+

+    };

     class TransportTestCallback : public MamaTransportCallback

     {

     public:

@@ -337,6 +402,19 @@ namespace Wombat

         return quality;

     }

+    void MamaTransport::setTransportTopicCallback (MamaTransportTopicEventCallback* callback)

+    {

+        if (mamaInternal_getCatchCallbackExceptions())

+        {

+            mPimpl->myTopicEventCallback = new TransportTopicTestCallback (callback);

+        }

+        else

+        {

+            mPimpl->myTopicEventCallback = callback;

+        }

+        mamaTry (mamaTransport_setTransportTopicCallback (

+                    mTransport, transportTopicEventCb, this));

+    }

     void MamaTransport::setTransportCallback (MamaTransportCallback* callback)

     {

                   if (mamaInternal_getCatchCallbackExceptions ())

@@ -364,7 +442,8 @@ namespace Wombat

     }

     MamaTransport::MamaTransportImpl::MamaTransportImpl ()

-        : mCallback         (NULL)

+        : myTopicEventCallback  (NULL)

+        , mCallback             (NULL)

         , mMap              (NULL)

         , mDeleteCTransport (true)

     {

diff --git a/mama/c_cpp/src/cpp/mama/MamaTransport.h b/mama/c_cpp/src/cpp/mama/MamaTransport.h

index 95426b3..7022495 100644

--- a/mama/c_cpp/src/cpp/mama/MamaTransport.h

+++ b/mama/c_cpp/src/cpp/mama/MamaTransport.h

@@ -33,6 +33,36 @@ namespace Wombat

     class MamaServerConnection;

     /**

+    * TransportTopicEvent callback

+    */

+

+    class MAMACPPExpDLL MamaTransportTopicEventCallback

+    {

+    public:

+                             virtual ~MamaTransportTopicEventCallback()

+        {

+        };

+        /**

+         * Invoked when a topic is subscribed to.

+         */

+

+        virtual void onTopicSubscribe (MamaTransport* transport,

+                                       const char* topic,

+                                       const void* platformInfo)

+        {

+            return;

+        }

+

+        virtual void onTopicUnsubscribe (MamaTransport* transport,

+                                         const char* topic,

+                                         const void* platformInfo)

+        {

+            return;

+        }

+

+    };

+

+    /**

      * Transport callback.

      */

     class MAMACPPExpDLL MamaTransportCallback

@@ -281,6 +311,11 @@ namespace Wombat

             mamaThrottleInstance instance = MAMA_THROTTLE_DEFAULT);

         /**

+         * Set the transport topic callback

+         */

+

+        void setTransportTopicCallback (MamaTransportTopicEventCallback* callback);

+        /**

          * Set the transport callback.

          */

         void setTransportCallback (

--

1.7.9.5

 




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________ Openmama-dev mailing list Openmama-dev@... https://lists.openmama.org/mailman/listinfo/openmama-dev



Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.