[asterisk-scf-commits] team/dlee/servicediscovery.git branch "ami" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Dec 1 13:31:33 CST 2010


branch "ami" has been updated
       via  923d41eba94771e3b06f70e3377d80616764ad4e (commit)
       via  a635a2ab72376fb2e89a84122faf007bdab5a139 (commit)
       via  30c86cadeef19796f48b08c667d22bbae85595aa (commit)
       via  58a220a5358da8cee5f0ae1de995c264a1d61d65 (commit)
      from  4e2fc7fe6b4405bda7fdf6c6f465455aeae5e88c (commit)

Summary of changes:
 src/ServiceLocatorManagement.cpp |  101 +++++++++++++++++++-------------------
 src/ServiceLocatorManagement.h   |    2 +-
 src/ServiceManagement.cpp        |    4 +-
 test/TestComparatorBlocking.cpp  |    4 +-
 4 files changed, 56 insertions(+), 55 deletions(-)


- Log -----------------------------------------------------------------
commit 923d41eba94771e3b06f70e3377d80616764ad4e
Author: David M. Lee <dlee at digium.com>
Date:   Wed Dec 1 13:26:35 2010 -0600

    Disallow negative numVotes.
    
    See CR-ASTSCF-7.

diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index a115e2d..914ce7b 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -151,6 +151,7 @@ public:
     LocateOneCollector(const AMD_ServiceLocator_locatePtr& cb, int numVotes) :
         mCallback(cb), mNumVotes(numVotes)
     {
+        assert(mNumVotes >= 0);
         if (mNumVotes == 0)
         {
             ServiceNotFound e;
@@ -204,6 +205,7 @@ public:
     LocateAllCollector(const AMD_ServiceLocator_locateAllPtr& cb, int numVotes) :
         mCallback(cb), mNumVotes(numVotes)
     {
+        assert(mNumVotes >= 0);
         if (mNumVotes == 0)
         {
             ServiceNotFound e;

commit a635a2ab72376fb2e89a84122faf007bdab5a139
Author: David M. Lee <dlee at digium.com>
Date:   Wed Dec 1 13:24:38 2010 -0600

    Fixed member variables to compile with coding style.
    
    Member variables should be mPrefixed.
    See CR-ASTSCF-7

diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index a42a5e2..a115e2d 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -149,13 +149,13 @@ public:
      * @param numVotes The number of times isSupported will be called.
      */
     LocateOneCollector(const AMD_ServiceLocator_locatePtr& cb, int numVotes) :
-        cb(cb), numVotes(numVotes)
+        mCallback(cb), mNumVotes(numVotes)
     {
-        if (numVotes == 0)
+        if (mNumVotes == 0)
         {
             ServiceNotFound e;
-            cb->ice_exception(e);
-            this->cb = 0;
+            mCallback->ice_exception(e);
+            mCallback = 0;
         }
     }
 
@@ -163,30 +163,30 @@ public:
     {
         boost::lock_guard<boost::mutex> guard(mLock);
 
-        if (supported && cb)
+        if (supported && mCallback)
         {
-            cb->ice_response(management->getService());
-            // clear the cb pointer so we only answer once
-            cb = 0;
+            mCallback->ice_response(management->getService());
+            // clear the mCallback pointer so we only answer once
+            mCallback = 0;
         }
 
-        assert(numVotes > 0); // isSupported was called too many times
+        assert(mNumVotes > 0); // isSupported was called too many times
 
-        if (--numVotes == 0 && cb)
+        if (--mNumVotes == 0 && mCallback)
         {
             ServiceNotFound e;
-            cb->ice_exception(e);
-            // clear the cb pointer so we only answer once
-            cb = 0;
+            mCallback->ice_exception(e);
+            // clear the mCallback pointer so we only answer once
+            mCallback = 0;
         }
     }
 
 private:
     boost::mutex mLock;
     /** Ice callback */
-    AMD_ServiceLocator_locatePtr cb;
+    AMD_ServiceLocator_locatePtr mCallback;
     /** The number of times isSupported will be called. */
-    int numVotes;
+    int mNumVotes;
 };
 
 /**
@@ -202,13 +202,13 @@ public:
      * @param numVotes The number of times isSupported will be called.
      */
     LocateAllCollector(const AMD_ServiceLocator_locateAllPtr& cb, int numVotes) :
-        cb(cb), numVotes(numVotes)
+        mCallback(cb), mNumVotes(numVotes)
     {
-        if (numVotes == 0)
+        if (mNumVotes == 0)
         {
             ServiceNotFound e;
-            cb->ice_exception(e);
-            this->cb = 0;
+            mCallback->ice_exception(e);
+            mCallback = 0;
         }
     }
 
@@ -218,34 +218,34 @@ public:
 
         if (supported)
         {
-            value.push_back(management->getService());
+            mValue.push_back(management->getService());
         }
 
-        if (--numVotes == 0 && cb)
+        if (--mNumVotes == 0 && mCallback)
         {
             // the votes are in!
-            if (!value.empty())
+            if (!mValue.empty())
             {
-                cb->ice_response(value);
+                mCallback->ice_response(mValue);
             }
             else
             {
                 ServiceNotFound e;
-                cb->ice_exception(e);
+                mCallback->ice_exception(e);
             }
             // we're done with the callback
-            cb = 0;
+            mCallback = 0;
         }
     }
 
 private:
     boost::mutex mLock;
     /** Ice callback */
-    AMD_ServiceLocator_locateAllPtr cb;
+    AMD_ServiceLocator_locateAllPtr mCallback;
     /** The number of times isSupported will be called. */
-    int numVotes;
+    int mNumVotes;
     /** Collected results */
-    Ice::ObjectProxySeq value;
+    Ice::ObjectProxySeq mValue;
 };
 typedef IceUtil::Handle<LocateCollector> LocateCollectorPtr;
 

commit 30c86cadeef19796f48b08c667d22bbae85595aa
Author: David M. Lee <dlee at digium.com>
Date:   Wed Dec 1 13:04:54 2010 -0600

    Foo const & -> const Foo&
    
    Updated formatting of const references to match the rest of the code.
    See CR-ASTSCF-7.

diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 813f57e..a42a5e2 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -35,7 +35,7 @@ using namespace AsteriskSCF::ServiceDiscovery;
 namespace
 {
 
-Logger const &lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
+const Logger& lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
 
 /**
  * Callback class for isSupported AMI calls.  Acts as a bridge between
@@ -45,7 +45,7 @@ Logger const &lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
 class Comparator_IsSupported_Callback : public IceUtil::Shared
 {
 public:
-    Comparator_IsSupported_Callback(IsSupportedCallbackPtr const &callback) :
+    Comparator_IsSupported_Callback(const IsSupportedCallbackPtr& callback) :
         callback(callback)
     {
     }
@@ -60,7 +60,7 @@ public:
             // forward result to callback
             callback->result(comparator->end_isSupported(r));
         }
-        catch (std::exception const &e)
+        catch (const std::exception& e)
         {
             lg(Error) << "Error communicating with comparator: " << e.what();
             callback->result(false);
@@ -101,7 +101,7 @@ public:
      * @param callback Callback object which receives the results.
      */
     void isSupported(const ServiceLocatorParamsPtr& params,
-        IsSupportedCallbackPtr const &callback)
+        const IsSupportedCallbackPtr& callback)
     {
         // wrap our callback with an Ice callback
         Comparator_IsSupported_CallbackPtr iceCallback =
@@ -132,7 +132,7 @@ public:
      * @param management Pointer to the management object
      * @param supported resultsf from ServiceManagementImplPtr::isSupported
      */
-    virtual void isSupported(ServiceManagementImplPtr management,
+    virtual void isSupported(const ServiceManagementImplPtr& management,
         bool supported) = 0;
 };
 
@@ -159,7 +159,7 @@ public:
         }
     }
 
-    void isSupported(ServiceManagementImplPtr management, bool supported)
+    void isSupported(const ServiceManagementImplPtr& management, bool supported)
     {
         boost::lock_guard<boost::mutex> guard(mLock);
 
@@ -212,7 +212,7 @@ public:
         }
     }
 
-    void isSupported(ServiceManagementImplPtr management, bool supported)
+    void isSupported(const ServiceManagementImplPtr& management, bool supported)
     {
         boost::lock_guard<boost::mutex> guard(mLock);
 
@@ -469,7 +469,7 @@ void ServiceLocatorManagementImpl::removeCompare(const string& guid, const Ice::
 
 void ServiceLocatorManagementImpl::isSupported(const string& compareGuid,
     const ServiceLocatorParamsPtr& params,
-    IsSupportedCallbackPtr const &callback)
+    const IsSupportedCallbackPtr& callback)
 {
     /* You'll note there is no lock here. This is because we already have a lock in the locate or locateAll
      * functions.
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 4dddc41..0261939 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -87,7 +87,7 @@ public:
 
     void isSupported(const std::string&,
         const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&,
-        IsSupportedCallbackPtr const &);
+        const IsSupportedCallbackPtr&);
     void removeService(const ServiceManagementImplPtr&);
 private:
     /**
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 4f96399..a389ef0 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -33,7 +33,7 @@ using namespace AsteriskSCF::System::Logging;
 
 namespace
 {
-Logger const &lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
+const Logger& lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
 }
 
 namespace AsteriskSCF
@@ -256,7 +256,7 @@ void ServiceManagementImpl::isSupported(const ServiceLocatorParamsPtr& params, c
     }
 }
 
-std::string const &ServiceManagementImpl::getGuid() const
+const std::string& ServiceManagementImpl::getGuid() const
 {
     return mImpl->mGuid;
 }
diff --git a/test/TestComparatorBlocking.cpp b/test/TestComparatorBlocking.cpp
index d3701e2..65c137d 100644
--- a/test/TestComparatorBlocking.cpp
+++ b/test/TestComparatorBlocking.cpp
@@ -90,7 +90,7 @@ class BlockingCallback : public IceUtil::Shared
 public:
     BlockingCallback() : beenCalled(false) {}
 
-    void locateCB(const Ice::ObjectPrx&located)
+    void locateCB(const Ice::ObjectPrx& located)
     {
         boost::unique_lock<boost::mutex> lock(mut);
         beenCalled = true;
@@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(testNonBlocking)
     {
         Ice::ObjectPrx undiscovered = discovery->locate(dne);
         BOOST_FAIL("Should not have found dne");
-    } catch (ServiceNotFound const &expected) {
+    } catch (const ServiceNotFound& expected) {
         // expected
     }
 }

commit 58a220a5358da8cee5f0ae1de995c264a1d61d65
Author: David M. Lee <dlee at digium.com>
Date:   Mon Nov 29 09:09:36 2010 -0600

    Debug and formatting.

diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 7fed90f..813f57e 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -165,8 +165,6 @@ public:
 
         if (supported && cb)
         {
-            lg(Debug) << "  ...locate() = "
-                      << management->getService()->ice_toString() << '\n';
             cb->ice_response(management->getService());
             // clear the cb pointer so we only answer once
             cb = 0;
@@ -176,7 +174,6 @@ public:
 
         if (--numVotes == 0 && cb)
         {
-            lg(Debug) << "  ...locate() = ServiceNotFound\n";
             ServiceNotFound e;
             cb->ice_exception(e);
             // clear the cb pointer so we only answer once
@@ -344,7 +341,7 @@ ServiceLocatorManagementImpl::ServiceLocatorManagementImpl(
 void ServiceLocatorManagementImpl::locate(const AMD_ServiceLocator_locatePtr& cb,
     const ServiceLocatorParamsPtr& params)
 {
-    lg(Debug) << "locate(" << params->category << ")\n";
+    lg(Debug) << "locate(" << params->category << ')';
     boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
 
     LocateCollectorPtr collector = new LocateOneCollector(cb,
@@ -364,7 +361,7 @@ void ServiceLocatorManagementImpl::locateAll(
     const AMD_ServiceLocator_locateAllPtr& cb,
     const ServiceLocatorParamsPtr& params)
 {
-    lg(Debug) << "locateAll(" << params->category << ")\n";
+    lg(Debug) << "locateAll(" << params->category << ')';
     boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
 
     LocateCollectorPtr collector = new LocateAllCollector(cb,
@@ -383,11 +380,13 @@ void ServiceLocatorManagementImpl::locateAll(
 /**
  * Implementation of the addService method as defined in service_locator.ice
  */
-ServiceManagementPrx ServiceLocatorManagementImpl::addService(const Ice::ObjectPrx& service, const string& guid, const Ice::Current&)
+ServiceManagementPrx ServiceLocatorManagementImpl::addService(
+    const Ice::ObjectPrx& service, const string& guid, const Ice::Current&)
 {
-    lg(Info) << "addService " << guid << '.';
+    lg(Debug) << "addService(" << guid << ')';
     boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-    ServiceManagementImplPtr new_service = new ServiceManagementImpl(this, service,
+    ServiceManagementImplPtr new_service = new ServiceManagementImpl(this,
+        service,
         mImpl->mAdapter, mImpl->mLocatorTopic, guid);
 
     mImpl->mServices.push_back(new_service);
@@ -397,6 +396,7 @@ ServiceManagementPrx ServiceLocatorManagementImpl::addService(const Ice::ObjectP
 
 ServiceInfoSeq ServiceLocatorManagementImpl::getServices(const ::Ice::Current&) const
 {
+    lg(Debug) << "getServices()";
     boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
     ServiceInfoSeq r;
     for (std::vector<ServiceManagementImplPtr>::const_iterator i = mImpl->mServices.begin();
@@ -430,7 +430,7 @@ ServiceInfo ServiceLocatorManagementImpl::getService(const std::string &guid, co
 void ServiceLocatorManagementImpl::addCompare(const string& guid,
     const ServiceLocatorParamsComparePrx& service, const Ice::Current&)
 {
-    lg(Info) << "addCompare(" << guid << ")\n";
+    lg(Info) << "addCompare(" << guid << ')';
     boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
     ServiceLocatorComparator newComparator(service);
 
@@ -453,7 +453,7 @@ void ServiceLocatorManagementImpl::addCompare(const string& guid,
  */
 void ServiceLocatorManagementImpl::removeCompare(const string& guid, const Ice::Current&)
 {
-    lg(Info) << "removeCompare(" << guid << ")\n";
+    lg(Info) << "removeCompare(" << guid << ')';
     boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
     int erased = mImpl->mCompares.erase(guid);
 
@@ -467,9 +467,6 @@ void ServiceLocatorManagementImpl::removeCompare(const string& guid, const Ice::
     }
 }
 
-/**
- * Implementation of the isSupported method as defined in service_locator.ice
- */
 void ServiceLocatorManagementImpl::isSupported(const string& compareGuid,
     const ServiceLocatorParamsPtr& params,
     IsSupportedCallbackPtr const &callback)
@@ -494,7 +491,7 @@ void ServiceLocatorManagementImpl::isSupported(const string& compareGuid,
  */
 void ServiceLocatorManagementImpl::removeService(const ServiceManagementImplPtr& service)
 {
-    lg(Info) << "removeService " << service->getGuid() << '.';
+    lg(Info) << "removeService(" << service->getGuid() << ')';
     boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
     for (vector<ServiceManagementImplPtr>::iterator existingService =
              mImpl->mServices.begin();
@@ -506,4 +503,6 @@ void ServiceLocatorManagementImpl::removeService(const ServiceManagementImplPtr&
             return;
         }
     }
+    lg(Error) << "removeService(" << service->getGuid() <<
+        ") failed.  service not found";
 }

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


-- 
team/dlee/servicediscovery.git



More information about the asterisk-scf-commits mailing list