[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "logformat2" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Sep 2 18:36:13 CDT 2011
branch "logformat2" has been created
at b07fa38a549385d8721eb51ff23ff1d2bc33f1fb (commit)
- Log -----------------------------------------------------------------
commit b07fa38a549385d8721eb51ff23ff1d2bc33f1fb
Author: Ken Hunt <ken.hunt at digium.com>
Date: Fri Sep 2 18:34:42 2011 -0500
Set additional logger information specific to the component.
diff --git a/src/Component/Component.cpp b/src/Component/Component.cpp
index afef647..c584c57 100644
--- a/src/Component/Component.cpp
+++ b/src/Component/Component.cpp
@@ -689,6 +689,7 @@ void Component::configureLogger()
try
{
ConfiguredIceLoggerPtr mIceLogger = createIceLogger(mBackplaneAdapter);
+ mIceLogger->getLogger().setComponentInfo(mComponentDiscoveryCategory, mServiceName, mName);
getLoggerFactory().setLogOutput(mIceLogger->getLogger());
}
catch(const std::exception& e)
commit 16212c6a5a5c648cc7a3d4a001b1fabee8303e10
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Aug 25 13:41:33 2011 -0500
Fix spelling of getServiceManagement
diff --git a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index 2cef1fa..e6d410f 100644
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@ -122,7 +122,7 @@ public:
mServiceManagement->unsuspend();
}
- AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx getServiceMangement()
+ AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx getServiceManagement()
{
return mServiceManagement;
}
commit 3deea66aefa19e940ca6a5ec0649a0c722a15e23
Author: Ken Hunt <ken.hunt at digium.com>
Date: Thu Aug 11 17:00:36 2011 -0500
- Incorporates suggest to rename Set.
- Moved each template class defined in Set.h into its own file.
- Incorporated suggestion to support "set" semantics on the interface rather than a mix os "set" and "hashtable".
diff --git a/include/AsteriskSCF/Collections/HandleSet.h b/include/AsteriskSCF/Collections/HandleSet.h
new file mode 100644
index 0000000..04772d9
--- /dev/null
+++ b/include/AsteriskSCF/Collections/HandleSet.h
@@ -0,0 +1,72 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/locks.hpp>
+
+#include <Ice/Ice.h>
+
+#include <AsteriskSCF/System/ExceptionsIf.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Helpers/ProxyHelper.h>
+#include <AsteriskSCF/Collections/LoggedSet.h>
+
+namespace AsteriskSCF
+{
+namespace Collections
+{
+
+/**
+ * Maintains a set of Handle objects of type S.
+ * The type S is must be derived from Ice::Handle.
+ * For further details, refer to the LoggedSet definition.
+ * @see LoggedSet
+ */
+ template <typename S>
+ class HandleSet : public LoggedSet<S, std::string, AsteriskSCF::System::V1::NullHandleException>
+ {
+ public:
+ HandleSet(const AsteriskSCF::System::Logging::Logger& logger,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : LoggedSet<S, std::string, AsteriskSCF::System::V1::NullHandleException>
+ (logger,
+ loggingLabel,
+ doesThrow)
+ {
+ }
+
+ HandleSet(const std::string& loggingLabel,
+ bool doesThrow = true)
+ : LoggedSet<S, std::string, AsteriskSCF::System::V1::NullHandleException>
+ (loggingLabel,
+ doesThrow)
+
+ {
+ }
+
+protected:
+ virtual std::string getIdentity(const S & item)
+ {
+ return item->ice_id();
+ }
+ };
+
+} // end namespace Collections
+} // end namespace AsteriskSCF
diff --git a/include/AsteriskSCF/Collections/Set.h b/include/AsteriskSCF/Collections/LoggedSet.h
similarity index 66%
rename from include/AsteriskSCF/Collections/Set.h
rename to include/AsteriskSCF/Collections/LoggedSet.h
index 78f7f21..c43111d 100644
--- a/include/AsteriskSCF/Collections/Set.h
+++ b/include/AsteriskSCF/Collections/LoggedSet.h
@@ -33,32 +33,33 @@ namespace Collections
/**
* Maintains a set of type T.
- * The items are keyed on a type K.
- * The set maintains at most one item of a given id.
- * The id for an item is obtained via an overridable member function
- * getIdentity().
+ * - The items are keyed on a type K.
+ * - The set maintains at most one item of a given key.
+ * - The key for an item must be obtainable from the item itself. The
+ * getIdentity(item) operation (a required override) allows flexibility
+ * in how the identity is obtained.
+ * - Operations on the set are made internally thread safe.
+ * - The set will log (at Warning level) calls that don't complete in normal
+ * fashion. (ex: attempt to add a null object, attempt to acquire a non-existent member, etc.)
+ * - Execeptions are optionally thrown based on argument to constructor.
*/
template <typename T, typename K, typename NullItemException>
-class Set
+class LoggedSet
{
public:
- Set(const Ice::ObjectAdapterPtr& adapter,
- const AsteriskSCF::System::Logging::Logger& logger,
+ LoggedSet(const AsteriskSCF::System::Logging::Logger& logger,
const std::string& loggingLabel,
bool doesThrow = true)
: mLogger(logger),
mLoggingLabel(loggingLabel),
- mAdapter(adapter),
mDoesThrow(doesThrow)
{
}
- Set(const Ice::ObjectAdapterPtr& adapter,
- const std::string& loggingLabel,
+ LoggedSet(const std::string& loggingLabel,
bool doesThrow = true)
: mLogger(AsteriskSCF::System::Logging::getLoggerFactory().getLogger("AsteriskSCF.Collections")),
mLoggingLabel(loggingLabel),
- mAdapter(adapter),
mDoesThrow(doesThrow)
{
@@ -78,7 +79,7 @@ public:
boost::unique_lock<boost::shared_mutex> lock(mLock);
if (item == 0)
{
- mLogger(AsteriskSCF::System::Logging::Warning) << "Attempting to add a null member for " << mLoggingLabel;
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempt to add a null member for " << mLoggingLabel << " rejected.";
if (mDoesThrow)
{
throw NullItemException();
@@ -106,7 +107,7 @@ public:
{
if ((*i) == 0)
{
- mLogger(AsteriskSCF::System::Logging::Warning) << "Attempting to add a null member for " << mLoggingLabel;
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempt to add a null member for " << mLoggingLabel << " rejected.";
continue;
}
@@ -146,7 +147,7 @@ public:
for(typename std::vector<K>::const_iterator s = idsNotFound.begin(); s != idsNotFound.end(); ++s)
{
- mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to remove non-existent member " << (*s);
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to remove non-existent member " << (*s) << " from " << mLoggingLabel;
}
}
@@ -165,7 +166,7 @@ public:
return;
}
- mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to remove non-existent member " << id;
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to remove non-existent member " << id << " from " << mLoggingLabel;
if (mDoesThrow)
{
throw AsteriskSCF::System::V1::UnknownObject(id);
@@ -220,6 +221,8 @@ public:
return pair->second;
}
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to get a non-existent member " << key << " from " << mLoggingLabel;
+
if (mDoesThrow)
{
throw AsteriskSCF::System::V1::UnknownObject(key);
@@ -227,101 +230,35 @@ public:
return 0;
}
- bool has(K key)
+ bool has(const T& item)
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
- typename std::map<K, T>::const_iterator search = mMap.find(key);
+ typename std::map<K, T>::const_iterator search = mMap.find(getIdentity(item));
return (search != mMap.end());
}
- typedef boost::shared_ptr< Set<T, K, NullItemException> > SetPtr;
+ bool empty()
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ return mMap.empty();
+ }
+
+ // A shared pointer to this set type.
+ typedef boost::shared_ptr< LoggedSet<T, K, NullItemException> > SetPtr;
protected:
+ // Overridable operation that determines how the key is obtained from an item.
virtual K getIdentity(const T & item) = 0;
AsteriskSCF::System::Logging::Logger mLogger;
std::string mLoggingLabel;
- Ice::ObjectAdapterPtr mAdapter;
boost::shared_mutex mLock;
std::map<K, T> mMap;
bool mDoesThrow;
};
-/**
- * Maintains a set of handles of type S.
- * The type S is assumed to be derived from Ice::Handle.
- */
- template <typename S>
- class HandleSet : public Set<S, std::string, AsteriskSCF::System::V1::NullHandleException>
- {
- public:
- HandleSet(const Ice::ObjectAdapterPtr& adapter,
- const AsteriskSCF::System::Logging::Logger& logger,
- const std::string& loggingLabel,
- bool doesThrow = true)
- : Set<S, std::string, AsteriskSCF::System::V1::NullHandleException>(adapter,
- logger,
- loggingLabel,
- doesThrow)
- {
- }
-
- HandleSet(const Ice::ObjectAdapterPtr& adapter,
- const std::string& loggingLabel,
- bool doesThrow = true)
- : Set<S, std::string, AsteriskSCF::System::V1::NullHandleException>(adapter,
- loggingLabel,
- doesThrow)
-
- {
- }
-
-protected:
- virtual std::string getIdentity(const S & item)
- {
- return item->ice_id();
- }
- };
-
-/**
-* Maintains a set of proxies of type S.
-* The type S is assumed to be derived from Ice::Proxy.
-*/
-template <typename S>
-class ProxySet : public Set<S, std::string, AsteriskSCF::System::V1::NullProxyException>
-{
-public:
- ProxySet(const Ice::ObjectAdapterPtr& adapter,
- const AsteriskSCF::System::Logging::Logger& logger,
- const std::string& loggingLabel,
- bool doesThrow = true)
- : Set<S, std::string, AsteriskSCF::System::V1::NullProxyException>(adapter,
- logger,
- loggingLabel,
- doesThrow)
- {
- }
-
- ProxySet(const Ice::ObjectAdapterPtr& adapter,
- const std::string& loggingLabel,
- bool doesThrow = true)
- : Set<S, std::string, AsteriskSCF::System::V1::NullProxyException>(adapter,
- loggingLabel,
- doesThrow)
-
- {
- }
-
-protected:
- virtual std::string getIdentity(const S & item)
- {
- // Note: In referencing a member of a base template class, gcc requires the "this"
- // to know where to look for the member variable.
- return this->mAdapter->getCommunicator()->identityToString(item->ice_getIdentity());
- }
-};
} // end namespace Collections
} // end namespace AsteriskSCF
diff --git a/include/AsteriskSCF/Collections/ProxySet.h b/include/AsteriskSCF/Collections/ProxySet.h
new file mode 100644
index 0000000..8f41b6e
--- /dev/null
+++ b/include/AsteriskSCF/Collections/ProxySet.h
@@ -0,0 +1,78 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/locks.hpp>
+
+#include <Ice/Ice.h>
+
+#include <AsteriskSCF/System/ExceptionsIf.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Helpers/ProxyHelper.h>
+#include <AsteriskSCF/Collections/LoggedSet.h>
+
+namespace AsteriskSCF
+{
+namespace Collections
+{
+
+/**
+* Maintains a set of Ice proxies of type S.
+* The type S must be derived from Ice::Proxy.
+ * For further details, refer to the LoggedSet definition.
+* @see LoggedSet
+*/
+template <typename S>
+class ProxySet : public LoggedSet<S, std::string, AsteriskSCF::System::V1::NullProxyException>
+{
+public:
+ ProxySet(const Ice::ObjectAdapterPtr& adapter,
+ const AsteriskSCF::System::Logging::Logger& logger,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : LoggedSet<S, std::string, AsteriskSCF::System::V1::NullProxyException>(
+ logger,
+ loggingLabel,
+ doesThrow),
+ mAdapter(adapter)
+ {
+ }
+
+ ProxySet(const Ice::ObjectAdapterPtr& adapter,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : LoggedSet<S, std::string, AsteriskSCF::System::V1::NullProxyException>(
+ loggingLabel,
+ doesThrow),
+ mAdapter(adapter)
+
+ {
+ }
+
+protected:
+ virtual std::string getIdentity(const S & item)
+ {
+ return mAdapter->getCommunicator()->identityToString(item->ice_getIdentity());
+ }
+
+ Ice::ObjectAdapterPtr mAdapter;
+};
+
+} // end namespace Collections
+} // end namespace AsteriskSCF
diff --git a/test/Collections/TestCollections.cpp b/test/Collections/TestCollections.cpp
index fb54ce9..ac1ccf7 100644
--- a/test/Collections/TestCollections.cpp
+++ b/test/Collections/TestCollections.cpp
@@ -24,7 +24,8 @@
#include <AsteriskSCF/Testing/IceBoxBoostTest.h>
#include <TestCollectionsIf.h>
-#include <AsteriskSCF/Collections/Set.h>
+#include <AsteriskSCF/Collections/HandleSet.h>
+#include <AsteriskSCF/Collections/ProxySet.h>
using namespace std;
using namespace AsteriskSCF::Collections;
@@ -189,8 +190,9 @@ BOOST_AUTO_TEST_CASE(ProxySetTest)
BOOST_CHECK(caught == false);
BOOST_CHECK(results.size() == 0);
+ BOOST_CHECK(proxySet.empty() == true);
- BOOST_CHECK(proxySet.has("Something") == false);
+ BOOST_CHECK(proxySet.has(global.prx2) == false);
///////////////////////////////////////////////////////
// Now add some content added.
@@ -203,10 +205,12 @@ BOOST_AUTO_TEST_CASE(ProxySetTest)
proxySet.add(multiple);
- BOOST_CHECK(proxySet.has( IceBoxTestEnv.adapter->getCommunicator()->identityToString(global.prx1->ice_getIdentity())) == true);
+ BOOST_CHECK(proxySet.has( global.prx1) == true);
BOOST_CHECK(proxySet.size() == 3);
+ BOOST_CHECK(proxySet.has(global.prx2) == true);
+
proxySet.remove(global.prx2);
BOOST_CHECK(proxySet.size() == 2);
@@ -214,6 +218,8 @@ BOOST_AUTO_TEST_CASE(ProxySetTest)
results = proxySet.getAll();
BOOST_CHECK(results.size() == 2);
+ BOOST_CHECK(proxySet.has(global.prx2) == false);
+
SampleListenerPrx prx = proxySet.get(IceBoxTestEnv.adapter->getCommunicator()->identityToString(global.prx1->ice_getIdentity()));
BOOST_CHECK(prx->ice_getIdentity() == global.prx1->ice_getIdentity());
@@ -237,7 +243,7 @@ BOOST_AUTO_TEST_CASE(ProxySetTest)
*/
BOOST_AUTO_TEST_CASE(HandleSetTest)
{
- HandleSet<BaseValuePtr> handleSet(IceBoxTestEnv.adapter, lg, "Values Set");
+ HandleSet<BaseValuePtr> handleSet(lg, "Values Set");
/////////////////////////////////////////////////////////////
// Try accessing the empty set first.
@@ -288,7 +294,9 @@ BOOST_AUTO_TEST_CASE(HandleSetTest)
BOOST_CHECK(caught == false);
BOOST_CHECK(results.size() == 0);
- BOOST_CHECK(handleSet.has("Something") == false);
+ BOOST_CHECK(handleSet.has(global.ptr1) == false);
+
+ BOOST_CHECK(handleSet.empty() == true);
///////////////////////////////////////////////////////
// Now add some content added.
@@ -299,15 +307,18 @@ BOOST_AUTO_TEST_CASE(HandleSetTest)
multiple.push_back(global.ptr2);
multiple.push_back(global.ptr3);
+ BOOST_CHECK(handleSet.empty() == false);
+
handleSet.add(multiple);
- BOOST_CHECK(handleSet.has(global.ptr1->ice_id()) == true);
+ BOOST_CHECK(handleSet.has(global.ptr2) == true);
BOOST_CHECK(handleSet.size() == 3);
handleSet.remove(global.ptr2);
BOOST_CHECK(handleSet.size() == 2);
+ BOOST_CHECK(handleSet.has(global.ptr2) == false);
results = handleSet.getAll();
BOOST_CHECK(results.size() == 2);
commit a5fe978beeaeff3362834fbf4a9210106988f6d8
Author: Ken Hunt <ken.hunt at digium.com>
Date: Wed Aug 10 20:09:45 2011 -0500
Some minor gcc template requirements addressed.
diff --git a/include/AsteriskSCF/Collections/Set.h b/include/AsteriskSCF/Collections/Set.h
index ce250c3..78f7f21 100644
--- a/include/AsteriskSCF/Collections/Set.h
+++ b/include/AsteriskSCF/Collections/Set.h
@@ -64,7 +64,7 @@ public:
{
}
- int size()
+ size_t size()
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
return mMap.size();
@@ -102,7 +102,7 @@ public:
void add(const std::vector<T>& items)
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
- for (std::vector<T>::const_iterator i = items.begin(); i != items.end(); ++i)
+ for (typename std::vector<T>::const_iterator i = items.begin(); i != items.end(); ++i)
{
if ((*i) == 0)
{
@@ -129,11 +129,11 @@ public:
boost::unique_lock<boost::shared_mutex> lock(mLock);
std::vector<K> idsNotFound;
- for (std::vector<T>::const_iterator i = items.begin(); i != items.end(); ++i)
+ for (typename std::vector<T>::const_iterator i = items.begin(); i != items.end(); ++i)
{
K id = getIdentity(*i);
- std::map<K, T>::iterator searchResult = mMap.find(id);
+ typename std::map<K, T>::iterator searchResult = mMap.find(id);
if (searchResult != mMap.end())
{
mMap.erase(searchResult);
@@ -144,7 +144,7 @@ public:
}
}
- for(std::vector<K>::const_iterator s = idsNotFound.begin(); s != idsNotFound.end(); ++s)
+ for(typename std::vector<K>::const_iterator s = idsNotFound.begin(); s != idsNotFound.end(); ++s)
{
mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to remove non-existent member " << (*s);
}
@@ -157,7 +157,7 @@ public:
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
K id = getIdentity(item);
- std::map<K, T>::iterator searchResult = mMap.find(id);
+ typename std::map<K, T>::iterator searchResult = mMap.find(id);
if (searchResult != mMap.end())
{
@@ -180,7 +180,7 @@ public:
boost::unique_lock<boost::shared_mutex> lock(mLock);
std::vector<T> result;
- for (std::map<K,T>::const_iterator pair = mMap.begin(); pair != mMap.end(); ++pair)
+ for (typename std::map<K,T>::const_iterator pair = mMap.begin(); pair != mMap.end(); ++pair)
{
result.push_back(pair->second);
}
@@ -198,9 +198,9 @@ public:
boost::unique_lock<boost::shared_mutex> lock(mLock);
std::vector<T> result;
- for (std::vector<T>::const_iterator i = toRetrieve.begin(); i != toRetrieve.end(); ++i)
+ for (typename std::vector<T>::const_iterator i = toRetrieve.begin(); i != toRetrieve.end(); ++i)
{
- std::map<K,T>::const_iterator pair = mMap.find(getIdentity(*i));
+ typename std::map<K,T>::const_iterator pair = mMap.find(getIdentity(*i));
if (pair != mMap.end())
{
result.push_back(pair->second);
@@ -213,7 +213,7 @@ public:
T get(const K& key)
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
- std::map<K, T>::const_iterator pair = mMap.find(key);
+ typename std::map<K, T>::const_iterator pair = mMap.find(key);
if (pair != mMap.end())
{
@@ -231,7 +231,7 @@ public:
{
boost::unique_lock<boost::shared_mutex> lock(mLock);
- std::map<K, T>::const_iterator search = mMap.find(key);
+ typename std::map<K, T>::const_iterator search = mMap.find(key);
return (search != mMap.end());
}
@@ -239,7 +239,7 @@ public:
protected:
- virtual K getIdentity(const T& item) = 0;
+ virtual K getIdentity(const T & item) = 0;
AsteriskSCF::System::Logging::Logger mLogger;
std::string mLoggingLabel;
@@ -261,7 +261,7 @@ protected:
const AsteriskSCF::System::Logging::Logger& logger,
const std::string& loggingLabel,
bool doesThrow = true)
- : Set(adapter,
+ : Set<S, std::string, AsteriskSCF::System::V1::NullHandleException>(adapter,
logger,
loggingLabel,
doesThrow)
@@ -271,15 +271,15 @@ protected:
HandleSet(const Ice::ObjectAdapterPtr& adapter,
const std::string& loggingLabel,
bool doesThrow = true)
- : Set(adapter,
+ : Set<S, std::string, AsteriskSCF::System::V1::NullHandleException>(adapter,
loggingLabel,
doesThrow)
{
}
- protected:
- virtual std::string getIdentity(const S& item)
+protected:
+ virtual std::string getIdentity(const S & item)
{
return item->ice_id();
}
@@ -293,31 +293,33 @@ template <typename S>
class ProxySet : public Set<S, std::string, AsteriskSCF::System::V1::NullProxyException>
{
public:
-ProxySet(const Ice::ObjectAdapterPtr& adapter,
- const AsteriskSCF::System::Logging::Logger& logger,
- const std::string& loggingLabel,
- bool doesThrow = true)
- : Set(adapter,
- logger,
- loggingLabel,
- doesThrow)
-{
-}
-
-ProxySet(const Ice::ObjectAdapterPtr& adapter,
- const std::string& loggingLabel,
- bool doesThrow = true)
- : Set(adapter,
- loggingLabel,
- doesThrow)
+ ProxySet(const Ice::ObjectAdapterPtr& adapter,
+ const AsteriskSCF::System::Logging::Logger& logger,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : Set<S, std::string, AsteriskSCF::System::V1::NullProxyException>(adapter,
+ logger,
+ loggingLabel,
+ doesThrow)
+ {
+ }
+
+ ProxySet(const Ice::ObjectAdapterPtr& adapter,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : Set<S, std::string, AsteriskSCF::System::V1::NullProxyException>(adapter,
+ loggingLabel,
+ doesThrow)
-{
-}
+ {
+ }
protected:
- virtual std::string getIdentity(const S& item)
+ virtual std::string getIdentity(const S & item)
{
- return mAdapter->getCommunicator()->identityToString(item->ice_getIdentity());
+ // Note: In referencing a member of a base template class, gcc requires the "this"
+ // to know where to look for the member variable.
+ return this->mAdapter->getCommunicator()->identityToString(item->ice_getIdentity());
}
};
commit aa7afeacd622f141bb97c70c40a983243491433c
Author: Ken Hunt <ken.hunt at digium.com>
Date: Wed Aug 10 19:12:44 2011 -0500
Added Set.h and tests.
diff --git a/include/AsteriskSCF/Collections/Set.h b/include/AsteriskSCF/Collections/Set.h
new file mode 100644
index 0000000..ce250c3
--- /dev/null
+++ b/include/AsteriskSCF/Collections/Set.h
@@ -0,0 +1,325 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/locks.hpp>
+
+#include <Ice/Ice.h>
+
+#include <AsteriskSCF/System/ExceptionsIf.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Helpers/ProxyHelper.h>
+
+namespace AsteriskSCF
+{
+namespace Collections
+{
+
+/**
+ * Maintains a set of type T.
+ * The items are keyed on a type K.
+ * The set maintains at most one item of a given id.
+ * The id for an item is obtained via an overridable member function
+ * getIdentity().
+ */
+template <typename T, typename K, typename NullItemException>
+class Set
+{
+public:
+ Set(const Ice::ObjectAdapterPtr& adapter,
+ const AsteriskSCF::System::Logging::Logger& logger,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : mLogger(logger),
+ mLoggingLabel(loggingLabel),
+ mAdapter(adapter),
+ mDoesThrow(doesThrow)
+ {
+ }
+
+ Set(const Ice::ObjectAdapterPtr& adapter,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : mLogger(AsteriskSCF::System::Logging::getLoggerFactory().getLogger("AsteriskSCF.Collections")),
+ mLoggingLabel(loggingLabel),
+ mAdapter(adapter),
+ mDoesThrow(doesThrow)
+
+ {
+ }
+
+ int size()
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ return mMap.size();
+ }
+
+ /**
+ * Add a single item.
+ */
+ void add(const T& item)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ if (item == 0)
+ {
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempting to add a null member for " << mLoggingLabel;
+ if (mDoesThrow)
+ {
+ throw NullItemException();
+ }
+ return;
+ }
+
+ K id = getIdentity(item);
+
+ if (mMap.find(id) != mMap.end())
+ {
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Replacing member " << id << " for " << mLoggingLabel;
+ }
+
+ mMap[id] = item;
+ }
+
+ /**
+ * Add a vector of items.
+ */
+ void add(const std::vector<T>& items)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ for (std::vector<T>::const_iterator i = items.begin(); i != items.end(); ++i)
+ {
+ if ((*i) == 0)
+ {
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempting to add a null member for " << mLoggingLabel;
+ continue;
+ }
+
+ K id = getIdentity(*i);
+
+ if (mMap.find(id) != mMap.end())
+ {
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Replacing member " << id << " for " << mLoggingLabel;
+ }
+
+ mMap[id] = (*i);
+ }
+ }
+
+ /**
+ * Remove a vector of items.
+ */
+ void remove(const std::vector<T>& items)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ std::vector<K> idsNotFound;
+
+ for (std::vector<T>::const_iterator i = items.begin(); i != items.end(); ++i)
+ {
+ K id = getIdentity(*i);
+
+ std::map<K, T>::iterator searchResult = mMap.find(id);
+ if (searchResult != mMap.end())
+ {
+ mMap.erase(searchResult);
+ }
+ else
+ {
+ idsNotFound.push_back(id);
+ }
+ }
+
+ for(std::vector<K>::const_iterator s = idsNotFound.begin(); s != idsNotFound.end(); ++s)
+ {
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to remove non-existent member " << (*s);
+ }
+ }
+
+ /**
+ * Remove an item.
+ */
+ void remove(const T& item)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ K id = getIdentity(item);
+ std::map<K, T>::iterator searchResult = mMap.find(id);
+
+ if (searchResult != mMap.end())
+ {
+ mMap.erase(searchResult);
+ return;
+ }
+
+ mLogger(AsteriskSCF::System::Logging::Warning) << "Attempted to remove non-existent member " << id;
+ if (mDoesThrow)
+ {
+ throw AsteriskSCF::System::V1::UnknownObject(id);
+ }
+ }
+
+ /**
+ * Retrieves all the items in the set.
+ */
+ std::vector<T> getAll()
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ std::vector<T> result;
+
+ for (std::map<K,T>::const_iterator pair = mMap.begin(); pair != mMap.end(); ++pair)
+ {
+ result.push_back(pair->second);
+ }
+
+ return result;
+ }
+
+ /**
+ * Retrieves specific items from the set.
+ * The identies of the items in the collection passed in
+ * are used to retrieve from the managed set.
+ */
+ std::vector<T> get(const std::vector<T>& toRetrieve)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ std::vector<T> result;
+
+ for (std::vector<T>::const_iterator i = toRetrieve.begin(); i != toRetrieve.end(); ++i)
+ {
+ std::map<K,T>::const_iterator pair = mMap.find(getIdentity(*i));
+ if (pair != mMap.end())
+ {
+ result.push_back(pair->second);
+ }
+ }
+
+ return result;
+ }
+
+ T get(const K& key)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ std::map<K, T>::const_iterator pair = mMap.find(key);
+
+ if (pair != mMap.end())
+ {
+ return pair->second;
+ }
+
+ if (mDoesThrow)
+ {
+ throw AsteriskSCF::System::V1::UnknownObject(key);
+ }
+ return 0;
+ }
+
+ bool has(K key)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+
+ std::map<K, T>::const_iterator search = mMap.find(key);
+ return (search != mMap.end());
+ }
+
+ typedef boost::shared_ptr< Set<T, K, NullItemException> > SetPtr;
+
+protected:
+
+ virtual K getIdentity(const T& item) = 0;
+
+ AsteriskSCF::System::Logging::Logger mLogger;
+ std::string mLoggingLabel;
+ Ice::ObjectAdapterPtr mAdapter;
+ boost::shared_mutex mLock;
+ std::map<K, T> mMap;
+ bool mDoesThrow;
+};
+
+/**
+ * Maintains a set of handles of type S.
+ * The type S is assumed to be derived from Ice::Handle.
+ */
+ template <typename S>
+ class HandleSet : public Set<S, std::string, AsteriskSCF::System::V1::NullHandleException>
+ {
+ public:
+ HandleSet(const Ice::ObjectAdapterPtr& adapter,
+ const AsteriskSCF::System::Logging::Logger& logger,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : Set(adapter,
+ logger,
+ loggingLabel,
+ doesThrow)
+ {
+ }
+
+ HandleSet(const Ice::ObjectAdapterPtr& adapter,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : Set(adapter,
+ loggingLabel,
+ doesThrow)
+
+ {
+ }
+
+ protected:
+ virtual std::string getIdentity(const S& item)
+ {
+ return item->ice_id();
+ }
+ };
+
+/**
+* Maintains a set of proxies of type S.
+* The type S is assumed to be derived from Ice::Proxy.
+*/
+template <typename S>
+class ProxySet : public Set<S, std::string, AsteriskSCF::System::V1::NullProxyException>
+{
+public:
+ProxySet(const Ice::ObjectAdapterPtr& adapter,
+ const AsteriskSCF::System::Logging::Logger& logger,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : Set(adapter,
+ logger,
+ loggingLabel,
+ doesThrow)
+{
+}
+
+ProxySet(const Ice::ObjectAdapterPtr& adapter,
+ const std::string& loggingLabel,
+ bool doesThrow = true)
+ : Set(adapter,
+ loggingLabel,
+ doesThrow)
+
+{
+}
+
+protected:
+ virtual std::string getIdentity(const S& item)
+ {
+ return mAdapter->getCommunicator()->identityToString(item->ice_getIdentity());
+ }
+};
+
+} // end namespace Collections
+} // end namespace AsteriskSCF
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index e6e992c..068c0ed 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -16,6 +16,7 @@ astscf_test_icebox(astscf-ice-util-cpp-test config/IceUtilCppTests.conf)
add_subdirectory(Async)
add_subdirectory(Component)
+add_subdirectory(Collections)
add_subdirectory(Replication)
add_subdirectory(ThreadPool)
add_subdirectory(WorkQueue)
diff --git a/test/Collections/CMakeLists.txt b/test/Collections/CMakeLists.txt
new file mode 100644
index 0000000..87768a6
--- /dev/null
+++ b/test/Collections/CMakeLists.txt
@@ -0,0 +1,10 @@
+
+astscf_component_init(CollectionsTest)
+astscf_slice_collection(LOCAL PATH "${CMAKE_CURRENT_SOURCE_DIR}")
+astscf_component_add_files(CollectionsTest TestCollections.cpp)
+astscf_component_add_slices(CollectionsTest LOCAL TestCollectionsIf.ice)
+astscf_component_add_boost_libraries(CollectionsTest unit_test_framework thread date_time)
+astscf_component_add_slice_collection_libraries(CollectionsTest ASTSCF)
+astscf_component_build_icebox(CollectionsTest)
+astscf_test_icebox(CollectionsTest test/Collections/TestCollections.conf)
+target_link_libraries(CollectionsTest logging-client)
diff --git a/test/Collections/TestCollections.conf b/test/Collections/TestCollections.conf
new file mode 100644
index 0000000..fa50cb4
--- /dev/null
+++ b/test/Collections/TestCollections.conf
@@ -0,0 +1,3 @@
+
+IceBox.Service.CollectionsTest = CollectionsTest:create --log_level=all
+
diff --git a/test/Collections/TestCollections.cpp b/test/Collections/TestCollections.cpp
new file mode 100644
index 0000000..fb54ce9
--- /dev/null
+++ b/test/Collections/TestCollections.cpp
@@ -0,0 +1,324 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#define BOOST_TEST_MODULE StateReplicatorComponentTestSuite
+#define BOOST_TEST_NO_MAIN
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/debug.hpp>
+
+#include <Ice/Ice.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Testing/IceBoxBoostTest.h>
+
+#include <TestCollectionsIf.h>
+#include <AsteriskSCF/Collections/Set.h>
+
+using namespace std;
+using namespace AsteriskSCF::Collections;
+using namespace AsteriskSCF::CollectionsTest;
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::System::V1;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.TestCollections");
+}
+
+class SampleListenerImpl : public SampleListener
+{
+public:
+ SampleListenerImpl() : mHiCalled(0) {}
+
+ void hiThere(const Ice::Current &)
+ {
+ mHiCalled++;
+ }
+
+int mHiCalled;
+};
+typedef IceUtil::Handle<SampleListenerImpl> SampleListenerImplPtr;
+
+struct GlobalData
+{
+public:
+ SampleListenerPrx prx1;
+ SampleListenerPrx prx2;
+ SampleListenerPrx prx3;
+
+ ChildValue1Ptr ptr1;
+ ChildValue2Ptr ptr2;
+ ChildValue3Ptr ptr3;
+};
+GlobalData global;
+
+/**
+ * A global fixture for Ice initialization.
+ * Provides setup/teardown for the entire set of tests.
+ */
+struct GlobalIceFixture
+{
+ GlobalIceFixture()
+ {
+ ::boost::debug::detect_memory_leaks(false);
+ ::boost::unit_test::unit_test_log.set_stream( std::cout );
+
+ int status = 0;
+ try
+ {
+ IceBoxTestEnv.adapter = IceBoxTestEnv.communicator->createObjectAdapterWithEndpoints("TestCollections","default");
+
+ SampleListenerImplPtr listener = new SampleListenerImpl();
+ global.prx1 = SampleListenerPrx::uncheckedCast(IceBoxTestEnv.adapter->addWithUUID(listener));
+
+ listener = new SampleListenerImpl();
+ global.prx2 = SampleListenerPrx::uncheckedCast(IceBoxTestEnv.adapter->addWithUUID(listener));
+
+ listener = new SampleListenerImpl();
+ global.prx3 = SampleListenerPrx::uncheckedCast(IceBoxTestEnv.adapter->addWithUUID(listener));
+
+ global.ptr1 = new ChildValue1();
+ global.ptr1->base = 1;
+ global.ptr1->foo = 500;
+
+ global.ptr2 = new ChildValue2();
+ global.ptr2->base = 2;
+ global.ptr2->bar = "bar";
+
+ global.ptr3 = new ChildValue3();
+ global.ptr3->base = 3;
+ }
+ catch (const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = 1;
+ }
+ catch (const char* msg)
+ {
+ cerr << msg << endl;
+ status = 1;
+ }
+ } // end Fixture() constructor
+
+
+ ~GlobalIceFixture()
+ {
+ }
+};
+
+BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
+
+
+struct PerTestFixture
+{
+public:
+ PerTestFixture()
+ {
+ }
+
+ ~PerTestFixture()
+ {
+ }
+
+};
+
+/**
+ * Test a proxy collection
+ */
+BOOST_AUTO_TEST_CASE(ProxySetTest)
+{
+ ProxySet<SampleListenerPrx> proxySet(IceBoxTestEnv.adapter, lg, "Sample Listeners");
+
+ /////////////////////////////////////////////////////////////
+ // Try accessing the empty set first.
+ // We'll try all the accessor operations just to make sure
+ // the template instantiation is fully compiled.
+
+ bool caught(false);
+ vector<SampleListenerPrx> results;
+
+ try
+ {
+ vector<SampleListenerPrx> toRetrieve;
+
+ toRetrieve.push_back(global.prx1);
+ toRetrieve.push_back(global.prx2);
+ results = proxySet.get(toRetrieve);
+ }
+ catch(const NullProxyException&)
+ {
+ caught = true;
+ }
+
+ BOOST_CHECK(caught == false);
+ BOOST_CHECK(results.size() == 0);
+
+ caught = false;
+ try
+ {
+ SampleListenerPrx single = proxySet.get("RandomNonsense");
+ }
+ catch(const UnknownObject&)
+ {
+ caught = true;
+ }
+
+ BOOST_CHECK(caught == true);
+
+ caught = false;
+ try
+ {
+ results = proxySet.getAll();
+ }
+ catch(...)
+ {
+ caught = true;
+ }
+
+ BOOST_CHECK(caught == false);
+ BOOST_CHECK(results.size() == 0);
+
+ BOOST_CHECK(proxySet.has("Something") == false);
+
+ ///////////////////////////////////////////////////////
+ // Now add some content added.
+
+ proxySet.add(global.prx1);
+
+ vector<SampleListenerPrx> multiple;
+ multiple.push_back(global.prx2);
+ multiple.push_back(global.prx3);
+
+ proxySet.add(multiple);
+
+ BOOST_CHECK(proxySet.has( IceBoxTestEnv.adapter->getCommunicator()->identityToString(global.prx1->ice_getIdentity())) == true);
+
+ BOOST_CHECK(proxySet.size() == 3);
+
+ proxySet.remove(global.prx2);
+
+ BOOST_CHECK(proxySet.size() == 2);
+
+ results = proxySet.getAll();
+ BOOST_CHECK(results.size() == 2);
+
+ SampleListenerPrx prx = proxySet.get(IceBoxTestEnv.adapter->getCommunicator()->identityToString(global.prx1->ice_getIdentity()));
+ BOOST_CHECK(prx->ice_getIdentity() == global.prx1->ice_getIdentity());
+
+ vector<SampleListenerPrx> toRetrieve;
+ toRetrieve.push_back(global.prx3);
+
+ results = proxySet.get(toRetrieve);
+ BOOST_CHECK(results.size() == 1);
+
+ vector<SampleListenerPrx> toRemove;
+ toRemove.push_back(global.prx1);
+ toRemove.push_back(global.prx3);
+
+ proxySet.remove(toRemove);
+
+ BOOST_CHECK(proxySet.size() == 0);
+}
+
+/**
+ * Test a handle collection
+ */
+BOOST_AUTO_TEST_CASE(HandleSetTest)
+{
+ HandleSet<BaseValuePtr> handleSet(IceBoxTestEnv.adapter, lg, "Values Set");
+
+ /////////////////////////////////////////////////////////////
+ // Try accessing the empty set first.
+ // We'll try all the accessor operations just to make sure
+ // the template instantiation is fully compiled.
+
+ bool caught(false);
+ vector<BaseValuePtr> results;
+
+ try
+ {
+ vector<BaseValuePtr> toRetrieve;
+
+ toRetrieve.push_back(global.ptr1);
+ toRetrieve.push_back(global.ptr2);
+ results = handleSet.get(toRetrieve);
+ }
+ catch(const NullProxyException&)
+ {
+ caught = true;
+ }
+
+ BOOST_CHECK(caught == false);
+ BOOST_CHECK(results.size() == 0);
+
+ caught = false;
+ try
+ {
+ BaseValuePtr single = handleSet.get("RandomNonsense");
+ }
+ catch(const UnknownObject&)
+ {
+ caught = true;
+ }
+
+ BOOST_CHECK(caught == true);
+
+ caught = false;
+ try
+ {
+ results = handleSet.getAll();
+ }
+ catch(...)
+ {
+ caught = true;
+ }
+
+ BOOST_CHECK(caught == false);
+ BOOST_CHECK(results.size() == 0);
+
+ BOOST_CHECK(handleSet.has("Something") == false);
+
+ ///////////////////////////////////////////////////////
+ // Now add some content added.
+
+ handleSet.add(global.ptr1);
+
+ vector<BaseValuePtr> multiple;
+ multiple.push_back(global.ptr2);
+ multiple.push_back(global.ptr3);
+
+ handleSet.add(multiple);
+
+ BOOST_CHECK(handleSet.has(global.ptr1->ice_id()) == true);
+
+ BOOST_CHECK(handleSet.size() == 3);
+
+ handleSet.remove(global.ptr2);
+
+ BOOST_CHECK(handleSet.size() == 2);
+
+ results = handleSet.getAll();
+ BOOST_CHECK(results.size() == 2);
+
+ BaseValuePtr ptr = handleSet.get(global.ptr1->ice_id());
+ BOOST_CHECK(ptr->ice_id() == global.ptr1->ice_id());
+
+ vector<BaseValuePtr> toRetrieve;
+ toRetrieve.push_back(global.ptr3);
+
+ results = handleSet.get(toRetrieve);
+ BOOST_CHECK(results.size() == 1);
+
+}
diff --git a/test/Collections/TestCollectionsIf.ice b/test/Collections/TestCollectionsIf.ice
new file mode 100644
index 0000000..c1ef54f
--- /dev/null
+++ b/test/Collections/TestCollectionsIf.ice
@@ -0,0 +1,48 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+module AsteriskSCF
+{
+module CollectionsTest
+{
+interface SampleListener
+{
+ void hiThere();
+};
+
+class BaseValue
+{
+ int base;
+};
+
+class ChildValue1 extends BaseValue
+{
+ int foo;
+};
+
+class ChildValue2 extends BaseValue
+{
+ string bar;
+};
+
+class ChildValue3 extends BaseValue
+{
+ int other;
+};
+
+}; /* End of module CollectionsTest*/
+}; /* End of module AsteriskSCF */
\ No newline at end of file
commit 2efc4dd6dcc3a180f47a5c2b71c1809b2372c104
Author: Ken Hunt <ken.hunt at digium.com>
Date: Mon Aug 8 11:14:51 2011 -0500
Fixed odd namespace typo not caught by VisualStudio.
diff --git a/include/AsteriskSCF/Discovery/SmartProxy.h b/include/AsteriskSCF/Discovery/SmartProxy.h
index ed7e44f..6cf287c 100644
--- a/include/AsteriskSCF/Discovery/SmartProxy.h
+++ b/include/AsteriskSCF/Discovery/SmartProxy.h
@@ -108,7 +108,7 @@ public:
{
initOneWay();
}
- catch(const steriskSCF::Core::Discovery::V1::ServiceNotFound&)
+ catch(const AsteriskSCF::Core::Discovery::V1::ServiceNotFound&)
{
// The original proxy isn't reachable.
return false;
commit 94660b642445ea1bf456d1106276d154939f462e
Author: Ken Hunt <ken.hunt at digium.com>
Date: Mon Aug 8 03:06:04 2011 -0500
Changes to support a base Component class.
diff --git a/include/AsteriskSCF/Component/Component.h b/include/AsteriskSCF/Component/Component.h
new file mode 100644
index 0000000..5377bc8
--- /dev/null
+++ b/include/AsteriskSCF/Component/Component.h
@@ -0,0 +1,326 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+#include <IceBox/IceBox.h>
+
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Replication/ReplicationContext.h>
+#include <AsteriskSCF/Component/TestContext.h>
+#include <AsteriskSCF/Discovery/LocatorRegistrationWrapper.h>
+#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
+
+namespace AsteriskSCF
+{
+namespace Component
+{
+class ASTSCF_DLL_EXPORT Component : public IceBox::Service
+{
+public:
+ Component(const AsteriskSCF::System::Logging::Logger& logger,
+ const std::string& componentDiscoveryCategory);
+
+ /////////////////////////////////////////////////////////////////////
+ // Support for ComponentService interface.
+ void suspended();
+ void resumed();
+ void shutdown();
+
+ /////////////////////////////////////////////////////////////////////
+ // Support for ComponentTest interface.
+ void setTestMode(const std::string& mode);
+ void setTestModeWithArgs(const std::string& mode,
+ const AsteriskSCF::System::Component::V1::ComponentTestParamSeq& args);
+ void clearTestModes();
+ void clearTestMode(const std::string& mode);
+
+ ////////////////////////////////
+ // Support for Replica control interface.
+ bool isActive();
+ void activated();
+ void standby();
+
+protected:
+
+ /////////////////////////////////////////////////////////////////////
+ // Notification for some of
+ // the component events.
+ virtual void onPreInitialize() {}
+ virtual void onPostInitialize() {}
+ virtual void onSuspend() {}
+ virtual void onResume() {}
+ virtual void onStop() {}
+ virtual void onStart() {}
+ virtual void onActivated() {}
+ virtual void onStandby() {}
+ virtual void onRegisterPrimaryServices() {}
+ virtual void onRegisterBackplaneServices() {}
+ virtual void onUnregisterPrimaryServices() {}
+ virtual void onUnregisterBackplaneServices() {}
+ virtual void onSuspendPrimaryServices() {}
+ virtual void onSuspendBackplaneServices() {}
+ virtual void onUnsuspendPrimaryServices() {}
+ virtual void onUnsuspendBackplaneServices() {}
+
+ /////////////////////////////////////////////////////////////////////
+ // Every component must provide custom
+ // implementations of these replication
+ // operations.
+ virtual void createReplicationStateListeners() = 0;
+
+ /**
+ * Unregister as a listener to our state replicator.
+ * A component in active mode doesn't neeed to listen to
+ * state replication data.
+ */
+ virtual void stopListeningToStateReplicators() = 0;
+
+ /**
+ * Register as a listener to our state replicator.
+ * A component in standby mode will do this to monitor state changes
+ * being sent from an active component.
+ */
+ virtual void listenToStateReplicators() = 0;
+
+ /**
+ * A factory method.
+ * Allows subclasses to easily extend the ReplicationContext if needed.
+ */
+ virtual AsteriskSCF::Replication::ReplicationContextPtr createReplicationContext(
+ AsteriskSCF::Replication::ReplicationStateType state);
+
+ /////////////////////////////////////////////////////////////////////
+ // Operations called by the initialize() method. The initialize() method
+ // implements the Template Method pattern. These methods are called in
+ // the order declared below. If you override any of the default implementations,
+ // you probably want to call the default implementation from your override.
+
+ /**
+ * Verifies the configured parameters in the Ice config file meet
+ * minimum expectations, particularly thread pool sizes. If the do not,
+ * this method alters the configuration and logs the changes.
+ */
+ virtual void verifyProperties();
+
+ /**
+ * Creates the primary service adapter and the backplane adapters.
+ * If you need other adapter you can override this, but be sure to
+ * call the default implementation from you override.
+ */
+ virtual void createAdapters();
+
+ /**
+ * Activates the primary and backplane adapters.
+ */
+ virtual void activateAdapters();
+
+ /**
+ * Acquires references to the Service Locator proxies that can be accessed
+ * with the getServiceLocatorManagement() and getServiceLocator() accessors.
+ * The adapters must be activated prior to calling, which should always be
+ * the case due to the flow of the initialize() template method.
+ */
+ virtual void initServiceLocatorProxies();
+
+ /**
+ * Creates a replication context using the factory method
+ * createReplicationContext(). Override the factory method if
+ * you want to create a custom replication context.
+ * Note: Custom context must derive from AsteriskSCF::Replication::ReplicationContext.
+ */
+ virtual void initReplicationContext();
+
+ /**
+ * Creates a test context for component to use to detemine if it
+ * has test modes enabled. Support for test modes is optional.
+ */
+ virtual void initTestContext();
+
+ /**
+ * Create the logger. The generic implementation creates an IceLogger.
+ */
+ virtual void configureLogger();
+
+ /**
+ * Create all services to be associated with the primary service adapter.
+ * Note: This is a REQUIRED override.
+ */
+ virtual void createPrimaryServices() = 0;
+
+ /**
+ * Create any services to be associated with the primary service adapter.
+ * If you override this operation, you should call the default implementation.
+ */
+ virtual void createBackplaneServices();
+
+ /**
+ * A required override for the component to locate and cache any
+ * proxies to remote services that it needs to operate.
+ * Note: This is a REQUIRED override.
+ */
+ virtual void findRemoteServices() = 0;
+
+
+ /////////////////////////////////////////////////////////////////////
+ // Remote service registration operations.
+ // Components are usually discovered via the Service Locator,
+ // but some components may need to push proxies directly to other
+ // components. These operations assume you should only be registered
+ // when you're active.
+
+ /**
+ * Register this component's proxies with some service
+ * (other than the ServiceLocator).
+ */
+ virtual void registerWithRemoteServices() {}
+
+ /**
+ * Unregister this component's proxies from service
+ * (other than the ServiceLocator).
+ */
+ virtual void unregisterFromRemoteServices() {}
+
+ /////////////////////////////////////////////////////////////////////
+ // Service locator operations
+
+ /**
+ * Helper that caches the service references for the primary adapter.
+ */
+ void managePrimaryService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+
+ /**
+ * Helper that caches the service references for the backplane adapter.
+ */
+ void manageBackplaneService(const AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr& service);
+
+ /**
+ * Helper that wraps a service for registration.
+ */
+ AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr
+ wrapServiceForRegistration(const Ice::ObjectPrx& proxy,
+ const std::string& category,
+ const std::string& service,
+ const std::string& id) const;
+
+ /**
+ * Overload that uses the <adapterName>.ServiceName and <adapterName> as
+ * the values for the service and id.
+ */
+ AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr
+ wrapServiceForRegistration(const Ice::ObjectPrx& proxy,
+ const std::string& category) const;
+
+ /**
+ * The derived component is expected to wrap each
+ * primary adapter service that should be
+ * registered with the Service Locator. Refer to
+ * documentation.
+ */
+ virtual void preparePrimaryServicesForDiscovery() = 0;
+ void registerPrimaryServices();
+ void unregisterPrimaryServices();
+ void suspendPrimaryServices();
+ void unsuspendPrimaryServices();
+
+ /**
+ * The derived component should override this operation only if it wishes
+ * register its own backplane services. If this method is overridden,
+ * this class's implmentation should be called from the override.
+ */
+ virtual void prepareBackplaneServicesForDiscovery();
+ void registerBackplaneServices();
+ void unregisterBackplaneServices();
+ void suspendBackplaneServices();
+ void unsuspendBackplaneServices();
+
+ /////////////////////////////////////////////////////////////////////
+ // Accessors to state.
+ const AsteriskSCF::Replication::ReplicationContextPtr& getReplicationContext() const {return mReplicationContext;}
+ const AsteriskSCF::Component::TestContextPtr& getTestContext() const {return mTestContext;}
+ const std::string& getName() const {return mName;}
+ const std::string& getServiceName() const {return mServiceName;}
+ const Ice::CommunicatorPtr& getCommunicator() const {return mCommunicator;}
+ const Ice::StringSeq& getArgs() const {return mArgs;}
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx& getServiceLocatorManagement() const {return mServiceLocatorManagement;}
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& getServiceLocator() const {return mServiceLocator;}
+ const Ice::ObjectAdapterPtr& getServiceAdapter() const {return mServiceAdapter;}
+ const Ice::ObjectAdapterPtr& getBackplaneAdapter() const {return mBackplaneAdapter;}
+ std::string getServiceLocatorManagementProperty() const;
+
+ // Allow setting an alternative communicator.
+ // This should only be done in onPreInitialize() override, or
+ // things may already be using the IceBox-provided communicator.
+ void setCommunicator(const Ice::CommunicatorPtr& communicator) {mCommunicator = communicator;}
+
+ // State data
+ AsteriskSCF::System::Logging::Logger mLogger;
+
+private:
+ void initialize();
+ void suspendService(bool shuttingDown);
+
+ /////////////////////////////////////////////////////////////////////
+ // Overrides for IceBox::Service
+ void start(const std::string& name,
+ const Ice::CommunicatorPtr& communicator,
+ const Ice::StringSeq& args);
+ void stop();
+
+ /////////////////////////////////////////////////////////////////////
+ // State data
+
+ bool mInitialized;
+ bool mRunning;
+ bool mPublishTestInterface;
+
+ std::string mComponentDiscoveryCategory;
+
+ std::string mName;
+ std::string mServiceName;
+ Ice::CommunicatorPtr mCommunicator;
+ Ice::StringSeq mArgs;
+
+ AsteriskSCF::System::Component::V1::ComponentServicePtr mComponentService;
+ AsteriskSCF::System::Component::V1::ComponentServicePrx mComponentServicePrx;
+ AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr mComponentRegistration;
+
+ AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+ AsteriskSCF::System::Component::V1::ReplicaPrx mReplicaPrx;
+ AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr mReplicaRegistration;
+
+ AsteriskSCF::System::Component::V1::ComponentTestPtr mComponentTest;
+ AsteriskSCF::System::Component::V1::ComponentTestPrx mComponentTestPrx;
+
+ AsteriskSCF::Replication::ReplicationContextPtr mReplicationContext;
+ AsteriskSCF::Component::TestContextPtr mTestContext;
+
+ Ice::ObjectAdapterPtr mServiceAdapter;
+ Ice::ObjectAdapterPtr mBackplaneAdapter;
+
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorManagementPrx mServiceLocatorManagement;
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
+
+ std::vector<AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr> mPrimaryServices;
+ std::vector<AsteriskSCF::Discovery::LocatorRegistrationWrapperPtr> mBackplaneServices;
+};
+
+
+} // end Component
+} // end AsteriskSCF
diff --git a/include/AsteriskSCF/Component/TestContext.h b/include/AsteriskSCF/Component/TestContext.h
new file mode 100644
index 0000000..0934abf
--- /dev/null
+++ b/include/AsteriskSCF/Component/TestContext.h
@@ -0,0 +1,96 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
+
+namespace AsteriskSCF
+{
+namespace Component
+{
+class ASTSCF_DLL_EXPORT InvalidTestMode : public std::exception
+{
+public:
+ InvalidTestMode(const std::string& mode)
+ {
+ mMsg = "Invalid Test Mode. Mode " + mode + " is not set.";
+ }
+
+ ~InvalidTestMode() throw() {};
+
+ virtual const char* what() const throw()
+ {
+ return mMsg.c_str();
+ }
+
+private:
+ std::string mMsg;
+};
+
+/**
+ * This class provides the component's classes with the context
+ * needed for testing.
+ */
+class ASTSCF_DLL_EXPORT TestContext
+{
+public:
+ TestContext() ;
+
+ /**
+ * Indicates whether a test mode with given name
+ * has been set.
+ * @param mode The name of the mode to query.
+ */
+ bool hasTestMode(const std::string& mode);
+
+ /**
+ * Gets the paramters to for the test mode.
+ * If the mode hasn't been set, throws InvalidTestMode.
+ */
+ AsteriskSCF::System::Component::V1::ComponentTestParamSeq
+ getTestModeParams(const std::string& mode);
+
+ /**
+ * Sets a test mode.
+ */
+ void setTestMode(const std::string& mode);
+
+ /**
+ * Sets a current test mode with parameters.
+ */
+ void setTestMode(const std::string& mode,
+ const AsteriskSCF::System::Component::V1::ComponentTestParamSeq& params);
+
+ /**
+ * Clears a testing mode.
+ */
+ void clearTestMode(const std::string& mode);
+
+ /**
+ * Clears testing mode.
+ */
+ void clearAllTestModes();
+
+private:
+ std::map<std::string, AsteriskSCF::System::Component::V1::ComponentTestParamSeq> mTestModeMap;
+ boost::shared_mutex mLock;
+};
+typedef boost::shared_ptr<TestContext> TestContextPtr;
+
+} // end Component
+} // end AsteriskSCF
diff --git a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
index ca8e81a..2cef1fa 100644
--- a/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
+++ b/include/AsteriskSCF/Discovery/LocatorRegistrationWrapper.h
@@ -27,14 +27,13 @@ namespace Discovery
/**
*
- * Helper template for services that need to be registered with the locator service. If the service may not
+ * Helper class for services that need to be registered with the locator service. If the service is not
* immediately available, the RegisterThread can be used to continue to try and register the service.
*
* TODO: It might be handy to add some "termination conditions" so it doesn't simply wait forever.
*
**/
-template <class T>
-class LocatorRegistrationWrapper : public IceUtil::Shared
+class ASTSCF_DLL_EXPORT LocatorRegistrationWrapper : public IceUtil::Shared
{
public:
@@ -42,10 +41,12 @@ public:
* Normally, I avoid default args, but you can't really implement one constructor in terms of another
* so it's less maintenance overhead to have the single constructor with the defaults.
**/
- LocatorRegistrationWrapper(const Ice::CommunicatorPtr& communicator, const std::string& proxyString,
- const T& service, const std::string& name,
- const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
- const std::string& comparatorGUID = "") :
+ LocatorRegistrationWrapper(const Ice::CommunicatorPtr& communicator,
+ const std::string& proxyString,
+ const Ice::ObjectPrx& service,
+ const std::string& name,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params,
+ const std::string& comparatorGUID = "") :
mCommunicator(communicator),
mProxyString(proxyString),
mService(service),
@@ -97,6 +98,35 @@ public:
mServiceManagement->unregister();
}
+ void suspend()
+ {
+ {
+ IceUtil::Mutex::Lock lock(mLock);
+ if(!mServiceManagement)
+ {
+ return;
+ }
+ }
+ mServiceManagement->suspend();
+ }
+
+ void unsuspend()
+ {
+ {
+ IceUtil::Mutex::Lock lock(mLock);
+ if(!mServiceManagement)
+ {
+ return;
+ }
+ }
+ mServiceManagement->unsuspend();
+ }
+
+ AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx getServiceMangement()
+ {
+ return mServiceManagement;
+ }
+
private:
//
@@ -106,30 +136,30 @@ private:
IceUtil::Mutex mLock;
Ice::CommunicatorPtr mCommunicator;
... 2366 lines suppressed ...
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list