[asterisk-scf-commits] asterisk-scf/release/servicediscovery.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Jan 19 09:57:49 CST 2011
branch "master" has been updated
via 5cee63f2b8093c9c9362d8b7d19b866fc04f2e78 (commit)
via a9587a147f1330a6ce06f92dc622fdd3f3c54766 (commit)
via c543bbda89efbb282f87361eb745fedea1de813b (commit)
via 9b8eccbfc360a670bc17745dc7b3a5e6f2130095 (commit)
via af8f47d218d96feef91bdd8ab11595b65d543bf5 (commit)
via fac42e6c1a9dd61fe5d1fa28e137141d56443a1c (commit)
via e27fb2812f4e636c49ea171bf07c55cb4ff76b38 (commit)
via ce4af3b38292f34cf39ead9b498cd23c065e6ee3 (commit)
from e21294d36cf83676af9cf8c556cc69d885cb840c (commit)
Summary of changes:
src/CMakeLists.txt | 1 +
src/ServiceLocatorManagement.cpp | 243 ++++++++++++++------------------------
src/ServiceLocatorManagement.h | 5 +-
src/ServiceManagement.cpp | 42 ++++---
4 files changed, 118 insertions(+), 173 deletions(-)
- Log -----------------------------------------------------------------
commit 5cee63f2b8093c9c9362d8b7d19b866fc04f2e78
Merge: e21294d a9587a1
Author: David M. Lee <dlee at digium.com>
Date: Wed Jan 19 09:37:10 2011 -0600
Merge branch 'ami-collector'
diff --cc src/CMakeLists.txt
index 260911f,a271793..0ec6f4a
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@@ -25,8 -28,8 +25,9 @@@ asterisk_scf_component_add_boost_librar
if(NOT logger_dir)
message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
endif()
+ include_directories(${utils_dir}/AmiCollector/include)
include_directories(${logger_dir}/include)
+include_directories(${API_INCLUDE_DIR})
asterisk_scf_component_build_icebox(service_locator)
target_link_libraries(service_locator logging-client)
commit a9587a147f1330a6ce06f92dc622fdd3f3c54766
Author: David M. Lee <dlee at digium.com>
Date: Wed Jan 19 09:33:19 2011 -0600
typo. See CR-ASTSCF-40.
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index ad1e367..5bc0c74 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -43,7 +43,7 @@ namespace ServiceLocatorManagementImplNS
const Logger& lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
-/** Paramater type for Locator, to allow use of ResponseCollector. */
+/** Parameter type for Locator, to allow use of ResponseCollector. */
typedef std::pair<bool, ServiceManagementImplPtr> LocateParam;
/**
commit c543bbda89efbb282f87361eb745fedea1de813b
Author: David M. Lee <dlee at digium.com>
Date: Fri Jan 7 15:45:48 2011 -0600
Fixed AmiCollector for include file changes.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4771d6a..a271793 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -28,7 +28,7 @@ asterisk_scf_component_add_boost_libraries(service_locator core thread date_time
if(NOT logger_dir)
message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
endif()
-include_directories(${utils_dir}/AmiCollector/src)
+include_directories(${utils_dir}/AmiCollector/include)
include_directories(${logger_dir}/include)
asterisk_scf_component_build_icebox(service_locator)
commit 9b8eccbfc360a670bc17745dc7b3a5e6f2130095
Merge: af8f47d 624e9a2
Author: David M. Lee <dlee at digium.com>
Date: Fri Jan 7 15:29:15 2011 -0600
Merge branch 'master' of git://git.asterisk.org/asterisk-scf/release/servicediscovery into ami-collector
Conflicts:
src/CMakeLists.txt
src/ServiceLocatorManagement.cpp
src/ServiceManagement.cpp
diff --cc src/CMakeLists.txt
index 113a797,16acc68..4771d6a
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@@ -28,9 -28,7 +28,8 @@@ asterisk_scf_component_add_boost_librar
if(NOT logger_dir)
message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
endif()
- include_directories(${logger_dir}/common)
- include_directories(${logger_dir}/client/src)
+include_directories(${utils_dir}/AmiCollector/src)
+ include_directories(${logger_dir}/include)
asterisk_scf_component_build_icebox(service_locator)
target_link_libraries(service_locator logging-client)
diff --cc src/ServiceLocatorManagement.cpp
index f620d85,793fd0f..ad1e367
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@@ -19,8 -19,9 +19,10 @@@
#include <boost/thread.hpp>
#include <boost/thread/shared_mutex.hpp>
- #include "Core/Discovery/ServiceLocatorIf.h"
- #include "Core/Discovery/ServiceLocatorEventsIf.h"
+ #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+ #include <AsteriskSCF/Core/Discovery/ServiceLocatorEventsIf.h>
+ #include <AsteriskSCF/logger.h>
++#include <AsteriskSCF/ResponseCollector.h>
#include "ServiceLocatorManagement.h"
#include "ServiceManagement.h"
diff --cc src/ServiceManagement.cpp
index 7e3f108,7c04930..6542f01
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@@ -19,8 -19,9 +19,10 @@@
#include <boost/thread.hpp>
#include <boost/thread/shared_mutex.hpp>
- #include "Core/Discovery/ServiceLocatorIf.h"
- #include "Core/Discovery/ServiceLocatorEventsIf.h"
+ #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+ #include <AsteriskSCF/Core/Discovery/ServiceLocatorEventsIf.h>
+ #include <AsteriskSCF/logger.h>
++#include <AsteriskSCF/ResponseCollector.h>
#include "ServiceLocatorManagement.h"
#include "ServiceManagement.h"
commit af8f47d218d96feef91bdd8ab11595b65d543bf5
Author: David M. Lee <dlee at digium.com>
Date: Thu Jan 6 13:02:39 2011 -0600
Simplified the isSupported callbacks.
Instead of building a couple of layers of objects, added a callback
function directly on ServiceLocatorManagementImpl. It's good to delete
code :-)
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 3253736..f620d85 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -43,88 +43,6 @@ namespace ServiceLocatorManagementImplNS
const Logger& lg = getLoggerFactory().getLogger("AsteriskSCF.System.Discovery");
-/**
- * Callback class for isSupported AMI calls. Acts as a bridge between
- * Ice callbacks and IsSupportedCallback.
- * @see IsSupportedCallback
- */
-class Comparator_IsSupported_Callback : public IceUtil::Shared
-{
-public:
- Comparator_IsSupported_Callback(const IsSupportedCallbackPtr& callback) :
- callback(callback)
- {
- }
-
- void finished(const Ice::AsyncResultPtr& r)
- {
- ServiceLocatorParamsComparePrx comparator =
- ServiceLocatorParamsComparePrx::uncheckedCast(r->getProxy());
-
- try
- {
- // forward result to callback
- callback->result(comparator->end_isSupported(r));
- }
- catch (const std::exception& e)
- {
- lg(Error) << "Error communicating with comparator: " << e.what();
- callback->result(false);
- }
- catch(...)
- {
- lg(Error) << "Error communicating with comparator";
- callback->result(false);
- }
- }
-
-private:
- IsSupportedCallbackPtr callback;
-};
-typedef IceUtil::Handle<Comparator_IsSupported_Callback> Comparator_IsSupported_CallbackPtr;
-
-/**
- * Small internal class which is used to store information about a comparator.
- */
-class ServiceLocatorComparator
-{
-public:
- /**
- * 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.
- * Results are returned via callback object.
- *
- * @param params Service locator parameters that describe a locator request.
- * @param callback Callback object which receives the results.
- */
- void isSupported(const ServiceLocatorParamsPtr& params,
- const IsSupportedCallbackPtr& callback)
- {
- // wrap our callback with an Ice callback
- Comparator_IsSupported_CallbackPtr iceCallback =
- new Comparator_IsSupported_Callback(callback);
- // which is wrapped again...
- Ice::CallbackPtr d = Ice::newCallback(iceCallback,
- &Comparator_IsSupported_Callback::finished);
- // async forward to the comparator
- mCompare->begin_isSupported(params, d);
- }
-private:
- /**
- * A proxy to the comparator service that we are wrapping.
- */
- ServiceLocatorParamsComparePrx mCompare;
-};
-
/** Paramater type for Locator, to allow use of ResponseCollector. */
typedef std::pair<bool, ServiceManagementImplPtr> LocateParam;
@@ -274,7 +192,7 @@ private:
};
typedef IceUtil::Handle<LocateCallback> LocateCallbackPtr;
-} // end of ServiceLocatorManagementImplNS namespace
+} // end of ServiceLocatorManagementImplNS namespace
using namespace ServiceLocatorManagementImplNS;
IsSupportedCallback::~IsSupportedCallback()
@@ -311,7 +229,7 @@ public:
* 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;
+ std::map<std::string, ServiceLocatorParamsComparePrx> mCompares;
/**
* A vector of all the services that have been added.
@@ -428,10 +346,9 @@ void ServiceLocatorManagementImpl::addCompare(const string& guid,
{
lg(Info) << "addCompare(" << guid << ')';
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
- ServiceLocatorComparator newComparator(service);
- pair<map<string, ServiceLocatorComparator>::iterator, bool> insertPair = mImpl->mCompares.insert(pair<string, ServiceLocatorComparator>(guid,
- newComparator));
+ pair<map<string, ServiceLocatorParamsComparePrx>::iterator, bool> insertPair =
+ mImpl->mCompares.insert(make_pair(guid, service));
if (insertPair.second == false)
{
@@ -467,10 +384,10 @@ void ServiceLocatorManagementImpl::isSupported(const string& compareGuid,
const ServiceLocatorParamsPtr& params,
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.
+ /* 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 =
+ map<string, ServiceLocatorParamsComparePrx>::iterator comparator =
mImpl->mCompares.find(compareGuid);
if (comparator == mImpl->mCompares.end())
@@ -479,13 +396,40 @@ void ServiceLocatorManagementImpl::isSupported(const string& compareGuid,
return;
}
- (comparator->second).isSupported(params, callback);
+ Ice::CallbackPtr iceCallback = Ice::newCallback(this,
+ &ServiceLocatorManagementImpl::finish_isSupported);
+ (comparator->second)->begin_isSupported(params, iceCallback, callback);
+}
+
+void ServiceLocatorManagementImpl::finish_isSupported(
+ const Ice::AsyncResultPtr& r)
+{
+ ServiceLocatorParamsComparePrx compare =
+ ServiceLocatorParamsComparePrx::uncheckedCast(r->getProxy());
+ IsSupportedCallbackPtr callback =
+ IsSupportedCallbackPtr::dynamicCast(r->getCookie());
+
+ try
+ {
+ callback->result(compare->end_isSupported(r));
+ }
+ catch (const std::exception& e)
+ {
+ lg(Error) << "Error communicating with comparator: " << e.what();
+ callback->result(false);
+ }
+ catch(...)
+ {
+ lg(Error) << "Error communicating with comparator";
+ callback->result(false);
+ }
}
/**
* Implementation of the removeService method as defined in service_locator.ice
*/
-void ServiceLocatorManagementImpl::removeService(const ServiceManagementImplPtr& service)
+void ServiceLocatorManagementImpl::removeService(
+ const ServiceManagementImplPtr& service)
{
lg(Info) << "removeService(" << service->getGuid() << ')';
boost::unique_lock<boost::shared_mutex> lock(mImpl->mLock);
diff --git a/src/ServiceLocatorManagement.h b/src/ServiceLocatorManagement.h
index 0261939..6d9f65d 100644
--- a/src/ServiceLocatorManagement.h
+++ b/src/ServiceLocatorManagement.h
@@ -43,7 +43,7 @@ class ServiceLocatorManagementImplPriv;
* Callback interface for ServiceLocatorManagementImpl::isSupported.
* @see ServiceLocatorManagementImpl::isSupported
*/
-class IsSupportedCallback : public IceUtil::Shared
+class IsSupportedCallback : public Ice::LocalObject
{
public:
virtual ~IsSupportedCallback();
@@ -94,6 +94,9 @@ private:
* Private implementation data for ServiceLocatorManagementImpl.
*/
boost::shared_ptr<ServiceLocatorManagementImplPriv> mImpl;
+
+ /** Ice callback function */
+ void finish_isSupported(const Ice::AsyncResultPtr& r);
};
} /* end of ServiceDiscovery */
commit fac42e6c1a9dd61fe5d1fa28e137141d56443a1c
Author: David M. Lee <dlee at digium.com>
Date: Thu Jan 6 12:42:50 2011 -0600
Refactored CountedIsSupported to use ResponseCollector.
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
index 678bbd0..7e3f108 100644
--- a/src/ServiceManagement.cpp
+++ b/src/ServiceManagement.cpp
@@ -25,11 +25,13 @@
#include "ServiceLocatorManagement.h"
#include "ServiceManagement.h"
#include "logger.h"
+#include "ResponseCollector.h"
using namespace std;
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::ServiceDiscovery;
using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF;
namespace
{
@@ -181,31 +183,39 @@ ServiceManagementPrx ServiceManagementImpl::getServiceManagementPrx()
* invocations to a single callback. If any callbacks are true, true is
* called back. If none are true, false is called back.
*/
-class CountedIsSupported : public IsSupportedCallback
+class CountedIsSupported :
+ public IsSupportedCallback,
+ public ResponseCollector<bool>
{
public:
- CountedIsSupported(const IsSupportedCallbackPtr& callback, int numVotes) :
- callback(callback),
- numVotes(numVotes)
+ CountedIsSupported(const IsSupportedCallbackPtr& callback, size_t numVotes) :
+ callback(callback)
{
- if (numVotes == 0)
- {
- callback->result(false);
- this->callback = 0;
- }
+ init(numVotes);
}
- void result(bool result)
+ void result(bool result) { invoke(result); }
+
+protected:
+ void processInvocation(bool result)
{
- boost::lock_guard<boost::mutex> guard(mLock);
// any affirmitive vote means success
- if (result && callback)
+ if (result)
{
- callback->result(true);
- callback = 0;
+ boost::lock_guard<boost::mutex> guard(mMutex);
+ if (callback)
+ {
+ callback->result(true);
+ callback = 0;
+ }
}
+ }
+
+ void processCompletion()
+ {
+ boost::lock_guard<boost::mutex> guard(mMutex);
// all negative votes means failure
- if (--numVotes == 0 && callback)
+ if (callback)
{
callback->result(false);
callback = 0;
@@ -213,9 +223,7 @@ public:
}
private:
- boost::mutex mLock;
IsSupportedCallbackPtr callback;
- int numVotes;
};
/**
commit e27fb2812f4e636c49ea171bf07c55cb4ff76b38
Author: David M. Lee <dlee at digium.com>
Date: Thu Jan 6 10:41:23 2011 -0600
Refactored LocateOneCollector and LocateAllCollector.
diff --git a/src/ServiceLocatorManagement.cpp b/src/ServiceLocatorManagement.cpp
index 29ca8b8..3253736 100644
--- a/src/ServiceLocatorManagement.cpp
+++ b/src/ServiceLocatorManagement.cpp
@@ -25,12 +25,14 @@
#include "ServiceLocatorManagement.h"
#include "ServiceManagement.h"
#include "logger.h"
+#include "ResponseCollector.h"
using namespace std;
using namespace AsteriskSCF::System::Discovery;
using namespace AsteriskSCF::System::Logging;
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::ServiceDiscovery;
+using namespace AsteriskSCF;
//
// Normally would use an anonymous namespace here, but there is a compiler
@@ -123,28 +125,26 @@ private:
ServiceLocatorParamsComparePrx mCompare;
};
+/** Paramater type for Locator, to allow use of ResponseCollector. */
+typedef std::pair<bool, ServiceManagementImplPtr> LocateParam;
+
/**
* Interface that the LocateCallback uses for collecting information on which
* services are supported and which are not.
*/
-class LocateCollector : public IceUtil::Shared
+class LocateCollector :
+ public IceUtil::Shared,
+ public ResponseCollector<const LocateParam&>
+
{
-public:
- virtual ~LocateCollector() {}
- /**
- * Invoked for every service in ServiceLocatorManagementImplPriv::mServices.
- * @param management Pointer to the management object
- * @param supported resultsf from ServiceManagementImplPtr::isSupported
- */
- virtual void isSupported(const ServiceManagementImplPtr& management,
- bool supported) = 0;
};
/**
* A LocateCollector which forwards the first supported service to the
* given Ice callback.
*/
-class LocateOneCollector : public LocateCollector
+class LocateOneCollector :
+ public LocateCollector
{
public:
/**
@@ -152,32 +152,31 @@ public:
* @param cb Ice callback.
* @param numVotes The number of times isSupported will be called.
*/
- LocateOneCollector(const AMD_ServiceLocator_locatePtr& cb, int numVotes) :
- mCallback(cb), mNumVotes(numVotes)
+ LocateOneCollector(const AMD_ServiceLocator_locatePtr& cb, size_t numVotes) :
+ mCallback(cb)
{
- assert(mNumVotes >= 0);
- if (mNumVotes == 0)
- {
- ServiceNotFound e;
- mCallback->ice_exception(e);
- mCallback = 0;
- }
+ init(numVotes);
}
- void isSupported(const ServiceManagementImplPtr& management, bool supported)
+protected:
+ void processInvocation(const LocateParam& p)
{
- boost::lock_guard<boost::mutex> guard(mLock);
-
- if (supported && mCallback)
+ if (p.first)
{
- mCallback->ice_response(management->getService());
- // clear the mCallback pointer so we only answer once
- mCallback = 0;
+ boost::lock_guard<boost::mutex> guard(mMutex);
+ if (mCallback)
+ {
+ mCallback->ice_response(p.second->getService());
+ // clear the mCallback pointer so we only answer once
+ mCallback = 0;
+ }
}
+ }
- assert(mNumVotes > 0); // isSupported was called too many times
-
- if (--mNumVotes == 0 && mCallback)
+ void processCompletion()
+ {
+ boost::lock_guard<boost::mutex> guard(mMutex);
+ if (mCallback)
{
ServiceNotFound e;
mCallback->ice_exception(e);
@@ -187,18 +186,16 @@ public:
}
private:
- boost::mutex mLock;
/** Ice callback */
AMD_ServiceLocator_locatePtr mCallback;
- /** The number of times isSupported will be called. */
- int mNumVotes;
};
/**
* A LocateCollector which makes a list of all supported services to
* forward to the given Ice callback.
*/
-class LocateAllCollector : public LocateCollector
+class LocateAllCollector :
+ public LocateCollector
{
public:
/**
@@ -206,50 +203,42 @@ public:
* @param cb Ice callback.
* @param numVotes The number of times isSupported will be called.
*/
- LocateAllCollector(const AMD_ServiceLocator_locateAllPtr& cb, int numVotes) :
- mCallback(cb), mNumVotes(numVotes)
+ LocateAllCollector(const AMD_ServiceLocator_locateAllPtr& cb, size_t numVotes)
+ :
+ mCallback(cb)
+ {
+ init(numVotes);
+ }
+
+protected:
+ void processInvocation(const LocateParam& p)
{
- assert(mNumVotes >= 0);
- if (mNumVotes == 0)
+ if (p.first)
{
- ServiceNotFound e;
- mCallback->ice_exception(e);
- mCallback = 0;
+ boost::lock_guard<boost::mutex> guard(mMutex);
+ mValue.push_back(p.second->getService());
}
}
- void isSupported(const ServiceManagementImplPtr& management, bool supported)
+ void processCompletion()
{
- boost::lock_guard<boost::mutex> guard(mLock);
-
- if (supported)
+ // the votes are in!
+ if (!mValue.empty())
{
- mValue.push_back(management->getService());
+ mCallback->ice_response(mValue);
}
-
- if (--mNumVotes == 0 && mCallback)
+ else
{
- // the votes are in!
- if (!mValue.empty())
- {
- mCallback->ice_response(mValue);
- }
- else
- {
- ServiceNotFound e;
- mCallback->ice_exception(e);
- }
- // we're done with the callback
- mCallback = 0;
+ ServiceNotFound e;
+ mCallback->ice_exception(e);
}
+ // we're done with the callback
+ mCallback = 0;
}
private:
- boost::mutex mLock;
/** Ice callback */
AMD_ServiceLocator_locateAllPtr mCallback;
- /** The number of times isSupported will be called. */
- int mNumVotes;
/** Collected results */
Ice::ObjectProxySeq mValue;
};
@@ -276,7 +265,7 @@ public:
{
// delegation to thread safe object
// no lock needed
- collector->isSupported(management, result);
+ collector->invoke(LocateParam(result, management));
collector = 0;
}
private:
commit ce4af3b38292f34cf39ead9b498cd23c065e6ee3
Author: David M. Lee <dlee at digium.com>
Date: Thu Jan 6 10:28:43 2011 -0600
Adding AmiCollector to include path.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2d9a45b..113a797 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -30,6 +30,7 @@ if(NOT logger_dir)
endif()
include_directories(${logger_dir}/common)
include_directories(${logger_dir}/client/src)
+include_directories(${utils_dir}/AmiCollector/src)
asterisk_scf_component_build_icebox(service_locator)
target_link_libraries(service_locator logging-client)
-----------------------------------------------------------------------
--
asterisk-scf/release/servicediscovery.git
More information about the asterisk-scf-commits
mailing list