[asterisk-scf-commits] asterisk-scf/release/ice-util-cpp.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Jan 5 10:11:55 CST 2012


branch "master" has been updated
       via  2caccb8646c9ffac4ce4851e8842c8f45582d1e5 (commit)
      from  cd330e8a7fd8520dba57d6b6f6707c5283de0c6e (commit)

Summary of changes:
 .../{NAT/Candidates.h => WorkQueue/Dispatched.h}   |   38 +++++++---
 test/WorkQueue/TestWorkQueue.cpp                   |   74 ++++++++++++++++++++
 2 files changed, 100 insertions(+), 12 deletions(-)
 copy include/AsteriskSCF/{NAT/Candidates.h => WorkQueue/Dispatched.h} (51%)


- Log -----------------------------------------------------------------
commit 2caccb8646c9ffac4ce4851e8842c8f45582d1e5
Author: Joshua Colp <jcolp at digium.com>
Date:   Thu Jan 5 11:13:14 2012 -0400

    Add helper class for marking an item as destroyed and retrieving the destruction status. (issue ASTSCF-290)

diff --git a/include/AsteriskSCF/WorkQueue/Dispatched.h b/include/AsteriskSCF/WorkQueue/Dispatched.h
new file mode 100644
index 0000000..b69bcf8
--- /dev/null
+++ b/include/AsteriskSCF/WorkQueue/Dispatched.h
@@ -0,0 +1,49 @@
+/*
+ * 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 <boost/interprocess/detail/atomic.hpp>
+
+namespace AsteriskSCF
+{
+namespace WorkQueue
+{
+
+class ASTSCF_DLL_EXPORT Dispatched
+{
+public:
+    Dispatched() : mDestroyed(0) { }
+
+    void setDestroyed() { boost::interprocess::detail::atomic_inc32(&mDestroyed); }
+
+    bool isDestroyed()
+    {
+        if (boost::interprocess::detail::atomic_read32(&mDestroyed) > 0)
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+private:
+    unsigned int mDestroyed;
+};
+
+}; //end namespace WorkQueue
+}; //end namespace AsteriskSCF
diff --git a/test/WorkQueue/TestWorkQueue.cpp b/test/WorkQueue/TestWorkQueue.cpp
index 099445f..b7d77ef 100644
--- a/test/WorkQueue/TestWorkQueue.cpp
+++ b/test/WorkQueue/TestWorkQueue.cpp
@@ -19,6 +19,7 @@
 
 #include <AsteriskSCF/WorkQueue/WorkQueue.h>
 #include <AsteriskSCF/WorkQueue/DefaultQueueListener.h>
+#include <AsteriskSCF/WorkQueue/Dispatched.h>
 
 using namespace AsteriskSCF::System::WorkQueue::V1;
 using namespace AsteriskSCF::WorkQueue;
@@ -75,6 +76,34 @@ public:
 
 typedef IceUtil::Handle<Task> TaskPtr;
 
+class RandomObject : public IceUtil::Shared, public Dispatched
+{
+};
+
+typedef IceUtil::Handle<RandomObject> RandomObjectPtr;
+
+class DispatchedTask : public Work
+{
+public:
+    DispatchedTask(const RandomObjectPtr& object) : mObject(object), taskExecuted(false), taskAborted(false) { }
+    void execute()
+    {
+        if (mObject->isDestroyed())
+        {
+            taskAborted = true;
+        }
+        else
+        {
+            taskExecuted = true;
+        }
+    }
+    RandomObjectPtr mObject;
+    bool taskExecuted;
+    bool taskAborted;
+};
+
+typedef IceUtil::Handle<DispatchedTask> DispatchedTaskPtr;
+
 class ThreadHook : public Ice::ThreadNotification
 {
 public:
@@ -353,6 +382,51 @@ BOOST_AUTO_TEST_CASE(executeNonExistent)
     BOOST_CHECK(listener->shutdownNotice == true);
 }
 
+BOOST_AUTO_TEST_CASE(dispatchedWorkExecution)
+{
+    TestListenerPtr listener(new TestListener);
+    QueuePtr queue(new WorkQueue(listener));
+    RandomObjectPtr randomObject(new RandomObject());
+    DispatchedTaskPtr work(new DispatchedTask(randomObject));
+
+    queue->enqueueWork(work);
+    bool moreWork = queue->executeWork();
+
+    BOOST_CHECK(moreWork == false);
+    BOOST_CHECK(work->taskExecuted == true);
+    BOOST_CHECK(work->taskAborted == false);
+    BOOST_CHECK(listener->emptyNotice == true);
+    BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutdown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
+}
+
+BOOST_AUTO_TEST_CASE(dispatchedWorkAbortion)
+{
+    TestListenerPtr listener(new TestListener);
+    QueuePtr queue(new WorkQueue(listener));
+    RandomObjectPtr randomObject(new RandomObject());
+    DispatchedTaskPtr work(new DispatchedTask(randomObject));
+
+    queue->enqueueWork(work);
+
+    randomObject->setDestroyed();
+
+    bool moreWork = queue->executeWork();
+
+    BOOST_CHECK(moreWork == false);
+    BOOST_CHECK(work->taskExecuted == false);
+    BOOST_CHECK(work->taskAborted == true);
+    BOOST_CHECK(listener->emptyNotice == true);
+    BOOST_CHECK(queue->getSize() == 0);
+
+    queue->shutdown();
+
+    BOOST_CHECK(listener->shutdownNotice == true);
+}
+
 BOOST_AUTO_TEST_CASE(executionOrder1)
 {
     TestListenerPtr listener(new TestListener);

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


-- 
asterisk-scf/release/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list