[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
Mon May 23 16:08:47 CDT 2011


branch "master" has been updated
       via  c857c099bf0825ee10e637b0ba5a6860ba0289d2 (commit)
      from  f7cba542d05950d203efac40d3e96bcd1ba51734 (commit)

Summary of changes:
 .../CollocatedIceStorm/CollocatedIceStorm.h        |   57 +++++++++++++
 src/CMakeLists.txt                                 |    2 +
 src/CollocatedIceStorm/CollocatedIceStorm.cpp      |   88 ++++++++++++++++++++
 3 files changed, 147 insertions(+), 0 deletions(-)
 create mode 100644 include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h
 create mode 100644 src/CollocatedIceStorm/CollocatedIceStorm.cpp


- Log -----------------------------------------------------------------
commit c857c099bf0825ee10e637b0ba5a6860ba0289d2
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue May 17 10:20:02 2011 -0300

    Make the collocated icestorm available to all.

diff --git a/include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h b/include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h
new file mode 100644
index 0000000..f135838
--- /dev/null
+++ b/include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+#pragma once
+
+#include <IceUtil/DynamicLibrary.h>
+#include <Ice/Service.h>
+#include <IceBox/IceBox.h>
+#include <Ice/Ice.h>
+#include <IceStorm/IceStorm.h>
+#include <string>
+
+namespace AsteriskSCF
+{
+namespace CollocatedIceStorm
+{
+
+/**
+ * A helper class that instantiates IceStorm in-process, removing the need to launch
+ * a separate process to access IceStorm services.
+ */
+
+class CollocatedIceStorm : public IceUtil::Shared
+{
+public:
+    CollocatedIceStorm(const std::string&, const Ice::PropertiesPtr&);
+    ~CollocatedIceStorm();
+
+    /**
+     * "nice" applications should explictly call stop !
+     */
+    void stop();
+
+private:
+    IceUtilInternal::DynamicLibraryPtr mLibrary;
+    IceBox::ServicePtr mService;
+    Ice::CommunicatorPtr mCommunicator;
+    bool mStopped;
+};
+
+typedef IceUtil::Handle<CollocatedIceStorm> CollocatedIceStormPtr;
+
+} /* end of CollocatedIceStorm */
+} /* end of AsteriskSCF */
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6bd28d1..79698d6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -32,6 +32,8 @@ asterisk_scf_component_add_file(ice-util-cpp ../include/AsteriskSCF/ThreadPool/T
 asterisk_scf_component_add_file(ice-util-cpp ../include/AsteriskSCF/ThreadPool/WorkerThread.h)
 asterisk_scf_component_add_file(ice-util-cpp ThreadPool/ThreadPool.cpp)
 asterisk_scf_component_add_file(ice-util-cpp ThreadPool/WorkerThread.cpp)
+asterisk_scf_component_add_file(ice-util-cpp ../include/AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h)
+asterisk_scf_component_add_file(ice-util-cpp CollocatedIceStorm/CollocatedIceStorm.cpp)
 
 #
 # Note, strictly speaking this isn't for component development, but as it is part of this
diff --git a/src/CollocatedIceStorm/CollocatedIceStorm.cpp b/src/CollocatedIceStorm/CollocatedIceStorm.cpp
new file mode 100644
index 0000000..8903918
--- /dev/null
+++ b/src/CollocatedIceStorm/CollocatedIceStorm.cpp
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+#include <Ice/Ice.h>
+#include <IceStorm/IceStorm.h>
+#include <assert.h>
+#include <algorithm>
+
+#include <AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h>
+
+using namespace AsteriskSCF::CollocatedIceStorm;
+
+//
+// The idea behind this class is that it needs to access the entry point that IceBox would
+// have used and then invoke the methods that are needed to start and stop the IceStorm
+// service.
+//
+typedef IceBox::Service* (*FACTORY)(Ice::CommunicatorPtr);
+
+CollocatedIceStorm::CollocatedIceStorm(const std::string& namePrefix, const Ice::PropertiesPtr& properties) :
+    mStopped(false)
+{
+    //
+    // We create our own communicator to avoid issues with call order on shutdown.
+    //
+    Ice::InitializationData initData;
+    initData.properties = properties;
+    mCommunicator = Ice::initialize(initData);
+
+    std::string loadString = mCommunicator->getProperties()->getPropertyWithDefault("IceStorm.EntryPoint", "IceStormService:createIceStorm");
+
+    mLibrary = new IceUtilInternal::DynamicLibrary;
+    IceUtilInternal::DynamicLibrary::symbol_type entry = mLibrary->loadEntryPoint(loadString);
+    if(entry == 0)
+    {
+        throw mLibrary->getErrorMessage();
+    }
+    FACTORY factory = (FACTORY)entry;
+    mService = factory(mCommunicator);
+    assert(mService != 0);
+    Ice::StringSeq options;
+    mService->start(namePrefix, mCommunicator, options);
+}
+
+CollocatedIceStorm::~CollocatedIceStorm()
+{
+    if(!mStopped)
+    {
+        try
+        {
+            stop();
+            mCommunicator->destroy();
+        }
+        catch(...)
+        {
+        }
+    }
+}
+
+void CollocatedIceStorm::stop()
+{
+    //
+    // NOTE: there isn't any mutex protection here. It can be added later if needed, but at the moment multiple threads
+    // do not have access to this object instance.
+    //
+    if(!mStopped)
+    {
+        if(mService)
+        {
+            mService->stop();
+        }
+        mCommunicator->shutdown();
+        mCommunicator->waitForShutdown();
+        mStopped = true;
+    }
+}

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


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



More information about the asterisk-scf-commits mailing list