[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "replication-new" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Jan 21 13:45:55 CST 2011


branch "replication-new" has been updated
       via  4e2b7a05462d2342f7ab9178385b2245fd152a46 (commit)
      from  aa7bb69a4f986fa9eb7fb5ec59e4da12d1d33a67 (commit)

Summary of changes:
 src/RtpStateReplicatorListener.cpp |   72 +++++++++++++++++++++---------------
 1 files changed, 42 insertions(+), 30 deletions(-)


- Log -----------------------------------------------------------------
commit 4e2b7a05462d2342f7ab9178385b2245fd152a46
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Jan 21 13:45:15 2011 -0600

    Update to use visitor pattern for processing RtpStateReplicatorItem objects.
    
    Add 'using namespace std;' and remove explicit references to 'std::'.

diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index 58da256..35f490d 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -30,6 +30,7 @@
 #include "RTPSink.h"
 #include "RTPSource.h"
 
+using namespace std;
 using namespace AsteriskSCF::Media::RTP::V1;
 
 class RtpStateReplicatorItem
@@ -67,29 +68,34 @@ public:
     }
     void setStateNoticeImpl(const RtpStateItemSeq& items)
     {
-        for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
-        {
-            std::map<std::string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = mStateItems.find((*item)->mSessionId);
-	    RtpGeneralStateItemPtr general;
-	    RtpSessionStateItemPtr session;
-	    RtpStreamSinkStateItemPtr sink;
-	    RtpStreamSourceStateItemPtr source;
-	    boost::shared_ptr<RtpStateReplicatorItem> localitem;
-
-	    if ((general = RtpGeneralStateItemPtr::dynamicCast((*item))))
+	class visitor : public AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor
+	{
+	public:
+	visitor(RtpStateReplicatorListenerImpl *impl) : impl(impl)
 	    {
-		mGeneralState->mServiceManagement = general->mServiceManagement;
 	    }
-	    else if ((session = RtpSessionStateItemPtr::dynamicCast((*item))))
+
+	private:
+	    RtpStateReplicatorListenerImpl *impl;
+
+	    void visitGeneral(const RtpGeneralStateItemPtr &item, const Ice::Current &)
 	    {
-		if (i == mStateItems.end())
+		impl->mGeneralState->mServiceManagement = item->mServiceManagement;
+	    }
+		    
+	    void visitSession(const RtpSessionStateItemPtr &item, const Ice::Current &)
+	    {
+		map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+		boost::shared_ptr<RtpStateReplicatorItem> localitem;
+
+		if (i == impl->mStateItems.end())
 		{
 		    boost::shared_ptr<RtpStateReplicatorItem> newitem(new RtpStateReplicatorItem());
 		    localitem = newitem;
-		    mStateItems.insert(std::make_pair<std::string, boost::shared_ptr<RtpStateReplicatorItem> >((*item)->mSessionId, newitem));
+		    impl->mStateItems.insert(make_pair<string, boost::shared_ptr<RtpStateReplicatorItem> >(item->mSessionId, newitem));
 
-		    RTPSessionImplPtr localSession = new RTPSessionImpl(mAdapter, mPoolFactory, session->mSessionIdentity, session->mSinkIdentity,
-			session->mSourceIdentity, session->mPort, session->mFormats);
+		    RTPSessionImplPtr localSession = new RTPSessionImpl(impl->mAdapter, impl->mPoolFactory, item->mSessionIdentity, item->mSinkIdentity,
+			item->mSourceIdentity, item->mPort, item->mFormats);
 		    localitem->setSession(localSession);
 		}
 		else
@@ -97,31 +103,37 @@ public:
 		    localitem = i->second;
 		}
 
-	        localitem->getSession()->associatePayloads(session->mPayloadstoFormats, Ice::Current());
+	        localitem->getSession()->associatePayloads(item->mPayloadstoFormats, Ice::Current());
 	    }
-	    else if ((sink = RtpStreamSinkStateItemPtr::dynamicCast((*item))))
+		    
+	    void visitStreamSink(const RtpStreamSinkStateItemPtr &item, const Ice::Current &)
 	    {
-		if (i == mStateItems.end())
+		map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+		if (i != impl->mStateItems.end())
 		{
-		    continue;
+		    i->second->getSession()->getSink()->setSource(item->mSource, Ice::Current());
+		    i->second->getSession()->getSink()->setRemoteDetails(item->mRemoteAddress, item->mRemotePort, Ice::Current());
 		}
-
-		i->second->getSession()->getSink()->setSource(sink->mSource, Ice::Current());
-		i->second->getSession()->getSink()->setRemoteDetails(sink->mRemoteAddress, sink->mRemotePort, Ice::Current());
 	    }
-	    else if ((source = RtpStreamSourceStateItemPtr::dynamicCast((*item))))
+		    
+	    void visitStreamSource(const RtpStreamSourceStateItemPtr &item, const Ice::Current &)
 	    {
-		if (i == mStateItems.end())
+		map<string, boost::shared_ptr<RtpStateReplicatorItem> >::iterator i = impl->mStateItems.find(item->mSessionId);
+		if (i != impl->mStateItems.end())
 		{
-		    continue;
+		    i->second->getSession()->getSource()->setSink(item->mSink, Ice::Current());
 		}
-
-		i->second->getSession()->getSource()->setSink(source->mSink, Ice::Current());
 	    }
+	} v(this);
+
+        for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
+        {
+	    (*item)->visit(&v);
         }
     }
-    std::string mId;
-    std::map<std::string, boost::shared_ptr<RtpStateReplicatorItem> > mStateItems;
+
+    string mId;
+    map<string, boost::shared_ptr<RtpStateReplicatorItem> > mStateItems;
     Ice::ObjectAdapterPtr mAdapter;
     pj_pool_factory *mPoolFactory;
     RtpGeneralStateItemPtr mGeneralState;

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


-- 
asterisk-scf/integration/media_rtp_pjmedia.git



More information about the asterisk-scf-commits mailing list