[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "smart-proxy" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Nov 23 09:55:42 CST 2010
branch "smart-proxy" has been created
at 909b2ff2d9b7796c1533718af692fe3cd2d69e01 (commit)
- Log -----------------------------------------------------------------
commit 909b2ff2d9b7796c1533718af692fe3cd2d69e01
Author: David M. Lee <dlee at digium.com>
Date: Mon Nov 22 20:55:14 2010 -0600
First round of SmartProxy cleanups.
* ProxyWrapper -> SmartProxy
* Log to Logger instead of cout
* Throw real exception instead of string
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 79e7361..8212b2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,5 +3,5 @@ if (integrated_build STREQUAL "true")
set(utils_bindir ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
endif()
-add_subdirectory(ProxyWrapper)
+add_subdirectory(SmartProxy)
add_subdirectory(StateReplicator)
diff --git a/ProxyWrapper/src/CMakeLists.txt b/ProxyWrapper/src/CMakeLists.txt
deleted file mode 100644
index da2461d..0000000
--- a/ProxyWrapper/src/CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-# Define the SIP Channel Service component
-
-asterisk_scf_component_init(ProxyWrapper CXX)
-
-asterisk_scf_component_add_slice(ProxyWrapper ServiceLocatorIf)
-asterisk_scf_component_add_file(ProxyWrapper ProxyWrapper.h)
-asterisk_scf_component_add_file(ProxyWrapper ProxyWrapper.cpp)
-asterisk_scf_component_add_boost_libraries(ProxyWrapper core)
-
-asterisk_scf_component_build_library(ProxyWrapper)
-
-# MACH-O requires libraries for linking libraries
-if(APPLE)
- target_link_libraries(ProxyWrapper ${ICE_CXX_LIB_IceUtil})
- target_link_libraries(ProxyWrapper ${ICE_CXX_LIB_ZeroCIce})
-endif()
-
-asterisk_scf_component_install(ProxyWrapper LIBRARY lib "Proxy Wrapper" ProxyWrapper ARCHIVE DESTINATION lib)
-
diff --git a/ProxyWrapper/CMakeLists.txt b/SmartProxy/CMakeLists.txt
similarity index 100%
rename from ProxyWrapper/CMakeLists.txt
rename to SmartProxy/CMakeLists.txt
diff --git a/SmartProxy/src/CMakeLists.txt b/SmartProxy/src/CMakeLists.txt
new file mode 100644
index 0000000..cb7ea20
--- /dev/null
+++ b/SmartProxy/src/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Define the SIP Channel Service component
+
+asterisk_scf_component_init(SmartProxy CXX)
+
+asterisk_scf_component_add_slice(SmartProxy ServiceLocatorIf)
+asterisk_scf_component_add_file(SmartProxy SmartProxy.h)
+asterisk_scf_component_add_file(SmartProxy SmartProxy.cpp)
+asterisk_scf_component_add_boost_libraries(SmartProxy core)
+
+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)
+
+asterisk_scf_component_build_library(SmartProxy)
+
+# MACH-O requires libraries for linking libraries
+if(APPLE)
+ target_link_libraries(SmartProxy ${ICE_CXX_LIB_IceUtil})
+ target_link_libraries(SmartProxy ${ICE_CXX_LIB_ZeroCIce})
+endif()
+
+asterisk_scf_component_install(SmartProxy LIBRARY lib "Smart Proxy" SmartProxy ARCHIVE DESTINATION lib)
+
diff --git a/ProxyWrapper/src/ProxyWrapper.cpp b/SmartProxy/src/SmartProxy.cpp
similarity index 96%
rename from ProxyWrapper/src/ProxyWrapper.cpp
rename to SmartProxy/src/SmartProxy.cpp
index 875d360..d4e7c45 100644
--- a/ProxyWrapper/src/ProxyWrapper.cpp
+++ b/SmartProxy/src/SmartProxy.cpp
@@ -14,7 +14,7 @@
* at the top of the source tree.
*/
-#include "ProxyWrapper.h"
+#include "SmartProxy.h"
namespace AsteriskSCF
{
diff --git a/ProxyWrapper/src/ProxyWrapper.h b/SmartProxy/src/SmartProxy.h
similarity index 58%
rename from ProxyWrapper/src/ProxyWrapper.h
rename to SmartProxy/src/SmartProxy.h
index 3439f3f..8e5da1f 100644
--- a/ProxyWrapper/src/ProxyWrapper.h
+++ b/SmartProxy/src/SmartProxy.h
@@ -15,21 +15,23 @@
*/
#pragma once
+#include <iostream>
+
#include <Ice/Ice.h>
-#include <boost/shared_ptr.hpp>
#include "Core/Discovery/ServiceLocatorIf.h"
+#include "logger.h"
namespace AsteriskSCF
{
-namespace ProxyWrapper
+namespace SmartProxy
{
/**
* A wrapper for an Ice Proxy.
* The Template parameter P is the proxy we're wrapping
*
- * The main feature of using a proxy wrapper at this stage is that
+ * The main feature of using a smart proxy at this stage is that
* it provides the ability to detect if we could find a given proxy
* at initialization. If we did not, then the first time we try to
* invoke a proxy operation, then we will attempt to acquire a proxy
@@ -39,43 +41,44 @@ namespace ProxyWrapper
* more general purpose.
*/
template <class P>
-class ProxyWrapper
+class SmartProxy
{
public:
- ProxyWrapper() : mServiceLocator(0), mLocatorParams(0), mInitialized(false) {}
+ SmartProxy() : mServiceLocator(0), mLocatorParams(0), mInitialized(false), mLg(0) {}
- ProxyWrapper(const ProxyWrapper &pw)
+ SmartProxy(const SmartProxy &rhs)
{
- copy(pw);
+ copy(rhs);
}
- ProxyWrapper(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params)
- : mServiceLocator(locator), mLocatorParams(params), mInitialized(false)
+ SmartProxy(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params,
+ AsteriskSCF::System::Logging::Logger const &lg)
+ : mServiceLocator(locator), mLocatorParams(params), mInitialized(false), mLg(&lg)
{
initialize();
}
- P& operator->()
+ P& operator->() throw (AsteriskSCF::Core::Discovery::V1::ServiceNotFound)
{
assert(mServiceLocator && mLocatorParams);
if (!verifyInitialized())
{
- throw "No access to Proxy";
+ throw AsteriskSCF::Core::Discovery::V1::ServiceNotFound();
}
return mProxy;
}
- ProxyWrapper operator=(const ProxyWrapper &pw)
+ SmartProxy &operator=(const SmartProxy &rhs)
{
// Boo to self-assignment
- if (this == &pw)
+ if (this == &rhs)
{
return *this;
}
- copy(pw);
+ copy(rhs);
return *this;
}
@@ -95,24 +98,38 @@ private:
*/
void initialize()
{
+ using namespace AsteriskSCF::System::Logging;
+ if (!mServiceLocator)
+ {
+ // uninitialized; probably no logger setup yet, either
+ std::clog << "Missing ServiceLocator proxy. Cannot initialize.\n";
+ return;
+ }
+
try
{
// Use the locator to find the Proxy
- Ice::ObjectPrx bridgeManagerObject = mServiceLocator->locate(mLocatorParams);
- mProxy = P::checkedCast(bridgeManagerObject);
+ Ice::ObjectPrx obj = mServiceLocator->locate(mLocatorParams);
+ mProxy = P::checkedCast(obj);
+ if (obj && !mProxy)
+ {
+ (*mLg)(Error) << "Object (" << obj->ice_toString() << ") isn't of expected type";
+ }
}
catch (const Ice::Exception &e)
{
- std::cout << "Exception locating " << mLocatorParams->category << ": " << e.what() << std::endl;
+ (*mLg)(Error) << "Exception locating " << mLocatorParams->category << ": " << e.what();
return;
}
if (mProxy == 0)
{
- std::cout << "Unable to locate " << mLocatorParams->category << std::endl;
+ (*mLg)(Error) << "Unable to locate " << mLocatorParams->category;
+ }
+ else
+ {
+ mInitialized = true;
}
-
- mInitialized = true;
}
/**
@@ -130,20 +147,22 @@ private:
return mInitialized;
}
- void copy(const ProxyWrapper &pw)
+ void copy(const SmartProxy &rhs)
{
- mServiceLocator = pw.mServiceLocator;
- mLocatorParams = pw.mLocatorParams;
- mProxy = pw.mProxy;
- mInitialized = pw.mInitialized;
+ mProxy = rhs.mProxy;
+ mServiceLocator = rhs.mServiceLocator;
+ mLocatorParams = rhs.mLocatorParams;
+ mLg = rhs.mLg;
+ mInitialized = rhs.mInitialized;
}
P mProxy;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr mLocatorParams;
+ AsteriskSCF::System::Logging::Logger const *mLg;
bool mInitialized;
};
-}; // end ProxyWrapper
+}; // end SmartProxy
}; // end AsteriskSCF
commit fedbf5bc207cfbf4b46b4a3f890793568bb07b69
Author: David M. Lee <dlee at digium.com>
Date: Mon Nov 15 14:03:38 2010 -0600
Updated indentation to match the style guide.
diff --git a/ProxyWrapper/src/ProxyWrapper.cpp b/ProxyWrapper/src/ProxyWrapper.cpp
index 25281d6..875d360 100644
--- a/ProxyWrapper/src/ProxyWrapper.cpp
+++ b/ProxyWrapper/src/ProxyWrapper.cpp
@@ -20,8 +20,8 @@ namespace AsteriskSCF
{
namespace ProxyWrapper
{
- /*
- * This .cpp is a temporary solution to get a CMakeProject that consists only of header files.
+/*
+ * This .cpp is a temporary solution to get a CMakeProject that consists only of header files.
*/
};
diff --git a/ProxyWrapper/src/ProxyWrapper.h b/ProxyWrapper/src/ProxyWrapper.h
index 65a6f4e..3439f3f 100644
--- a/ProxyWrapper/src/ProxyWrapper.h
+++ b/ProxyWrapper/src/ProxyWrapper.h
@@ -42,106 +42,106 @@ template <class P>
class ProxyWrapper
{
public:
- ProxyWrapper() : mServiceLocator(0), mLocatorParams(0), mInitialized(false) {}
-
- ProxyWrapper(const ProxyWrapper &pw)
- {
- copy(pw);
- }
-
- ProxyWrapper(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params)
- : mServiceLocator(locator), mLocatorParams(params), mInitialized(false)
- {
- initialize();
- }
-
- P& operator->()
- {
- assert(mServiceLocator && mLocatorParams);
-
- if (!verifyInitialized())
- {
- throw "No access to Proxy";
- }
-
- return mProxy;
- }
-
- ProxyWrapper operator=(const ProxyWrapper &pw)
- {
- // Boo to self-assignment
- if (this == &pw)
- {
- return *this;
- }
- copy(pw);
- return *this;
- }
-
- operator void*() const
- {
- return mProxy ? (void *)1 : 0;
- }
-
- bool isInitialized()
- {
- return mInitialized;
- }
+ ProxyWrapper() : mServiceLocator(0), mLocatorParams(0), mInitialized(false) {}
+
+ ProxyWrapper(const ProxyWrapper &pw)
+ {
+ copy(pw);
+ }
+
+ ProxyWrapper(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr params)
+ : mServiceLocator(locator), mLocatorParams(params), mInitialized(false)
+ {
+ initialize();
+ }
+
+ P& operator->()
+ {
+ assert(mServiceLocator && mLocatorParams);
+
+ if (!verifyInitialized())
+ {
+ throw "No access to Proxy";
+ }
+
+ return mProxy;
+ }
+
+ ProxyWrapper operator=(const ProxyWrapper &pw)
+ {
+ // Boo to self-assignment
+ if (this == &pw)
+ {
+ return *this;
+ }
+ copy(pw);
+ return *this;
+ }
+
+ operator void*() const
+ {
+ return mProxy ? (void *)1 : 0;
+ }
+
+ bool isInitialized()
+ {
+ return mInitialized;
+ }
private:
- /**
- * Initialization. Primarily involves acquring access to specific IceStorm topic.
- */
- void initialize()
- {
- try
- {
- // Use the locator to find the Proxy
- Ice::ObjectPrx bridgeManagerObject = mServiceLocator->locate(mLocatorParams);
- mProxy = P::checkedCast(bridgeManagerObject);
- }
- catch (const Ice::Exception &e)
- {
- std::cout << "Exception locating " << mLocatorParams->category << ": " << e.what() << std::endl;
- return;
- }
-
- if (mProxy == 0)
- {
- std::cout << "Unable to locate " << mLocatorParams->category << std::endl;
- }
-
- mInitialized = true;
- }
-
- /**
- * Utiltity to check for initialization state.
- */
- bool verifyInitialized()
- {
- if (mInitialized)
- {
- return true;
- }
-
- // Try again to initialize.
- initialize();
- return mInitialized;
- }
-
- void copy(const ProxyWrapper &pw)
- {
- mServiceLocator = pw.mServiceLocator;
- mLocatorParams = pw.mLocatorParams;
- mProxy = pw.mProxy;
- mInitialized = pw.mInitialized;
- }
-
- P mProxy;
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr mLocatorParams;
- bool mInitialized;
+ /**
+ * Initialization. Primarily involves acquring access to specific IceStorm topic.
+ */
+ void initialize()
+ {
+ try
+ {
+ // Use the locator to find the Proxy
+ Ice::ObjectPrx bridgeManagerObject = mServiceLocator->locate(mLocatorParams);
+ mProxy = P::checkedCast(bridgeManagerObject);
+ }
+ catch (const Ice::Exception &e)
+ {
+ std::cout << "Exception locating " << mLocatorParams->category << ": " << e.what() << std::endl;
+ return;
+ }
+
+ if (mProxy == 0)
+ {
+ std::cout << "Unable to locate " << mLocatorParams->category << std::endl;
+ }
+
+ mInitialized = true;
+ }
+
+ /**
+ * Utiltity to check for initialization state.
+ */
+ bool verifyInitialized()
+ {
+ if (mInitialized)
+ {
+ return true;
+ }
+
+ // Try again to initialize.
+ initialize();
+ return mInitialized;
+ }
+
+ void copy(const ProxyWrapper &pw)
+ {
+ mServiceLocator = pw.mServiceLocator;
+ mLocatorParams = pw.mLocatorParams;
+ mProxy = pw.mProxy;
+ mInitialized = pw.mInitialized;
+ }
+
+ P mProxy;
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr mLocatorParams;
+ bool mInitialized;
};
}; // end ProxyWrapper
diff --git a/StateReplicator/src/StateReplicator.cpp b/StateReplicator/src/StateReplicator.cpp
index dfd6aa0..5674a57 100644
--- a/StateReplicator/src/StateReplicator.cpp
+++ b/StateReplicator/src/StateReplicator.cpp
@@ -22,8 +22,8 @@ namespace AsteriskSCF
{
namespace StateReplication
{
- /*
- * This .cpp is a temporary solution to get a CMakeProject that consists only of header files.
+/*
+ * This .cpp is a temporary solution to get a CMakeProject that consists only of header files.
*/
};
diff --git a/StateReplicator/src/StateReplicator.h b/StateReplicator/src/StateReplicator.h
index f119668..b778aeb 100644
--- a/StateReplicator/src/StateReplicator.h
+++ b/StateReplicator/src/StateReplicator.h
@@ -25,216 +25,216 @@ namespace StateReplication
{
/**
- * Templatization of a state replicator. This particular implementation preserves the order
- * of the fields from the order in which they were added to the collection. If an item is removed and
- * re-added later, it goes to the back of the list.
- * - The state item type is assumed to have a public field named "key" which is of type "K".
+ * Templatization of a state replicator. This particular implementation preserves the order
+ * of the fields from the order in which they were added to the collection. If an item is removed and
+ * re-added later, it goes to the back of the list.
+ * - The state item type is assumed to have a public field named "key" which is of type "K".
The Replicator should implement (at a minimum) these operations:
- interface FooStateReplicator
- {
- void addListener(TestStateReplicatorListener *listener);
- void removeListener(TestStateReplicatorListener *listener);
- void setState (FooStateItemSeq items);
- void removeState(FooKeySeq items);
- idempotent TestStateItemSeq getState(FooKeySeq itemKeys);
- idempotent TestStateItemSeq getAllState();
- };
+ interface FooStateReplicator
+ {
+ void addListener(TestStateReplicatorListener *listener);
+ void removeListener(TestStateReplicatorListener *listener);
+ void setState (FooStateItemSeq items);
+ void removeState(FooKeySeq items);
+ idempotent TestStateItemSeq getState(FooKeySeq itemKeys);
+ idempotent TestStateItemSeq getAllState();
+ };
The Listener should implement (at a minimum) these operations:
- interface FooStateReplicatorListener
- {
- void stateRemoved(FooKeySeq itemKeys);
- void stateSet(FooStateItemSeq items);
- };
-
- * NOTE: - The process should be made asynchronous.
- * NOTE: - Should probably use IceStorm for forwarding to all listeners.
+ interface FooStateReplicatorListener
+ {
+ void stateRemoved(FooKeySeq itemKeys);
+ void stateSet(FooStateItemSeq items);
+ };
+
+ * NOTE: - The process should be made asynchronous.
+ * NOTE: - Should probably use IceStorm for forwarding to all listeners.
*/
-template<typename R, typename S, typename K, typename L>
+template<typename R, typename S, typename K, typename L>
class StateReplicator : public R
{
// Template Types: R - Replicator, S - State item, K - Key element, L - Listener
public:
- /**
- * Functor for forwarding setState() notices.
- */
- template<typename T, typename U> class SetStateNotice
- {
- // Types: T - Listener type, U - State Item seq.
- public:
- SetStateNotice(const U& stateSeq) : mStateSeq(stateSeq) {}
- ~SetStateNotice() {}
- void operator() (T x)
- {
- try
- {
- x->stateSet(mStateSeq);
- }
- catch(const Ice::Exception&)
- {
- }
- catch(...)
- {
- }
- }
- U mStateSeq;
- };
-
- /**
- * Functor for forwarding removeState() notices.
- */
- template<typename T, typename V> class RemoveStateNotice
- {
- // Types: T - Listener type, V - Key Item seq.
- public:
- RemoveStateNotice(const V& keys) : mKeys(keys) {}
- ~RemoveStateNotice() {}
- void operator() (T x)
- {
- try
- {
- x->stateRemoved(mKeys);
- }
- catch(const Ice::Exception&)
- {
- }
- catch(...)
- {
- }
- }
- V mKeys;
- };
-
- /**
- * Functor to use as find_if predicate.
- */
- template<typename T> class IdentifyListener
- {
- public:
- IdentifyListener(const T& listener) : mListener(listener) {}
- ~IdentifyListener() {}
- bool operator() (T x) {return (x->ice_getIdentity() == mListener->ice_getIdentity());}
- T mListener;
- };
-
- template<typename T, typename D> class MatchItem
- {
- public:
- MatchItem(const D& key) : mKey(key) {}
- ~MatchItem() {}
- bool operator() (T x) {return (x->key == mKey); }
- D mKey;
- };
+ /**
+ * Functor for forwarding setState() notices.
+ */
+ template<typename T, typename U> class SetStateNotice
+ {
+ // Types: T - Listener type, U - State Item seq.
+ public:
+ SetStateNotice(const U& stateSeq) : mStateSeq(stateSeq) {}
+ ~SetStateNotice() {}
+ void operator() (T x)
+ {
+ try
+ {
+ x->stateSet(mStateSeq);
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ catch(...)
+ {
+ }
+ }
+ U mStateSeq;
+ };
+
+ /**
+ * Functor for forwarding removeState() notices.
+ */
+ template<typename T, typename V> class RemoveStateNotice
+ {
+ // Types: T - Listener type, V - Key Item seq.
+ public:
+ RemoveStateNotice(const V& keys) : mKeys(keys) {}
+ ~RemoveStateNotice() {}
+ void operator() (T x)
+ {
+ try
+ {
+ x->stateRemoved(mKeys);
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ catch(...)
+ {
+ }
+ }
+ V mKeys;
+ };
+
+ /**
+ * Functor to use as find_if predicate.
+ */
+ template<typename T> class IdentifyListener
+ {
+ public:
+ IdentifyListener(const T& listener) : mListener(listener) {}
+ ~IdentifyListener() {}
+ bool operator() (T x) {return (x->ice_getIdentity() == mListener->ice_getIdentity());}
+ T mListener;
+ };
+
+ template<typename T, typename D> class MatchItem
+ {
+ public:
+ MatchItem(const D& key) : mKey(key) {}
+ ~MatchItem() {}
+ bool operator() (T x) {return (x->key == mKey); }
+ D mKey;
+ };
public:
- StateReplicator() {};
- virtual ~StateReplicator() {};
-
- /**
- * Adds a listener of state update notices.
- * @Override
- */
- void addListener(const L& listener, const Ice::Current& = ::Ice::Current())
- {
- { // critical scope
- boost::unique_lock<boost::shared_mutex> lock(mListenerLock);
- mListeners.push_back(listener);
- }
-
- // Give this listener the current state.
- boost::shared_lock<boost::shared_mutex> lock(mStateLock);
- try
- {
- listener->stateSet(mStateItems);
- }
- catch(const Ice::Exception&)
- {
- }
- catch(...)
- {
- }
- }
-
- /**
- * Removes a listener of state update notices.
- * @Override
- */
- void removeListener(const L& listener, const Ice::Current& = ::Ice::Current())
- {
- boost::unique_lock<boost::shared_mutex> lock(mListenerLock);
- typename std::vector<L>::iterator it = std::find_if(mListeners.begin(), mListeners.end(), IdentifyListener<L>(listener));
-
- if (it != mListeners.end())
- {
- mListeners.erase(it);
- }
- }
-
- /**
- * Drops all listeners of state update notices.
- */
- void clearListeners()
- {
- boost::unique_lock<boost::shared_mutex> lock(mListenerLock);
- mListeners.clear();
- }
-
- /**
- * Drops all state that has previously been set. Notifies listeners.
- */
- void clearState()
- {
- std::vector<K> allIds;
-
- { // critical scope
- boost::unique_lock<boost::shared_mutex> lock(mStateLock);
- for(typename std::vector<S>::const_iterator it = mStateItems.begin(); it != mStateItems.end(); ++it)
- {
- allIds.push_back((*it)->key);
- }
- mStateItems.clear();
- }
-
- boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
- for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<K> >(allIds));
- }
-
- /**
- * Add or update the specified state variables, and notify listeners.
- * @Override
- */
- void setState(const std::vector<S>& items, const Ice::Current& = ::Ice::Current())
- {
- { // critical scope
+ StateReplicator() {};
+ virtual ~StateReplicator() {};
+
+ /**
+ * Adds a listener of state update notices.
+ * @Override
+ */
+ void addListener(const L& listener, const Ice::Current& = ::Ice::Current())
+ {
+ { // critical scope
+ boost::unique_lock<boost::shared_mutex> lock(mListenerLock);
+ mListeners.push_back(listener);
+ }
+
+ // Give this listener the current state.
+ boost::shared_lock<boost::shared_mutex> lock(mStateLock);
+ try
+ {
+ listener->stateSet(mStateItems);
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ catch(...)
+ {
+ }
+ }
+
+ /**
+ * Removes a listener of state update notices.
+ * @Override
+ */
+ void removeListener(const L& listener, const Ice::Current& = ::Ice::Current())
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mListenerLock);
+ typename std::vector<L>::iterator it = std::find_if(mListeners.begin(), mListeners.end(), IdentifyListener<L>(listener));
+
+ if (it != mListeners.end())
+ {
+ mListeners.erase(it);
+ }
+ }
+
+ /**
+ * Drops all listeners of state update notices.
+ */
+ void clearListeners()
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mListenerLock);
+ mListeners.clear();
+ }
+
+ /**
+ * Drops all state that has previously been set. Notifies listeners.
+ */
+ void clearState()
+ {
+ std::vector<K> allIds;
+
+ { // critical scope
+ boost::unique_lock<boost::shared_mutex> lock(mStateLock);
+ for(typename std::vector<S>::const_iterator it = mStateItems.begin(); it != mStateItems.end(); ++it)
+ {
+ allIds.push_back((*it)->key);
+ }
+ mStateItems.clear();
+ }
+
+ boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
+ for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<K> >(allIds));
+ }
+
+ /**
+ * Add or update the specified state variables, and notify listeners.
+ * @Override
+ */
+ void setState(const std::vector<S>& items, const Ice::Current& = ::Ice::Current())
+ {
+ { // critical scope
boost::unique_lock<boost::shared_mutex> lock(mStateLock);
for (typename std::vector<S>::const_iterator iter = items.begin();
- iter != items.end(); ++iter)
+ iter != items.end(); ++iter)
{
- typename std::vector<S>::iterator it = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >((*iter)->key));
+ typename std::vector<S>::iterator it = std::find_if(mStateItems.begin(), mStateItems.end(), MatchItem<S,K >((*iter)->key));
- if (it != mStateItems.end())
- {
+ if (it != mStateItems.end())
+ {
(*it) = (*iter);
- }
- else
- {
+ }
+ else
+ {
mStateItems.push_back(*iter);
- }
+ }
}
}
- boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
- for_each( mListeners.begin(), mListeners.end(), SetStateNotice<L,std::vector<S> >(items) );
- }
+ boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
+ for_each( mListeners.begin(), mListeners.end(), SetStateNotice<L,std::vector<S> >(items) );
+ }
- /**
- * Remove the specified state variables, and notify listeners.
- * @Override
- */
- void removeState(const std::vector<K>& ids, const Ice::Current& = ::Ice::Current())
- {
+ /**
+ * Remove the specified state variables, and notify listeners.
+ * @Override
+ */
+ void removeState(const std::vector<K>& ids, const Ice::Current& = ::Ice::Current())
+ {
{ // critical scope
boost::unique_lock<boost::shared_mutex> lock(mStateLock);
@@ -248,17 +248,17 @@ public:
}
}
}
-
+
boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
for_each(mListeners.begin(), mListeners.end(), RemoveStateNotice<L,std::vector<K> >(ids));
- }
+ }
/**
- * Retrieve the state variables identifed by the key collection.
- * @Override
- */
+ * Retrieve the state variables identifed by the key collection.
+ * @Override
+ */
std::vector<S> getState(const std::vector<K>& itemKeys, const Ice::Current& = ::Ice::Current())
- {
+ {
std::vector<S> results;
{ // critical scope
@@ -270,38 +270,38 @@ public:
if (locateIt != mStateItems.end())
{
- results.push_back(*locateIt);
+ results.push_back(*locateIt);
}
}
}
return results;
}
- /**
- * Retrieve all the state variables currently known to this replicator.
- * @Override
- */
- std::vector<S> getAllState(const Ice::Current& = ::Ice::Current())
- {
- boost::shared_lock<boost::shared_mutex> lock(mStateLock);
- return mStateItems;
- }
-
- /**
- * Returns the number of listeners currently registered with this replicator.
- */
- int getListenerCount()
- {
- boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
- return mListeners.size();
- }
+ /**
+ * Retrieve all the state variables currently known to this replicator.
+ * @Override
+ */
+ std::vector<S> getAllState(const Ice::Current& = ::Ice::Current())
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mStateLock);
+ return mStateItems;
+ }
+
+ /**
+ * Returns the number of listeners currently registered with this replicator.
+ */
+ int getListenerCount()
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mListenerLock);
+ return mListeners.size();
+ }
private:
- std::vector<L> mListeners;
- std::vector<S> mStateItems;
+ std::vector<L> mListeners;
+ std::vector<S> mStateItems;
- boost::shared_mutex mListenerLock;
- boost::shared_mutex mStateLock;
+ boost::shared_mutex mListenerLock;
+ boost::shared_mutex mStateLock;
};
} // end namespace StateReplication
diff --git a/StateReplicator/test/MockStateReplicatorListener.h b/StateReplicator/test/MockStateReplicatorListener.h
index f9901a9..bb76ec0 100644
--- a/StateReplicator/test/MockStateReplicatorListener.h
+++ b/StateReplicator/test/MockStateReplicatorListener.h
@@ -26,35 +26,35 @@ namespace StateReplicatorTest
class MockStateReplicatorListenerImpl : public AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListener
{
public:
- MockStateReplicatorListenerImpl() : mRemoveStateCalled(false), mSetStateCalled(true)
- {
- }
+ MockStateReplicatorListenerImpl() : mRemoveStateCalled(false), mSetStateCalled(true)
+ {
+ }
void stateRemoved(const ::Ice::StringSeq& itemKeys, const ::Ice::Current& )
{
- mItemKeys = itemKeys;
- mRemoveStateCalled = true;
+ mItemKeys = itemKeys;
+ mRemoveStateCalled = true;
}
void stateSet(const ::AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq& items, const ::Ice::Current& )
{
- mStateItems = items;
- mSetStateCalled = true;
+ mStateItems = items;
+ mSetStateCalled = true;
}
- void reset()
+ void reset()
{
- mRemoveStateCalled = false;
- mSetStateCalled = false;
- mStateItems.clear();
- mItemKeys.clear();
+ mRemoveStateCalled = false;
+ mSetStateCalled = false;
+ mStateItems.clear();
+ mItemKeys.clear();
}
public:
- bool mRemoveStateCalled;
- bool mSetStateCalled;
- AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq mStateItems;
- Ice::StringSeq mItemKeys;
+ bool mRemoveStateCalled;
+ bool mSetStateCalled;
+ AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq mStateItems;
+ Ice::StringSeq mItemKeys;
};
typedef ::IceInternal::ProxyHandle<MockStateReplicatorListenerImpl> MockStateReplicatorListenerImplPrx;
typedef ::IceInternal::Handle<MockStateReplicatorListenerImpl> MockStateReplicatorListenerImplPtr;
diff --git a/StateReplicator/test/SharedTestData.h b/StateReplicator/test/SharedTestData.h
index 5655049..4632e9a 100644
--- a/StateReplicator/test/SharedTestData.h
+++ b/StateReplicator/test/SharedTestData.h
@@ -23,37 +23,37 @@ namespace AsteriskSCF
{
namespace StateReplicatorTest
{
- // typedef AsteriskSCF::StateReplication::StateReplicator<AsteriskSCF::StateReplicatorTest::V1::TestStateReplicator, AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq, AsteriskSCF::StateReplicatorTest::V1::TestStateItemPtr, Ice::StringSeq, std::string, AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx> TestReplicatorImpl;
- typedef AsteriskSCF::StateReplication::StateReplicator<AsteriskSCF::StateReplicatorTest::V1::TestStateReplicator, AsteriskSCF::StateReplicatorTest::V1::TestStateItemPtr, std::string, AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx> TestReplicatorImpl;
- typedef IceUtil::Handle<TestReplicatorImpl> TestReplicatorImplPtr;
+// typedef AsteriskSCF::StateReplication::StateReplicator<AsteriskSCF::StateReplicatorTest::V1::TestStateReplicator, AsteriskSCF::StateReplicatorTest::V1::TestStateItemSeq, AsteriskSCF::StateReplicatorTest::V1::TestStateItemPtr, Ice::StringSeq, std::string, AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx> TestReplicatorImpl;
+typedef AsteriskSCF::StateReplication::StateReplicator<AsteriskSCF::StateReplicatorTest::V1::TestStateReplicator, AsteriskSCF::StateReplicatorTest::V1::TestStateItemPtr, std::string, AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx> TestReplicatorImpl;
+typedef IceUtil::Handle<TestReplicatorImpl> TestReplicatorImplPtr;
-/**
+/**
* Pseudo singleton for sharing data among test artifacts.
*/
class SharedTestData
{
public:
- static SharedTestData instance;
+ static SharedTestData instance;
- // Communicator for outgoing stuff.
- Ice::CommunicatorPtr communicator_out;
+ // Communicator for outgoing stuff.
+ Ice::CommunicatorPtr communicator_out;
- // Communicator for incoming stuff. This is where we add the test servants.
- Ice::CommunicatorPtr communicator_in;
+ // Communicator for incoming stuff. This is where we add the test servants.
+ Ice::CommunicatorPtr communicator_in;
- Ice::ObjectAdapterPtr adapter_in;
- Ice::ObjectAdapterPtr adapter_out;
+ Ice::ObjectAdapterPtr adapter_in;
+ Ice::ObjectAdapterPtr adapter_out;
- TestReplicatorImplPtr mTestReplicatorImplPtr;
- AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorPrx mTestStateReplicatorPrx;
+ TestReplicatorImplPtr mTestReplicatorImplPtr;
+ AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorPrx mTestStateReplicatorPrx;
- MockStateReplicatorListenerImplPtr mMockStateListener1Ptr;
- MockStateReplicatorListenerImplPtr mMockStateListener2Ptr;
- MockStateReplicatorListenerImplPtr mMockStateListener3Ptr;
-
- AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener1Prx;
- AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener2Prx;
- AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener3Prx;
+ MockStateReplicatorListenerImplPtr mMockStateListener1Ptr;
+ MockStateReplicatorListenerImplPtr mMockStateListener2Ptr;
+ MockStateReplicatorListenerImplPtr mMockStateListener3Ptr;
+
+ AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener1Prx;
+ AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener2Prx;
+ AsteriskSCF::StateReplicatorTest::V1::TestStateReplicatorListenerPrx mTestStateListener3Prx;
};
}; // StateReplicatorTest
diff --git a/StateReplicator/test/TestStateReplicator.cpp b/StateReplicator/test/TestStateReplicator.cpp
index 8a8e5f4..5cc81a8 100644
--- a/StateReplicator/test/TestStateReplicator.cpp
+++ b/StateReplicator/test/TestStateReplicator.cpp
@@ -40,8 +40,8 @@ SharedTestData SharedTestData::instance;
struct ArgCacheType
{
public:
- int argc;
- char **argv;
+ int argc;
+ char **argv;
};
static ArgCacheType mCachedArgs;
@@ -51,88 +51,88 @@ static ArgCacheType mCachedArgs;
*/
struct GlobalIceFixture
{
- GlobalIceFixture()
- {
- BOOST_TEST_MESSAGE("Setting up State Replicator test fixture");
-
- ::boost::debug::detect_memory_leaks(false);
- ::boost::unit_test::unit_test_log.set_stream( std::cout );
-
- int status = 0;
- try
- {
- Ice::PropertiesPtr props = Ice::createProperties(mCachedArgs.argc, mCachedArgs.argv);
- Ice::InitializationData initData;
- initData.properties = props;
-
- // NOTE: See the typedef at top of ShareTestData.h to see how the StateReplicator template is invoked.
-
- // Set up incoming adapter. This is where we'll publish our proxies.
- SharedTestData::instance.communicator_in = Ice::initialize(initData);
-
- SharedTestData::instance.adapter_in = SharedTestData::instance.communicator_in->createObjectAdapterWithEndpoints("TestReplicatorAdapterIn", "default -p 10070");
-
- string replicatorId("TestReplicator");
- SharedTestData::instance.mTestReplicatorImplPtr = new TestReplicatorImpl();
- SharedTestData::instance.adapter_in->add(SharedTestData::instance.mTestReplicatorImplPtr, SharedTestData::instance.communicator_in->stringToIdentity(replicatorId));
-
- string listenerId1("Listener1");
- SharedTestData::instance.mMockStateListener1Ptr = new MockStateReplicatorListenerImpl();
- SharedTestData::instance.adapter_in->add(SharedTestData::instance.mMockStateListener1Ptr, SharedTestData::instance.communicator_in->stringToIdentity(listenerId1));
-
- string listenerId2("Listener2");
- SharedTestData::instance.mMockStateListener2Ptr = new MockStateReplicatorListenerImpl();
- SharedTestData::instance.adapter_in->add(SharedTestData::instance.mMockStateListener2Ptr, SharedTestData::instance.communicator_in->stringToIdentity(listenerId2));
-
- string listenerId3("Listener3");
- SharedTestData::instance.mMockStateListener3Ptr = new MockStateReplicatorListenerImpl();
- SharedTestData::instance.adapter_in->add(SharedTestData::instance.mMockStateListener3Ptr, SharedTestData::instance.communicator_in->stringToIdentity(listenerId3));
-
- SharedTestData::instance.adapter_in->activate();
-
- // Now that the adapter has been activated, get a local proxy to the replicator.
- Ice::ObjectPrx replicatorObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(replicatorId));
- SharedTestData::instance.mTestStateReplicatorPrx = TestStateReplicatorPrx::checkedCast(replicatorObjectPrx);
-
- Ice::ObjectPrx listener1ObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(listenerId1));
- SharedTestData::instance.mTestStateListener1Prx = TestStateReplicatorListenerPrx::checkedCast(listener1ObjectPrx);
-
- Ice::ObjectPrx listener2ObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(listenerId2));
- SharedTestData::instance.mTestStateListener2Prx = TestStateReplicatorListenerPrx::checkedCast(listener2ObjectPrx);
-
- Ice::ObjectPrx listener3ObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(listenerId3));
- SharedTestData::instance.mTestStateListener3Prx = TestStateReplicatorListenerPrx::checkedCast(listener3ObjectPrx);
-
- }
- catch (const Ice::Exception& ex)
- {
- cerr << ex << endl;
- status = 1;
- }
- catch (const char* msg)
- {
- cerr << msg << endl;
- status = 1;
- }
- } // end Fixture() constructor
-
-
- ~GlobalIceFixture()
- {
- BOOST_TEST_MESSAGE("Tearing down service discovery test fixture");
-
-
- if (SharedTestData::instance.communicator_in)
- {
- SharedTestData::instance.communicator_in->shutdown();
- SharedTestData::instance.communicator_in = 0;
- }
- if (SharedTestData::instance.communicator_out)
- {
- SharedTestData::instance.communicator_out->shutdown();
- SharedTestData::instance.communicator_out = 0;
- }
- }
+ GlobalIceFixture()
+ {
+ BOOST_TEST_MESSAGE("Setting up State Replicator test fixture");
+
+ ::boost::debug::detect_memory_leaks(false);
+ ::boost::unit_test::unit_test_log.set_stream( std::cout );
+
+ int status = 0;
+ try
+ {
+ Ice::PropertiesPtr props = Ice::createProperties(mCachedArgs.argc, mCachedArgs.argv);
+ Ice::InitializationData initData;
+ initData.properties = props;
+
+ // NOTE: See the typedef at top of ShareTestData.h to see how the StateReplicator template is invoked.
+
+ // Set up incoming adapter. This is where we'll publish our proxies.
+ SharedTestData::instance.communicator_in = Ice::initialize(initData);
+
+ SharedTestData::instance.adapter_in = SharedTestData::instance.communicator_in->createObjectAdapterWithEndpoints("TestReplicatorAdapterIn", "default -p 10070");
+
+ string replicatorId("TestReplicator");
+ SharedTestData::instance.mTestReplicatorImplPtr = new TestReplicatorImpl();
+ SharedTestData::instance.adapter_in->add(SharedTestData::instance.mTestReplicatorImplPtr, SharedTestData::instance.communicator_in->stringToIdentity(replicatorId));
+
+ string listenerId1("Listener1");
+ SharedTestData::instance.mMockStateListener1Ptr = new MockStateReplicatorListenerImpl();
+ SharedTestData::instance.adapter_in->add(SharedTestData::instance.mMockStateListener1Ptr, SharedTestData::instance.communicator_in->stringToIdentity(listenerId1));
+
+ string listenerId2("Listener2");
+ SharedTestData::instance.mMockStateListener2Ptr = new MockStateReplicatorListenerImpl();
+ SharedTestData::instance.adapter_in->add(SharedTestData::instance.mMockStateListener2Ptr, SharedTestData::instance.communicator_in->stringToIdentity(listenerId2));
+
+ string listenerId3("Listener3");
+ SharedTestData::instance.mMockStateListener3Ptr = new MockStateReplicatorListenerImpl();
+ SharedTestData::instance.adapter_in->add(SharedTestData::instance.mMockStateListener3Ptr, SharedTestData::instance.communicator_in->stringToIdentity(listenerId3));
+
+ SharedTestData::instance.adapter_in->activate();
+
+ // Now that the adapter has been activated, get a local proxy to the replicator.
+ Ice::ObjectPrx replicatorObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(replicatorId));
+ SharedTestData::instance.mTestStateReplicatorPrx = TestStateReplicatorPrx::checkedCast(replicatorObjectPrx);
+
+ Ice::ObjectPrx listener1ObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(listenerId1));
+ SharedTestData::instance.mTestStateListener1Prx = TestStateReplicatorListenerPrx::checkedCast(listener1ObjectPrx);
+
+ Ice::ObjectPrx listener2ObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(listenerId2));
+ SharedTestData::instance.mTestStateListener2Prx = TestStateReplicatorListenerPrx::checkedCast(listener2ObjectPrx);
+
+ Ice::ObjectPrx listener3ObjectPrx = SharedTestData::instance.adapter_in->createDirectProxy(SharedTestData::instance.communicator_in->stringToIdentity(listenerId3));
+ SharedTestData::instance.mTestStateListener3Prx = TestStateReplicatorListenerPrx::checkedCast(listener3ObjectPrx);
+
+ }
+ catch (const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = 1;
+ }
+ catch (const char* msg)
+ {
+ cerr << msg << endl;
+ status = 1;
+ }
+ } // end Fixture() constructor
+
+
+ ~GlobalIceFixture()
+ {
+ BOOST_TEST_MESSAGE("Tearing down service discovery test fixture");
+
+
+ if (SharedTestData::instance.communicator_in)
+ {
+ SharedTestData::instance.communicator_in->shutdown();
+ SharedTestData::instance.communicator_in = 0;
+ }
+ if (SharedTestData::instance.communicator_out)
+ {
+ SharedTestData::instance.communicator_out->shutdown();
+ SharedTestData::instance.communicator_out = 0;
+ }
+ }
private:
int mGlob;
};
@@ -146,68 +146,68 @@ BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
*/
int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
{
- mCachedArgs.argc = argc;
- mCachedArgs.argv = argv;
- return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
+ mCachedArgs.argc = argc;
+ mCachedArgs.argv = argv;
+ return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
}
struct PerTestFixture
{
-public:
- PerTestFixture()
- {
- try
- {
- SharedTestData::instance.mMockStateListener1Ptr->reset();
- SharedTestData::instance.mMockStateListener2Ptr->reset();
-
- SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener1Prx);
- SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener2Prx);
-
- mTestValues.clear();
-
- TestStateItemFooPtr item1 = new TestStateItemFoo();
- item1->key = "FooBabar";
- item1->mFooCount = 12;
- item1->mFooString = "Baileys";
- mTestValues.push_back(item1);
-
- TestStateItemBarPtr item2 = new TestStateItemBar();
- item2->key = "BarMouse";
- item2->mBarString = "Ringling";
- mTestValues.push_back(item2);
-
- TestStateItemFooPtr item3 = new TestStateItemFoo();
- item3->key = "FooDumbo";
- item3->mFooCount = 7;
- item3->mFooString = "Barnum";
- mTestValues.push_back(item3);
-
- }
- catch (...)
- {
- BOOST_TEST_MESSAGE("PerTestFixture failed to initialize.");
-
- SharedTestData::instance.mTestReplicatorImplPtr->clearListeners();
- SharedTestData::instance.mTestReplicatorImplPtr->clearState();
- }
- }
-
- ~PerTestFixture()
- {
- try
- {
- SharedTestData::instance.mTestReplicatorImplPtr->clearListeners();
- SharedTestData::instance.mTestReplicatorImplPtr->clearState();
- }
- catch (...)
- {
- BOOST_TEST_MESSAGE("PerTestFixture failed in shutdown.");
- }
- }
+public:
+ PerTestFixture()
+ {
+ try
+ {
+ SharedTestData::instance.mMockStateListener1Ptr->reset();
+ SharedTestData::instance.mMockStateListener2Ptr->reset();
+
+ SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener1Prx);
+ SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener2Prx);
+
+ mTestValues.clear();
+
+ TestStateItemFooPtr item1 = new TestStateItemFoo();
+ item1->key = "FooBabar";
+ item1->mFooCount = 12;
+ item1->mFooString = "Baileys";
+ mTestValues.push_back(item1);
+
+ TestStateItemBarPtr item2 = new TestStateItemBar();
+ item2->key = "BarMouse";
+ item2->mBarString = "Ringling";
+ mTestValues.push_back(item2);
+
+ TestStateItemFooPtr item3 = new TestStateItemFoo();
+ item3->key = "FooDumbo";
+ item3->mFooCount = 7;
+ item3->mFooString = "Barnum";
+ mTestValues.push_back(item3);
+
+ }
+ catch (...)
+ {
+ BOOST_TEST_MESSAGE("PerTestFixture failed to initialize.");
+
+ SharedTestData::instance.mTestReplicatorImplPtr->clearListeners();
+ SharedTestData::instance.mTestReplicatorImplPtr->clearState();
+ }
+ }
+
+ ~PerTestFixture()
+ {
+ try
+ {
+ SharedTestData::instance.mTestReplicatorImplPtr->clearListeners();
+ SharedTestData::instance.mTestReplicatorImplPtr->clearState();
+ }
+ catch (...)
+ {
+ BOOST_TEST_MESSAGE("PerTestFixture failed in shutdown.");
+ }
+ }
public:
- TestStateItemSeq mTestValues;
+ TestStateItemSeq mTestValues;
};
/**
@@ -215,37 +215,37 @@ public:
*/
BOOST_AUTO_TEST_CASE(AddRemoveListeners)
{
- bool addListenerSucceeded(true);
- try
- {
- SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener1Prx);
- SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener2Prx);
- }
- catch (...)
- {
- addListenerSucceeded = false;
- BOOST_TEST_MESSAGE("Exception adding Listeners.");
- }
-
- BOOST_CHECK(addListenerSucceeded);
- BOOST_CHECK(SharedTestData::instance.mTestReplicatorImplPtr->getListenerCount() == 2);
-
- bool removeListenerSucceeded(true);
- try
- {
- SharedTestData::instance.mTestStateReplicatorPrx->removeListener(SharedTestData::instance.mTestStateListener1Prx);
- SharedTestData::instance.mTestStateReplicatorPrx->removeListener(SharedTestData::instance.mTestStateListener2Prx);
- }
- catch (...)
- {
- removeListenerSucceeded = false;
- BOOST_TEST_MESSAGE("Exception removing Listener.");
- }
- BOOST_CHECK(removeListenerSucceeded);
- BOOST_CHECK(SharedTestData::instance.mTestReplicatorImplPtr->getListenerCount() == 0);
-
-
- BOOST_TEST_MESSAGE("Completed AddRemoveListeners test.");
+ bool addListenerSucceeded(true);
+ try
+ {
+ SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener1Prx);
+ SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener2Prx);
+ }
+ catch (...)
+ {
+ addListenerSucceeded = false;
+ BOOST_TEST_MESSAGE("Exception adding Listeners.");
+ }
+
+ BOOST_CHECK(addListenerSucceeded);
+ BOOST_CHECK(SharedTestData::instance.mTestReplicatorImplPtr->getListenerCount() == 2);
+
+ bool removeListenerSucceeded(true);
+ try
+ {
+ SharedTestData::instance.mTestStateReplicatorPrx->removeListener(SharedTestData::instance.mTestStateListener1Prx);
+ SharedTestData::instance.mTestStateReplicatorPrx->removeListener(SharedTestData::instance.mTestStateListener2Prx);
+ }
+ catch (...)
+ {
+ removeListenerSucceeded = false;
+ BOOST_TEST_MESSAGE("Exception removing Listener.");
+ }
+ BOOST_CHECK(removeListenerSucceeded);
+ BOOST_CHECK(SharedTestData::instance.mTestReplicatorImplPtr->getListenerCount() == 0);
+
+
+ BOOST_TEST_MESSAGE("Completed AddRemoveListeners test.");
}
/**
@@ -253,31 +253,31 @@ BOOST_AUTO_TEST_CASE(AddRemoveListeners)
*/
BOOST_FIXTURE_TEST_CASE(PushData, PerTestFixture)
{
- try
- {
- SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
-
- }
- catch(const IceUtil::Exception &ie)
- {
- bool IceException(false);
- string msg = "Exception pushing state data.";
- msg += ie.what();
- BOOST_TEST_MESSAGE(msg);
- BOOST_CHECK(IceException);
- }
- catch (...)
- {
- bool unknownException(false);
- BOOST_CHECK(unknownException);
- }
-
- BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mStateItems.size() == 3);
- BOOST_CHECK(SharedTestData::instance.mMockStateListener2Ptr->mStateItems.size() == 3);
-
- BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mStateItems.front()->key == "FooBabar");
-
- BOOST_TEST_MESSAGE("Completed PushData test.");
+ try
+ {
+ SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
+
+ }
+ catch(const IceUtil::Exception &ie)
+ {
+ bool IceException(false);
+ string msg = "Exception pushing state data.";
+ msg += ie.what();
+ BOOST_TEST_MESSAGE(msg);
+ BOOST_CHECK(IceException);
+ }
+ catch (...)
+ {
+ bool unknownException(false);
+ BOOST_CHECK(unknownException);
+ }
+
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mStateItems.size() == 3);
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener2Ptr->mStateItems.size() == 3);
+
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mStateItems.front()->key == "FooBabar");
+
+ BOOST_TEST_MESSAGE("Completed PushData test.");
}
@@ -286,83 +286,83 @@ BOOST_FIXTURE_TEST_CASE(PushData, PerTestFixture)
*/
BOOST_FIXTURE_TEST_CASE(ForwardRemoveState, PerTestFixture)
{
- TestStateItemSeq retrievedValues;
-
- try
- {
- SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
- // {FooBabar, BarMouse, FooDumbo}
-
- Ice::StringSeq keys;
- keys.push_back("FooBabar");
- keys.push_back("FooDumbo");
-
- SharedTestData::instance.mTestStateReplicatorPrx->removeState(keys);
- }
- catch(const IceUtil::Exception &ie)
- {
- bool IceException(false);
- string msg = "Exception removing state data.";
- msg += ie.what();
- BOOST_TEST_MESSAGE(msg);
- BOOST_CHECK(IceException);
- }
- catch (...)
- {
- bool unknownException(false);
- BOOST_CHECK(unknownException);
- }
-
- BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mItemKeys.size() == 2);
- BOOST_CHECK(SharedTestData::instance.mMockStateListener2Ptr->mItemKeys.size() == 2);
-
- BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mItemKeys.front() == "FooBabar");
-
- BOOST_TEST_MESSAGE("Completed ForwardRemoveState test.");
+ TestStateItemSeq retrievedValues;
+
+ try
+ {
+ SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
+ // {FooBabar, BarMouse, FooDumbo}
+
+ Ice::StringSeq keys;
+ keys.push_back("FooBabar");
+ keys.push_back("FooDumbo");
+
+ SharedTestData::instance.mTestStateReplicatorPrx->removeState(keys);
+ }
+ catch(const IceUtil::Exception &ie)
+ {
+ bool IceException(false);
+ string msg = "Exception removing state data.";
+ msg += ie.what();
+ BOOST_TEST_MESSAGE(msg);
+ BOOST_CHECK(IceException);
+ }
+ catch (...)
+ {
+ bool unknownException(false);
+ BOOST_CHECK(unknownException);
+ }
+
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mItemKeys.size() == 2);
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener2Ptr->mItemKeys.size() == 2);
+
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener1Ptr->mItemKeys.front() == "FooBabar");
+
+ BOOST_TEST_MESSAGE("Completed ForwardRemoveState test.");
}
/**
- * Test removing state. Also tests retrieving all the state.
+ * Test removing state. Also tests retrieving all the state.
*/
BOOST_FIXTURE_TEST_CASE(RemoveState, PerTestFixture)
{
- TestStateItemSeq retrievedValues;
-
- try
- {
- // Set the basic 3 items of state.
- // {FooBabar, BarMouse, FooDumbo}
- SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
-
- // Try removing two of them.
- Ice::StringSeq keys;
- keys.push_back("FooBabar");
- keys.push_back("FooDumbo");
-
- SharedTestData::instance.mTestStateReplicatorPrx->removeState(keys);
-
- retrievedValues = SharedTestData::instance.mTestStateReplicatorPrx->getAllState();
- }
- catch(const IceUtil::Exception &ie)
- {
- bool IceException(false);
- string msg = "Exception removing state data.";
- msg += ie.what();
- BOOST_TEST_MESSAGE(msg);
- BOOST_CHECK(IceException);
- }
- catch (...)
- {
- bool unknownException(false);
- BOOST_CHECK(unknownException);
- }
-
- BOOST_CHECK(retrievedValues.size() == 1);
-
- BOOST_CHECK(retrievedValues.front()->key == "BarMouse");
-
- BOOST_TEST_MESSAGE("Completed RemoveState test.");
+ TestStateItemSeq retrievedValues;
+
+ try
+ {
+ // Set the basic 3 items of state.
+ // {FooBabar, BarMouse, FooDumbo}
+ SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
+
+ // Try removing two of them.
+ Ice::StringSeq keys;
+ keys.push_back("FooBabar");
+ keys.push_back("FooDumbo");
+
+ SharedTestData::instance.mTestStateReplicatorPrx->removeState(keys);
+
+ retrievedValues = SharedTestData::instance.mTestStateReplicatorPrx->getAllState();
+ }
+ catch(const IceUtil::Exception &ie)
+ {
+ bool IceException(false);
+ string msg = "Exception removing state data.";
+ msg += ie.what();
+ BOOST_TEST_MESSAGE(msg);
+ BOOST_CHECK(IceException);
+ }
+ catch (...)
+ {
+ bool unknownException(false);
+ BOOST_CHECK(unknownException);
+ }
+
+ BOOST_CHECK(retrievedValues.size() == 1);
+
+ BOOST_CHECK(retrievedValues.front()->key == "BarMouse");
+
+ BOOST_TEST_MESSAGE("Completed RemoveState test.");
}
/**
@@ -370,38 +370,38 @@ BOOST_FIXTURE_TEST_CASE(RemoveState, PerTestFixture)
*/
BOOST_FIXTURE_TEST_CASE(GetSomeState, PerTestFixture)
{
- TestStateItemSeq retrievedValues;
-
- try
- {
- SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
- // {FooBabar, BarMouse, FooDumbo}
-
- Ice::StringSeq keys;
- keys.push_back("FooBabar");
- keys.push_back("FooDumbo");
-
- retrievedValues = SharedTestData::instance.mTestStateReplicatorPrx->getState(keys);
- }
- catch(const IceUtil::Exception &ie)
- {
- bool IceException(false);
- string msg = "Exception getting partial state data.";
- msg += ie.what();
- BOOST_TEST_MESSAGE(msg);
- BOOST_CHECK(IceException);
- }
- catch (...)
- {
- bool unknownException(false);
- BOOST_CHECK(unknownException);
- }
-
- BOOST_CHECK(retrievedValues.size() == 2);
-
- BOOST_CHECK(retrievedValues.front()->key == "FooBabar");
-
- BOOST_TEST_MESSAGE("Completed GetSomeState test.");
+ TestStateItemSeq retrievedValues;
+
+ try
+ {
+ SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
+ // {FooBabar, BarMouse, FooDumbo}
+
+ Ice::StringSeq keys;
+ keys.push_back("FooBabar");
+ keys.push_back("FooDumbo");
+
+ retrievedValues = SharedTestData::instance.mTestStateReplicatorPrx->getState(keys);
+ }
+ catch(const IceUtil::Exception &ie)
+ {
+ bool IceException(false);
+ string msg = "Exception getting partial state data.";
+ msg += ie.what();
+ BOOST_TEST_MESSAGE(msg);
+ BOOST_CHECK(IceException);
+ }
+ catch (...)
+ {
+ bool unknownException(false);
+ BOOST_CHECK(unknownException);
+ }
+
+ BOOST_CHECK(retrievedValues.size() == 2);
+
+ BOOST_CHECK(retrievedValues.front()->key == "FooBabar");
+
+ BOOST_TEST_MESSAGE("Completed GetSomeState test.");
}
/**
@@ -409,77 +409,77 @@ BOOST_FIXTURE_TEST_CASE(GetSomeState, PerTestFixture)
*/
BOOST_FIXTURE_TEST_CASE(PreserveOrder, PerTestFixture)
{
- TestStateItemSeq retrievedValues;
-
- try
- {
- SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
-
- // {FooBabar, BarMouse, FooDumbo}
- Ice::StringSeq keys;
- keys.push_back("BarMouse");
- SharedTestData::instance.mTestStateReplicatorPrx->removeState(keys);
- // {FooBabar, FooDumbo}
-
- TestStateItemSeq moreItems;
- TestStateItemBarPtr item1 = new TestStateItemBar();
- item1->key = "Extra";
- moreItems.push_back(item1);
-
- // Re-add BarMouse
- TestStateItemBarPtr item2 = new TestStateItemBar();
- item2->key = "BarMouse";
- moreItems.push_back(item2);
-
- SharedTestData::instance.mTestStateReplicatorPrx->setState(moreItems);
- // {FooBabar, FooDumbo, Extra, BarMouse}
-
- retrievedValues = SharedTestData::instance.mTestStateReplicatorPrx->getAllState();
- }
- catch(const IceUtil::Exception &ie)
- {
- bool IceException(false);
- string msg = "Exception altering state data.";
- msg += ie.what();
- BOOST_TEST_MESSAGE(msg);
- BOOST_CHECK(IceException);
- }
- catch (...)
- {
- bool unknownException(false);
- BOOST_CHECK(unknownException);
- }
-
- BOOST_CHECK(retrievedValues.size() == 4);
-
- BOOST_CHECK(retrievedValues[0]->key == "FooBabar");
- BOOST_CHECK(retrievedValues[1]->key == "FooDumbo");
- BOOST_CHECK(retrievedValues[2]->key == "Extra");
- BOOST_CHECK(retrievedValues[3]->key == "BarMouse");
-
- try
- {
- //Insure that a late joiner is pushed the correct current state, in correct order.
- SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener3Prx);
-
- // NOTE: This test currently is reliable only because we are NOT doing asynchronous sends to the listeners.
- // Will need a delay when asynch.
- BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems.size() == 4);
-
- BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[0]->key == "FooBabar");
- BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[1]->key == "FooDumbo");
- BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[2]->key == "Extra");
- BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[3]->key == "BarMouse");
- }
- catch(const IceUtil::Exception &ie)
- {
- bool IceException(false);
- string msg = "Exception adding a late listener.";
- msg += ie.what();
- BOOST_TEST_MESSAGE(msg);
- BOOST_CHECK(IceException);
- }
-
- BOOST_TEST_MESSAGE("Completed PreserveOrder test.");
+ TestStateItemSeq retrievedValues;
+
+ try
+ {
+ SharedTestData::instance.mTestStateReplicatorPrx->setState(mTestValues);
+
+ // {FooBabar, BarMouse, FooDumbo}
+ Ice::StringSeq keys;
+ keys.push_back("BarMouse");
+ SharedTestData::instance.mTestStateReplicatorPrx->removeState(keys);
+ // {FooBabar, FooDumbo}
+
+ TestStateItemSeq moreItems;
+ TestStateItemBarPtr item1 = new TestStateItemBar();
+ item1->key = "Extra";
+ moreItems.push_back(item1);
+
+ // Re-add BarMouse
+ TestStateItemBarPtr item2 = new TestStateItemBar();
+ item2->key = "BarMouse";
+ moreItems.push_back(item2);
+
+ SharedTestData::instance.mTestStateReplicatorPrx->setState(moreItems);
+ // {FooBabar, FooDumbo, Extra, BarMouse}
+
+ retrievedValues = SharedTestData::instance.mTestStateReplicatorPrx->getAllState();
+ }
+ catch(const IceUtil::Exception &ie)
+ {
+ bool IceException(false);
+ string msg = "Exception altering state data.";
+ msg += ie.what();
+ BOOST_TEST_MESSAGE(msg);
+ BOOST_CHECK(IceException);
+ }
+ catch (...)
+ {
+ bool unknownException(false);
+ BOOST_CHECK(unknownException);
+ }
+
+ BOOST_CHECK(retrievedValues.size() == 4);
+
+ BOOST_CHECK(retrievedValues[0]->key == "FooBabar");
+ BOOST_CHECK(retrievedValues[1]->key == "FooDumbo");
+ BOOST_CHECK(retrievedValues[2]->key == "Extra");
+ BOOST_CHECK(retrievedValues[3]->key == "BarMouse");
+
+ try
+ {
+ //Insure that a late joiner is pushed the correct current state, in correct order.
+ SharedTestData::instance.mTestStateReplicatorPrx->addListener(SharedTestData::instance.mTestStateListener3Prx);
+
+ // NOTE: This test currently is reliable only because we are NOT doing asynchronous sends to the listeners.
+ // Will need a delay when asynch.
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems.size() == 4);
+
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[0]->key == "FooBabar");
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[1]->key == "FooDumbo");
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[2]->key == "Extra");
+ BOOST_CHECK(SharedTestData::instance.mMockStateListener3Ptr->mStateItems[3]->key == "BarMouse");
+ }
+ catch(const IceUtil::Exception &ie)
+ {
+ bool IceException(false);
+ string msg = "Exception adding a late listener.";
+ msg += ie.what();
+ BOOST_TEST_MESSAGE(msg);
+ BOOST_CHECK(IceException);
+ }
+
+ BOOST_TEST_MESSAGE("Completed PreserveOrder test.");
}
commit ad69c4da94a39577523a162f7d6ca4b49d1b1e69
Author: David M. Lee <dlee at digium.com>
Date: Wed Nov 3 13:34:41 2010 -0500
Fixed Solaris build: incorrectly specified boost dependency.
diff --git a/ProxyWrapper/src/CMakeLists.txt b/ProxyWrapper/src/CMakeLists.txt
index 383649c..da2461d 100644
--- a/ProxyWrapper/src/CMakeLists.txt
+++ b/ProxyWrapper/src/CMakeLists.txt
@@ -5,12 +5,7 @@ asterisk_scf_component_init(ProxyWrapper CXX)
asterisk_scf_component_add_slice(ProxyWrapper ServiceLocatorIf)
asterisk_scf_component_add_file(ProxyWrapper ProxyWrapper.h)
asterisk_scf_component_add_file(ProxyWrapper ProxyWrapper.cpp)
-
-if (NOT ${Boost_INCUDE_DIR})
- find_package(Boost)
-endif()
-
-include_directories(${Boost_INCLUDE_DIR})
+asterisk_scf_component_add_boost_libraries(ProxyWrapper core)
asterisk_scf_component_build_library(ProxyWrapper)
commit 51a9381adda75cd6dc091757762c90f6004e9e38
Author: David M. Lee <dlee at digium.com>
Date: Wed Nov 3 13:31:34 2010 -0500
Removed bogus subdir.
diff --git a/ice-util-c++/LICENSE.txt b/ice-util-c++/LICENSE.txt
deleted file mode 100644
index ff0499c..0000000
--- a/ice-util-c++/LICENSE.txt
+++ /dev/null
@@ -1,84 +0,0 @@
-Asterisk SCF is distributed by Digium, Inc. (Digium) under the GNU
-General Public License version 2 (GPLv2) and is also available under
-alternative licenses negotiated directly with Digium. If you obtained
-Asterisk SCF under the GPLv2, then those terms apply to all programs
-you distribute that communicate using the Asterisk SCF object
-interfaces (APIs) on objects provided by Asterisk SCF's components, as
-defined below. A copy of the GPLv2 is included in the Asterisk SCF
-source tree in the file COPYING.txt.
-
-Asterisk SCF is a collection of programs that communicate with each
-other over defined APIs. This communication can occur within a single
-process (if two programs are loaded into a suitable container),
-between processes on a single machine, between processes on different
-machines, or some combination. In addition, these APIs are usable
-across a number of platforms and also across a variety of programming
-languages, many of which are interpreted (scripting)
-languages. Because of this flexibility and the possible ambiguity in
-interpretation of the provisions of the GPLv2 as they apply to
-Asterisk SCF, Digium makes the following statement:
-
- It is Digium's interpretation that because the Asterisk SCF APIs,
- by definition, expose direct, and indirect, complex remote, and
- non-remote, function calls on objects provided by Asterisk SCF's
- programs, that usage of these APIs between the program hosting the
- object(s) and the program accessing the object(s) creates a
- derivative work that must be covered wholly by GPLv2, even if the
... 2967 lines suppressed ...
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list