[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "replication-visitor" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Sun Dec 26 19:02:28 UTC 2010


branch "replication-visitor" has been created
        at  2dfff43d9914d8a460f57a4b863dcf6fe6d844aa (commit)

- Log -----------------------------------------------------------------
commit 2dfff43d9914d8a460f57a4b863dcf6fe6d844aa
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Sun Dec 26 13:02:02 2010 -0600

    Example of using Visitor pattern to process RTPStateItem objects.

diff --git a/local-slice/RtpStateReplicationIf.ice b/local-slice/RtpStateReplicationIf.ice
index b449ee5..aed5cf4 100644
--- a/local-slice/RtpStateReplicationIf.ice
+++ b/local-slice/RtpStateReplicationIf.ice
@@ -42,10 +42,13 @@ module V1
       string mName;
    };
 
+   local interface RtpStateItemVisitor;
+
    class RtpStateItem
    {
       string key;
       string mSessionId;
+      /* local void visit(RtpStateItemVisitor *visitor) ;*/
    };
 
    sequence<RtpStateItem> RtpStateItemSeq;
@@ -93,6 +96,20 @@ module V1
        AsteriskSCF::Media::V1::StreamSink *mSink;
    };
 
+/*
+  Cannot use this method yet because the member function
+  signatures are written to accept proxy pointers to the
+  concrete class objects, not local object pointers
+
+   local interface RtpStateItemVisitor
+   {
+       void visitGeneral(RtpGeneralStateItem *item);
+       void visitSession(RtpSessionStateItem *item);
+       void visitStreamSink(RtpStreamSinkStateItem *item);
+       void visitStreamSource(RtpStreamSourceStateItem *item);
+   };
+*/
+
 }; //module V1
 
 }; //module RTP
diff --git a/test/TestRTPpjmedia.cpp b/test/TestRTPpjmedia.cpp
index 3951eb5..f838127 100644
--- a/test/TestRTPpjmedia.cpp
+++ b/test/TestRTPpjmedia.cpp
@@ -72,31 +72,80 @@ void TestRtpReplicatorListener::stateRemoved(const Ice::StringSeq& items, const
 {
 }
 
+// this interface should be written by the Slice translator,
+// but can't be currently
+struct AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor
+{
+public:
+    virtual void visitGeneral(RtpGeneralStateItemPtr item) = 0;
+    virtual void visitSession(RtpSessionStateItemPtr item) = 0;
+    virtual void visitStreamSink(RtpStreamSinkStateItemPtr item) = 0;
+    virtual void visitStreamSource(RtpStreamSourceStateItemPtr item) = 0;
+};
+
+// these visitor functions are also common to all users of the
+// interface above, but the translator can't write them
+void AsteriskSCF::Media::RTP::V1::RtpStateItem::visit(RtpStateItemVisitorPtr visitor)
+{
+// nothing to do for unsupported state items
+}
+
+void AsteriskSCF::Media::RTP::V1::RtpGeneralStateItem::visit(RtpStateItemVisitorPtr visitor)
+{
+    visitor->visitGeneral(this);
+}
+
+void AsteriskSCF::Media::RTP::V1::RtpSessionStateItem::visit(RtpStateItemVisitorPtr visitor)
+{
+    visitor->visitSession(this);
+}
+
+void AsteriskSCF::Media::RTP::V1::RtpStreamSinkStateItem::visit(RtpStateItemVisitorPtr visitor)
+{
+    visitor->visitStreamSink(this);
+}
+
+void AsteriskSCF::Media::RTP::V1::RtpStreamSourceStateItem::visit(RtpStateItemVisitorPtr visitor)
+{
+    visitor->visitStreamSource(this);
+}
+
 void TestRtpReplicatorListener::stateSet(const RtpStateItemSeq& items, const Ice::Current&)
 {
-    for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
+    class visitor : public AsteriskSCF::Media::RTP::V1::RtpStateItemVisitor
     {
-	RtpGeneralStateItemPtr general;
-	RtpSessionStateItemPtr session;
-	RtpStreamSinkStateItemPtr sink;
-	RtpStreamSourceStateItemPtr source;
+    public:
+        visitor(TestRtpReplicatorListener *listener) : listener(listener)
+	{
+	}
 
-        if ((general = RtpGeneralStateItemPtr::dynamicCast((*item))))
-        {
-	    mGeneral = general;
-        }
-	else if ((session = RtpSessionStateItemPtr::dynamicCast((*item))))
+    private:
+	TestRtpReplicatorListener *listener;
+
+	void visitGeneral(RtpGeneralStateItemPtr item)
 	{
-	    mSession = session;
+            listener->mGeneral = item;
 	}
-	else if ((sink = RtpStreamSinkStateItemPtr::dynamicCast((*item))))
+
+	void visitSession(RtpSessionStateItemPtr item)
+	{
+            listener->mSession = item;
+	}
+
+	void visitStreamSink(RtpStreamSinkStateItemPtr item)
 	{
-	    mSink = sink;
+            listener->mSink = item;
 	}
-	else if ((source = RtpStreamSourceStateItemPtr::dynamicCast((*item))))
+
+	void visitStreamSource(RtpStreamSourceStateItemPtr item)
 	{
-	    mSource = source;
+            listener->mSource = item;
 	}
+    } v(this);
+
+    for (RtpStateItemSeq::const_iterator item = items.begin(); item != items.end(); ++item)
+    {
+        (*item)->visit(&v);
     }
 }
 

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


-- 
asterisk-scf/integration/media_rtp_pjmedia.git



More information about the asterisk-scf-commits mailing list