[asterisk-scf-commits] asterisk-scf/integration/servicediscovery.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Oct 5 09:14:48 CDT 2010


branch "master" has been updated
       via  329e36483144d3d7e63827d09d46fdbacb9d3ad7 (commit)
      from  c3ced1377a3c9d60d561af1dcdf047bfbf836410 (commit)

Summary of changes:
 src/ServiceLocator.cpp           |  152 +++++++++++---------
 src/ServiceLocatorManagement.cpp |  298 ++++++++++++++++++++------------------
 2 files changed, 240 insertions(+), 210 deletions(-)


- Log -----------------------------------------------------------------
commit 329e36483144d3d7e63827d09d46fdbacb9d3ad7
Author: David M. Lee <dlee at digium.com>
Date:   Mon Oct 4 16:51:34 2010 -0500

    pretty-print ServiceLocator.cpp and ServiceLocatorManagement.cpp

diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
index 37a133e..d4c16bb 100644
--- a/src/ServiceLocator.cpp
+++ b/src/ServiceLocator.cpp
@@ -27,9 +27,9 @@ using namespace AsteriskSCF::Core::Discovery::V1;
 class ServiceLocatorApp : public IceBox::Service
 {
 public:
-   void start(const std::string&,
-              const Ice::CommunicatorPtr&,
-              const Ice::StringSeq&);
+   void start(const string& name,
+      const Ice::CommunicatorPtr& communicator,
+      const Ice::StringSeq& args);
    void stop();
 
 private:
@@ -43,33 +43,39 @@ private:
 class ServiceLocatorImpl : public ServiceLocator
 {
 public:
-	ServiceLocatorImpl(ServiceLocatorManagementImpl* LocatorServiceManagement) : mLocatorServiceManagement(LocatorServiceManagement) { };
-	Ice::ObjectPrx locate(const ServiceLocatorParamsPtr&, const Ice::Current&);
-	Ice::ObjectProxySeq locateAll(const ServiceLocatorParamsPtr&, const Ice::Current&);
+   ServiceLocatorImpl(ServiceLocatorManagementImpl* LocatorServiceManagement) : 
+      mLocatorServiceManagement(LocatorServiceManagement) { };
+   Ice::ObjectPrx locate(const ServiceLocatorParamsPtr&, const Ice::Current&);
+   Ice::ObjectProxySeq locateAll(const ServiceLocatorParamsPtr&, const Ice::Current&);
 private:
-	/**
-	 * A pointer to the ServiceManagement implementation as that is where everything is actually
-	 * stored. Our ServiceLocator implementation simply acts as a read-only frontend to it.
-	 */
-	ServiceLocatorManagementImpl* mLocatorServiceManagement;
+   /**
+    * A pointer to the ServiceManagement implementation as that is where everything is
+    * actually stored. Our ServiceLocator implementation simply acts as a read-only
+    *  frontend to it.
+    */
+   ServiceLocatorManagementImpl* mLocatorServiceManagement;
 };
 
 /**
  * Implementation of the locate method as defined in service_locator.ice
  */
-Ice::ObjectPrx ServiceLocatorImpl::locate(const ServiceLocatorParamsPtr& params, const Ice::Current&)
+Ice::ObjectPrx ServiceLocatorImpl::locate(const ServiceLocatorParamsPtr& params,
+   const Ice::Current&)
 {
-	/* This API call forwards into the management implementation, it is separated to provide a level of security. */
-	return mLocatorServiceManagement->locate(params);
+   /* This API call forwards into the management implementation, it is separated to 
+    * provide a level of security. */
+   return mLocatorServiceManagement->locate(params);
 }
 
 /**
  * Implementation of the locateAll method as defined in service_locator.ice
  */
-Ice::ObjectProxySeq ServiceLocatorImpl::locateAll(const ServiceLocatorParamsPtr& params, const Ice::Current&)
+Ice::ObjectProxySeq ServiceLocatorImpl::locateAll(const ServiceLocatorParamsPtr& params,
+   const Ice::Current&)
 {
-	/* This API call forwards into the management implementation, it is separated to provide a level of security. */
-	return mLocatorServiceManagement->locateAll(params);
+   /* This API call forwards into the management implementation, it is separated to
+    * provide a level of security. */
+   return mLocatorServiceManagement->locateAll(params);
 }
 
 void ServiceLocatorApp::start(
@@ -79,73 +85,79 @@ void ServiceLocatorApp::start(
 {
     mIceStorm = new CollocatedIceStorm("HydraIceStorm", communicator->getProperties());
 
-	cout << "[INFO] Initializing service discovery component" << endl;
+   cout << "[INFO] Initializing service discovery component" << endl;
 
-	/* Talk to the topic manager to either create or get the service discovery topic, configured or default */
-	IceStorm::TopicManagerPrx topicManager = IceStorm::TopicManagerPrx::checkedCast(communicator->propertyToProxy("TopicManager.Proxy"));
+   /* Talk to the topic manager to either create or get the service discovery topic,
+    * configured or default */
+   IceStorm::TopicManagerPrx topicManager = IceStorm::TopicManagerPrx::checkedCast(
+      communicator->propertyToProxy("TopicManager.Proxy"));
 
-	EventsPrx service_discovery_topic;
+   EventsPrx service_discovery_topic;
 
-	if (topicManager)
-	{
-	   Ice::PropertiesPtr props = communicator->getProperties();
-	   string topicName = props->getProperty("ServiceLocator.TopicName");
-
-	   if (topicName.empty())
-	   {
-	      topicName = TOPIC;
-	   }
-
-	   IceStorm::TopicPrx topic;
-	   try
-	   {
-	      topic = topicManager->retrieve(topicName);
-	   }
-	   catch (const IceStorm::NoSuchTopic&)
-	   {
-	      try
-	      {
-		 topic = topicManager->create(topicName);
-	      }
-	      catch (const IceStorm::TopicExists&)
-	      {
-		 cerr << "Oh snap! Race condition creating topic, aborting" << endl;
-		 return;
-	      }
-	      cout << "[INFO] Created service discovery event topic" << endl;
-	   }
-
-	   service_discovery_topic = EventsPrx::uncheckedCast(topic->getPublisher());
-	}
-	else
-	{
-	   cout << "[INFO] IceStorm topic manager proxy not present, events disabled." << endl;
-	}
+   if (topicManager)
+   {
+      Ice::PropertiesPtr props = communicator->getProperties();
+      string topicName = props->getProperty("ServiceLocator.TopicName");
+
+      if (topicName.empty())
+      {
+         topicName = TOPIC;
+      }
+
+      IceStorm::TopicPrx topic;
+      try
+      {
+         topic = topicManager->retrieve(topicName);
+      }
+      catch (const IceStorm::NoSuchTopic&)
+      {
+         try
+         {
+       topic = topicManager->create(topicName);
+         }
+         catch (const IceStorm::TopicExists&)
+         {
+       cerr << "Oh snap! Race condition creating topic, aborting" << endl;
+       return;
+         }
+         cout << "[INFO] Created service discovery event topic" << endl;
+      }
+
+      service_discovery_topic = EventsPrx::uncheckedCast(topic->getPublisher());
+   }
+   else
+   {
+      cout << "[INFO] IceStorm topic manager proxy not present, events disabled." << endl;
+   }
 
-	/* Management and discovery use separate adapters to provide a level of security, management may want to be protected so arbitrary
-	 * people can't inject bad services into the infrastructure while discovery as a read only function may be allowed to all.
-	 */
-	Ice::ObjectAdapterPtr management_adapter = communicator->createObjectAdapter("ServiceLocatorManagementAdapter");
+   /* Management and discovery use separate adapters to provide a level of security,
+    * management may want to be protected so arbitrary people can't inject bad services
+    * into the infrastructure while discovery as a read only function may be allowed to all.
+    */
+   Ice::ObjectAdapterPtr management_adapter = communicator->createObjectAdapter(
+      "ServiceLocatorManagementAdapter");
 
-	ServiceLocatorManagementImpl* LocatorServiceManagement = new ServiceLocatorManagementImpl(management_adapter, service_discovery_topic);
+   ServiceLocatorManagementImpl* LocatorServiceManagement =
+      new ServiceLocatorManagementImpl(management_adapter, service_discovery_topic);
 
-	management_adapter->add(LocatorServiceManagement, communicator->stringToIdentity("LocatorServiceManagement"));
+   management_adapter->add(LocatorServiceManagement,
+      communicator->stringToIdentity("LocatorServiceManagement"));
 
-	management_adapter->activate();
+   management_adapter->activate();
 
-	cout << "[INFO] Activated service discovery management." << endl;
+   cout << "[INFO] Activated service discovery management." << endl;
 
-	discovery_adapter = communicator->createObjectAdapter("ServiceLocatorAdapter");
+   discovery_adapter = communicator->createObjectAdapter("ServiceLocatorAdapter");
 
-	ServiceLocatorPtr LocatorService = new ServiceLocatorImpl(LocatorServiceManagement);
+   ServiceLocatorPtr LocatorService = new ServiceLocatorImpl(LocatorServiceManagement);
 
-	discovery_adapter->add(LocatorService, communicator->stringToIdentity("LocatorService"));
+   discovery_adapter->add(LocatorService, communicator->stringToIdentity("LocatorService"));
 
-	discovery_adapter->activate();
+   discovery_adapter->activate();
 
-	cout << "[INFO] Activated service discovery." << endl;
+   cout << "[INFO] Activated service discovery." << endl;
 
-	cout << "[INFO] Waiting for requests." << endl;
+   cout << "[INFO] Waiting for requests." << endl;
 }
 
 void ServiceLocatorApp::stop()
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index b32cd80..de8f0bd 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -27,69 +27,77 @@ using namespace AsteriskSCF::Core::Discovery::V1;
 class ServiceLocatorComparator
 {
 public:
-	/**
-	 * Constructor for the ServiceLocatorComparator class.
-	 *
-	 * @param compare A proxy to the comparator service we are wrapping.
-	 */
-	ServiceLocatorComparator(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsComparePrx& compare) : mCompare(compare) { };
-
-	/**
-	 * API call which forwards an isSupported over ICE to a remote comparator.
-	 *
-	 * @param params Service locator parameters that describe a locator request.
-	 *
-	 * @return A boolean value with true indicating the parameters are supported while false indicates otherwise.
-	 */
-	bool isSupported(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params) { return mCompare->isSupported(params); };
+   /**
+    * Constructor for the ServiceLocatorComparator class.
+    *
+    * @param compare A proxy to the comparator service we are wrapping.
+    */
+   ServiceLocatorComparator(const ServiceLocatorParamsComparePrx& compare) :
+      mCompare(compare) { }
+
+   /**
+    * API call which forwards an isSupported over ICE to a remote comparator.
+    *
+    * @param params Service locator parameters that describe a locator request.
+    *
+    * @return A boolean value with true indicating the parameters are supported while
+    *         false indicates otherwise.
+    */
+   bool isSupported(const ServiceLocatorParamsPtr& params)
+   {
+      return mCompare->isSupported(params);
+   }
 private:
-	/**
-	 * A proxy to the comparator service that we are wrapping.
-	 */
-	AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsComparePrx mCompare;
+   /**
+    * A proxy to the comparator service that we are wrapping.
+    */
+   ServiceLocatorParamsComparePrx mCompare;
 };
 
 /**
- * Small internal class which is used to store private details for ServiceLocatorManagementImpl.
+ * Small internal class which is used to store private details for
+ * ServiceLocatorManagementImpl.
  */
 class ServiceLocatorManagementImplPriv : public Ice::Object
 {
 public:
-	ServiceLocatorManagementImplPriv(Ice::ObjectAdapterPtr adapter, const AsteriskSCF::System::Discovery::EventsPrx& service_discovery_topic) :
-		mAdapter(adapter), mLocatorTopic(service_discovery_topic) { };
-	/**
-	 * Shared mutex lock which protects the services and comparators.
-	 */
-	boost::shared_mutex mLock;
-
-	/**
-	 * Object adapter that our service management proxies originate from, it is houses the
-	 * main management service.
-	 */
-	Ice::ObjectAdapterPtr mAdapter;
-
-	/**
-	 * A map of all the comparators that have been added by external components. The key
-	 * is the unique identifier that they add themselves with.
-	 */
-	std::map<std::string, ServiceLocatorComparator> mCompares;
-
-	/**
-	 * A vector of all the services that have been added.
-	 */
-	std::vector<ServiceManagementImplPtr> mServices;
-
-	/**
-	 * A proxy that can be used to publish locator events.
-	 */
-	AsteriskSCF::System::Discovery::EventsPrx mLocatorTopic;
+   ServiceLocatorManagementImplPriv(Ice::ObjectAdapterPtr adapter, 
+      const EventsPrx& service_discovery_topic) :
+      mAdapter(adapter), mLocatorTopic(service_discovery_topic) { };
+   /**
+    * Shared mutex lock which protects the services and comparators.
+    */
+   boost::shared_mutex mLock;
+
+   /**
+    * Object adapter that our service management proxies originate from, it is houses the
+    * main management service.
+    */
+   Ice::ObjectAdapterPtr mAdapter;
+
+   /**
+    * A map of all the comparators that have been added by external components. The key
+    * is the unique identifier that they add themselves with.
+    */
+   std::map<std::string, ServiceLocatorComparator> mCompares;
+
+   /**
+    * A vector of all the services that have been added.
+    */
+   std::vector<ServiceManagementImplPtr> mServices;
+
+   /**
+    * A proxy that can be used to publish locator events.
+    */
+   AsteriskSCF::System::Discovery::EventsPrx mLocatorTopic;
 };
 
 /**
  * Implementation of a constructor for the ServiceLocatorManagementImpl class.
  */
-ServiceLocatorManagementImpl::ServiceLocatorManagementImpl(Ice::ObjectAdapterPtr adapter, const AsteriskSCF::System::Discovery::EventsPrx& service_discovery_topic)
-        : mImpl(new ServiceLocatorManagementImplPriv(adapter, service_discovery_topic))
+ServiceLocatorManagementImpl::ServiceLocatorManagementImpl(Ice::ObjectAdapterPtr adapter, 
+   const EventsPrx& service_discovery_topic) :
+   mImpl(new ServiceLocatorManagementImplPriv(adapter, service_discovery_topic))
 {
 }
 
@@ -98,78 +106,84 @@ ServiceLocatorManagementImpl::ServiceLocatorManagementImpl(Ice::ObjectAdapterPtr
  */
 Ice::ObjectPrx ServiceLocatorManagementImpl::locate(const ServiceLocatorParamsPtr& params)
 {
-	boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
+   boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
 
-	for (vector<ServiceManagementImplPtr>::iterator service = mImpl->mServices.begin(); service != mImpl->mServices.end(); ++service)
-	{
-		if ((*service)->isSupported(params) == true)
-		{
-			return (*service)->GetService();
-		}
-	}
+   for (vector<ServiceManagementImplPtr>::iterator service = mImpl->mServices.begin(); service != mImpl->mServices.end(); ++service)
+   {
+      if ((*service)->isSupported(params) == true)
+      {
+         return (*service)->GetService();
+      }
+   }
 
-	throw ServiceNotFound();
+   throw ServiceNotFound();
 }
 
 /**
  * Implementation of the locateAll method as defined in service_locator.ice
  */
-Ice::ObjectProxySeq ServiceLocatorManagementImpl::locateAll(const ServiceLocatorParamsPtr& params)
+Ice::ObjectProxySeq ServiceLocatorManagementImpl::locateAll(
+   const ServiceLocatorParamsPtr& params)
 {
-	boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
-	Ice::ObjectProxySeq applicable_services;
-
-	for (vector<ServiceManagementImplPtr>::iterator service = mImpl->mServices.begin(); service != mImpl->mServices.end(); ++service)
-	{
-		if ((*service)->isSupported(params) == true)
-		{
-			applicable_services.push_back((*service)->GetService());
-		}
-	}
-
-	if (!applicable_services.empty())
-	{
-		return applicable_services;
-	}
-	else
-	{
-		throw ServiceNotFound();
-	}
+   boost::shared_lock<boost::shared_mutex> lock(mImpl->mLock);
+   Ice::ObjectProxySeq applicable_services;
+
+   for (vector<ServiceManagementImplPtr>::iterator service = mImpl->mServices.begin(); 
+        service != mImpl->mServices.end(); ++service)
+   {
+      if ((*service)->isSupported(params) == true)
+      {
+         applicable_services.push_back((*service)->GetService());
+      }
+   }
+
+   if (!applicable_services.empty())
+   {
+      return applicable_services;
+   }
+   else
+   {
+      throw ServiceNotFound();
+   }
 }
 
 /**
  * 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&)
 {
-	boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-	ServiceManagementImplPtr new_service = new ServiceManagementImpl(this, service, mImpl->mAdapter, mImpl->mLocatorTopic, guid);
+   boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+   ServiceManagementImplPtr new_service = new ServiceManagementImpl(this, service,
+      mImpl->mAdapter, mImpl->mLocatorTopic, guid);
 
-	mImpl->mServices.push_back(new_service);
+   mImpl->mServices.push_back(new_service);
 
-	return new_service->GetServiceManagementPrx();
+   return new_service->GetServiceManagementPrx();
 }
 
 /**
  * Implementation of the addCompare method as defined in service_locator.ice
  */
-void ServiceLocatorManagementImpl::addCompare(const string& guid, const ServiceLocatorParamsComparePrx& service, const Ice::Current&)
+void ServiceLocatorManagementImpl::addCompare(const string& guid,
+   const ServiceLocatorParamsComparePrx& service, const Ice::Current&)
 {
-	boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-	ServiceLocatorComparator new_comparator(service);
-
-	pair<map<string, ServiceLocatorComparator>::iterator, bool> insert_pair;
-	insert_pair = mImpl->mCompares.insert(pair<string, ServiceLocatorComparator>(guid, new_comparator));
-
-	if (insert_pair.second == false)
-	{
-		throw DuplicateCompare();
-	}
-
-	if (mImpl->mLocatorTopic)
-	{
-	   mImpl->mLocatorTopic->comparisonRegistered(guid);
-	}
+   boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+   ServiceLocatorComparator new_comparator(service);
+
+   pair<map<string, ServiceLocatorComparator>::iterator, bool> insert_pair;
+   insert_pair = mImpl->mCompares.insert(pair<string, ServiceLocatorComparator>(guid,
+      new_comparator));
+
+   if (insert_pair.second == false)
+   {
+      throw DuplicateCompare();
+   }
+
+   if (mImpl->mLocatorTopic)
+   {
+      mImpl->mLocatorTopic->comparisonRegistered(guid);
+   }
 };
 
 /**
@@ -177,43 +191,45 @@ void ServiceLocatorManagementImpl::addCompare(const string& guid, const ServiceL
  */
 void ServiceLocatorManagementImpl::removeCompare(const string& guid, const Ice::Current&)
 {
-	boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-	int erased = mImpl->mCompares.erase(guid);
-
-	if (!erased)
-	{
-		throw CompareNotFound();
-	}
-	else if (mImpl->mLocatorTopic)
-	{
-		mImpl->mLocatorTopic->comparisonUnregistered(guid);
-	}
+   boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+   int erased = mImpl->mCompares.erase(guid);
+
+   if (!erased)
+   {
+      throw CompareNotFound();
+   }
+   else if (mImpl->mLocatorTopic)
+   {
+      mImpl->mLocatorTopic->comparisonUnregistered(guid);
+   }
 };
 
 /**
  * Implementation of the isSupported method as defined in service_locator.ice
  */
-bool ServiceLocatorManagementImpl::isSupported(const string& compare_guid, const ServiceLocatorParamsPtr& params)
+bool ServiceLocatorManagementImpl::isSupported(const string& compare_guid,
+   const ServiceLocatorParamsPtr& params)
 {
-	/* You'll note there is no lock here. This is because we already have a lock in the locate or locateAll
-	 * functions.
-	 */
-	map<string, ServiceLocatorComparator>::iterator comparator = mImpl->mCompares.find(compare_guid);
-
-	if (comparator == mImpl->mCompares.end())
-	{
-		return false;
-	}
-
-	try
-	{
-		return (comparator->second).isSupported(params);
-	}
-	catch (...)
-	{
-		cout << "[ERROR] An exception was raised when attempting to contact comparator " << compare_guid << "." << endl;
-		return false;
-	}
+   /* You'll note there is no lock here. This is because we already have a lock in the locate or locateAll
+    * functions.
+    */
+   map<string, ServiceLocatorComparator>::iterator comparator =
+      mImpl->mCompares.find(compare_guid);
+
+   if (comparator == mImpl->mCompares.end())
+   {
+      return false;
+   }
+
+   try
+   {
+      return (comparator->second).isSupported(params);
+   }
+   catch (...)
+   {
+      cout << "[ERROR] An exception was raised when attempting to contact comparator " << compare_guid << "." << endl;
+      return false;
+   }
 }
 
 /**
@@ -221,13 +237,15 @@ bool ServiceLocatorManagementImpl::isSupported(const string& compare_guid, const
  */
 void ServiceLocatorManagementImpl::removeService(ServiceManagementImplPtr service)
 {
-	boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
-	for (vector<ServiceManagementImplPtr>::iterator existing_service = mImpl->mServices.begin(); existing_service != mImpl->mServices.end(); ++existing_service)
-	{
-		if ((*existing_service) == service)
-		{
-			mImpl->mServices.erase(existing_service);
-			return;
-		}
-	}
+   boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
+   for (vector<ServiceManagementImplPtr>::iterator existing_service =
+        mImpl->mServices.begin();
+        existing_service != mImpl->mServices.end(); ++existing_service)
+   {
+      if ((*existing_service) == service)
+      {
+         mImpl->mServices.erase(existing_service);
+         return;
+      }
+   }
 }

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


-- 
asterisk-scf/integration/servicediscovery.git



More information about the asterisk-scf-commits mailing list