[asterisk-scf-commits] asterisk-scf/release/test_channel.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Jul 13 15:46:15 CDT 2012


branch "master" has been updated
       via  fc30debb96c41343a4ac588ee87b7e6b69cde260 (commit)
      from  3a535448bdb70d4f77e34e7199934655c06619b3 (commit)

Summary of changes:
 src/CMakeLists.txt    |    1 -
 src/ListenerManager.h |  158 -------------------------------------------------
 src/TestEndpoint.cpp  |   33 +++++++---
 3 files changed, 23 insertions(+), 169 deletions(-)
 delete mode 100644 src/ListenerManager.h


- Log -----------------------------------------------------------------
commit fc30debb96c41343a4ac588ee87b7e6b69cde260
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Jul 13 13:18:20 2012 -0500

    ASTSCF-467 Consolidate ListenerManagerT into ASTSCFIceUtilCpp.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3819295..a148f13 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,7 +12,6 @@ astscf_component_add_files(TestChannel MediaSession.h)
 astscf_component_add_files(TestChannel TestEndpoint.cpp)
 astscf_component_add_files(TestChannel TestEndpoint.h)
 astscf_component_add_files(TestChannel Logger.h)
-astscf_component_add_files(TestChannel ListenerManager.h)
 astscf_component_add_files(TestChannel InternalExceptions.h)
 astscf_component_add_ice_libraries(TestChannel IceStorm)
 astscf_component_add_boost_libraries(TestChannel thread date_time)
diff --git a/src/ListenerManager.h b/src/ListenerManager.h
deleted file mode 100644
index 17f3932..0000000
--- a/src/ListenerManager.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Asterisk Scalable Communications Framework
- *
- * Copyright (C) 2010 -- Digium, Inc.
- *
- * All rights reserved.
- */
-#pragma once
-
-#include <Ice/Ice.h>
-#include <IceStorm/IceStorm.h>
-#include <boost/thread/shared_mutex.hpp>
-#include <string>
-#include <algorithm>
-#include <vector>
-#include "InternalExceptions.h"
-
-namespace AsteriskSCF
-{
-namespace TestUtil
-{
-//
-// Helper template for classes that need to implement listener style interfaces.
-//
-template <class T>
-class ListenerManagerT : public IceUtil::Shared
-{
-    typedef std::vector<T> ListenerSeq;
-    typename std::vector<T>::iterator ListenerIter;
-public:
-    ListenerManagerT(const Ice::CommunicatorPtr& communicator, const std::string& topicName) :
-        mCommunicator(communicator),
-        mTopicName(topicName)
-    {
-        //
-        // TODO: While this is being concocted for a single component, it would make more sense
-        // to have the topic manager passed in during construction for more general usage.
-        //
-        const std::string propertyName = "TopicManager.Proxy";
-        std::string topicManagerProperty = mCommunicator->getProperties()->getProperty(propertyName);
-        if(topicManagerProperty.size() == 0)
-        {
-            throw ConfigException(propertyName, "Topic manager proxy property missing. "
-                "Unable to initialize listener support.");
-        }
-
-        try
-        {
-            mTopicManager = IceStorm::TopicManagerPrx::checkedCast(mCommunicator->stringToProxy(topicManagerProperty));
-        }
-        catch(const Ice::Exception&)
-        {
-        }
-        if(!mTopicManager)
-        {
-            throw ConfigException(propertyName, "Topic manager proxy is not a valid proxy or is unreachable");
-        }
-
-        try
-        {
-            mTopic = mTopicManager->retrieve(mTopicName);
-        }
-        catch(const IceStorm::NoSuchTopic&)
-        {
-        }
-
-        if(!mTopic)
-        {
-            try
-            {
-                mTopic = mTopicManager->create(mTopicName);
-            }
-            catch(const IceStorm::TopicExists&)
-            {
-                //
-                // In case there is a race condition when creating the topic.
-                //
-                mTopic = mTopicManager->retrieve(mTopicName);
-            }
-        }
-
-        if(!mTopic)
-        {
-            throw ConfigException(propertyName,
-                std::string("unable to create topic with the provided configuration :") + mTopicName);
-        }
-    }
-
-    virtual ~ListenerManagerT()
-    {
-        if(mTopic)
-        {
-            try
-            {
-                mTopic->destroy();
-            }
-            catch(...)
-            {
-                //
-                // Destructors are no-throw!
-                //
-            }
-        }
-    }
-
-    //
-    // NOTE: The current implementation is a little fast and loose here. Inconsistent conditions
-    // and whatnot are not flagged.
-    //
-    void addListener(const T& listener)
-    {
-        boost::unique_lock<boost::shared_mutex> lock(mLock);
-        if(std::find(mListeners.begin(), mListeners.end(), listener) == mListeners.end())
-        {
-            mListeners.push_back(listener);
-        }
-        IceStorm::QoS qos;
-        qos["reliability"] = "ordered";
-        try
-        {
-            mTopic->subscribeAndGetPublisher(qos, listener);
-        }
-        catch(const IceStorm::AlreadySubscribed&)
-        {
-            //
-            // This indicates some kind of inconsistent state.
-            //
-        }
-    }
-
-    void removeListener(const T& listener)
-    {
-        boost::unique_lock<boost::shared_mutex> lock(mLock);
-        typename std::vector<T>::iterator i = std::find(mListeners.begin(), mListeners.end(), listener);
-        if(i != mListeners.end())
-        {
-            mListeners.erase(i);
-            mTopic->unsubscribe(listener);
-        }
-    }
-
-    std::vector<T> getListeners()
-    {
-        boost::shared_lock<boost::shared_mutex> lock(mLock);
-        std::vector<T> result(mListeners);
-        return result;
-    }
-
-protected:
-    boost::shared_mutex mLock;
-    Ice::CommunicatorPtr mCommunicator;
-    std::string mTopicName;
-    IceStorm::TopicPrx mTopic;
-    IceStorm::TopicManagerPrx mTopicManager;
-    ListenerSeq mListeners;
-};
-}
-}
diff --git a/src/TestEndpoint.cpp b/src/TestEndpoint.cpp
index 98d9d23..58ff0b9 100644
--- a/src/TestEndpoint.cpp
+++ b/src/TestEndpoint.cpp
@@ -15,8 +15,6 @@
  */
 #include "TestEndpoint.h"
 
-#include "ListenerManager.h"
-
 #include <Ice/Ice.h>
 #include <IceUtil/UUID.h>
 
@@ -33,7 +31,7 @@
 #include "MediaSession.h"
 #include <AsteriskSCF/TestChannel/CommandsIf.h>
 #include <AsteriskSCF/Operations/OperationContext.h>
-
+#include <AsteriskSCF/Listener/ListenerManager.h>
 
 using namespace AsteriskSCF::TestUtil;
 using namespace AsteriskSCF::SessionCommunications::V1;
@@ -65,11 +63,11 @@ typedef IceUtil::Handle<InternalManagerIf> InternalManagerPtr;
 // Specialization of ListenerManagerT helper template for SessionListeners. Basically takes care of invoking the
 // appropriate method on a publisher.
 //
-class SessionListenerMgr : public AsteriskSCF::TestUtil::ListenerManagerT<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>
+class SessionListenerMgr : public AsteriskSCF::ListenerManagerT<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>
 {
 public:
-    SessionListenerMgr(const Ice::CommunicatorPtr& communicator, const std::string& topicName) :
-        AsteriskSCF::TestUtil::ListenerManagerT<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>(communicator, topicName)
+    SessionListenerMgr(const IceStorm::TopicManagerPrx& topicManager, const std::string& topicName) :
+        AsteriskSCF::ListenerManagerT<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>(topicManager, topicName, true, IceUtil::Time::seconds(15))
     {
         mPublisher = AsteriskSCF::SessionCommunications::V1::SessionListenerPrx::uncheckedCast(mTopic->getPublisher());
     }
@@ -238,13 +236,17 @@ typedef IceUtil::Handle<TelephonyEventSourceI> TelephonyEventSourceIPtr;
 class SessionI : public AsteriskSCF::SessionCommunications::V1::TelephonySession
 {
 public:
-    SessionI(const InternalManagerPtr& m, const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& prx,  const std::string& id,
-        const Ice::ObjectAdapterPtr& adapter) :
+    SessionI(
+        const InternalManagerPtr& m, 
+        const AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx& prx,  
+        const std::string& id,
+        const Ice::ObjectAdapterPtr& adapter,
+        const IceStorm::TopicManagerPrx& topicManager) :
         mAdapter(adapter),
         mEndpointManager(m),
         mEndpointPrx(prx),
         mId(id),
-        mListeners(new SessionListenerMgr(adapter->getCommunicator(), mId))
+        mListeners(new SessionListenerMgr(topicManager, mId))
     {
         mInfo = new AsteriskSCF::SessionCommunications::V1::SessionInfo;
         mInfo->currentState = "ready";
@@ -611,6 +613,15 @@ public:
         mId(id),
         mDefaultListeners(adapter, "Default Session Listeners")
     {
+        const std::string propertyName = "TopicManager.Proxy";
+        std::string topicManagerProperty = adapter->getCommunicator()->getProperties()->getProperty(propertyName);
+        if(topicManagerProperty.size() == 0)
+        {
+            throw "Topic manager proxy property missing. "
+                "Unable to initialize listener support.";
+        }
+
+        mTopicManager = IceStorm::TopicManagerPrx::checkedCast(adapter->getCommunicator()->stringToProxy(topicManagerProperty));
     }
 
     AsteriskSCF::SessionCommunications::V1::SessionPrx createSession(
@@ -620,11 +631,12 @@ public:
         const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::SessionCreationHookPrx&,
         const Ice::Current& current)
     {
+
         InternalSessionInfo info;
         info.id = mId + "." + destination + "." + IceUtil::generateUUID();
         info.servant = new SessionI(this,
             AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx::checkedCast(current.adapter->createProxy(current.id)),
-            info.id, current.adapter);
+            info.id, current.adapter, mTopicManager);
         info.session =  AsteriskSCF::SessionCommunications::V1::SessionPrx::checkedCast(current.adapter->add(info.servant, current.adapter->getCommunicator()->stringToIdentity(info.id)));
         info.servant->setProxy(info.session);
         boost::unique_lock<boost::shared_mutex> lock(mMutex);
@@ -800,6 +812,7 @@ private:
     Ice::ObjectAdapterPtr mAdapter;
     std::string mId;
     AsteriskSCF::Collections::ProxySet<SessionListenerPrx> mDefaultListeners;
+    IceStorm::TopicManagerPrx mTopicManager;
 };
 
 class CommandImpl : public AsteriskSCF::TestChannel::V1::Commands

-----------------------------------------------------------------------


-- 
asterisk-scf/release/test_channel.git



More information about the asterisk-scf-commits mailing list