[asterisk-scf-commits] asterisk-scf/release/generic_component.git branch "master" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Aug 17 12:08:44 CDT 2010
branch "master" has been created
at 491ad461476ee6b55696d91029dd1850be245dcf (commit)
- Log -----------------------------------------------------------------
commit 491ad461476ee6b55696d91029dd1850be245dcf
Author: Joshua Colp <jcolp at digium.com>
Date: Tue Aug 17 14:21:06 2010 -0300
Add a generic component template which accesses the service locator to add a service, and also to locate another service.
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..4efe8ad
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,6 @@
+[submodule "cmake"]
+ path = cmake
+ url = git at git.asterisk.org:asterisk-scf/release/cmake
+[submodule "slice"]
+ path = slice
+ url = git at git.asterisk.org:asterisk-scf/integration/slice
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..bef478c
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Generic component build system
+
+# Minimum we require is 2.6, any lower and stuff would fail horribly
+cmake_minimum_required(VERSION 2.6)
+
+# Include common Hydra build infrastructure
+include(cmake/Hydra_v4.cmake)
+
+# This project is C++ based and requires a minimum of 3.4
+hydra_project(generic_component 3.4 CXX)
+
+# Knock out slice definitions
+add_subdirectory(slice EXCLUDE_FROM_ALL)
+
+# Take care of the source code for this project
+add_subdirectory(src)
+
diff --git a/cmake b/cmake
new file mode 160000
index 0000000..6f93993
--- /dev/null
+++ b/cmake
@@ -0,0 +1 @@
+Subproject commit 6f939932a3c35300208434795e42f5edae14e259
diff --git a/slice b/slice
new file mode 160000
index 0000000..0fd4cb3
--- /dev/null
+++ b/slice
@@ -0,0 +1 @@
+Subproject commit 0fd4cb3a22d7a3993ae64ee5e4ee73f9ae97a64d
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..4d6a554
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,6 @@
+hydra_component_init(generic_component CXX)
+hydra_component_add_slice(generic_component ServiceLocatorIf)
+hydra_component_add_slice(generic_component RoutingIf)
+hydra_component_add_file(generic_component GenericComponent.cpp)
+hydra_component_build_standalone(generic_component)
+hydra_component_install(generic_component RUNTIME bin "Generic Component." Core)
diff --git a/src/GenericComponent.cpp b/src/GenericComponent.cpp
new file mode 100644
index 0000000..b1a8297
--- /dev/null
+++ b/src/GenericComponent.cpp
@@ -0,0 +1,91 @@
+/*
+ * TBA -- An open source telephony framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See TBA for more information about
+ * the TBA 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 file
+ * at the top of the source tree.
+ */
+
+#include <Ice/Ice.h>
+
+#include "Core/Discovery/ServiceLocatorIf.h"
+#include "Core/Routing/RoutingIf.h"
+
+using namespace std;
+using namespace Hydra::Core::Discovery::V1;
+using namespace Hydra::Core::Routing::V1;
+
+/**
+ * Implementation of the Ice::Application class
+ */
+class GenericComponentApp : public Ice::Application
+{
+public:
+ int run(int, char*[]);
+ void interruptCallback(int);
+
+private:
+};
+
+/**
+ * Main entry point for our generic component.
+ */
+int main(int argc, char* argv[])
+{
+ GenericComponentApp app;
+ app.callbackOnInterrupt();
+ return app.main(argc, argv);
+}
+
+/**
+ * Overload of the Ice::Application::run method.
+ */
+int GenericComponentApp::run(int argc, char* argv[])
+{
+ /* Get a proxy to the management interface for the service locator, so we can add ourselves */
+ ServiceLocatorManagementPrx management = ServiceLocatorManagementPrx::checkedCast(communicator()->propertyToProxy("ServiceLocatorManagementProxy"));
+
+ /* TODO: Right now this generic component adds a proxy that goes nowhere, you would want to pass in a real proxy */
+ Ice::ObjectPrx dummy_proxy;
+
+ /* Add ourselves as a service to the service locator */
+ ServiceManagementPrx service_management = ServiceManagementPrx::uncheckedCast(management->addService(dummy_proxy, "generic_component"));
+
+ /* Now we can add some parameters to help find us. */
+ ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
+ genericparams->category = "generic_component";
+ service_management->addLocatorParams(genericparams, "");
+
+ /* Get a proxy to the service locator, so we can find stuff. */
+ ServiceLocatorPrx locator = ServiceLocatorPrx::checkedCast(communicator()->propertyToProxy("ServiceLocatorProxy"));
+
+ /* Populate parameters detailing that we want to find a routing locator registry service */
+ ServiceLocatorParamsPtr params = new ServiceLocatorParams();
+ params->category = "routing";
+
+ /* Now using the parameters we can do a locate request and get one */
+ LocatorRegistryPrx registry = LocatorRegistryPrx::uncheckedCast(locator->locate(params));
+
+ /* Wait for something to end us, like Ctrl+C */
+ communicator()->waitForShutdown();
+
+ /* Can't forget to remove ourselves from the service locator so stuff can't find us anymore */
+ service_management->unregister();
+
+ return EXIT_SUCCESS;
+}
+
+void GenericComponentApp::interruptCallback(int val)
+{
+ _exit(EXIT_SUCCESS);
+}
-----------------------------------------------------------------------
--
asterisk-scf/release/generic_component.git
More information about the asterisk-scf-commits
mailing list