[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "route_replica" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Apr 25 16:59:02 CDT 2011


branch "route_replica" has been updated
       via  1b336916985b349d629b0366bfb015ca45ddd038 (commit)
       via  ea2ec1b0da2d8df32c1aa74894d7f2f3dd459479 (commit)
       via  d9a750b47cca21090c89a702c18f0e7484fd06ce (commit)
       via  a7721c5453e659ac841b63cbfe5ef76cdbe9ecba (commit)
       via  e8001bdd50f0847b886fa85544e5be4ce85292c5 (commit)
       via  ff03bb063c8737d5ed3dbb31372269be9080fb1c (commit)
       via  2d86b6396e8ae2eee499da8995994e887701d93d (commit)
       via  cf2f9b9ada6a587a0cb2926c6c5d594eba26be76 (commit)
      from  ac6533138755e6ed1962dc1639705ccd9153fb2a (commit)

Summary of changes:
 AmiCollector/test/TestAmiCollector.h               |    4 +-
 SmartProxy/include/AsteriskSCF/SmartProxy.h        |   50 +++++++------------
 .../include/AsteriskSCF/StateReplicator.h          |    2 +-
 TestFixture/include/AsteriskSCF/IceBoxBoostTest.h  |    2 +-
 4 files changed, 23 insertions(+), 35 deletions(-)


- Log -----------------------------------------------------------------
commit 1b336916985b349d629b0366bfb015ca45ddd038
Merge: ea2ec1b ac65331
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Apr 25 16:58:26 2011 -0500

    Merge branch 'route_replica' of gitdepot:asterisk-scf/integration/ice-util-cpp into route_replica


commit ea2ec1b0da2d8df32c1aa74894d7f2f3dd459479
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Apr 25 10:32:59 2011 -0500

    Make one-way calls to listeners.

diff --git a/StateReplicator/include/AsteriskSCF/StateReplicator.h b/StateReplicator/include/AsteriskSCF/StateReplicator.h
index e302539..8cfd691 100644
--- a/StateReplicator/include/AsteriskSCF/StateReplicator.h
+++ b/StateReplicator/include/AsteriskSCF/StateReplicator.h
@@ -72,7 +72,8 @@ public:
         {
             try
             {
-                x->stateSet(mStateSeq);
+                T listenerOneWay = T::uncheckedCast(x->ice_oneway());
+                listenerOneWay->stateSet(mStateSeq);
             }
             catch(const Ice::Exception&)
             {
@@ -97,7 +98,8 @@ public:
         {
             try
             {
-                x->stateRemoved(mKeys);
+                T listenerOneWay = T::uncheckedCast(x->ice_oneway());
+                listenerOneWay->stateRemoved(mKeys);
             }
             catch(const Ice::Exception&)
             {
@@ -122,7 +124,8 @@ public:
         {
             try
             {
-                x->stateRemovedForItems(mStateSeq);
+                T listenerOneWay = T::uncheckedCast(x->ice_oneway());
+                listenerOneWay->stateRemovedForItems(mStateSeq);
             }
             catch(const Ice::Exception&)
             {
@@ -174,7 +177,8 @@ public:
         boost::shared_lock<boost::shared_mutex> lock(mStateLock);
         try
         {
-            listener->stateSet(mStateItems);
+            L listenerOneWay = L::uncheckedCast(listener->ice_oneway());
+            listenerOneWay->stateSet(mStateItems);
         }
         catch(const Ice::Exception&)
         {

commit d9a750b47cca21090c89a702c18f0e7484fd06ce
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Mon Apr 18 22:23:49 2011 -0500

    Added support for removing state by items rather than just string ids to allow visitors in remove implementations.

diff --git a/StateReplicator/include/AsteriskSCF/StateReplicator.h b/StateReplicator/include/AsteriskSCF/StateReplicator.h
index 6ecebce..e302539 100644
--- a/StateReplicator/include/AsteriskSCF/StateReplicator.h
+++ b/StateReplicator/include/AsteriskSCF/StateReplicator.h
@@ -37,7 +37,8 @@ namespace StateReplication
  void addListener(TestStateReplicatorListener *listener);
  void removeListener(TestStateReplicatorListener *listener);
  void setState (FooStateItemSeq items);
- void removeState(FooKeySeq items);
+ void removeState(FooKeySeq items);       // deprecated
+ void removeStateForItems(FooStateItemSeq items);
  idempotent TestStateItemSeq getState(FooKeySeq itemKeys);
  idempotent TestStateItemSeq getAllState();
  };
@@ -45,7 +46,8 @@ namespace StateReplication
  The Listener should implement (at a minimum) these operations:
  interface FooStateReplicatorListener
  {
- void stateRemoved(FooKeySeq itemKeys);
+ void stateRemoved(FooKeySeq itemKeys); // deprecated 
+ void stateRemovedForItems(FooStateItemSeq items);
  void stateSet(FooStateItemSeq items);
  };
 
@@ -83,14 +85,14 @@ public:
     };
 
     /**
-     * Functor for forwarding removeState() notices.
+     * Functor for forwarding removeStateByKey() notices.
      */
-    template<typename T, typename V> class RemoveStateNotice
+    template<typename T, typename V> class RemoveStateByKeyNotice
     {
         // Types: T - Listener type, V - Key Item seq.
     public:
-        RemoveStateNotice(const V& keys) : mKeys(keys) {}
-        ~RemoveStateNotice() {}
+        RemoveStateByKeyNotice(const V& keys) : mKeys(keys) {}
+        ~RemoveStateByKeyNotice() {}
         void operator() (T x)
         {
             try
@@ -108,6 +110,31 @@ public:
     };
 
     /**
+     * Functor for forwarding removeState() notices.
+     */
+    template<typename T, typename U> class RemoveStateNotice
+    {
+        // Types: T - Listener type, U - State Item seq.
+    public:
+        RemoveStateNotice(const U& stateSeq) : mStateSeq(stateSeq) {}
+        ~RemoveStateNotice() {}
+        void operator() (T x)
+        {
+            try
+            {
+                x->stateRemovedForItems(mStateSeq);
+            }
+            catch(const Ice::Exception&)
+            {
+            }
+            catch(...)
+            {
+            }
+        }
+        U mStateSeq;
+    };
+
+    /**
      * Functor to use as find_if predicate.
      */
     template<typename T> class IdentifyListener
@@ -186,19 +213,16 @@ public:
      */
     void clearState()
     {
-        std::vector<K> allIds;
+        std::vector<S> items;
 
         {   // critical scope
             boost::unique_lock<boost::shared_mutex> lock(mStateLock);
-            for(typename std::vector<S>::const_iterator it = mStateItems.begin(); it != mStateItems.end(); ++it)
-            {
-                allIds.push_back((*it)->key);
-            }
+            items = mStateItems;
             mStateItems.clear();
         }
 
         boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
-        for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<K> >(allIds));
+        for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<S> >(items));
     }
 
     /**
@@ -231,7 +255,7 @@ public:
     }
 
     /**
-     * Remove the specified state variables, and notify listeners.
+     * Remove specified state variables identified by the specified keys, and notify listeners.
      * @Override
      */
     void removeState(const std::vector<K>& ids, const Ice::Current& = ::Ice::Current())
@@ -251,7 +275,32 @@ public:
         }
 
         boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
-        for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<K> >(ids));
+        for_each(mListeners.begin(), mListeners.end(), RemoveStateByKeyNotice<L,std::vector<K> >(ids));
+    }
+
+    /**
+     * Remove state variables, and notify listeners. 
+     * The item's key is used to identify the item to remove. Any other field is ignored. 
+     * @Override
+     */
+    void removeStateForItems(const std::vector<S>& items, const Ice::Current& = ::Ice::Current())
+    {
+        {   // critical scope
+            boost::unique_lock<boost::shared_mutex> lock(mStateLock);
+
+            for (typename std::vector<S>::const_iterator itemIter = items.begin(); itemIter != items.end(); ++itemIter)
+            {
+                typename std::vector<S>::iterator locateIt = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >((*itemIter)->key));
+
+                if (locateIt != mStateItems.end())
+                {
+                    mStateItems.erase(locateIt);
+                }
+            }
+        }
+
+        boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
+        for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<S> >(items));
     }
 
     /**
diff --git a/StateReplicator/test/MockStateReplicatorListener.h b/StateReplicator/test/MockStateReplicatorListener.h
index 33dba6d..e91da85 100644
--- a/StateReplicator/test/MockStateReplicatorListener.h
+++ b/StateReplicator/test/MockStateReplicatorListener.h
@@ -23,10 +23,19 @@ namespace AsteriskSCF
 namespace StateReplicatorTest
 {
 
+class MatchItem
+{
+public:
+    MatchItem(const std::string& key) : mKey(key) {}
+    ~MatchItem() {}
+    bool operator() (const ::AsteriskSCF::StateReplicatorTest::V1::TestStateItemPtr& x) {return (x->key == mKey); }
+    std::string mKey;
+};
+
 class MockStateReplicatorListenerImpl : public AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListener
 {
 public:
-    MockStateReplicatorListenerImpl() : mRemoveStateCalled(false), mSetStateCalled(true)
+    MockStateReplicatorListenerImpl() : mRemoveStateCalled(false), mRemoveStateForItemsCalled(false), mSetStateCalled(true)
     {
     }
 
@@ -34,6 +43,16 @@ public:
     {
         mItemKeys = itemKeys;
         mRemoveStateCalled = true;
+
+        removeByKeys(itemKeys);
+    }
+
+    void stateRemovedForItems(const ::AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq& items,  const ::Ice::Current& )
+    {
+        mRemoveItems = items;
+        mRemoveStateForItemsCalled = true;
+
+        removeByItems(items);
     }
 
     void stateSet(const ::AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq& items, const ::Ice::Current& )
@@ -45,15 +64,45 @@ public:
     void reset()
     {
         mRemoveStateCalled = false;
+        mRemoveStateForItemsCalled = false;
         mSetStateCalled = false;
         mStateItems.clear();
         mItemKeys.clear();
+        mRemoveItems.clear();
+    }
+
+    void removeByKeys(const ::Ice::StringSeq& itemKeys)
+    {
+        for (::Ice::StringSeq::const_iterator keyIter = itemKeys.begin(); keyIter != itemKeys.end(); ++keyIter)
+        {
+            ::AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq::iterator locateIt = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem(*keyIter));
+
+            if (locateIt != mStateItems.end())
+            {
+                mStateItems.erase(locateIt);
+            }
+        }
+    }
+
+    void removeByItems(const ::AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq& itemSeq)
+    {
+        for (::AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq::const_iterator itemIter = itemSeq.begin(); itemIter != itemSeq.end(); ++itemIter)
+        {
+            ::AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq::iterator locateIt = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem((*itemIter)->key));
+
+            if (locateIt != mStateItems.end())
+            {
+                mStateItems.erase(locateIt);
+            }
+        }
     }
 
 public:
     bool mRemoveStateCalled;
+    bool mRemoveStateForItemsCalled;
     bool mSetStateCalled;
     AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq mStateItems;
+    AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq mRemoveItems;
     Ice::StringSeq mItemKeys;
 };
 typedef ::IceInternal::ProxyHandle<MockStateReplicatorListenerImpl> MockStateReplicatorListenerImplPrx;
diff --git a/StateReplicator/test/TestStateReplicator.cpp b/StateReplicator/test/TestStateReplicator.cpp
index 6058916..13d712e 100644
--- a/StateReplicator/test/TestStateReplicator.cpp
+++ b/StateReplicator/test/TestStateReplicator.cpp
@@ -215,7 +215,6 @@ public:
  */
 BOOST_AUTO_TEST_CASE(AddRemoveListeners)
 {
-    bool addListenerSucceeded(true);
     try
     {
         SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener1Prx);
@@ -223,14 +222,11 @@ BOOST_AUTO_TEST_CASE(AddRemoveListeners)
     }
     catch (...)
     {
-        addListenerSucceeded = false;
-        BOOST_TEST_MESSAGE("Exception adding Listeners.");
+        BOOST_FAIL("Exception adding Listeners.");
     }
 
-    BOOST_CHECK(addListenerSucceeded);
     BOOST_CHECK(SharedTestData::instance.mTestReplicatorImplPtr->getListenerCount() == 2);
 
-    bool removeListenerSucceeded(true);
     try
     {
         SharedTestData::instance.mTestStateReplicatorPrx->removeListener(SharedTestData::instance.mTestStateListener1Prx);
@@ -238,10 +234,8 @@ BOOST_AUTO_TEST_CASE(AddRemoveListeners)
     }
     catch (...)
     {
-        removeListenerSucceeded = false;
-        BOOST_TEST_MESSAGE("Exception removing Listener.");
+        BOOST_FAIL("Exception removing Listener.");
     }
-    BOOST_CHECK(removeListenerSucceeded);
     BOOST_CHECK(SharedTestData::instance.mTestReplicatorImplPtr->getListenerCount() == 0);
 
 
@@ -256,20 +250,16 @@ BOOST_FIXTURE_TEST_CASE(PushData, PerTestFixture)
     try
     {
         SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
-
     }
     catch(const IceUtil::Exception &ie)
     {
-        bool IceException(false);
         string msg = "Exception pushing state data.";
         msg += ie.what();
-        BOOST_TEST_MESSAGE(msg);
-        BOOST_CHECK(IceException);
+        BOOST_FAIL(msg);
     }
     catch (...)
     {
-        bool unknownException(false);
-        BOOST_CHECK(unknownException);
+        BOOST_FAIL("Unknown exception.");
     }
 
     BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mStateItems.size() == 3);
@@ -301,16 +291,13 @@ BOOST_FIXTURE_TEST_CASE(ForwardRemoveState, PerTestFixture)
     }
     catch(const IceUtil::Exception &ie)
     {
-        bool IceException(false);
         string msg = "Exception removing state data.";
         msg += ie.what();
-        BOOST_TEST_MESSAGE(msg);
-        BOOST_CHECK(IceException);
+        BOOST_FAIL(msg);
     }
     catch (...)
     {
-        bool unknownException(false);
-        BOOST_CHECK(unknownException);
+        BOOST_FAIL("Unknown exception.");
     }
 
     BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mItemKeys.size() == 2);
diff --git a/StateReplicator/testslice/StateReplicatorTestIf.ice b/StateReplicator/testslice/StateReplicatorTestIf.ice
index 6288901..bd54489 100644
--- a/StateReplicator/testslice/StateReplicatorTestIf.ice
+++ b/StateReplicator/testslice/StateReplicatorTestIf.ice
@@ -34,6 +34,7 @@ module V1
    interface TestStateReplicatorListener
    {
       void stateRemoved(Ice::StringSeq itemKeys);
+	  void stateRemovedForItems(TestStateItemSeq items);
 	  void stateSet(TestStateItemSeq items);
    };
 
@@ -42,7 +43,8 @@ module V1
       void addListener(TestStateReplicatorListener *listener);
 	  void removeListener(TestStateReplicatorListener *listener);
 	  void setState (TestStateItemSeq items);
-	  void removeState(Ice::StringSeq items);
+	  void removeState(Ice::StringSeq itemKeys);
+	  void removeStateForItems(TestStateItemSeq items);
 	  idempotent TestStateItemSeq getState(Ice::StringSeq itemKeys);
 	  idempotent TestStateItemSeq getAllState();
    };

commit a7721c5453e659ac841b63cbfe5ef76cdbe9ecba
Author: Brent Eagles <beagles at digium.com>
Date:   Fri Apr 22 16:51:52 2011 -0230

    Moved the initialize call into the public scope to address a routing service
    build error.  It has "at most once" semantics for successful initialization
    that the initializeOnce method that was recently removed had so it should
    behave in a similar fashion and thanks to the overloaded operators on proxies
    can be used as an accessor or boolean test.

diff --git a/SmartProxy/include/AsteriskSCF/SmartProxy.h b/SmartProxy/include/AsteriskSCF/SmartProxy.h
index 50463e9..3ee09ce 100644
--- a/SmartProxy/include/AsteriskSCF/SmartProxy.h
+++ b/SmartProxy/include/AsteriskSCF/SmartProxy.h
@@ -106,7 +106,6 @@ public:
         return mProxy != 0;
     }
 
-private:
     /**
      * Initialization. Primarily involves acquring access to specific IceStorm
      * topic.
@@ -163,6 +162,8 @@ private:
         return mProxy;
     }
 
+private:
+
     void copy(const SmartProxy &rhs)
     {
         // thread safe

commit e8001bdd50f0847b886fa85544e5be4ce85292c5
Author: Brent Eagles <beagles at digium.com>
Date:   Fri Apr 22 15:15:37 2011 -0230

    Merged branch smartproxy-threadsafety-update. Includes changes that:
    
     * Change catch block to catch only those exceptions that should result in
       retrying the locate call.
    
     * Modified initialization and the reference operator to be more consistent
       if multiple threads invoke the assignment and reference operators concurrently.

diff --git a/SmartProxy/include/AsteriskSCF/SmartProxy.h b/SmartProxy/include/AsteriskSCF/SmartProxy.h
index 27b8961..50463e9 100644
--- a/SmartProxy/include/AsteriskSCF/SmartProxy.h
+++ b/SmartProxy/include/AsteriskSCF/SmartProxy.h
@@ -67,17 +67,18 @@ public:
         initialize();
     }
 
-    P& operator->()
+    P operator->()
     {
         // everything this calls is thread safe.  no need to lock.
         assert(mServiceLocator && mLocatorParams);
 
-        if (!initializeOnce())
+        P t = initialize();
+        if (!t)
         {
             throw AsteriskSCF::Core::Discovery::V1::ServiceNotFound();
         }
 
-        return mProxy;
+        return t;
     }
 
     SmartProxy &operator=(const SmartProxy &rhs)
@@ -105,51 +106,36 @@ public:
         return mProxy != 0;
     }
 
-    /**
-     * Initializes this SmartProxy, but only if it hasn't already been
-     * initialized.
-     *
-     * @return True if initialization successful; false if unsuccessful.
-     */
-    bool initializeOnce()
-    {
-        // isInitialized() and initialize() are thread safe.  no need to lock
-        if (isInitialized())
-        {
-            return true;
-        }
-
-        // Try again to initialize.
-        initialize();
-        return isInitialized();
-    }
-
 private:
     /**
      * Initialization. Primarily involves acquring access to specific IceStorm
      * topic.
      */
-    void initialize()
+    P initialize()
     {
         // thread safe
         IceUtil::Mutex::Lock myLock(mMutex);
-
+        if (mProxy)
+        {
+            return mProxy;
+        }
+            
         using namespace AsteriskSCF::System::Logging;
         if (!mServiceLocator)
         {
             // uninitialized; probably no logger setup yet, either
             std::clog << "Missing ServiceLocator proxy.  Cannot initialize.\n";
-            return;
+            return 0;
         }
-
+            
         // all paths to set mServiceLocator also set mLogger.
         // but just in case things change in the future...
         assert(mLogger);
-
+            
         if (!mLocatorParams)
         {
             (*mLogger)(Error) << "Cannot find service with null parameters";
-            return;
+            return 0;
         }
 
         try
@@ -163,17 +149,18 @@ private:
                                   << ") isn't of expected type";
             }
         }
-        catch (const Ice::Exception &e)
+        catch (const Ice::SyscallException& e)
         {
             (*mLogger)(Error) << "Exception locating "
                               << mLocatorParams->category << ": " << e.what();
-            return;
+            return 0;
         }
 
         if (mProxy == 0)
         {
             (*mLogger)(Error) << "Unable to locate " << mLocatorParams->category;
         }
+        return mProxy;
     }
 
     void copy(const SmartProxy &rhs)

commit ff03bb063c8737d5ed3dbb31372269be9080fb1c
Author: David M. Lee <dlee at digium.com>
Date:   Fri Apr 15 15:21:08 2011 -0500

    Fixed warning about size_t/int conversion.

diff --git a/TestFixture/include/AsteriskSCF/IceBoxBoostTest.h b/TestFixture/include/AsteriskSCF/IceBoxBoostTest.h
index 46fef08..475d695 100644
--- a/TestFixture/include/AsteriskSCF/IceBoxBoostTest.h
+++ b/TestFixture/include/AsteriskSCF/IceBoxBoostTest.h
@@ -61,7 +61,7 @@ public:
 
         IceBoxTestEnv.communicator = communicator;
         IceBoxTestEnv.serviceName = name;
-        IceBoxTestEnv.argc = argv.size() - 1;
+        IceBoxTestEnv.argc = static_cast<int>(argv.size()) - 1;
         IceBoxTestEnv.argv = (char**)&argv[0];
 
         int r = ::boost::unit_test::unit_test_main(&init_unit_test, IceBoxTestEnv.argc, IceBoxTestEnv.argv);

commit 2d86b6396e8ae2eee499da8995994e887701d93d
Merge: d44d47a cf2f9b9
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Apr 15 12:18:38 2011 -0500

    Merge branch 'master' of git.asterisk.org:asterisk-scf/release/ice-util-cpp into test-utf


commit cf2f9b9ada6a587a0cb2926c6c5d594eba26be76
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Thu Apr 14 13:25:27 2011 -0500

    Minor fixes for various code constructs that trip up GCC with new warning
    options enabled (-Wextra, -Wconversion, -Wformat, and others).

diff --git a/AmiCollector/test/TestAmiCollector.h b/AmiCollector/test/TestAmiCollector.h
index b714f13..41fae09 100644
--- a/AmiCollector/test/TestAmiCollector.h
+++ b/AmiCollector/test/TestAmiCollector.h
@@ -59,11 +59,11 @@ public:
 
 protected:
     ~TestAmiCollector() {}
-    void processResult(AsyncResultType result)
+    void processResult(AsyncResultType)
     {
         ++results;
     }
-    void processException(const Ice::Exception& e)
+    void processException(const Ice::Exception&)
     {
         ++exceptions;
     }
diff --git a/StateReplicator/include/AsteriskSCF/StateReplicator.h b/StateReplicator/include/AsteriskSCF/StateReplicator.h
index 425d2fb..6ecebce 100644
--- a/StateReplicator/include/AsteriskSCF/StateReplicator.h
+++ b/StateReplicator/include/AsteriskSCF/StateReplicator.h
@@ -291,7 +291,7 @@ public:
     /**
      * Returns the number of listeners currently registered with this replicator.
      */
-    int getListenerCount()
+    typename std::vector<L>::size_type getListenerCount()
     {
         boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
         return mListeners.size();

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


-- 
asterisk-scf/integration/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list