[asterisk-scf-commits] asterisk-scf/integration/file_session_gateway.git branch "first_crack_for_review" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Dec 2 14:25:31 CST 2011
branch "first_crack_for_review" has been created
at 60eac847e0f64d000381357c0572d69810f01d8b (commit)
- Log -----------------------------------------------------------------
commit 60eac847e0f64d000381357c0572d69810f01d8b
Author: Brent Eagles <beagles at digium.com>
Date: Fri Dec 2 16:49:41 2011 -0330
Initial crack at file session gateway. Squashes commits from
initial_development to make it a bit easier to review. Revisions will
proceed from here.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8002327..f07ab19 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,12 @@
astscf_project(FileSessionGateway 3.4)
+add_subdirectory(slice)
add_subdirectory(src)
-if(BUILD_TESTING)
- add_subdirectory(test)
-endif()
+add_subdirectory(test)
+
+#
+#(BUILD_TESTING)
+#
+# add_subdirectory(test)
+#endif()
astscf_slice_collection_install(PROJECT)
diff --git a/TODO.txt b/TODO.txt
new file mode 100644
index 0000000..ad04d36
--- /dev/null
+++ b/TODO.txt
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+For tests, see test/TODO.txt
+
+- Analog of connect line info for sessions
+
+- Active components need to populate their replication listener so that
+ a switch to standby has them at close to the same state as any other
+ replica.
diff --git a/config/FileSessionGateway.config b/config/FileSessionGateway.config
index a72191a..b48c334 100755
--- a/config/FileSessionGateway.config
+++ b/config/FileSessionGateway.config
@@ -2,5 +2,46 @@
# A sample configuration file for the FileSessionGateway
#
+#
+# General configuration group is used to set component wide configurable properties.
+#
[general]
-endpoint-locator-id=basic.filesession.gtw
\ No newline at end of file
+routing_service=default
+media_service=default
+
+##
+## Anatomy of an endpoint specification.
+##
+## The name of the endpoint is derived from the section name.
+# [endpoint-name]
+#
+## The following line is required by the configuration script so that it
+## recognizes this as an endpoint configuration
+# type=endpoint
+#
+## supported_operations describes whether the endpoint is meant to support
+## recording, playback or both. The valid values are: recording, playback, both
+#
+# supported_operations=playback
+#
+## media_id is a string that specifies the catalog id for media, this
+## is a string that is used when querying the file media service for a
+## media session. Multiple endpoints may contain the same media_id. Valid
+## values are deployment dependent.
+#
+# media_id=X13A4AB.ADDA.AF
+#
+## destination is a string that is published by the file session
+## gateway as the number/destination for this endpoint. Once
+## registered with an endpoint locator, calls routed to this value
+## should result in a session being created on the endpoint.
+#
+# destination=1234
+#
+# e.g.:
+
+[hello_world]
+type=endpoint
+supported_operations=playback
+media_id=helloWorld
+destination=7777
\ No newline at end of file
diff --git a/config/FileSessionGatewayConfigurator.py b/config/FileSessionGatewayConfigurator.py
new file mode 100755
index 0000000..766cce8
--- /dev/null
+++ b/config/FileSessionGatewayConfigurator.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+
+#
+# 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.
+#
+
+# FileSessionGateway configurator
+
+# Bring in the common configuration infrastructure
+import ConfigParser, Ice, Configurator, sys, os, traceback
+
+# Load our component specific configuration definitions
+Ice.loadSlice("--underscore -I\"" + os.environ["ASTSCF_HOME"] + "\"" + " -I" + Ice.getSliceDir() + " --all ../slice/AsteriskSCF/Configuration/FileSessionGateway/FileSessionGatewayConfigurationIf.ice")
+import AsteriskSCF.Configuration.FileSessionGateway.V1
+
+# Add our own visitor implementations for the sections we support
+class SectionVisitors(Configurator.SectionVisitors):
+
+ def visit_general_group(self, config, section):
+ group = AsteriskSCF.Configuration.FileSessionGateway.V1.GeneralGroup()
+ group.configurationItems = { }
+
+ mapper = Configurator.OptionMapper()
+ item = AsteriskSCF.Configuration.FileSessionGateway.V1.RoutingService()
+ mapper.map('routing_service', item, 'serviceName',
+ AsteriskSCF.Configuration.FileSessionGateway.V1.RoutingServiceItem, config.get, "default")
+ item = AsteriskSCF.Configuration.FileSessionGateway.V1.FileMediaService()
+ mapper.map('media_service', item, 'serviceName',
+ AsteriskSCF.Configuration.FileSessionGateway.V1.FileMediaServiceItem(), config.get, "default");
+ for option in config.options(section):
+ mapper.execute(group, section, option)
+ mapper.finish()
+ self.groups.append(group)
+
+ def visit_endpoint_group(self, config, section):
+ #
+ # setup endpoint group.
+ #
+ group = AsteriskSCF.Configuration.FileSessionGateway.V1.EndpointGroup()
+ group.name = section
+ group.configurationItems = { }
+
+ #
+ # process config.
+ #
+ class FileOperationTransformer():
+ def __init__(self, config):
+ self.config = config
+
+ def get(self, section, item):
+ if (self.config.get(section, item) == 'playback'):
+ return AsteriskSCF.Media.File.V1.FileOperations.Playback
+ if (self.config.get(section, item) == 'recording'):
+ return AsteriskSCF.Media.File.V1.FileOperations.Recording
+ if (self.config.get(section, item) == 'both'):
+ return AsteriskSCF.Media.File.V1.FileOperations.Both
+
+ mapper = Configurator.OptionMapper()
+ item = AsteriskSCF.Configuration.FileSessionGateway.V1.EndpointDestinationName()
+ mapper.map('destination', item, 'destination',
+ AsteriskSCF.Configuration.FileSessionGateway.V1.EndpointDestinationItem, config.get, None)
+ item = AsteriskSCF.Configuration.FileSessionGateway.V1.MediaFile()
+ mapper.map('media_id', item, 'id',
+ AsteriskSCF.Configuration.FileSessionGateway.V1.EndpointMediaFileItem, config.get, None)
+ fileOpTransformer = FileOperationTransformer(config)
+ mapper.map('supported_operations', item, 'operations',
+ AsteriskSCF.Configuration.FileSessionGateway.V1.EndpointMediaFileItem, fileOpTransformer.get,
+ AsteriskSCF.Media.File.V1.FileOperations.Playback)
+ for option in config.options(section):
+ mapper.execute(group, section, option)
+ mapper.finish(group)
+ self.groups.append(group)
+
+ def visit_unsupported(self, config, section):
+ if config.get(section, 'type') == 'endpoint':
+ self.visit_endpoint_group(config, section)
+
+# In order to do service locator based lookup we need to pass in a params object
+serviceLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
+serviceLocatorParams.category = AsteriskSCF.Configuration.SipSessionManager.V1.ConfigurationDiscoveryCategory
+serviceLocatorParams.service = 'default'
+
+# Make a configurator application and let it run
+app = Configurator.ConfiguratorApp('FileSessionGateway.config', SectionVisitors(), None, serviceLocatorParams)
+sys.exit(app.main(sys.argv))
diff --git a/config/FileSessionGatewayTest.conf b/config/FileSessionGatewayTest.conf
new file mode 100644
index 0000000..a193178
--- /dev/null
+++ b/config/FileSessionGatewayTest.conf
@@ -0,0 +1,6 @@
+#
+# Configuration file for the FileSessionGatewaySessionTest test driver.
+#
+
+LocatorService.Proxy=LocatorService:tcp -p 4411
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
diff --git a/config/file_session_gateway.icebox b/config/file_session_gateway.icebox
index 63b2ea0..8f926b8 100755
--- a/config/file_session_gateway.icebox
+++ b/config/file_session_gateway.icebox
@@ -2,17 +2,63 @@
# IceBox service configuration file for the file session gateway.
#
-#
-# URN format: category:service[:id[:specific params]]
-#
-# Specify the search criteria for locating the file media service.
-#
-DefaultFileMediaService=astscf:filemedia:defaultfilemedia
-
+# All services loaded by this configuration file should also load these
+# properties.
Ice.InheritProperties=1
+
+#
+# Standard defaults.
+#
LocatorService.Proxy=LocatorService:default -p 4411
LocatorServiceManagement.Proxy=LocatorServiceManagement:default -p 4422
Ice.ThreadPool.Client.Size=4
+Ice.ThreadPool.Server.Size=4
+
+#
+# Load the gateway.
+#
IceBox.Service.FileSessionGateway=FileSessionGateway:create
+FileSessionGateway.ServiceAdapter.Endpoints=default -p 5121
+FileSessionGateway.ServiceAdapter.ThreadPool.Size=5
+FileSessionGateway.BackplaneAdapter.Endpoints=default -p 5122
+FileSessionGateway.BackplaneAdapter.ThreadPool.Size=4
+
+#
+# FileSessionGateway configuration properties.
+#
+
+# RoutingDestinationId :
+#
+# Set the string that the Endpoint locator will use to register itself with
+# the locator registry. While this defaults to 'component name'.fileSessionGateway,
+# where component name is derived from how the component's IceBox service
+# is configured, it is advisable to set a non-default value to prevent
+# trivial un-related changes to configuration from upsetting the validitiy
+# of as system, particularly in systems involving replication.
+#
+# FileSessionGateway.RoutingDestinationId=[string value]
+
+
+#
+# LocatorRegistry.SetupRetryInterval:
+#
+# Controls the retry period interval for registering an endpoint locator
+# with the locator registry. The value is in milliseconds and the default
+# value is 5000ms (5 seconds). This value affects the startup interaction
+# with another component, in effect altering how "nice" the service handles
+# out of order component startup. The syntax is 'component
+# name'.LocatorRegistry.SetupRetryInterval.
+#
+# FileSessionGateway.LocatorRegistry.SetupRetryInterval=[positive integer value, milliseconds]
+
+#
+# LocatorRegistry.UpdateRetryInterval
+#
+# Similar to SetupRetryInterval, this millisecond retry period
+# configures how long the component waits between attempts to update
+# the locator registry with changes to the configured endpoints.
+#
+
+
diff --git a/config/test_file_session_gateway.icebox b/config/test_file_session_gateway.icebox
new file mode 100644
index 0000000..fbdf501
--- /dev/null
+++ b/config/test_file_session_gateway.icebox
@@ -0,0 +1,86 @@
+#
+# IceBox service configuration file for the file session gateway.
+#
+
+# All services loaded by this configuration file should also load these
+# properties.
+IceBox.InheritProperties=1
+
+#
+# Some APIs are generated as AMD and some internal calls may use AMI, both
+# of which will fail if collocation optimization is used. Turn it off.
+#
+Ice.Default.CollocationOptimized=0
+
+#
+# Standard defaults.
+#
+LocatorService.Proxy=LocatorService:default -p 4411
+LocatorServiceManagement.Proxy=LocatorServiceManagement:default -p 4422
+Ice.ThreadPool.Client.Size=4
+Ice.ThreadPool.Server.Size=4
+
+LoggerAdapter.Endpoints=default
+Logger.ServiceAdapter.Endpoints=default
+AsteriskSCF.LoggingService.Endpoints=default
+AsteriskSCF.LoggingService.ThreadPool.Size=4
+AsteriskSCF.LoggingClient.Endpoints=default
+AsteriskSCF.LoggingClient.ThreadPool.Size=4
+
+ServiceDiscovery.IceStorm.TopicManager.Endpoints=default -p 4421
+ServiceDiscovery.IceStorm.TopicManager.ThreadPool.Size=4
+ServiceDiscovery.IceStorm.InstanceName=ServiceDiscovery
+ServiceDiscovery.IceStorm.Publish.Endpoints=tcp -p 10001:udp -p 10001
+ServiceDiscovery.IceStorm.Publish.ThreadPool.Size=4
+ServiceDiscovery.IceStorm.Transient=1
+ServiceDiscovery.IceStorm.Trace.TopicManager=0
+ServiceDiscovery.IceStorm.Flush.Timeout=2000
+TopicManager.Proxy=ServiceDiscovery/TopicManager:default -p 4421
+
+ServiceDiscovery.BackplaneAdapter.Endpoints=default -p 4410
+ServiceDiscovery.BackplaneAdapter.ThreadPool.Size=4
+ServiceDiscovery.Locator.ServiceAdapter.Endpoints=default -p 4411
+ServiceDiscovery.Locator.ServiceAdapter.ThreadPool.Size=4
+ServiceDiscovery.Management.ServiceAdapter.Endpoints=default -p 4422
+ServiceDiscovery.Management.ServiceAdapter.ThreadPool.Size=4
+
+BridgeService.BridgeManagerObjectId=TestBridge
+BridgeService.Standalone=true
+BridgeService.ServiceAdapter.Endpoints=default -p 5701
+BridgeService.ServiceAdapter.ThreadPool.Size=4
+BridgeService.BackplaneAdapter.Endpoints=default -p 5702
+BridgeService.BackplaneAdapter.ThreadPool.Size=4
+
+RoutingService.ServiceAdapter.Endpoints=default -p 5750
+RoutingService.ServiceAdapter.ThreadPool.Size=4
+RoutingService.Standalone=true
+RoutingService.BackplaneAdapter.Endpoints=default -p 5751
+
+FileSessionGateway.ServiceAdapter.Endpoints=default -p 5851
+FileSessionGateway.ServiceAdapter.ThreadPool.Size=4
+FileSessionGateway.BackplaneAdapter.Endpoints=default -p 5852
+FileSessionGateway.BackplaneAdapter.ThreadPool.Size=4
+FileSessionGateway.Standalone=true
+
+#
+# Load the ancillary componnents
+#
+IceBox.Service.Logger=logging-service:createLoggingService
+IceBox.Service.Replicator=FileSessionReplicator:create
+IceBox.Service.RoutingService=BasicRoutingService:create
+IceBox.Service.BridgeService=bridgeservice:create
+IceBox.Service.ServiceDiscovery=service_locator:create
+
+#
+# Load the gateway and the tester.
+#
+IceBox.Service.FileSessionGateway=FileSessionGateway:create
+IceBox.Service.GatewayTester=FileSessionGatewayTest:create
+
+IceBox.LoadOrder=ServiceDiscovery Logger RoutingService Replicator FileSessionGateway GatewayTester
+
+IceBox.ServiceManager.Endpoints=default -p 56000
+IceBox.ServiceManager.ThreadPool.Size=4
+IceBoxMgr.Proxy=IceBox/ServiceManager:default -p 56000
+
+Test.MediaServiceName=testFileMedia
diff --git a/slice/AsteriskSCF/Configuration/FileSessionGateway/.FileSessionGatewayConfigurationIf.ice.swp b/slice/AsteriskSCF/Configuration/FileSessionGateway/.FileSessionGatewayConfigurationIf.ice.swp
new file mode 100644
index 0000000..b416602
Binary files /dev/null and b/slice/AsteriskSCF/Configuration/FileSessionGateway/.FileSessionGatewayConfigurationIf.ice.swp differ
diff --git a/slice/AsteriskSCF/Configuration/FileSessionGateway/FileSessionGatewayConfigurationIf.ice b/slice/AsteriskSCF/Configuration/FileSessionGateway/FileSessionGatewayConfigurationIf.ice
new file mode 100644
index 0000000..47a8809
--- /dev/null
+++ b/slice/AsteriskSCF/Configuration/FileSessionGateway/FileSessionGatewayConfigurationIf.ice
@@ -0,0 +1,145 @@
+/*
+ * 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 <Ice/BuiltinSequences.ice>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice>
+#include <AsteriskSCF/System/Component/ConfigurationIf.ice>
+#include <AsteriskSCF/Media/File/FileMediaIf.ice>
+
+module AsteriskSCF
+{
+
+module Configuration
+{
+
+module FileSessionGateway
+{
+
+["suppress"]
+module V1
+{
+
+/**
+ * Service locator category for finding the configuration service
+ */
+const string ConfigurationDiscoveryCategory = "FileSessionGatewayConfiguration";
+
+/**
+ * Local visitor class for visiting configuration groups
+ */
+local class ConfigurationGroupVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationGroupVisitor
+{
+};
+
+/**
+ * Generic configuration group
+ */
+["visitor:ConfigurationGroupVisitor"] class ConfigurationGroup extends AsteriskSCF::System::Configuration::V1::ConfigurationGroup
+{
+};
+
+/**
+ * General configuration group that contains general items related to the component as a whole
+ */
+class GeneralGroup extends ConfigurationGroup
+{
+};
+
+/**
+ * Local visitor class for visiting configuration items
+ */
+local class ConfigurationItemVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationItemVisitor
+{
+};
+
+/**
+ * Generic configuration item
+ */
+["visitor:ConfigurationItemVisitor"] class ConfigurationItem extends AsteriskSCF::System::Configuration::V1::ConfigurationItem
+{
+};
+
+/**
+ * Routing service configuration item
+ */
+const string RoutingServiceItem = "routingService";
+class RoutingService extends ConfigurationItem
+{
+ /**
+ * Name of the routing service to use
+ */
+ string serviceName;
+};
+
+/**
+ * RTP Media service configuration item
+ */
+const string FileMediaServiceItem = "fileMediaServiceName";
+class FileMediaService extends ConfigurationItem
+{
+ /**
+ * Name of the File media service to use
+ */
+ string serviceName;
+};
+
+/**
+ * Endpoint group, used to configure an endpoint
+ */
+class EndpointGroup extends ConfigurationGroup
+{
+ string name;
+};
+
+/**
+ *
+ * Destination string for the endpoint.
+ *
+ */
+const string EndpointDestinationItem = "endpointDestination";
+class EndpointDestinationName extends ConfigurationItem
+{
+ string value;
+};
+
+/**
+ *
+ * Media file specification for the endpoint's media file.
+ *
+ **/
+const string EndpointMediaFileItem = "endpointMediaFile";
+class MediaFile extends ConfigurationItem
+{
+ /**
+ * Identifier for the file media.
+ */
+ string id;
+
+ /**
+ * Operations that it is supposed to support.
+ **/
+ AsteriskSCF::Media::File::V1::FileOperations operations =
+ AsteriskSCF::Media::File::V1::Playback;
+};
+}; /* module V1 */
+
+}; /* module FileSessionGateway */
+
+}; /* module Configuration */
+
+}; /* module AsteriskSCF */
diff --git a/slice/AsteriskSCF/SessionCommunications/FileSession/FileSessionGatewayIf.ice b/slice/AsteriskSCF/FileSessionGateway/FileSessionGatewayIf.ice
similarity index 65%
rename from slice/AsteriskSCF/SessionCommunications/FileSession/FileSessionGatewayIf.ice
rename to slice/AsteriskSCF/FileSessionGateway/FileSessionGatewayIf.ice
index 82fbd2e..94f0531 100755
--- a/slice/AsteriskSCF/SessionCommunications/FileSession/FileSessionGatewayIf.ice
+++ b/slice/AsteriskSCF/FileSessionGateway/FileSessionGatewayIf.ice
@@ -18,21 +18,14 @@
module AsteriskSCF
{
-module SessionCommunications
-{
-module FileSession
+module FileSessionGateway
{
module V1
{
+
+const string ComponentServiceDiscoveryCategory = "FileSessionGateway";
+const string EndpointLocatorDiscoveryCategory = "FileSessionGateway.EndpointLocator";
-interface FileSessionEndpoint
-{
- /** XXX
- can't think of any additional methods at the moment.
- */
-};
-
-} /* end of module V1 */
-} /* end of module FileSession */
-} /* end of module SessionCommunications */
-} /* end of module AsteriskSCF */
\ No newline at end of file
+}; /* end of module V1 */
+}; /* end of module FileSessionGatway */
+}; /* end of module AsteriskSCF */
diff --git a/slice/AsteriskSCF/Replication/FileSessionGateway/FileSessionReplicationIf.ice b/slice/AsteriskSCF/Replication/FileSessionGateway/FileSessionReplicationIf.ice
new file mode 100644
index 0000000..bb38551
--- /dev/null
+++ b/slice/AsteriskSCF/Replication/FileSessionGateway/FileSessionReplicationIf.ice
@@ -0,0 +1,147 @@
+/*
+ * 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 <Ice/BuiltinSequences.ice>
+#include <Ice/Identity.ice>
+#include <AsteriskSCF/Media/MediaIf.ice>
+#include <AsteriskSCF/Media/File/FileMediaIf.ice>
+#include <AsteriskSCF/Media/RTP/MediaRTPIf.ice>
+#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.ice>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice>
+#include <AsteriskSCF/System/Component/ConfigurationIf.ice>
+
+module AsteriskSCF
+{
+
+module Replication
+{
+
+module FileSessionGateway
+{
+
+["suppress"]
+module V1
+{
+
+const string StateReplicatorComponentCategory = "FileSessionReplicatorComponent";
+const string StateReplicatorDiscoveryCategory = "FileSessionReplicator";
+
+class StateItem
+{
+ string key;
+};
+
+sequence<StateItem> StateItemSeq;
+
+interface StateReplicatorListener
+{
+ void stateRemoved(Ice::StringSeq itemKeys);
+ void stateRemovedForItems(StateItemSeq items);
+ void stateSet(StateItemSeq items);
+};
+
+interface StateReplicator
+{
+ void addListener(StateReplicatorListener *listener);
+ void removeListener(StateReplicatorListener *listener);
+ void setState (StateItemSeq items);
+ void removeState(Ice::StringSeq items);
+ void removeStateForItems(StateItemSeq items);
+ idempotent StateItemSeq getState(Ice::StringSeq iteKeys);
+ idempotent StateItemSeq getAllState();
+};
+
+sequence<AsteriskSCF::Media::File::V1::FileSession*> MediaSessionSeq;
+
+class SessionDefinitionState extends StateItem
+{
+ string endpointName;
+ string endpointItemKey;
+ string sessionId;
+ Ice::Identity sessionObjectId;
+ AsteriskSCF::SessionCommunications::V1::Session* publishedProxy;
+};
+
+class SessionState extends StateItem
+{
+ string endpointItemKey;
+ string sessionId;
+};
+
+class MediaSessionIdState extends SessionState
+{
+ Ice::Identity mediaSessionObjectId;
+};
+
+class SessionControllerIdState extends SessionState
+{
+ Ice::Identity sessionControllerObjectId;
+};
+
+class SourcesState extends SessionState
+{
+ AsteriskSCF::Media::V1::StreamSourceSeq sources;
+};
+
+class SinksState extends SessionState
+{
+ AsteriskSCF::Media::V1::StreamSinkSeq sinks;
+};
+
+class StreamsState extends SessionState
+{
+ AsteriskSCF::Media::V1::StreamInformationDict streams;
+};
+
+class MediaSessionState extends SessionState
+{
+ MediaSessionSeq rtpMediaSessions;
+};
+
+class SessionListenerUpdate extends SessionState
+{
+ AsteriskSCF::SessionCommunications::V1::SessionListenerSeq listeners;
+};
+
+class BridgeState extends SessionState
+{
+ AsteriskSCF::SessionCommunications::V1::Bridge* bridgeProxy;
+ AsteriskSCF::SessionCommunications::V1::SessionListener* listener;
+};
+
+class CookieState extends SessionState
+{
+ AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+};
+
+class DefaultSessionListeners extends StateItem
+{
+ AsteriskSCF::SessionCommunications::V1::SessionListenerSeq listeners;
+};
+
+class DefaultSessionCookies extends StateItem
+{
+ AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+};
+
+}; /* module V1 */
+
+}; /* module FileSessionGateway */
+
+}; /* module Replication */
+
+}; /* module AsteriskSCF */
diff --git a/slice/CMakeLists.txt b/slice/CMakeLists.txt
new file mode 100644
index 0000000..90e1e47
--- /dev/null
+++ b/slice/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LIBNAME "AstScfFileSessionGatewayAPI")
+
+astscf_slice_collection(GLOBAL
+ NAME FILESESSIONGATEWAY
+ PATH "${CMAKE_CURRENT_SOURCE_DIR}"
+ HEADERS
+ "${CMAKE_CURRENT_BINARY_DIR}/${LIBNAME}/slice-FILESESSIONGATEWAY"
+ LIBRARY ${LIBNAME}
+ )
+
+astscf_slice_include_collection(FILESESSIONGATEWAY)
+
+astscf_component_init(${LIBNAME})
+astscf_component_add_slices(${LIBNAME} FILESESSIONGATEWAY GLOB_RECURSE
+ "AsteriskSCF/*.ice")
+astscf_component_add_slice_collection_libraries(${LIBNAME} ASTSCF)
+astscf_component_build_library(${LIBNAME})
+astscf_slice_collection_install(FILESESSIONGATEWAY)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
old mode 100755
new mode 100644
index 6d21a6b..6a4eabd
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,13 +1,55 @@
include_directories(${logger_dir}/include)
include_directories(${astscf-ice-util-cpp_dir}/include)
+astscf_slice_include_collection(FILESESSIONGATEWAY)
+
astscf_component_init(FileSessionGateway)
astscf_component_add_files(FileSessionGateway Config.h)
astscf_component_add_files(FileSessionGateway FileSessionGatewayComponent.h)
+astscf_component_add_files(FileSessionGateway
+ ComponentFeature.h
+ Config.h
+ EndpointSpecification.h
+ Endpoint.h
+ Endpoint.cpp
+ EndpointLocator.h
+ EndpointLocator.cpp
+ LoggerF.h
+ CookieManager.cpp
+ CookieManager.h
+ ReplicatedObject.cpp
+ ReplicatedObject.h
+ Replication.h
+ Replicator.h
+ ReplicationListener.h
+ ReplicationListener.cpp
+ RemoteServices.h
+ RemoteServices.cpp
+ Session.h
+ Session.cpp
+ )
astscf_component_add_files(FileSessionGateway Component.cpp)
astscf_component_add_files(FileSessionGateway Configuration.cpp)
astscf_component_add_files(FileSessionGateway Configuration.h)
astscf_component_add_ice_libraries(FileSessionGateway IceStorm)
astscf_component_add_boost_libraries(FileSessionGateway core)
-astscf_component_add_slice_collection_libraries(FileSessionGateway ASTSCF)
-astscf_component_add_build_icebox(FileSessionGateway)
+astscf_component_add_slice_collection_libraries(FileSessionGateway FILESESSIONGATEWAY ASTSCF)
+astscf_component_build_icebox(FileSessionGateway)
+target_link_libraries(FileSessionGateway astscf-ice-util-cpp logging-client)
+astscf_component_install(FileSessionGateway)
+
+astscf_component_init(FileSessionReplicator)
+astscf_component_add_files(FileSessionReplicator
+ FileSessionGatewayReplicator.cpp
+ Replicator.h
+ ReplicationListener.h
+ )
+
+astscf_component_add_ice_libraries(FileSessionReplicator IceStorm)
+astscf_component_add_boost_libraries(FileSessionReplicator core)
+astscf_component_add_slice_collection_libraries(FileSessionReplicator FILESESSIONGATEWAY ASTSCF)
+astscf_component_build_icebox(FileSessionReplicator)
+target_link_libraries(FileSessionReplicator astscf-ice-util-cpp logging-client)
+astscf_component_install(FileSessionReplicator)
+
+
diff --git a/src/Component.cpp b/src/Component.cpp
old mode 100755
new mode 100644
index b7456c0..62c7cd8
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -13,7 +13,18 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
+
+#include "EndpointLocator.h"
+#include "FileSessionGatewayComponent.h"
+#include "Config.h"
+#include "Replicator.h"
+#include "ReplicationListener.h"
+#include "ComponentDefs.h"
+#include "Configuration.h"
+#include "RemoteServices.h"
+
#include <AsteriskSCF/Component/Component.h>
+
#include <IceUtil/UUID.h>
#include <boost/thread.hpp>
@@ -23,38 +34,35 @@
#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
#include <AsteriskSCF/Discovery/SmartProxy.h>
#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+#include <AsteriskSCF/FileSessionGateway/FileSessionGatewayIf.h>
#include <AsteriskSCF/Logger/IceLogger.h>
#include <AsteriskSCF/logger.h>
-#include "EndpointLocator.h"
-#include "ReplicationListener.h"
-#include "ReplicationContext.h"
-#include "FileSessionGatewayComponent.h"
-
-using namespace std;
-using namespace AsteriskSCF::Core::Routing::V1;
-using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::System::Component::V1;
using namespace AsteriskSCF::System::Logging;
-using namespace AsteriskSCF::SessionCommunications::V1;
-using namespace AsteriskSCF::System::Configuration::V1;
+using namespace std;
namespace AsteriskSCF
{
namespace FileSessionGtw
{
- //
- // NOTE:
- // With respect to proxies to infrastructure services and peers. I wonder
- // about how long these are held onto. It might be better for certain
- // tiers of objects to grab their own reference to some things instead of
- // using a cached instance.
-
-
+//
+// NOTE:
+// With respect to proxies to infrastructure services and peers. I wonder
+// about how long these are held onto. It might be better for certain
+// tiers of objects to grab their own reference to some things instead of
+// using a cached instance.
+//
class FileSessionGatewayComponentImpl : public FileSessionGatewayComponent
{
public:
+ FileSessionGatewayComponentImpl() :
+ FileSessionGatewayComponent(getLoggerFactory().getLogger(LoggerId + ".Gateway"),
+ AsteriskSCF::FileSessionGateway::V1::ComponentServiceDiscoveryCategory)
+ {
+ }
+
void addFeatureProxyToServices(const Ice::ObjectPrx& proxy, const std::string& category)
{
managePrimaryService(wrapServiceForRegistration(proxy, category));
@@ -63,452 +71,261 @@ public:
{
manageBackplaneService(wrapServiceForRegistration(proxy, category));
}
-};
-
-/**
- * This private class initializes the startup and controls the shutdown of the component.
- */
-class Component : public AsteriskSCF::Component::Component
-{
-public:
- Component(const Logger& logger, const std::string& category)
- : AsteriskSCF::Component::Component(logger, ComponentServiceDiscoveryCategory),
- mListeningToReplicator(false)
- {
- }
-
-private:
-#if 0
- //
- // Required base Component overrides
- //
- void createPrimaryServices();
- void preparePrimaryServicesForDiscovery();
- void createReplicationStateListeners();
- void stopListeningToStateReplicators();
- void listenToStateReplicators();
- void findRemoteServices();
-
- //
- // Notification overrides
- //
- void onPreInitialize();
- void onPostInitialize();
- void onStop();
-
- //
- // Other base Component overrides
- //
- void createBackplaneServices();
- void prepareBackplaneServicesForDiscovery();
- ReplicationContextPtr createReplicationContext(ReplicationStateType state);
- void unregisterFromRemoteServices();
- void registerWithRemoteServices();
-
- //
- // Our own implementation operations.
- //
- void registerWithRoutingService();
- void unregisterFromRoutingService();
-
- void registerWithServiceLocator();
- void unregisterFromServiceLocator();
- void locateRoutingService();
- void locateSessionRouter();
- void locateStateReplicator();
-#endif
-
-#if 0
- ComponentServicePtr mEndpointLocator;
- ComponentServicePtr mReplicationListener;
-#endif
-
- ComponentServicePtr mConfiguration;
-
- //
- // Unique Id for this component's EndpointLocator. This id is used when adding this
- // EndpointLocator to a locator registry.
- //
- std::string mRoutingId;
-};
-
-static const string DefaultEndpointLocatorId("FileSessionEndpointLocator");
-static const string DefaultReplicaListenerId("FileSessionGtwReplica");
-
-/**
- * Override of factory method to create our custom replication context.
- */
-ReplicationContextPtr Component::createReplicationContext(ReplicationStateType state)
-{
- return createReplicationContext(state);
-}
-
-/**
- * Register this component's primary public interfaces with the Service Locator.
- * This enables other Asterisk SCF components to locate our interfaces.
- */
-void Component::preparePrimaryServicesForDiscovery()
-{
- try
- {
- // Wrap our authentication extensions point for the Service Locator.
- mAuthExtensionRegistration = wrapServiceForRegistration(mAuthExtensionPrx,
- AsteriskSCF::SIP::V1::AuthExtensionPointCategory);
- managePrimaryService(mAuthExtensionRegistration);
- }
- catch(const std::exception& e)
- {
- lg(Error) << "Unable to publish component interfaces in " << getName() << BOOST_CURRENT_FUNCTION <<
- ". Exception: " << e.what();
- throw; // rethrow
- }
-}
-
-/**
- * Prepare this component's backplane interfaces for discovery via the Service Locator.
- */
-void Component::prepareBackplaneServicesForDiscovery()
-{
- // Insure the default Component services are prepped.
- AsteriskSCF::Component::Component::prepareBackplaneServicesForDiscovery();
-
- try
- {
- // Wrap our configuration interface for the Service Locator.
- mConfigurationRegistration = wrapServiceForRegistration(mConfigurationServiceProxy,
- ConfigurationDiscoveryCategory);
- manageBackplaneService(mConfigurationRegistration);
- }
- catch(const std::exception& e)
- {
- lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION << " : " << e.what();
- }
-}
-
-/**
- * Get a reference to the Routing Service interface that we care about, and cache it in the Data Model.
- * This will allow us to lookup endpoints anywhere in the Asterisk SCF system.
- */
-void Component::locateRoutingService()
-{
- ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
- genericparams->category = Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory;
- genericparams->service =
- getCommunicator()->getProperties()->getPropertyWithDefault("Sip.RoutingService", "default");
-
- AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> pw(getServiceLocator(), genericparams, lg);
- mRoutingServiceLocatorRegistry = pw;
-
- // This exists here since it may need to be known before actually contacting the routing service
- mRoutingId = getCommunicator()->getProperties()->getPropertyWithDefault("Sip.RoutingDestinationId", "pjsip");
-}
-
-void Component::locateStateReplicator()
-{
- if (getReplicationContext()->getState() == ACTIVE_STANDALONE)
- {
- return;
- }
- ServiceLocatorParamsPtr replicatorParams = new ServiceLocatorParams();
- replicatorParams->category = StateReplicatorDiscoveryCategory;
- replicatorParams->service =
- getCommunicator()->getProperties()->getPropertyWithDefault("Sip.StateReplicatorService", "default");
-
- try
+ void onActivated()
{
- AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> pw(getServiceLocator(), replicatorParams, lg);
- SipReplicationContextPtr sipReplicationContext =
- boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
-
- sipReplicationContext->setReplicator(pw);
-
- // Since we're not in standalone mode, we'll get our configuration updates routed via the
- // replicator service.
- ConfigurationReplicatorPrx configurationReplicator = ConfigurationReplicatorPrx::checkedCast(
- sipReplicationContext->getReplicator().initialize(), ReplicatorFacet);
- configurationReplicator->registerConfigurationService(mConfigurationServiceProxy);
+ mEndpointLocatorFeature->getLocator()->updateReplicator(mReplicator);
}
- catch (...)
- {
- lg(Error) << "State replicator could not be found, operating without.";
- }
-}
-
-void Component::listenToStateReplicators()
-{
- SipReplicationContextPtr sipReplicationContext =
- boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
- if (mListeningToReplicator == true)
+ void onStandby()
{
- return;
+ //
+ // Nil'ing out the replicator object will stop an
+ // further replication.
+ //
+ mEndpointLocatorFeature->getLocator()->updateReplicator(ReplicatorSmartProxy());
}
- if (!sipReplicationContext->getReplicator().isInitialized())
+ void createReplicationStateListeners()
{
- lg(Error) << getName() << " : State replicator could not be found. Unable to listen for state updates!";
- return;
+ //
+ // Listener is created in startListening for now.. a little different
+ // than other implementations. It is implemented this way mostly to
+ // experiment with an alternate approach to handling the listener
+ // lifetime and moving to and from the standby state.
+ //
}
-
- try
+
+ void stopListeningToStateReplicators()
{
- // Are we in standby mode?
- if (sipReplicationContext->getState() == STANDBY_IN_REPLICA_GROUP)
+ boost::mutex::scoped_lock lock(mReplicationStateMutex);
+ if (!mReceivingReplicationUpdates)
{
- sipReplicationContext->getReplicator()->addListener(mReplicatorListenerProxy);
- mListeningToReplicator = true;
+ //
+ // We aren't listening, so we can just exit early.
+ //
+ return;
}
+ mReceivingReplicationUpdates = false;
+
+ //
+ // This will cause the object to be "destroyed" with respect to the
+ // object adapter. Since the components affected by the replication
+ // listeners are passive relative to the listener (ie. they don't know
+ // about the listener, the listener knows about them .. sort of)
+ //
+ mReplicationListener->destroy();
+ mReplicationListener = 0;
}
- catch (const Ice::Exception& e)
- {
- lg(Error) << e.what();
- throw;
- }
-}
-
-/**
- * Unregister as a listener to our state replicator.
- * A component in active mode doesn't neeed to listen to
- * state replication data.
- */
-void Component::stopListeningToStateReplicators()
-{
- SipReplicationContextPtr sipReplicationContext =
- boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
- if ((!sipReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
+ void listenToStateReplicators()
{
- return;
+ if (getReplicationContext()->getState() != AsteriskSCF::Replication::STANDBY_IN_REPLICA_GROUP)
+ {
+ //
+ // The code is setup so it does two locks. While suboptimal it
+ // prevents us having to have an RPC while holding a lock. This
+ // isn't a performance critical method so this should be ok.
+ //
+ {
+ //
+ // Check to see if we are already wired up and if so, exit early.
+ //
+ boost::mutex::scoped_lock lock(mReplicationStateMutex);
+ if (mReceivingReplicationUpdates)
+ {
+ return;
+ }
+ }
+
+ //
+ // This is a little different that how some of the other services
+ // are setup because the listener is perpetual in those other
+ // implemenations. In this case, we are trying something a bit
+ // different and only creating the listener when it's needed.
+ //
+ try
+ {
+ AsteriskSCF::Replication::FileSessionGateway::V1::StateReplicatorListenerPtr servant =
+ AsteriskSCF::FileSessionGtw::ReplicationListener::create(mEndpointLocatorFeature->getLocator(),
+ getServiceAdapter(), mLogger);
+ mReplicatorListenerProxy =
+ AsteriskSCF::Replication::FileSessionGateway::V1::StateReplicatorListenerPrx::uncheckedCast(
+ getServiceAdapter()->addWithUUID(servant));
+ try
+ {
+ mReplicatorListenerProxy =
+ AsteriskSCF::Replication::FileSessionGateway::V1::StateReplicatorListenerPrx::uncheckedCast(
+ mReplicatorListenerProxy->ice_oneway());
+ }
+ catch (const Ice::NoEndpointException&)
+ {
+ //
+ // If this exception is thrown it simply means that oneways
+ // cannot be supported, mReplicatorListenerProxy's original
+ // value will not be affected.
+ //
+ }
+ }
+ catch (const std::exception& ex)
+ {
+ mLogger(Error) << "Unable to instantiate replication listener in " << getName() << ": " << ex.what();
+ }
+ catch (...)
+ {
+ mLogger(Error) << "Unable to instantiate replication listener in " << getName() << " (unknown exception).";
+ }
+
+ //
+ // Find the replication service.
+ //
+ try
+ {
+ assert(mReplicator);
+ mReplicator->addListener(mReplicatorListenerProxy);
+ boost::mutex::scoped_lock lock(mReplicationStateMutex);
+ mReceivingReplicationUpdates = true;
+ }
+ catch (const std::exception& ex)
+ {
+ mLogger(Error) << "Unable to add listener to replication server: " << ex.what();
+ throw;
+ }
+ }
}
- try
- {
- sipReplicationContext->getReplicator()->removeListener(mReplicatorListenerProxy);
- mListeningToReplicator = false;
- }
- catch (const Ice::Exception& e)
+ void createPrimaryServices()
{
- lg(Error) << e.what();
- throw;
+ if (!mEndpointLocatorFeature)
+ {
+ mEndpointLocatorFeature = createEndpointLocatorFeature(getName(), getServiceAdapter(),
+ getRemoteServices());
+ }
}
-}
-/**
- * Get a reference to the routine service.
- */
-void Component::locateSessionRouter()
-{
- ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
- genericparams->category = Routing::V1::SessionRouterDiscoveryCategory;
- genericparams->service = getCommunicator()->getProperties()->getPropertyWithDefault(
- "SessionRouter.Service", "default");
-
- SmartProxy<SessionRouterPrx> pw(getServiceLocator(), genericparams, lg);
- mSessionRouter = pw;
-}
-
-/**
- * Register our own Endpoint Locator with the Routing Service so that
- * the endpoints that this channel manages can be accessed from any
- * Session Manager in the Asterisk SCF system.
- */
-void Component::registerWithRoutingService()
-{
- try
+ void createBackplaneServices()
{
- RegExSeq destinations;
-
- mEndpointFactory->generateRoutingDestinations(destinations);
-
- EndpointLocatorPrx locator = EndpointLocatorPrx::uncheckedCast(
- getServiceAdapter()->createDirectProxy(getCommunicator()->stringToIdentity(EndpointLocatorObjectId)));
- mRoutingServiceLocatorRegistry->addEndpointLocator(mRoutingId, destinations, locator);
- }
- catch(const std::exception& e)
- {
- lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION << " : " << e.what();
- }
-}
+ if (!mEndpointLocatorFeature)
+ {
+ mEndpointLocatorFeature = createEndpointLocatorFeature(getName(), getServiceAdapter(),
+ getRemoteServices());
+ }
-/**
- * Unregister our own Endpoint Locator from the Routing SErvice.
- */
-void Component::unregisterFromRoutingService()
-{
- try
- {
- mRoutingServiceLocatorRegistry->removeEndpointLocator(mRoutingId);
- }
- catch(const std::exception& e)
- {
- lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+ mConfigurationFeature =
+ createConfigurationFeature(mEndpointLocatorFeature->getLocator(),
+ getRemoteServices());
+ mConfigurationProxy =
+ AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx::uncheckedCast(
+ mConfigurationFeature->activate(getBackplaneAdapter()));
+ mConfigurationFeature->registerFeature(this);
}
-}
-void Component::registerWithRemoteServices()
-{
- //
- // XXX NO! the endpoint locator or whatever should take care of this.
- //
- try
+ RemoteServicesPtr getRemoteServices()
{
- RegExSeq destinations;
- mEndpointFactory->generateRoutingDestinations(destinations);
-
- EndpointLocatorPrx locator = EndpointLocatorPrx::uncheckedCast(
- getServiceAdapter()->createDirectProxy(getCommunicator()->stringToIdentity(EndpointLocatorObjectId)));
- mRoutingServiceLocatorRegistry->addEndpointLocator(mRoutingId, destinations, locator);
- }
- catch(const std::exception& e)
- {
- lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+ if (!mRemoteServices)
+ {
+ string routingServiceName =
+ getCommunicator()->getProperties()->getPropertyWithDefault(
+ getName() + ".RoutingServiceName", "default");
+ string mediaServiceName =
+ getCommunicator()->getProperties()->getPropertyWithDefault(
+ getName() + ".FileMediaServiceName", "default");
+ mRemoteServices = RemoteServices::create(getServiceLocator(), routingServiceName,
+ mediaServiceName, mLogger);
+ }
+ return mRemoteServices;
}
-}
-/**
- * This operation is called by the base Component class
- * at times such as standy, or paused, to allow us to
- * remove our own proxies from remote services.
- */
-void Component::unregisterFromRemoteServices()
-{
- unregisterFromRoutingService();
-}
-
-/**
- * Post-init notification from the base component. Allows us
- * to initialize things after the base component does common
- * initialization.
- */
-void Component::onPostInitialize()
-{
- try
- {
- registerPJSipModules();
- }
- catch(const std::exception& e)
+ void findRemoteServices()
{
- lg(Critical) << "Major problems in " << getName() << " initialization: " << e.what();
+ //
+ // If we are in a situation where replication is supported/required, locate the
+ // replicator.
+ //
+ if (getReplicationContext()->getState() != AsteriskSCF::Replication::ACTIVE_STANDALONE)
+ {
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr replicatorParams =
+ new AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams;
+ replicatorParams->category = AsteriskSCF::Replication::FileSessionGateway::V1::StateReplicatorDiscoveryCategory;
+ replicatorParams->service = getCommunicator()->getProperties()->getPropertyWithDefault(
+ getName() + ".StateReplicatorService", "default");
+ replicatorParams->id = getCommunicator()->getProperties()->getPropertyWithDefault(
+ getName() + ".StateReplicatorId", "");
+ try
+ {
+ mReplicator = AsteriskSCF::FileSessionGtw::ReplicatorSmartProxy(getServiceLocator(), replicatorParams,
+ mLogger);
+ }
+ catch (const AsteriskSCF::Core::Discovery::V1::ServiceNotFound&)
+ {
+ mLogger(Error) << getName() << ": unable to get replicator from service locator. Please check configuration.";
+ throw;
+ }
+ }
}
-}
-/**
- * Create the objects that implement the main services this component provides
- * the system.
- */
-void Component::createPrimaryServices()
-{
- try
+ void preparePrimaryServicesForDiscovery()
{
- SipReplicationContextPtr sipReplicationContext =
- boost::static_pointer_cast<SipReplicationContext>(getReplicationContext());
-
- mEventPublisher.reset(new SipSessionManagerEventPublisher(getServiceAdapter()));
- lg(Debug) << "Created SIP Session Manager event publisher";
-
- mEndpointFactory.reset(new SipEndpointFactory(getServiceAdapter(),
- mPJSipManager, getServiceLocator(), sipReplicationContext));
- lg(Debug) << "Created SIP endpoint factory";
-
- // Locate the Routing Service so that we can do routing. This is done here so it can be
- // passed to the configuration service.
- // (NOTE: I suspect that since we're using a smart pointer,
- // this could be deferred to findRemoteServices)
- locateRoutingService();
-
- // Create and configure our Endpoint Locator.
- mEndpointLocator = new SipSessionManagerEndpointLocator(mEndpointFactory);
- getServiceAdapter()->add(mEndpointLocator, getCommunicator()->stringToIdentity(EndpointLocatorObjectId));
- lg(Debug) << "Got proxy to endpoint locator";
-
- // Create our RegistrarListener
- mDefaultRegistrarListener = new SipDefaultRegistrarListener(mEndpointFactory);
- mDefaultRegistrarListenerPrx = RegistrarListenerPrx::uncheckedCast(
- getServiceAdapter()->add(mDefaultRegistrarListener, getCommunicator()->stringToIdentity(RegistrarListenerId)));
- lg(Debug) << "Added default registrar listener to object adapter";
-
- // Create our SipAuthExtensionPoint servant.
- mAuthExtension = new SipAuthExtensionPoint(mPJSipManager);
- mAuthExtensionPrx = AuthExtensionPointPrx::uncheckedCast(
- getServiceAdapter()->add(mAuthExtension, getCommunicator()->stringToIdentity(AuthServiceId)));
- lg(Debug) << "Added Authentication extension point to object adapter";
-
+ mEndpointLocatorProxy = AsteriskSCF::Core::Routing::V1::EndpointLocatorPrx::uncheckedCast(
+ mEndpointLocatorFeature->activate(getServiceAdapter()));
}
- catch(const Ice::Exception& e)
- {
- lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
- }
-}
-
-void Component::createBackplaneServices()
-{
- // Include the base Component services.
- AsteriskSCF::Component::Component::createBackplaneServices();
-
- try
- {
- // Create and publish our Configuration interface support.
- mConfigurationService = createConfigurationServant(mPJSipManager, mEndpointFactory, mRoutingId, mRoutingServiceLocatorRegistry);
- mConfigurationServiceProxy = ConfigurationServicePrx::uncheckedCast(
- getBackplaneAdapter()->addWithUUID(mConfigurationService));
- lg(Debug) << "Created SIP Configuration Implementation";
- }
- catch(const Ice::Exception& e)
+ void registerWithRemoteRemoteServices()
{
- lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+ if (mEndpointLocatorFeature)
+ {
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr routerParams =
+ new AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams;
+ routerParams->category = AsteriskSCF::Core::Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory;
+ routerParams->service =getCommunicator()->getProperties()->getPropertyWithDefault(getName() +
+ ".EndpointLocatorRegistry", "default");
+ mEndpointLocatorFeature->makeReady(getServiceLocator(), routerParams);
+ }
+ if (mConfigurationFeature)
+ {
+ //
+ // Configuration does not do anything like this at the moment, but we will call out
+ // just in case.
+ //
+ mConfigurationFeature->makeReady(getServiceLocator(), 0);
+ }
}
-}
-void Component::createReplicationStateListeners()
-{
- try
+ void unregisterFromRemoteServices()
{
- // Create and publish our state replicator listener interface.
- mReplicatorListener = new SipStateReplicatorListenerI(mEndpointFactory,
- mPJSipManager,
- getServiceAdapter(),
- boost::static_pointer_cast<SipReplicationContext>(getReplicationContext()));
+ if (mEndpointLocatorFeature)
+ {
+ mEndpointLocatorFeature->suspend();
+ }
- SipStateReplicatorListenerPrx replicatorListener = SipStateReplicatorListenerPrx::uncheckedCast(
- getBackplaneAdapter()->addWithUUID(mReplicatorListener));
- mReplicatorListenerProxy = SipStateReplicatorListenerPrx::uncheckedCast(replicatorListener->ice_oneway());
-
- lg(Debug) << "Got proxy to SIP state replicator";
- }
- catch(const Ice::Exception &e)
- {
- lg(Error) << getName() << " in " << BOOST_CURRENT_FUNCTION << " : " << e.what();
- throw;
+ if (mConfigurationFeature)
+ {
+ mConfigurationFeature->suspend();
+ }
}
-}
-void Component::findRemoteServices()
-{
- // Locate the Session Router so we can REALLY do routing.
- locateSessionRouter();
-
- // Locate the State Replicator so we can fail over.
- locateStateReplicator();
-}
+private:
+ AsteriskSCF::FileSessionGtw::ReplicatorSmartProxy mReplicator;
+ AsteriskSCF::Replication::FileSessionGateway::V1::StateReplicatorListenerPrx mReplicatorListenerProxy;
+ AsteriskSCF::FileSessionGtw::ReplicationListenerPtr mReplicationListener;
+
+ boost::mutex mReplicationStateMutex;
+ bool mReceivingReplicationUpdates;
+
+ EndpointLocatorFeaturePtr mEndpointLocatorFeature;
+ AsteriskSCF::Core::Routing::V1::EndpointLocatorPrx mEndpointLocatorProxy;
+ ComponentFeaturePtr mConfigurationFeature;
+ AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx mConfigurationProxy;
+ RemoteServicesPtr mRemoteServices;
+};
-/**
- * Notification from the component that we're stopping.
- */
-void Component::onStop()
-{
- // Remove our endpoint locator from the routing service.
- unregisterFromRoutingService();
-}
+}; // end FileSessionGtw
+}; // end AsteriskSCF
extern "C"
{
ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
{
- return new AsteriskSCF::SipSessionManager::Component;
+ return new AsteriskSCF::FileSessionGtw::FileSessionGatewayComponentImpl;
}
}
-
-}; // end SipSessionManager
-}; // end AsteriskSCF
diff --git a/src/ReplicationContext.h b/src/ComponentDefs.h
old mode 100755
new mode 100644
similarity index 57%
copy from src/ReplicationContext.h
copy to src/ComponentDefs.h
index 77a671b..4e4116f
--- a/src/ReplicationContext.h
+++ b/src/ComponentDefs.h
@@ -1,7 +1,7 @@
/*
* Asterisk SCF -- An open-source communications framework.
*
- * Copyright (C) 2011, Digium, Inc.
+ * Copyright (C) 2010, Digium, Inc.
*
* See http://www.asterisk.org for more information about
* the Asterisk SCF project. Please do not directly contact
@@ -13,35 +13,29 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
+
#pragma once
-#include <AsteriskSCF/Replication/ReplicationContext.h>
-#include "FileSessionStateReplicationIf.h"
-#include <boost/shared_ptr.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/locks.hpp>
+#include <AsteriskSCF/Discovery/SmartProxy.h>
+#include <AsteriskSCF/Replication/FileSessionGateway/FileSessionReplicationIf.h>
namespace AsteriskSCF
{
namespace FileSessionGtw
{
-typedef AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::FileSessionGateway::V1::StateReplicatorPrx>
-ReplicatorSmartPrx;
-
-//
-// Forward declarations.
-//
-class ReplicationContext;
-typedef boost::shared_ptr<ReplicationContext> ReplicationContextPtr;
-
-class ReplicationContext : public AsteriskSCF::Replication::ReplicationContext
-{
-public:
- static ReplicationContextPtr create(const AsteriskSCF::Replication::ReplicationStateType stateType);
-protected:
- ReplicationContext() {}
-};
+/**
+ * Some simple typedefs to abbreviate code a bit. Arguably makes it
+ * a bit more readable too.
+ */
+typedef boost::unique_lock<boost::shared_mutex> UniqueLock;
+typedef boost::shared_lock<boost::shared_mutex> SharedLock;
+typedef AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Replication::FileSessionGateway::V1::StateReplicatorPrx>
+ ReplicatorSmartProxy;
} /* End of namespace FileSessionGtw */
} /* End of namespace AsteriskSCF */
-
+
diff --git a/src/ComponentFeature.h b/src/ComponentFeature.h
old mode 100755
new mode 100644
index a2b0d65..ad5c820
--- a/src/ComponentFeature.h
+++ b/src/ComponentFeature.h
@@ -15,7 +15,12 @@
*/
#pragma once
+
+
+#include "FileSessionGatewayComponent.h"
+
#include <IceUtil/Shared.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
namespace AsteriskSCF
{
@@ -33,20 +38,22 @@ class ComponentFeature : public IceUtil::Shared
public:
virtual ~ComponentFeature() {}
- virtual void activate(const Ice::ObjectAdapterPtr& adapter) = 0;
+ virtual Ice::ObjectPrx activate(const Ice::ObjectAdapterPtr& adapter) = 0;
+ virtual void registerFeature(const FileSessionGatewayComponentPtr& component) = 0;
+
+ /**
+ * make final preparations.
+ */
+ virtual void makeReady(const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& locator,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr& params) = 0;
/**
- * Perform startup/registration related operations. This method will throw
- * and InvalidInvocationOrder exception if it is called before the feature
- * has been "activated". Note that there is no need to have a
- * corresponding "unregister" here. The file session gateway component
- * automatically cleans up the registrations when it is no longer needed.
+ *
*/
- virtual void registerFeature(
- const AsteriskSCF::FileSessionGtw::FileSessionGatewayComponentPtr& fileSessionComponent) = 0;
+ virtual void suspend() = 0;
};
typedef IceUtil::Handle<ComponentFeature> ComponentFeaturePtr;
} /* End of namespace FileSessionGtw */
-} /* End of
+} /* End of namespace AsteriskSCF */
diff --git a/src/Config.h b/src/Config.h
old mode 100755
new mode 100644
diff --git a/src/Configuration.cpp b/src/Configuration.cpp
old mode 100755
new mode 100644
index 6f9b21e..a81f95f
--- a/src/Configuration.cpp
+++ b/src/Configuration.cpp
@@ -1,115 +1,377 @@
-/*
- * 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.
- */
-
-#include "Configuration.h"
-
-#include <AsteriskSCF/System/Component/ConfigurationIf.h>
-#include <AsteriskSCF/logger.h>
-#include <IceUtil/UUID.h>
-
-using namespace AsteriskSCF::FileSessionGtw;
-using namespace AsteriskSCF::System::Configuration::V1;
-using namespace AsteriskSCF::System::Logging;
-using namespace std;
-
-namespace
-{
- class ConfigurationImpl : public AsteriskSCF::System::Configuration::V1::ConfigurationService
- {
- public:
- ConfigurationImpl()
- {
- }
-
- ConfigurationGroupSeq getConfiguration(const ConfigurationGroupSeq& groups, const Ice::Current& current)
- {
- }
-
- ConfigurationGroupSeq getConfigurationAll(const ConfigurationGroupSeq& groups, const Ice::Current& current)
- {
- }
-
- ConfigurationGroupSeq getConfigurationGroups(const Ice::Current& current)
- {
- }
-
- void setConfiguration(const ConfigurationGroupSeq& groups, const Ice::Current& current)
- {
- }
-
- void removeConfigurationItems(const ConfigurationGroupSeq& groups, const Ice::Current& current)
- {
- }
-
- void removeConfigurationGroups(const ConfigurationGroupSeq& groups, const Ice::Current& current)
- {
- }
- };
- typedef IceUtil::Handle<ConfigurationImpl> ConfigurationImplPtr;
-
- class ConfigurationFeature : public ComponentFeature
- {
- public:
- ConfigurationFeature(const Logger& logger) :
- mServant(new ConfiurationImpl),
- mId(std::string("ascf.fsgtw.") + IceUtil::generateUUID()),
- mLogger(logger)
- {
- }
-
- void activate(const Ice::ObjectAdapterPtr& adapter)
- {
- Ice::Identity id(adapter->getCommunicator()->stringToIdentity(mId));
- mPublicProxy = ConfigurationPrx::uncheckedCast(adapter->add(mServant, id));
- mDirectoryProxy = ConfigurationPrx::uncheckedCast(adapter->createDirectProxy(id));
- }
-
- void registerFeature(const FileSessionGatewayComponentPtr& gatewayComponent)
- {
- assert(gatewayComponent);
- if (gatewayComponent)
- {
- //
- // This should be a public proxy because if we fail over to a
- // replica, we want the proxy in discovery to be remain generally
- // valid.
- //
- gatewayComponent->addFeatureProxyToBackplane(mPublicProxy,
- AsteriskSCF::System::Configuration::V1::ConfigurationDiscoveryCategory);
- }
- else
- {
- mLogger(Error) << "Unable to register configuration service. Provided component reference is nil";
- }
- }
-
- private:
- //
- // These variable names are pretty self-explanatory, so we will let them.
- //
- ConfigurationImplPtr mServant;
- string mId;
- ConfigurationPrx mPublicProxy;
- ConfigurationPrx mDirectProxy;
- Logger mLogger;
- };
- typedef IceUtil::Handle<ConfigurationFeature> ConfigurationFeaturePtr;
-}
-
-AsteriskSCF::FileSessionGtw::ComponentFeaturePtr AsteriskSCF::FileSessionGtw::createConfigurationFeature()
-{
- return new ConfigurationFeature(getLoggerFactory().getLogger(LoggerId + ".Configuration"));
-}
+/*
+ * 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.
+ */
+
+#include "Configuration.h"
+#include "Config.h"
+
+#include "EndpointLocator.h"
+
+#include <AsteriskSCF/Configuration/FileSessionGateway/FileSessionGatewayConfigurationIf.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+#include <Ice/Ice.h>
+#include <IceUtil/UUID.h>
+
+using namespace AsteriskSCF::FileSessionGtw;
+using namespace AsteriskSCF::Configuration::FileSessionGateway::V1;
+using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::System::Logging;
+using namespace std;
+
+namespace
+{
+
+EndpointGroupPtr createGroupForEndpoint(const EndpointImplPtr& endpoint)
+{
+ EndpointSpecificationPtr spec = endpoint->getSpecification();
+ EndpointGroupPtr endpointGroup = new EndpointGroup;
+ endpointGroup->name = spec->name;
+
+ EndpointDestinationNamePtr destination = new EndpointDestinationName;
+ destination->value = spec->destination;
+ endpointGroup->configurationItems[EndpointDestinationItem] = destination;
+
+ MediaFilePtr mediaFile = new MediaFile;
+ mediaFile->id = spec->mediaFile;
+ mediaFile->operations = spec->operations;
+ endpointGroup->configurationItems[EndpointMediaFileItem] = mediaFile;
+ return endpointGroup;
+}
+
+EndpointSpecificationPtr createSpecificationFromGroup(const EndpointGroupPtr& group)
+{
+ if (!group || group->name.empty())
+ {
+ return EndpointSpecificationPtr();
+ }
+ EndpointSpecificationPtr newSpec(new EndpointSpecification);
+ newSpec->name = group->name;
+
+ ConfigurationItemDict::iterator propertyIter = group->configurationItems.find(EndpointDestinationItem);
+ if (propertyIter != group->configurationItems.end())
+ {
+ EndpointDestinationNamePtr destination = EndpointDestinationNamePtr::dynamicCast(propertyIter->second);
+ if (destination)
+ {
+ newSpec->destination = destination->value;
+ }
+ }
+
+ propertyIter = group->configurationItems.find(EndpointMediaFileItem);
+ if (propertyIter != group->configurationItems.end())
+ {
+ MediaFilePtr mediaFile = MediaFilePtr::dynamicCast(propertyIter->second);
+ if (mediaFile)
+ {
+ newSpec->mediaFile = mediaFile->id;
+ newSpec->operations = mediaFile->operations;
+ }
+ }
+ return newSpec;
+}
+
+class ConfigurationImpl : public AsteriskSCF::System::Configuration::V1::ConfigurationService
+{
+public:
+ ConfigurationImpl(const EndpointLocatorImplPtr& endpointLocator,
+ const RemoteServicesPtr& remoteServices,
+ const Logger& logger) :
+ mEndpointLocator(endpointLocator),
+ mRemoteServices(remoteServices),
+ mLogger(logger)
+ {
+ }
+
+ ConfigurationGroupSeq getConfiguration(const ConfigurationGroupSeq& groups, const Ice::Current&)
+ {
+ ConfigurationGroupSeq result;
+ for (ConfigurationGroupSeq::const_iterator iter = groups.begin(); iter != groups.end(); ++iter)
+ {
+ //
+ // There aren't a lot of different types, so the visitor is a little overkill.
+ //
+ EndpointGroupPtr endpointGroup = EndpointGroupPtr::dynamicCast(*iter);
+ if (endpointGroup)
+ {
+ EndpointImplSeq endpointImpls = mEndpointLocator->getEndpoints();
+ for (EndpointImplSeq::const_iterator endpointIter = endpointImpls.begin();
+ endpointIter != endpointImpls.end(); ++endpointIter)
+ {
+ if (endpointGroup->name == (*endpointIter)->getName())
+ {
+ result.push_back(createGroupForEndpoint(*endpointIter));
+ }
+ }
+ continue;
+ }
+ GeneralGroupPtr generalGroup = GeneralGroupPtr::dynamicCast(*iter);
+ if (generalGroup)
+ {
+ RoutingServicePtr routingService = new RoutingService;
+ routingService->serviceName = mRemoteServices->getRoutingServiceName();
+ generalGroup->configurationItems[RoutingServiceItem] = routingService;
+
+ FileMediaServicePtr fileMediaService = new FileMediaService;
+ fileMediaService->serviceName = mRemoteServices->getMediaServiceName();
+ generalGroup->configurationItems[FileMediaServiceItem] = fileMediaService;
+ }
+ }
+ return result;
+ }
+
+ ConfigurationGroupSeq getConfigurationAll(const ConfigurationGroupSeq& groups, const Ice::Current&)
+ {
+ ConfigurationGroupSeq result;
+ for (ConfigurationGroupSeq::const_iterator iter = groups.begin(); iter != groups.end(); ++iter)
+ {
+ //
+ // There aren't a lot of different types, so the visitor is a little overkill.
+ //
+ EndpointGroupPtr endpointGroup = EndpointGroupPtr::dynamicCast(*iter);
+ if (endpointGroup)
+ {
+ EndpointImplSeq endpointImpls = mEndpointLocator->getEndpoints();
+ for (EndpointImplSeq::const_iterator endpointIter = endpointImpls.begin();
+ endpointIter != endpointImpls.end(); ++endpointIter)
+ {
+ result.push_back(createGroupForEndpoint(*endpointIter));
+ }
+ continue;
+ }
+ //
+ // TODO: get from something real.
+ //
+ GeneralGroupPtr generalGroup = GeneralGroupPtr::dynamicCast(*iter);
+ if (generalGroup)
+ {
+ RoutingServicePtr routingService = new RoutingService;
+ routingService->serviceName = mRemoteServices->getRoutingServiceName();
+ generalGroup->configurationItems[RoutingServiceItem] = routingService;
+
+ FileMediaServicePtr fileMediaService = new FileMediaService;
+ fileMediaService->serviceName = mRemoteServices->getMediaServiceName();
+ generalGroup->configurationItems[FileMediaServiceItem] = fileMediaService;
+ }
+ }
+
+ return result;
+ }
+
+ ConfigurationGroupSeq getConfigurationGroups(const Ice::Current&)
+ {
+ ConfigurationGroupSeq groups;
+
+ EndpointImplSeq endpointImpls = mEndpointLocator->getEndpoints();
+ for (EndpointImplSeq::const_iterator iter = endpointImpls.begin();
+ iter != endpointImpls.end(); ++iter)
+ {
+ EndpointGroupPtr endpointGroup = new EndpointGroup;
+ endpointGroup->name = (*iter)->getName();
+ groups.push_back(endpointGroup);
+ }
... 6100 lines suppressed ...
--
asterisk-scf/integration/file_session_gateway.git
More information about the asterisk-scf-commits
mailing list