[asterisk-scf-commits] asterisk-scf/integration/util-cpp.git branch "route_replica" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Mon Mar 7 01:25:12 CST 2011
branch "route_replica" has been created
at 841b6f6da15190289390c5b4ba900793a497dc7f (commit)
- Log -----------------------------------------------------------------
commit 841b6f6da15190289390c5b4ba900793a497dc7f
Author: Ken Hunt <ken.hunt at digium.com>
Date: Mon Mar 7 01:25:11 2011 -0600
Changes for routing service replication.
diff --git a/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h b/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
index acabef9..538c941 100644
--- a/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
+++ b/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
@@ -40,16 +40,21 @@ public:
/**
* Listener interface for monitoring the state machine.
*/
- template<typename S>
+
class StateMachineListener
{
public:
- ~StateMachineListener() {}
+ virtual ~StateMachineListener() {}
virtual void stateExecutionStart(S state) = 0;
virtual void stateExecutionComplete(S state) = 0;
virtual void stateTransition(S oldState, S newState) = 0;
+
+ protected:
+ StateMachineListener() {}
};
+ //typedef StateMachineListener<S> StateMachineListenerType;
+
public:
/**
* Constructor.
@@ -60,14 +65,19 @@ public:
mCurrentState = mNextState = defaultState;
}
+ ~SimpleStateMachine()
+ {
+ mListeners.clear();
+ }
+
//// Listener management.
- void addListener(const boost::shared_ptr<StateMachineListener<S> > & listener)
+ void addListener(const boost::shared_ptr<StateMachineListener >& listener)
{
- mListeners.add(listener);
+ mListeners.push_back(listener);
}
- void removeListener(const boost::shared_ptr<StateMachineListener<S> > & listener)
+ void removeListener(const boost::shared_ptr<StateMachineListener >& listener)
{
mListeners.remove(listener);
}
@@ -130,7 +140,7 @@ private:
public:
ExecutionStartNotice(S state) : mState(state) {}
~ExecutionStartNotice() {}
- void operator() (const boost::shared_ptr<StateMachineListener<S> >& x)
+ void operator() (boost::shared_ptr<StateMachineListener >& x)
{
try
{
@@ -165,7 +175,7 @@ private:
public:
ExecutionCompleteNotice(S state) : mState(state) {}
~ExecutionCompleteNotice() {}
- void operator() (const boost::shared_ptr<StateMachineListener<S> >& x)
+ void operator() (boost::shared_ptr<StateMachineListener >& x)
{
try
{
@@ -199,7 +209,7 @@ private:
public:
TransitionNotice(S oldState, S newState) : mOldState(oldState), mNewState(newState) {}
~TransitionNotice() {}
- void operator() (const boost::shared_ptr<StateMachineListener<S> >& x)
+ void operator() (boost::shared_ptr<StateMachineListener >& x)
{
try
{
@@ -229,7 +239,7 @@ private:
std::map<S, F> mStates;
S mCurrentState;
S mNextState;
- std::vector<const boost::shared_ptr<StateMachineListener<S> > > mListeners;
+ std::vector<boost::shared_ptr<StateMachineListener > > mListeners;
};
} // end namespace StateMachine
diff --git a/Threading/CMakeLists.txt b/Threading/CMakeLists.txt
index 6275408..7e60fb4 100644
--- a/Threading/CMakeLists.txt
+++ b/Threading/CMakeLists.txt
@@ -10,6 +10,8 @@ asterisk_scf_component_init(Threading CXX)
include_directories(include)
+asterisk_scf_slice_include_directories(${API_SLICE_DIR})
+
asterisk_scf_component_add_slice(Threading LoggerIf)
asterisk_scf_component_add_file(Threading include/AsteriskSCF/Threading/WorkQueue.h)
asterisk_scf_component_add_file(Threading include/AsteriskSCF/Threading/SimpleWorkQueue.h)
@@ -21,8 +23,9 @@ 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}/include)
include_directories(${logger_dir}/client/src)
+include_directories(${API_INCLUDE_DIR})
asterisk_scf_component_build_library(Threading)
diff --git a/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h b/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h
index 61ace49..3ecc00c 100644
--- a/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h
+++ b/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h
@@ -20,9 +20,10 @@
#include <boost/thread/condition.hpp>
#include <boost/shared_ptr.hpp>
+#include <AsteriskSCF/logger.h>
+
#include "WorkQueue.h"
#include "PausibleWorkQueue.h"
-#include "logger.h"
namespace AsteriskSCF
{
diff --git a/Threading/src/SimpleWorkQueue.cpp b/Threading/src/SimpleWorkQueue.cpp
index 0eb74cb..77fe099 100644
--- a/Threading/src/SimpleWorkQueue.cpp
+++ b/Threading/src/SimpleWorkQueue.cpp
@@ -25,7 +25,7 @@
#include <boost/thread.hpp>
#include <list>
-#include "logger.h"
+#include <AsteriskSCF/logger.h>
#include "AsteriskSCF/Threading/SimpleWorkQueue.h"
commit f6464a5c703bd8365d015795f78c3bf0c7ae4c52
Author: Ken Hunt <ken.hunt at digium.com>
Date: Thu Mar 3 11:07:05 2011 -0600
Added state machine implementation.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4bfc63e..bb1db1d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,3 +4,4 @@ if (integrated_build STREQUAL "true")
endif()
add_subdirectory(Threading)
+add_subdirectory(StateMachine)
diff --git a/StateMachine/CMakeLists.txt b/StateMachine/CMakeLists.txt
new file mode 100644
index 0000000..8c4b205
--- /dev/null
+++ b/StateMachine/CMakeLists.txt
@@ -0,0 +1,30 @@
+#
+# Asterisk Scalable Communications Framework
+#
+# Copyright (C) 2010, 2011 -- Digium, Inc.
+#
+# All rights reserved.
+#
+
+asterisk_scf_component_init(StateMachine CXX)
+
+include_directories(include)
+
+asterisk_scf_component_add_slice(StateMachine LoggerIf)
+asterisk_scf_component_add_file(StateMachine include/AsteriskSCF/StateMachine/SimpleStateMachine.h)
+asterisk_scf_component_add_file(StateMachine src/SimpleStateMachine.cpp)
+asterisk_scf_component_add_boost_libraries(StateMachine 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(StateMachine)
+
+target_link_libraries(StateMachine logging-client)
+
+asterisk_scf_component_install(StateMachine LIBRARY lib "State Machine" StateMachine ARCHIVE DESTINATION lib)
+
diff --git a/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h b/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
new file mode 100644
index 0000000..acabef9
--- /dev/null
+++ b/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
@@ -0,0 +1,236 @@
+/*
+ * 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 <boost/function.hpp>
+#include <map>
+#include <vector>
+
+namespace AsteriskSCF
+{
+namespace StateMachine
+{
+
+/**
+ * A simple state machine. User's provide a definition of the state type (probably an enum type) and
+ * a type that can be executed using operator() to handle execution for a given state.
+ * A listener interface is provided to allow monitoring state changes and state execution.
+ * - typename S State type
+ * - typename F An executable operation for state handler
+ */
+template<typename S, typename F>
+class SimpleStateMachine
+{
+public:
+
+ /**
+ * Listener interface for monitoring the state machine.
+ */
+ template<typename S>
+ class StateMachineListener
+ {
+ public:
+ ~StateMachineListener() {}
+ virtual void stateExecutionStart(S state) = 0;
+ virtual void stateExecutionComplete(S state) = 0;
+ virtual void stateTransition(S oldState, S newState) = 0;
+ };
+
+public:
+ /**
+ * Constructor.
+ * @param defaultState The default state for the state machine.
+ */
+ SimpleStateMachine(S defaultState)
+ {
+ mCurrentState = mNextState = defaultState;
+ }
+
+ //// Listener management.
+
+ void addListener(const boost::shared_ptr<StateMachineListener<S> > & listener)
+ {
+ mListeners.add(listener);
+ }
+
+ void removeListener(const boost::shared_ptr<StateMachineListener<S> > & listener)
+ {
+ mListeners.remove(listener);
+ }
+
+ /// State management.
+
+ /**
+ * Sets the execution handler for a given state.
+ */
+ void addState(S state, const F& handler)
+ {
+ mStates[state] = handler;
+ }
+
+ /**
+ * Sets the next state. State transitions occur after the current state's execution is complete.
+ */
+ void setNextState(S state)
+ {
+ mNextState = state;
+ }
+
+ /**
+ * This executes the state machine's current state.
+ */
+ void execute()
+ {
+ // Notify all listeners that execution is starting.
+ sendExecutionStartNotice(mCurrentState);
+
+ std::map<S, F>::iterator it = mStates.find(mCurrentState);
+ if (it != mStates.end())
+ {
+ // Execute
+ it->second();
+ }
+
+ // Notify all listeners that execution is complete.
+ sendExecutionCompleteNotice(mCurrentState);
+
+ // Did state transition occur?
+ if (mCurrentState != mNextState)
+ {
+ // Notify listeners if machine transitioned to new state.
+ sendTransitionNotice(mCurrentState, mNextState);
+ mCurrentState = mNextState;
+ }
+ }
+
+
+private:
+
+ /**
+ * Functor for forwarding stateExecutionStart() notices.
+ */
+ template<typename S>
+ class ExecutionStartNotice
+ {
+ // Types: S - State
+ public:
+ ExecutionStartNotice(S state) : mState(state) {}
+ ~ExecutionStartNotice() {}
+ void operator() (const boost::shared_ptr<StateMachineListener<S> >& x)
+ {
+ try
+ {
+ x->stateExecutionStart(mState);
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ catch(...)
+ {
+ }
+ }
+ S mState;
+ };
+
+ /**
+ * Forward the Exection Start notice to all registered listeners.
+ */
+ void sendExecutionStartNotice(S state)
+ {
+ std::for_each(mListeners.begin(), mListeners.end(), ExecutionStartNotice<S>(state));
+ }
+
+
+ /**
+ * Functor for forwarding stateExecutionComplete() notices.
+ */
+ template<typename S>
+ class ExecutionCompleteNotice
+ {
+ // Types: S - State
+ public:
+ ExecutionCompleteNotice(S state) : mState(state) {}
+ ~ExecutionCompleteNotice() {}
+ void operator() (const boost::shared_ptr<StateMachineListener<S> >& x)
+ {
+ try
+ {
+ x->stateExecutionComplete(mState);
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ catch(...)
+ {
+ }
+ }
+ S mState;
+ };
+
+ /**
+ * Forward the Exection Complete notice to all registered listeners.
+ */
+ void sendExecutionCompleteNotice(S state)
+ {
+ std::for_each(mListeners.begin(), mListeners.end(), ExecutionCompleteNotice<S> (state));
+ }
+
+ /**
+ * Functor for forwarding stateTransition() notices.
+ */
+ template<typename S>
+ class TransitionNotice
+ {
+ // Types: S - State
+ public:
+ TransitionNotice(S oldState, S newState) : mOldState(oldState), mNewState(newState) {}
+ ~TransitionNotice() {}
+ void operator() (const boost::shared_ptr<StateMachineListener<S> >& x)
+ {
+ try
+ {
+ x->stateTransition(mOldState, mNewState);
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+ catch(...)
+ {
+ }
+ }
+ S mOldState;
+ S mNewState;
+ };
+
+ /**
+ * Forward the state transition notice to all registered listeners.
+ */
+ void sendTransitionNotice(S oldState, S newState)
+ {
+ std::for_each(mListeners.begin(), mListeners.end(), TransitionNotice<S> (oldState, newState));
+ }
+
+ /// Class state
+
+ std::map<S, F> mStates;
+ S mCurrentState;
+ S mNextState;
+ std::vector<const boost::shared_ptr<StateMachineListener<S> > > mListeners;
+};
+
+} // end namespace StateMachine
+} // end namespace AsteriskSCF
diff --git a/StateMachine/src/SimpleStateMachine.cpp b/StateMachine/src/SimpleStateMachine.cpp
new file mode 100644
index 0000000..7d73a7f
--- /dev/null
+++ b/StateMachine/src/SimpleStateMachine.cpp
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+#include "AsteriskSCF/StateMachine/SimpleStateMachine.h"
+
+namespace AsteriskSCF
+{
+namespace StateMachine
+{
+
+
+} // end namespace StateMachine
+} // end namespace AsteriskSCF
diff --git a/Threading/CMakeLists.txt~ b/Threading/CMakeLists.txt~
deleted file mode 100644
index 61c91ab..0000000
--- a/Threading/CMakeLists.txt~
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Asterisk Scalable Communications Framework
-#
-# Copyright (C) 2010, 2011 -- Digium, Inc.
-#
-# All rights reserved.
-#
-
-asterisk_scf_component_init(Threading CXX)
-
-include_directories(include)
-
-asterisk_scf_component_add_slice(Threading LoggerIf)
-asterisk_scf_component_add_file(Threading include/AsteriskSCF/Threading/Threading.h)
-asterisk_scf_component_add_file(Threading include/AsteriskSCF/Threading/SimpleThreading.h)
-asterisk_scf_component_add_file(Threading include/AsteriskSCF/Threading/PausibleThreading.h)
-asterisk_scf_component_add_file(Threading src/SimpleThreading.cpp)
-asterisk_scf_component_add_boost_libraries(Threading core thread)
-
-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(Threading)
-
-target_link_libraries(Threading logging-client)
-
-asterisk_scf_component_install(Threading LIBRARY lib "Threading" Threading ARCHIVE DESTINATION lib)
-
diff --git a/Threading/src/SimpleWorkQueue.cpp b/Threading/src/SimpleWorkQueue.cpp
index 85766bf..0eb74cb 100644
--- a/Threading/src/SimpleWorkQueue.cpp
+++ b/Threading/src/SimpleWorkQueue.cpp
@@ -80,7 +80,12 @@ public:
mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called for queue " << mQid ;
mFinished = true;
- resume();
+ mPaused = false;
+
+ { // scope for the lock.
+ boost::lock_guard<boost::mutex> lock(mPauseMutex);
+ mPauseCondition.notify_all();
+ }
{ // scope for the lock.
boost::lock_guard<boost::mutex> lock(mQueueMutex);
diff --git a/Threading/src/SimpleWorkQueue.cpp~ b/Threading/src/SimpleWorkQueue.cpp~
deleted file mode 100644
index 943fcf2..0000000
--- a/Threading/src/SimpleWorkQueue.cpp~
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * A simple Work Queue implementation. On construction, starts an internal thread.
- * Work can be enqueued via the thread-safe enqueue() method. All work must implement
- * the Work interface.
- */
-#include <iostream>
-#include <boost/shared_ptr.hpp>
-#include <boost/bind.hpp>
-#include <boost/thread.hpp>
-#include <list>
-
-#include "logger.h"
-
-#include "AsteriskSCF/WorkQueue/SimpleWorkQueue.h"
-
-using namespace AsteriskSCF;
-using namespace AsteriskSCF::System::Logging;
-using namespace boost;
-
-namespace
-{
- /**
- * This is a private no-op implementation of a work item. Returned from WaitAndDequeue
- * if the program is Terminated while waiting on the EmptyQueueCondition.
- */
- class HiddenNoWorkClass : public WorkQueue::Work
- {
- public:
- HiddenNoWorkClass() {};
- void doWork() {} // Do nothing
- };
-}
-
-namespace AsteriskSCF
-{
-class SimpleWorkQueuePriv
-{
-public:
- SimpleWorkQueuePriv(const std::string& id, const Logger& logger)
- : mLogger(logger),
- mQid(id),
- mInitialized(false),
- mFinished(false),
- mPaused(false), // runs by default.
- mThread(boost::bind(&SimpleWorkQueuePriv::execute, this))
-
- {
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mQid;
- }
-
- ~SimpleWorkQueuePriv()
- {
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mQid;
- }
-
- WorkPtr dequeue();
- WorkPtr waitAndDequeue();
- void execute();
- bool isPaused();
-
- const Logger& mLogger;
- std::string mQid;
- bool mInitialized;
- bool mFinished;
- bool mPaused;
- std::list<WorkPtr> mQueue;
- boost::mutex mQueueMutex;
- boost::condition mEmptyQueueCondition;
- boost::mutex mPauseMutex;
- boost::condition mPauseCondition;
- boost::thread mThread; // This variable is last so that the class is fully initialized before the thread executes.
-};
-}
-
-SimpleWorkQueue::SimpleWorkQueue(const std::string& qid, const Logger& logger) : mImpl(new SimpleWorkQueuePriv(qid, logger))
-{
- mImpl->mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mImpl->mQid;
- mImpl->mInitialized = true;
-}
-
-SimpleWorkQueue::~SimpleWorkQueue()
-{
- mImpl->mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mImpl->mQid;
- terminate();
-
- // Wait for worker thread to shut down.
- join();
-}
-
-bool SimpleWorkQueue::isRunning()
-{
- return (mImpl->mInitialized && !mImpl->mPaused && !mImpl->mFinished);
-}
-
-/**
- * Pause the SimpleWorkQueue's thread.
- */
-void SimpleWorkQueue::pause()
-{
- mImpl->mLogger(Info) << BOOST_CURRENT_FUNCTION << ": called for queue " << mImpl->mQid;
-
- boost::lock_guard<boost::mutex> lock(mImpl->mPauseMutex);
- mImpl->mPaused = true;
-}
-
-/**
- * Resume from a Paused state.
- */
-void SimpleWorkQueue::resume()
-{
- mImpl->mLogger(Info) << BOOST_CURRENT_FUNCTION << ": called for queue " << mImpl->mQid;
-
- boost::lock_guard<boost::mutex> lock(mImpl->mPauseMutex);
- mImpl->mPaused = false;
- mImpl->mPauseCondition.notify_all();
-}
-
-/**
- * Stops this thread from executing.
- */
-void SimpleWorkQueue::terminate()
-{
- mImpl->mLogger(Info) << BOOST_CURRENT_FUNCTION << ": called for queue " << mImpl->mQid ;
-
- mImpl->mFinished = true;
- mImpl->mPaused = false;
-
- { // scope for the lock.
- boost::lock_guard<boost::mutex> lock(mImpl->mPauseMutex);
- mImpl->mPauseCondition.notify_all(); // In case the thread was waiting on the PauseCondition.
- }
-
- { // scope for the lock.
- boost::lock_guard<boost::mutex> lock(mImpl->mQueueMutex);
- mImpl->mEmptyQueueCondition.notify_all(); // In case the thread was waiting on an EmptyQueueCondition
- }
-}
-
-/**
- * A convenience method to determine if there is any pending work on the queue.
- */
-bool SimpleWorkQueue::workPending()
-{
- return !mImpl->mQueue.empty();
-}
-
-/**
- * Allows other thread to join to this thread. The caller needs to
- * call this object's Terminate method, or the join will block
- * indefinitely.
- */
-void SimpleWorkQueue::join()
-{
- mImpl->mThread.join();
-}
-
-static WorkQueue::PoolId noOpPoolId;
-
-/**
- * Enqueue an item of work for processing on this queue's thread.
- */
-WorkQueue::PoolId SimpleWorkQueue::enqueue(const WorkPtr& w)
-{
- bool wasEmpty(false);
-
- { // scope for the mutex.
- boost::lock_guard<boost::mutex> lock(mImpl->mQueueMutex);
- wasEmpty = mImpl->mQueue.empty();
- mImpl->mQueue.push_back(w);
-
- if (wasEmpty)
- {
- mImpl->mEmptyQueueCondition.notify_all();
- }
- }
-
- return noOpPoolId;
-}
-
-static shared_ptr<WorkQueue::Work> HiddenNoWorkPtr(new HiddenNoWorkClass());
-
-/**
- * This method returns the next work from the queue. If no work available,
- * this method waits on the EmptyQueueCondition.
- */
-WorkPtr SimpleWorkQueuePriv::waitAndDequeue()
-{
- boost::unique_lock<boost::mutex> lock(mQueueMutex);
-
- while (mQueue.empty())
- {
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Waiting on empty queue. Queue ID:" << mQid;
-
- if (mFinished)
- {
- mLogger(Info) << BOOST_CURRENT_FUNCTION << ": Returning the NO_WORK token. Queue ID:" << mQid;
- return HiddenNoWorkPtr;
- }
-
- mEmptyQueueCondition.wait(lock);
- }
-
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Dequeuing some work. Queue ID:" << mQid;
-
- shared_ptr<WorkQueue::Work> work = mQueue.front();
- mQueue.pop_front();
-
- return work;
-}
-
-bool SimpleWorkQueuePriv::isPaused()
-{
- boost::lock_guard<boost::mutex> lock(mPauseMutex);
- return mPaused;
-}
-
-/**
- * This is the thread's event loop. The thread terminates when this method returns.
- */
-void SimpleWorkQueuePriv::execute()
-{
- while (!mFinished)
- {
- { // scope the lock
- boost::unique_lock<boost::mutex> lock(mPauseMutex);
- while(mPaused)
- {
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Waiting while paused. Queue ID:" << mQid;
-
- mPauseCondition.wait(lock);
- }
-
- if (mFinished) // In case Terminate was called while in PauseCondition
- {
- break;
- }
- } // end lock scope
-
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Pinging the work queue. Queue ID:" << mQid;
-
- WorkPtr work = waitAndDequeue();
-
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Doing the work. Queue ID:" << mQid;
-
- try
- {
- work->doWork();
- }
- catch(const std::exception& e)
- {
- // Workers should be catching/managing their own exceptions!
- mLogger(Warning) << BOOST_CURRENT_FUNCTION << ": Work item threw exception for queue " << mQid;
- mLogger(Warning) << " Details: " << e.what();
- }
-
- } // while !mFinished
-
- mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Exiting the thread for good. Queue ID:" << mQid;
-}
-
-----------------------------------------------------------------------
--
asterisk-scf/integration/util-cpp.git
More information about the asterisk-scf-commits
mailing list