[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Sep 10 17:31:45 CDT 2010


branch "master" has been updated
       via  fae0328173486013b91b7ed81d7e5e7f574ae6e3 (commit)
      from  01eef6fe209394a617e6d4c60c7e221f922e746e (commit)

Summary of changes:
 src/CMakeLists.txt         |   13 +++
 src/SipStateReplicator.cpp |  182 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 195 insertions(+), 0 deletions(-)
 create mode 100644 src/SipStateReplicator.cpp


- Log -----------------------------------------------------------------
commit fae0328173486013b91b7ed81d7e5e7f574ae6e3
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Sep 10 16:56:20 2010 -0500

    Add skeleton application for Sip State Replicator.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5c759b6..2fbd687 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -43,4 +43,17 @@ pjproject_link(SipChannelService pjlib)
 
 hydra_component_install(SipChannelService RUNTIME bin "SIP Channel Service" SipChannelService)
 
+hydra_component_init(SipStateReplicator CXX)
 
+hydra_component_add_slice(SipStateReplicator ServiceLocatorIf)
+hydra_component_add_slice(SipStateReplicator ComponentServiceIf)
+hydra_component_add_slice(SipStateReplicator SipIf)
+hydra_component_add_slice(SipStateReplicator SipStateReplicationIf)
+
+hydra_component_add_file(SipStateReplicator SipStateReplicator.cpp)
+
+hydra_component_add_ice_libraries(SipStateReplicator IceStorm)
+
+hydra_component_build_standalone(SipStateReplicator)
+
+hydra_component_install(SipStateReplicator RUNTIME bin "Sip State Replicator" SipStateReplicator)
diff --git a/src/SipStateReplicator.cpp b/src/SipStateReplicator.cpp
new file mode 100644
index 0000000..79f828d
--- /dev/null
+++ b/src/SipStateReplicator.cpp
@@ -0,0 +1,182 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#include <Ice/Ice.h>
+#include <IceStorm/IceStorm.h>
+
+#include "ServiceLocatorIf.h"
+#include "ComponentServiceIf.h"
+#include "SipIf.h"
+#include "SipStateReplicationIf.h"
+
+using namespace std;
+using namespace AsteriskSCF::Core;
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::System::Component::V1;
+
+class SipStateReplicatorApp : public Ice::Application
+{
+public:
+   SipStateReplicatorApp() { };
+   ~SipStateReplicatorApp()
+   {
+      mComponentService = 0;
+	  mAdapter = 0;
+   };
+   virtual int run(int, char *[]);
+   virtual void interruptCallback(int);
+private:
+   void initialize(std::string appName);
+   void registerWithServiceLocator();
+   void deregisterFromServiceLocator();
+   void setCategory(Discovery::V1::ServiceManagementPrx serviceManagement, const string &category);
+   std::string mAppName;
+   //vector<SipStateReplicatorListenerPrx> mListeners;
+   Ice::ObjectAdapterPtr mAdapter;
+   ServiceLocatorManagementPrx mServiceLocatorManagement;
+   Discovery::V1::ServiceManagementPrx mComponentServiceManagement;
+   ComponentServicePtr mComponentService;
+};
+
+static const string ComponentServiceId("SipStateReplicatorComponent");
+
+/**
+ * This class provides implementation for the ComponentService interface, which
+ * every Asterisk SCF component is expected to publish.
+ */
+class ComponentServiceImpl : public ComponentService
+{
+public:
+   ComponentServiceImpl(SipStateReplicatorApp &app) : mApp(app) {}
+
+public: // Overrides of the ComponentService interface.
+   virtual void suspend(const ::Ice::Current& = ::Ice::Current())
+   {
+     // TBD
+   }
+
+   virtual void resume(const ::Ice::Current& = ::Ice::Current())
+   {
+      // TBD
+   }
+
+   virtual void shutdown(const ::Ice::Current& = ::Ice::Current())
+   {
+      // TBD
+   }
+
+private:
+   SipStateReplicatorApp& mApp;
+};
+
+/**
+ * Handles control characters in case the component is invoked as a console app.
+ */
+void SipStateReplicatorApp::interruptCallback(int val)
+{
+   cout << "Exiting..." << endl;
+   // Should probably do more to gracefully exit.
+   _exit(EXIT_SUCCESS);
+}
+
+/**
+ * Helper function to add some parameters to one of our registered interfaces in the ServiceLocator, so that
+ * other components can look up our interfaces.
+ */
+void SipStateReplicatorApp::setCategory(Discovery::V1::ServiceManagementPrx serviceManagement, const string &category)
+{
+   // Add category as a parameter to enable other components look this component up.
+   ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
+   genericparams->category = category;
+   serviceManagement->addLocatorParams(genericparams, "");
+}
+/**
+ * Register this component's primary public interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate our interfaces.
+ */
+void SipStateReplicatorApp::registerWithServiceLocator()
+{
+   try
+   {
+      // Get a proxy to the management interface for the Service Locator, so we can add ourselves into the system discovery mechanisms.
+	   mServiceLocatorManagement = ServiceLocatorManagementPrx::checkedCast(communicator()->propertyToProxy("LocatorServiceManagement.Proxy"));
+
+      if (mServiceLocatorManagement == 0)
+      {
+	 cout << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected." << endl;
+	 return;
+      }
+
+      // Get a proxy to our ComponentService interface and add it to the Service Locator.
+      Ice::ObjectPrx componentServiceObjectPrx = mAdapter->createDirectProxy(communicator()->stringToIdentity(ComponentServiceId));
+      ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
+
+      // The GUID passed in to add service needs to be unique for reporting.
+      string componentServiceGuid("SipStateReplicator");
+      mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
+
+	  //XXX Is it a problem that we use the same category as the SipChannelServiceApp here?
+      setCategory(mComponentServiceManagement, AsteriskSCF::SIP::V1::ComponentServiceDiscoveryCategory);
+
+      // TBD... We may have other interfaces to publish to the Service Locator.
+   }
+   catch(...)
+   {
+      cout << "Exception in " << mAppName << " registerWithServiceLocator()" << endl;
+   }
+}
+
+/**
+ * Deregister this component's primary public interfaces from the Service Locator.
+ * This is done at shutdown, and whenever we want to keep other services from locating
+ * our interfaces.
+ */
+void SipStateReplicatorApp::deregisterFromServiceLocator()
+{
+   try
+   {
+      mComponentServiceManagement->unregister();
+   }
+   catch(...)
+   {
+      cout << "Had trouble in deregisterFromServiceLocator()." << endl;
+   }
+}
+
+void SipStateReplicatorApp::initialize(const std::string appName)
+{
+   mAppName = appName;
+   // Create and publish our ComponentService interface support.
+   mComponentService = new ComponentServiceImpl(*this);
+   mAdapter->add(mComponentService, communicator()->stringToIdentity(ComponentServiceId));
+
+   mAdapter->activate();
+}
+
+int SipStateReplicatorApp::run(int argc, char *argv[])
+{
+   initialize(argv[0]);
+   // Plug into the Asterisk SCF discovery system so that the interfaces we provide
+   // can be located.
+   registerWithServiceLocator();
+
+   // Run until it's time to run no more.
+   communicator()->waitForShutdown();
+
+   // Remove our interfaces from the service locator.
+   deregisterFromServiceLocator();
+
+   return EXIT_SUCCESS;
+}
+
+int main(int argc, char *argv[])
+{
+   SipStateReplicatorApp app;
+   app.callbackOnInterrupt();
+   return app.main(argc, argv);
+}

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list