[asterisk-scf-commits] asterisk-scf/integration/servicediscovery.git branch "locate-with-id" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jun 28 20:20:05 CDT 2011


branch "locate-with-id" has been updated
       via  f7f94776ae4a9fe97b66cc0d732682d6390c69b8 (commit)
      from  ae9bde043071e5067ced90d0b11ae157904b26c1 (commit)

Summary of changes:
 src/ServiceLocatorManagement.cpp |   11 +++++-
 src/ServiceManagement.cpp        |   70 ++++++++++++++++++++++++++++----------
 test/TestComparatorBlocking.cpp  |    2 +
 test/TestServiceLocator.cpp      |   39 ++++++++++++---------
 4 files changed, 85 insertions(+), 37 deletions(-)


- Log -----------------------------------------------------------------
commit f7f94776ae4a9fe97b66cc0d732682d6390c69b8
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Jun 28 20:19:27 2011 -0500

    Incorporating review feedback. Expands ServiceLocatorParams to include category, service and id.

diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 868c932..212ca8e 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -369,10 +369,17 @@ ServiceLocatorManagementImpl::ServiceLocatorManagementImpl(
 {
 }
 
+static string debugPrintParams(const ServiceLocatorParamsPtr& params)
+{
+    string result;
+    result = "(category=" + params->category + ", service=" + params->service + ", id=" + params->id + ")";
+    return result;
+}
+
 void ServiceLocatorManagementImpl::locate(const AMD_ServiceLocator_locatePtr& cb,
     const ServiceLocatorParamsPtr& params)
 {
-    lg(Debug) << "locate(" << params->category << ", " << params->id << ")";
+    lg(Debug) << "locate(" << debugPrintParams(params);
     boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
 
     LocateCollectorPtr collector = new LocateOneCollector(cb,
@@ -392,7 +399,7 @@ void ServiceLocatorManagementImpl::locateAll(
     const AMD_ServiceLocator_locateAllPtr& cb,
     const ServiceLocatorParamsPtr& params)
 {
-    lg(Debug) << "locateAll(" << params->category << ", " << params->id << ")";
+    lg(Debug) << "locateAll(" << debugPrintParams(params);
     boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
 
     LocateCollectorPtr collector = new LocateAllCollector(cb,
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index c8e75fe..35405e6 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -72,7 +72,7 @@ public:
 	mManagement->removeState(mStateItem);
     }
 
-    void isSupported(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const IsSupportedCallbackPtr&);
+    bool isSupported(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr&, const IsSupportedCallbackPtr&);
 
 private:
     /**
@@ -230,6 +230,13 @@ private:
     IsSupportedCallbackPtr mCallback;
 };
 
+static string debugPrintParams(const ServiceLocatorParamsPtr& params)
+{
+    string result;
+    result = "(category=" + params->category + ", service=" + params->service + ", id=" + params->id + ")";
+    return result;
+}
+
 /**
  * An internal function which is called by the service locator to perform a
  * locator parameters comparison at the service level.
@@ -247,7 +254,7 @@ void ServiceManagementImpl::isSupported(const ServiceLocatorParamsPtr& params, c
      */
     if (mImpl->mStateItem->suspended)
     {
-        lg(Debug) << "  ...isSupported(" << params->category << ", " << params->id << ") = false (suspended)\n";
+        lg(Debug) << "  ...isSupported" << debugPrintParams(params) + " = false (suspended)\n";
         callback->result(false);
         return;
     }
@@ -260,7 +267,10 @@ void ServiceManagementImpl::isSupported(const ServiceLocatorParamsPtr& params, c
          spec != mImpl->mSupportedLocatorParams.end();
          ++spec)
     {
-        (*spec)->isSupported(params, myCallback);
+        if ((*spec)->isSupported(params, myCallback))
+        {
+            break;
+        }
     }
 }
 
@@ -276,46 +286,70 @@ const std::string& ServiceManagementImpl::getGuid() const
  * @param params A concrete class containing parameters describing the service
  *               that is trying to be found.
  * @param callback Callback to asynchronously rx the results.
+ *
+ * @return True only if we determined a match without any need for calling a custom comparator. 
+ *         Otherwise, the callback may be accumulating the results, or it's not a match. 
  */
-void ServiceLocatorParamsSpec::isSupported(const ServiceLocatorParamsPtr& params, const IsSupportedCallbackPtr& callback)
+bool ServiceLocatorParamsSpec::isSupported(const ServiceLocatorParamsPtr& params, const IsSupportedCallbackPtr& callback)
 {
-    // If no category is passed to us then the component doing the locate wants
-    // everything/anything, so give it to them
-    if (params->category.empty())
+    // Does the component doing the locate 
+    // want to filter based on category. 
+    if (!params->category.empty())
+    {
+        // Is this the wrong category?
+        if (mStateItem->params->category != params->category)
+        {
+            lg(Debug) << "  ...isSupported" << debugPrintParams(params) + " = false (different categories)\n";
+            callback->result(false);
+            return false;
+        }
+    }
+
+    // Does the component doing the locate 
+    // want all services in the category? 
+    if (params->service.empty())
     {
-        lg(Debug) << "  ...isSupported(" << params->category << ") = true (empty category)\n";
+        // If a comparator was provided then yield to it. 
+        if (!mStateItem->compareGuid.empty())
+        {
+            mManagement->isSupported(mStateItem->compareGuid, params, callback);
+            return false;
+        }
+
+        // Ignore the id and treat this as a wildcard search. 
         callback->result(true);
-        return;
+        return true;
     }
 
-    // Is this the wrong category?
-    if (mStateItem->params->category != params->category)
+    // Wrong service?
+    if (mStateItem->params->service != params->service)
     {
-        lg(Debug) << "  ...isSupported(" << params->category << ") = false (different categories)\n";
         callback->result(false);
-        return;
+        return true;
     }
 
-    // Is query for a specific instance?
+    // Is this query for a specific instance?
     if (!params->id.empty())
     {
         // Wrong instance?
         if (mStateItem->params->id != params->id)
         {
             callback->result(false);
-            return;
+            return false;
         }
     }
 
-    // If a comparator was provided then yield to it for a final yay or nay 
+    // If a comparator was provided then yield to it. 
     if (!mStateItem->compareGuid.empty())
     {
         mManagement->isSupported(mStateItem->compareGuid, params, callback);
-        return;
+        return false;
     }
 
-    // If we get here we have a match. 
+    // If we get here we have a match on service and id. 
+    // (and category, if one was passed in.) 
     callback->result(true);
+    return true;
 }
 
 /**
diff --git a/test/TestComparatorBlocking.cpp b/test/TestComparatorBlocking.cpp
index c10b0da..c8cc599 100644
--- a/test/TestComparatorBlocking.cpp
+++ b/test/TestComparatorBlocking.cpp
@@ -207,6 +207,7 @@ BOOST_AUTO_TEST_CASE(testNonBlocking)
 
     ServiceLocatorParamsPtr dne = new ServiceLocatorParams();
     dne->category = "dne";
+    dne->service = "dne.com";
 
     try
     {
@@ -226,6 +227,7 @@ BOOST_AUTO_TEST_CASE(testBlocking)
     // try to locate something else while blocker is blocking
     ServiceLocatorParamsPtr dne = new ServiceLocatorParams();
     dne->category = "dne";
+    dne->service = "dne.com";
 
     BlockingCallbackPtr callback = new BlockingCallback();
 
diff --git a/test/TestServiceLocator.cpp b/test/TestServiceLocator.cpp
index 85a8cbf..c920c22 100644
--- a/test/TestServiceLocator.cpp
+++ b/test/TestServiceLocator.cpp
@@ -91,17 +91,18 @@ public:
     ServiceLocatorParamsComparePrx foundCompare;
 
     /* Common implementation for locating a service */
-    bool findService(const string& category)
+    bool findService(const string& category, const string& service)
     {
         bool found = true;
 
         try
         {
-            /* Setup our parameters, for now we are simply using test as the category */
+            // Setup our parameters.
             ServiceLocatorParamsPtr params = new ServiceLocatorParams;
             params->category = category;
+            params->service = service;
 
-            /* Actually do the locate request */
+            // Actually do the locate request 
             foundCompare = ServiceLocatorParamsComparePrx::uncheckedCast(discovery->locate(params));
 
             /* If we get here we didn't get an exception back telling us no service found... which is wrong! */
@@ -121,7 +122,7 @@ public:
     }
 
     /* Common implementation for finding multiple services */
-    bool findServices(const string& category, unsigned int expectedNumOfResults)
+    bool findServices(const string& category, const string& service, unsigned int expectedNumOfResults)
     {
         bool found = true;
 
@@ -129,6 +130,7 @@ public:
         {
             ServiceLocatorParamsPtr params = new ServiceLocatorParams;
             params->category = category;
+            params->service = service;
 
             Ice::ObjectProxySeq services = discovery->locateAll(params);
 
@@ -241,7 +243,7 @@ BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
  */
 BOOST_AUTO_TEST_CASE(ServiceNotFoundBeforeAdd)
 {
-    bool found = testbed.findService("test");
+    bool found = testbed.findService("test", "default");
 
     BOOST_CHECK(!found);
 }
@@ -251,7 +253,7 @@ BOOST_AUTO_TEST_CASE(ServiceNotFoundBeforeAdd)
  */
 BOOST_AUTO_TEST_CASE(ServicesNotFoundBeforeAdd)
 {
-    bool found = testbed.findServices("test", 1);
+    bool found = testbed.findServices("test", "default", 1);
 
     BOOST_CHECK(!found);
 }
@@ -289,7 +291,7 @@ BOOST_AUTO_TEST_CASE(AddService)
  */
 BOOST_AUTO_TEST_CASE(ServiceNotFoundAfterAdd)
 {
-    bool found = testbed.findService("test");
+    bool found = testbed.findService("test", "default");
 
     BOOST_CHECK(!found);
 }
@@ -299,7 +301,7 @@ BOOST_AUTO_TEST_CASE(ServiceNotFoundAfterAdd)
  */
 BOOST_AUTO_TEST_CASE(ServicesNotFoundAfterAdd)
 {
-    bool found = testbed.findServices("test", 0);
+    bool found = testbed.findServices("test", "default", 0);
 
     BOOST_CHECK(!found);
 }
@@ -315,6 +317,7 @@ BOOST_AUTO_TEST_CASE(AddLocatorParamsWithoutCompareService)
     {
         ServiceLocatorParamsPtr params = new ServiceLocatorParams;
         params->category = "test";
+        params->service = "default";
 
         testbed.compareManagement->addLocatorParams(params, "");
 
@@ -337,7 +340,7 @@ BOOST_AUTO_TEST_CASE(AddLocatorParamsWithoutCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindServiceWithoutCompareService)
 {
-    bool found = testbed.findService("test");
+    bool found = testbed.findService("test", "default");
 
     BOOST_CHECK(found);
 }
@@ -347,7 +350,7 @@ BOOST_AUTO_TEST_CASE(FindServiceWithoutCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindServicesWithoutCompareService)
 {
-    bool found = testbed.findServices("test", 1);
+    bool found = testbed.findServices("test", "default", 1);
 
     BOOST_CHECK(found);
 }
@@ -448,6 +451,7 @@ BOOST_AUTO_TEST_CASE(AddLocatorParamsWithCompareService)
     {
         ServiceLocatorParamsPtr params = new ServiceLocatorParams;
         params->category = "test2";
+        params->service = "default";
 
         testbed.compareManagement->addLocatorParams(params, "testcompare");
 
@@ -470,7 +474,7 @@ BOOST_AUTO_TEST_CASE(AddLocatorParamsWithCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindServiceWithCompareService)
 {
-    bool found = testbed.findService("test2");
+    bool found = testbed.findService("test2", "default");
 
     BOOST_CHECK(found);
 }
@@ -513,10 +517,11 @@ BOOST_AUTO_TEST_CASE(FindMultipleServices)
     ServiceManagementPrx compareManagement = testbed.management->addService(testbed.compare, "testcompare2");
 
     params->category = "test";
+    params->service = "default";
 
     compareManagement->addLocatorParams(params, "");
 
-    bool found = testbed.findServices("test", 2);
+    bool found = testbed.findServices("test", "", 2);
 
     compareManagement->unregister();
 
@@ -535,7 +540,7 @@ BOOST_AUTO_TEST_CASE(FindMultipleServicesUsingEmptyCategory)
 
     compareManagement->addLocatorParams(params, "");
 
-    bool found = testbed.findServices("", 2);
+    bool found = testbed.findServices("", "", 2);
 
     compareManagement->unregister();
 
@@ -571,7 +576,7 @@ BOOST_AUTO_TEST_CASE(ServiceSuspend)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterSuspend)
 {
-    bool found = testbed.findService("test");
+    bool found = testbed.findService("test", "default");
 
     BOOST_CHECK(!found);
 }
@@ -605,7 +610,7 @@ BOOST_AUTO_TEST_CASE(ServiceUnsuspend)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterUnsuspend)
 {
-    bool found = testbed.findService("test");
+    bool found = testbed.findService("test", "default");
 
     BOOST_CHECK(found);
 }
@@ -696,7 +701,7 @@ BOOST_AUTO_TEST_CASE(RemoveAlreadyRemovedCompareService)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterCompareServiceRemoved)
 {
-    bool found = testbed.findService("test2");
+    bool found = testbed.findService("test2", "default");
 
     BOOST_CHECK(!found);
 }
@@ -730,7 +735,7 @@ BOOST_AUTO_TEST_CASE(ServiceUnregister)
  */
 BOOST_AUTO_TEST_CASE(FindServiceAfterUnregister)
 {
-    bool found = testbed.findService("test");
+    bool found = testbed.findService("test", "default");
 
     BOOST_CHECK(!found);
 }

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


-- 
asterisk-scf/integration/servicediscovery.git



More information about the asterisk-scf-commits mailing list