[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "basecomponent" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Jul 13 15:45:08 CDT 2011
branch "basecomponent" has been created
at 99a16a762d9a30872f49d7d6e29756770245d2ec (commit)
- Log -----------------------------------------------------------------
commit 99a16a762d9a30872f49d7d6e29756770245d2ec
Author: Ken Hunt <ken.hunt at digium.com>
Date: Wed Jul 13 15:44:36 2011 -0500
Using base Component. Also using the new SipReplicationContext class.
diff --git a/config/test_sip.conf b/config/test_sip.conf
index b96ee9c..640ef9f 100644
--- a/config/test_sip.conf
+++ b/config/test_sip.conf
@@ -22,7 +22,7 @@ LocatorService.Proxy=LocatorService:tcp -p 4411
# ID to use when registering with the routing service
# Useful if registering multiple active SIP session managers
-Sip.RoutingId=pjsip
+Sip.RoutingDestinationId=pjsip
# PJSIP Modules to register
Sip.Modules=Session
@@ -30,8 +30,8 @@ Sip.Modules=Session
# UDP Bind address.
Sip.Transport.UdpBindAddr=0.0.0.0:5060
-# The name of the State replicator to use
-Sip.StateReplicatorName=default
+# The service name of the State replicator to use
+Sip.StateReplicatorService=default
# Whether we are only a listener or not
Sip.StateReplicatorListener=no
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5aa8e59..f515361 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,7 +11,8 @@ include_directories(${API_INCLUDE_DIR})
asterisk_scf_slice_include_directories(${API_SLICE_DIR})
asterisk_scf_component_init(SipSessionManager)
-asterisk_scf_component_add_file(SipSessionManager SipSessionManagerApp.cpp)
+asterisk_scf_component_add_file(SipSessionManager SipSessionGateway.cpp)
+asterisk_scf_component_add_file(SipSessionManager SipReplicationContext.h)
asterisk_scf_component_add_file(SipSessionManager SipSessionManagerEventPublisher.cpp)
asterisk_scf_component_add_file(SipSessionManager SipSessionManagerEventPublisher.h)
asterisk_scf_component_add_file(SipSessionManager SipSessionManagerEndpointLocator.cpp)
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index ffd2854..6e7aebd 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -80,12 +80,11 @@ void PJSipManager::registerSessionModule(const boost::shared_ptr<SipEndpointFact
const AsteriskSCF::Discovery::SmartProxy<
AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>& sessionRouter,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica
+ const SipReplicationContextPtr& stateReplicationContext
)
{
mSessionModule = new PJSipSessionModule(mEndpoint, endpointFactoryPtr, sessionRouter,
- serviceLocator, stateReplicator, replica);
+ serviceLocator, stateReplicationContext);
}
void PJSipManager::registerLoggingModule()
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 9138770..6224419 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -30,6 +30,7 @@
#include "PJSipSessionModule.h"
#include "PJSipLoggingModule.h"
+#include "SipReplicationContext.h"
namespace AsteriskSCF
{
@@ -73,8 +74,7 @@ public:
const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
sessionRouter,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica
+ const SipReplicationContextPtr& stateReplicationContext
);
/**
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 74fe6f3..de4822c 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -19,7 +19,7 @@
#include "SipEndpointFactory.h"
#include "SipSession.h"
#include "PJSipManager.h"
-#include "SipStateReplicator.h"
+#include "SipReplicationContext.h"
#include <IceUtil/UUID.h>
@@ -251,14 +251,14 @@ void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransa
}
}
lg(Debug) << "========== End State Replication Dump ==========";
- if (mReplica->isActive() == true)
+ if (mReplicationContext->isReplicating() == true)
{
- if (setItems.size() != 0 && mStateReplicator)
+ if (setItems.size() != 0)
{
Ice::ObjectPrx oneway;
try
{
- oneway = mStateReplicator->ice_oneway();
+ oneway = mReplicationContext->getReplicator()->ice_oneway();
}
catch (const Ice::NoEndpointException&)
{
@@ -278,12 +278,12 @@ void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransa
}
}
- if (removeItems.size() != 0 && mStateReplicator)
+ if (removeItems.size() != 0)
{
Ice::ObjectPrx oneway;
try
{
- oneway = mStateReplicator->ice_oneway();
+ oneway = mReplicationContext->getReplicator()->ice_oneway();
}
catch (const Ice::NoEndpointException&)
{
diff --git a/src/PJSipSessionModule.h b/src/PJSipSessionModule.h
index 73fd186..ffa799b 100644
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@ -24,11 +24,11 @@
#include <boost/thread/shared_mutex.hpp>
#include <AsteriskSCF/Discovery/SmartProxy.h>
-#include <AsteriskSCF/System/Component/ReplicaIf.h>
#include <AsteriskSCF/System/ThreadPool/ThreadPoolIf.h>
#include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
-#include "SipStateReplicator.h"
+#include "SipEndpointFactory.h"
+#include "SipReplicationContext.h"
#include "SipSession.h"
#include "PJSipModule.h"
@@ -89,8 +89,7 @@ public:
const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
sessionRouter,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica);
+ const SipReplicationContextPtr& replicationContext);
pj_status_t load(pjsip_endpoint *endpoint);
pj_status_t start();
pj_status_t stop();
@@ -126,8 +125,7 @@ private:
boost::shared_ptr<SipEndpointFactory> mEndpointFactory;
AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> mSessionRouter;
AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
- AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> mStateReplicator;
- AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+ SipReplicationContextPtr mReplicationContext;
pjsip_endpoint *mEndpoint;
AsteriskSCF::System::ThreadPool::V1::PoolPtr mPool;
AsteriskSCF::System::WorkQueue::V1::QueuePtr mPoolQueue;
diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index 14e0718..bcdd1c2 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -101,11 +101,10 @@ PJSipSessionModule::PJSipSessionModule(pjsip_endpoint *endpt,
const boost::shared_ptr<SipEndpointFactory>& endpointFactoryPtr,
const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>& sessionRouter,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica)
+ const SipReplicationContextPtr& replicationContext)
: mName(moduleName), mEndpointFactory(endpointFactoryPtr),
mSessionRouter(sessionRouter), mServiceLocator(serviceLocator),
- mStateReplicator(stateReplicator), mReplica(replica), mEndpoint(endpt)
+ mReplicationContext(replicationContext), mEndpoint(endpt)
{
sessionModule = this;
mModule.name = pj_str(moduleName);
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 3ff806f..7db57a1 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -46,9 +46,9 @@ public:
SipEndpointImplPriv(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
const std::string& name, PJSipManager *manager,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica) :
+ const SipReplicationContextPtr& replicationContext) :
mName(name), mAdapter(adapter), mEndpointFactory(factory), mManager(manager), mServiceLocator(serviceLocator),
- mReplica(replica)
+ mReplicationContext(replicationContext)
{
};
@@ -95,7 +95,7 @@ public:
/**
*
*/
- AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+ SipReplicationContextPtr mReplicationContext;
};
/**
@@ -104,8 +104,8 @@ public:
SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
const std::string& name, const Ice::PropertyDict& props, PJSipManager *manager,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica)
- : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replica))
+ const SipReplicationContextPtr& replicationContext)
+ : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replicationContext))
{
lg(Debug) << "Constructing SIP endpoint " << name;
@@ -117,8 +117,8 @@ SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shar
}
SipEndpoint::SipEndpoint(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, PJSipManager *manager,
- const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const AsteriskSCF::System::Component::V1::ReplicaPtr replica)
- : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replica))
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const SipReplicationContextPtr& replicationContext)
+ : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replicationContext))
{
lg(Debug) << "Constructing SIP endpoint " << name;
@@ -277,7 +277,7 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(co
}
SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, listener, mImplPriv->mManager,
- mImplPriv->mServiceLocator, mImplPriv->mReplica, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, true);
+ mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, true);
mImplPriv->mSessions.push_back(session);
std::cout << "And now we're returing a session proxy..." << std::endl;
return session->getSessionProxy();
@@ -286,7 +286,7 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(co
AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination)
{
SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, 0, mImplPriv->mManager,
- mImplPriv->mServiceLocator, mImplPriv->mReplica, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false);
+ mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false);
mImplPriv->mSessions.push_back(session);
return session;
}
@@ -297,7 +297,7 @@ AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const s
const AsteriskSCF::Media::V1::StreamSinkSeq& sinks)
{
SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, sessionid, mediaid, mediasession,
- sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplica, false);
+ sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, false);
mImplPriv->mSessions.push_back(session);
return session;
}
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index 40a8e25..21cdd62 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -34,7 +34,7 @@
#include <AsteriskSCF/Media/RTP/MediaRTPIf.h>
#include "SipSession.h"
-
+#include "SipReplicationContext.h"
namespace AsteriskSCF
{
@@ -214,10 +214,10 @@ public:
SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
const std::string& name, const Ice::PropertyDict& props, PJSipManager *manager,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica);
+ const SipReplicationContextPtr& replicationContext);
SipEndpoint(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, PJSipManager *manager,
- const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const AsteriskSCF::System::Component::V1::ReplicaPtr replica);
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const SipReplicationContextPtr& replicationContext);
bool operator==(const std::string &name) const;
diff --git a/src/SipEndpointFactory.cpp b/src/SipEndpointFactory.cpp
index 09c4704..e5a1892 100644
--- a/src/SipEndpointFactory.cpp
+++ b/src/SipEndpointFactory.cpp
@@ -28,14 +28,15 @@ SipEndpointPtr SipEndpointFactory::createEndpoint(const std::string& destination
prefix.append(destination);
Ice::PropertyDict endpointProps = props->getPropertiesForPrefix(prefix);
SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), destination, endpointProps, mManager,
- mServiceLocator, mReplica);
+ mServiceLocator, mReplicationContext);
mEndpoints.push_back(endpoint);
return endpoint;
}
SipEndpointPtr SipEndpointFactory::createEndpoint(std::string endpointName)
{
- SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), endpointName, mManager, mServiceLocator, mReplica);
+ SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), endpointName, mManager,
+ mServiceLocator, mReplicationContext);
mEndpoints.push_back(endpoint);
return endpoint;
}
diff --git a/src/SipEndpointFactory.h b/src/SipEndpointFactory.h
index 48cfd97..6d75b84 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
@@ -21,6 +21,7 @@
#include <boost/enable_shared_from_this.hpp>
#include <AsteriskSCF/Core/Endpoint/EndpointIf.h>
+#include "SipReplicationContext.h"
namespace AsteriskSCF
{
@@ -37,8 +38,8 @@ class SipEndpointFactory : public boost::enable_shared_from_this<SipEndpointFact
public:
SipEndpointFactory(const Ice::ObjectAdapterPtr& adapter, PJSipManager *manager,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica) :
- mAdapter(adapter), mManager(manager), mServiceLocator(serviceLocator), mReplica(replica) { };
+ const SipReplicationContextPtr& replicationContext) :
+ mAdapter(adapter), mManager(manager), mServiceLocator(serviceLocator), mReplicationContext(replicationContext) {};
SipEndpointPtr createEndpoint(const std::string& destination, const Ice::PropertiesPtr& props);
@@ -73,7 +74,7 @@ private:
/**
* A pointer to the replica information.
*/
- AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+ SipReplicationContextPtr mReplicationContext;
};
}; // end SipSessionManager
diff --git a/src/SipReplicationContext.h b/src/SipReplicationContext.h
new file mode 100644
index 0000000..53de8cf
--- /dev/null
+++ b/src/SipReplicationContext.h
@@ -0,0 +1,83 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-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/shared_ptr.hpp>
+
+#include <AsteriskSCF/Discovery/SmartProxy.h>
+#include <AsteriskSCF/Replication/ReplicationContext.h>
+#include <AsteriskSCF/Component/TestContext.h>
+
+#include "SipStateReplicationIf.h"
+
+namespace AsteriskSCF
+{
+namespace SipSessionManager
+{
+typedef AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> ReplicatorSmartPrx;
+
+/**
+ * This class provides the component's classes with the context needed to perform replication.
+ */
+class SipReplicationContext : public AsteriskSCF::Replication::ReplicationContext
+{
+public:
+ SipReplicationContext(AsteriskSCF::Replication::ReplicationStateType state) :
+ AsteriskSCF::Replication::ReplicationContext(state)
+ {
+ }
+
+ // Override
+ virtual bool isReplicating()
+ {
+ // If the base context says we aren't replicating, we aren't.
+ if (!ReplicationContext::isReplicating())
+ {
+ return false;
+ }
+
+ // Do we have a replicator proxy?
+ if (mReplicator.isInitialized())
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get a reference to the state replicator service.
+ */
+ ReplicatorSmartPrx getReplicator()
+ {
+ return mReplicator;
+ }
+
+ /**
+ * Sets the reference to the state replicator service.
+ */
+ void setReplicator(const ReplicatorSmartPrx& replicator)
+ {
+ mReplicator = replicator;
+ }
+
+private:
+ ReplicatorSmartPrx mReplicator;
+};
+typedef boost::shared_ptr<SipReplicationContext> SipReplicationContextPtr;
+
+} // end SipSessionManager
+} // end AsteriskSCF
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 63df653..92ab1b1 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -86,9 +86,9 @@ public:
SipSessionPriv(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
const std::string& destination, PJSipManager *manager,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica)
+ const SipReplicationContextPtr& replicationContext)
: mAdapter(adapter), mDialog(0), mInviteSession(0), mEndpoint(endpoint), mDestination(destination),
- mManager(manager), mServiceLocator(serviceLocator), mReplica(replica) { };
+ mManager(manager), mServiceLocator(serviceLocator), mReplicationContext(replicationContext) { };
AsteriskSCF::SessionCommunications::V1::SessionInfoPtr getInfo()
{
@@ -245,7 +245,7 @@ public:
AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
- AsteriskSCF::System::Component::V1::ReplicaPtr mReplica;
+ SipReplicationContextPtr mReplicationContext;
SessionWorkPtr mSessionWork;
};
@@ -313,8 +313,8 @@ void SipSession::initializePJSIPStructs()
SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
const std::string& destination, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
PJSipManager *manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica, bool ipv6, bool isUAC)
- : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replica))
+ const SipReplicationContextPtr& replicationContext, bool ipv6, bool isUAC)
+ : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext))
{
if (listener != 0)
{
@@ -346,8 +346,8 @@ SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPt
const Ice::Identity& mediaid, const AsteriskSCF::Media::V1::SessionPrx& mediasession,
const AsteriskSCF::Media::V1::StreamSourceSeq& sources, const AsteriskSCF::Media::V1::StreamSinkSeq& sinks,
PJSipManager *manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica, bool isUAC)
- : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replica))
+ const SipReplicationContextPtr& replicationContext, bool isUAC)
+ : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext))
{
mImplPriv->mSessionProxy =
AsteriskSCF::SessionCommunications::V1::SessionPrx::uncheckedCast(adapter->add(this, sessionid));
@@ -853,7 +853,7 @@ public:
mSessionPriv->mAdapter->remove(mSessionPriv->mMediaSessionProxy->ice_getIdentity());
mSessionPriv->mMediaSession = 0;
- if (mSessionPriv->mReplica->isActive() == true)
+ if (mSessionPriv->mReplicationContext->isActive() == true)
{
//XXX This loop may be a candidate for making AMI-ified and returning "Suspended"
// Release all the RTP sessions we are using
diff --git a/src/SipSession.h b/src/SipSession.h
index 2a60c76..d737bd7 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -32,10 +32,10 @@
#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
#include <AsteriskSCF/Media/MediaIf.h>
#include <AsteriskSCF/Media/RTP/MediaRTPIf.h>
-#include <AsteriskSCF/System/Component/ReplicaIf.h>
#include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
#include <SipStateReplicationIf.h>
+#include "SipReplicationContext.h"
namespace AsteriskSCF
{
@@ -96,14 +96,14 @@ public:
SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&,
const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, PJSipManager *manager,
const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+ const SipReplicationContextPtr& replicationContext,
bool ipv6, bool isUAC);
SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&, const Ice::Identity&,
const Ice::Identity&, const AsteriskSCF::Media::V1::SessionPrx&,
const AsteriskSCF::Media::V1::StreamSourceSeq&, const AsteriskSCF::Media::V1::StreamSinkSeq&,
PJSipManager *manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
- const AsteriskSCF::System::Component::V1::ReplicaPtr& replica,
+ const SipReplicationContextPtr& replicationContext,
bool isUAC);
bool operator==(const SipSession &other) const;
diff --git a/src/SipSessionGateway.cpp b/src/SipSessionGateway.cpp
new file mode 100644
index 0000000..64ec9a5
--- /dev/null
+++ b/src/SipSessionGateway.cpp
@@ -0,0 +1,566 @@
+/*
+ * 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 <pjlib.h>
+
+#include <Ice/Ice.h>
+#include <IceStorm/IceStorm.h>
+#include <IceBox/IceBox.h>
+#include <IceUtil/UUID.h>
+
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/Core/Routing/RoutingIf.h>
+#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
+#include <AsteriskSCF/Discovery/SmartProxy.h>
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+#include <AsteriskSCF/Logger/IceLogger.h>
+#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/Component/Component.h>
+#include <AsteriskSCF/Replication/ReplicationContext.h>
+
+#include "SipSessionManagerEventPublisher.h"
+#include "SipSessionManagerEndpointLocator.h"
+#include "SipEndpointFactory.h"
+#include "PJSipSessionModule.h"
+#include "PJSipManager.h"
+#include "SipSession.h"
+#include "SipStateReplicator.h"
+#include "SipConfiguration.h"
+#include "SipReplicationContext.h"
+
+using namespace std;
+using namespace AsteriskSCF::SipSessionManager;
+using namespace AsteriskSCF::Core;
+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 AsteriskSCF::Component;
+using namespace AsteriskSCF::Replication;
+using namespace AsteriskSCF::Discovery;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionGateway");
+}
+
+namespace AsteriskSCF
+{
+namespace SipSessionManager
+{
+
+/**
+ * This private class initializes the startup and controls the shutdown of the component.
+ */
+class SipSessionGateway : public Component
+{
+public:
+ SipSessionGateway()
+ : Component(lg, AsteriskSCF::SIP::V1::ComponentServiceDiscoveryCategory),
+ mListeningToReplicator(false)
+ {
+ }
+
+ ~SipSessionGateway()
+ {
+ }
+
+private:
+ // Required Component overrides
+ virtual void createPrimaryServices();
+ virtual void registerPrimaryServices();
+ virtual void createReplicationStateListeners();
+ virtual void stopListeningToStateReplicators();
+ virtual void listenToStateReplicators();
+ virtual void findRemoteServices();
+
+ // Notification overrides
+ virtual void onPreInitialize();
+ virtual void onPostInitialize();
+ virtual void onStop();
+
+ // Other overrides
+ virtual void createBackplaneServices();
+ virtual void registerBackplaneServices();
+ virtual ReplicationContextPtr createReplicationContext(ReplicationStateType state);
+ virtual void deregisterFromRemoteServices();
+ virtual void registerWithRemoteServices();
+
+ // Our own implementation operations.
+ void registerWithRoutingService();
+ void deregisterFromRoutingService();
+
+ void registerWithServiceLocator();
+ void deregisterFromServiceLocator();
+ void locateRoutingService();
+ void locateSessionRouter();
+ void locateStateReplicator();
+
+ void configureEndpoints();
+ void registerPJSipModules();
+
+ bool mListeningToReplicator;
+
+ // Unique Id for this component's EndpointLocator.
+ // Used when registering with routing service.
+ std::string mRoutingId;
+
+ // Configuration
+ LocatorRegistrationWrapperPtr mConfigurationRegistration;
+ ConfigurationServicePtr mConfigurationService;
+ ConfigurationServicePrx mConfigurationServiceProxy;
+
+ // State Replication listener
+ SipStateReplicatorListenerPtr mReplicatorListener;
+ SipStateReplicatorListenerPrx mReplicatorListenerProxy;
+
+ // Implementation support classes
+ boost::shared_ptr<SipSessionManagerEventPublisher> mEventPublisher;
+ Routing::V1::EndpointLocatorPtr mEndpointLocator;
+ boost::shared_ptr<SipEndpointFactory> mEndpointFactory;
+ PJSipManager *mPJSipManager;
+
+ // Remote references
+ AsteriskSCF::Discovery::SmartProxy<SessionRouterPrx> mSessionRouter;
+ AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> mRoutingServiceLocatorRegistry;
+};
+
+static const string EndpointLocatorObjectId("SipChannelEndpointLocator");
+static const string ReplicaServiceId("SipChannelReplica");
+
+/**
+ * Override of factory method to create our custom replication context.
+ */
+ReplicationContextPtr SipSessionGateway::createReplicationContext(ReplicationStateType state)
+{
+ SipReplicationContextPtr context(new SipReplicationContext(state));
+ return context;
+}
+
+/**
+ * Register this component's primary public interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate our interfaces.
+ */
+void SipSessionGateway::registerPrimaryServices()
+{
+ // This is a required override. As a gateway, this component doesn't expose
+ // any interfaces on it's primary service adapter.
+}
+
+/**
+ * Register this component's backplane interfaces with the Service Locator.
+ * This enables other Asterisk SCF components to locate our interfaces.
+ */
+void SipSessionGateway::registerBackplaneServices()
+{
+ // Insure the default Component services are registered.
+ Component::registerBackplaneServices();
+
+ try
+ {
+ std::string serviceName = getCommunicator()->getProperties()->getPropertyWithDefault(
+ getName() + ".Service", "default");
+
+ // Register our RoutingAdmin interface with the Service Locator.
+ mConfigurationRegistration = wrapServiceForRegistration(mConfigurationServiceProxy,
+ ConfigurationDiscoveryCategory,
+ serviceName,
+ getName());
+ bool registered = registerBackplaneService(mConfigurationRegistration);
+ }
+ catch(const std::exception& e)
+ {
+ lg(Error) << "Exception in " << getName() << ", " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+ }
+}
+/**
+ * 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 SipSessionGateway::registerWithRoutingService()
+{
+ RegExSeq destinations;
+
+ mEndpointFactory->generateRoutingDestinations(destinations);
+
+ EndpointLocatorPrx locator = EndpointLocatorPrx::uncheckedCast(
+ getServiceAdapter()->createDirectProxy(getCommunicator()->stringToIdentity(EndpointLocatorObjectId)));
+ mRoutingServiceLocatorRegistry->addEndpointLocator(mRoutingId, destinations, locator);
+}
+
+/**
+ * Deregister our own Endpoint Locator from the Routing SErvice.
+ */
+void SipSessionGateway::deregisterFromRoutingService()
+{
+ mRoutingServiceLocatorRegistry->removeEndpointLocator(mRoutingId);
+}
+
+/**
+ * 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 SipSessionGateway::locateRoutingService()
+{
+ ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
+ genericparams->category = Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory;
+ genericparams->service =
+ getCommunicator()->getProperties()->getPropertyWithDefault("Sip.RoutingService", "default");
+ genericparams->id =
+ getCommunicator()->getProperties()->getPropertyWithDefault("Sip.RoutingId", "");
+
+ 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 SipSessionGateway::locateStateReplicator()
+{
+ if (getReplicationContext()->getState() == ACTIVE_STANDALONE)
+ {
+ return;
+ }
+
+ ServiceLocatorParamsPtr replicatorParams = new ServiceLocatorParams();
+ replicatorParams->category = SIP::V1::StateReplicatorDiscoveryCategory;
+ replicatorParams->service =
+ getCommunicator()->getProperties()->getPropertyWithDefault("Sip.StateReplicatorService", "default");
+
+ try
+ {
+ AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> pw(getServiceLocator(), replicatorParams, lg);
+ SipReplicationContextPtr sipReplicationContext =
+ 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);
+ }
+ catch (...)
+ {
+ lg(Error) << "State replicator could not be found, operating without.";
+ }
+}
+
+void SipSessionGateway::listenToStateReplicators()
+{
+ SipReplicationContextPtr sipReplicationContext =
+ static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+ if (mListeningToReplicator == true)
+ {
+ return;
+ }
+
+ if (!sipReplicationContext->getReplicator().isInitialized())
+ {
+ lg(Error) << getName() << " : State replicator could not be found. Unable to listen for state updates!";
+ return;
+ }
+
+ try
+ {
+ // Are we in standby mode?
+ if (sipReplicationContext->getState() == ACTIVE_IN_REPLICA_GROUP)
+ {
+ SipStateReplicatorPrx oneWayStateReplicator =
+ SipStateReplicatorPrx::uncheckedCast(sipReplicationContext->getReplicator()->ice_oneway());
+
+ oneWayStateReplicator->addListener(mReplicatorListenerProxy);
+ mListeningToReplicator = true;
+ }
+ }
+ 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 SipSessionGateway::stopListeningToStateReplicators()
+{
+ SipReplicationContextPtr sipReplicationContext =
+ static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+ if ((!sipReplicationContext->getReplicator().isInitialized()) || (mListeningToReplicator == false))
+ {
+ return;
+ }
+
+ try
+ {
+ SipStateReplicatorPrx oneWayStateReplicator =
+ SipStateReplicatorPrx::uncheckedCast(sipReplicationContext->getReplicator()->ice_oneway());
+
+ oneWayStateReplicator->removeListener(mReplicatorListenerProxy);
+ mListeningToReplicator = false;
+ }
+ catch (const Ice::Exception& e)
+ {
+ lg(Error) << e.what();
+ throw;
+ }
+}
+
+/**
+ * Get a reference to the Session Routing Service interface that we care about, and cache it in the Data Model.
+ * This will allow us to route sessions.
+ */
+void SipSessionGateway::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;
+}
+
+void SipSessionGateway::configureEndpoints()
+{
+ Ice::PropertiesPtr props = getCommunicator()->getProperties();
+ Ice::StringSeq endpointNames = props->getPropertyAsList("Sip.Endpoints");
+ for (Ice::StringSeq::iterator i = endpointNames.begin();
+ i != endpointNames.end();
+ ++i)
+ {
+ SipEndpointPtr endpoint = mEndpointFactory->createEndpoint(*i, props);
+ }
+}
+
+void SipSessionGateway::registerPJSipModules()
+{
+ SipReplicationContextPtr sipReplicationContext =
+ static_pointer_cast<SipReplicationContext>(getReplicationContext());
+
+ Ice::PropertiesPtr props = getCommunicator()->getProperties();
+ Ice::StringSeq moduleNames = props->getPropertyAsList("Sip.Modules");
+ for (Ice::StringSeq::iterator i = moduleNames.begin();
+ i != moduleNames.end();
+ ++i)
+ {
+ //We should probably delegate the responsibility of mapping
+ //module names to modules to the PJSIP session manager instead.
+ //Since there's only a single configurable module at the moment,
+ //we'll just do it here instead.
+ if ((*i) == "Session")
+ {
+ mPJSipManager->registerSessionModule(mEndpointFactory,
+ mSessionRouter, getServiceLocator(), sipReplicationContext);
+ }
+ else if ((*i) == "Logging" || (*i) == "Logger")
+ {
+ mPJSipManager->registerLoggingModule();
+ }
+ }
+ lg(Debug) << "Registered PJSIP modules";
+}
+
+/**
+ * Pre-init notification from the base component. Allows us
+ * to initialize things before the base component does anything
+ * else.
+ */
+void SipSessionGateway::onPreInitialize()
+{
+ try
+ {
+ // Initialize PJSIP
+ mPJSipManager = new PJSipManager(getCommunicator()->getProperties());
+ lg(Debug) << "Created PJSIP manager";
+
+ //As nice as it is of IceBox to provide us with a communicator,
+ //we're going to create our own so that we can provide it with a threadhook.
+ //Yes, this could be done via a plugin, but this is easier. Go away.
+ Ice::InitializationData id;
+ id.threadHook = new pjlibHook();
+ id.properties = getCommunicator()->getProperties();
+
+ setCommunicator(Ice::initialize(id));
+ }
+ catch(const std::exception& e)
+ {
+ lg(Critical) << "Major problems in " << getName() << " initialization: " << e.what();
+ }
+}
+
+/**
+ * This operation is called by the base Component class
+ * at times such as activation, or resumed, to allow us to
+ * add our own proxies with remote services.
+ */
+void SipSessionGateway::registerWithRemoteServices()
+{
+ // Register our Endpoint Locator so that we can provide endpoints to the
+ // Routing Service for the endpoints we manage.
+ registerWithRoutingService();
+}
+
+/**
+ * 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 SipSessionGateway::deregisterFromRemoteServices()
+{
+ deregisterFromRoutingService();
+}
+
+/**
+ * Post-init notification from the base component. Allows us
+ * to initialize things after the base component does common
+ * initialization.
+ */
+void SipSessionGateway::onPostInitialize()
+{
+ try
+ {
+ configureEndpoints();
+
+ registerPJSipModules();
+ }
+ catch(const std::exception& e)
+ {
+ lg(Critical) << "Major problems in " << getName() << " initialization: " << e.what();
+ }
+}
+
+/**
+ * Create the objects that implement the main services this component provides
+ * the system.
+ */
+void SipSessionGateway::createPrimaryServices()
+{
+ try
+ {
+ SipReplicationContextPtr sipReplicationContext =
+ 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";
+ }
+ catch(const Ice::Exception& e)
+ {
+ lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+ }
+}
+
+void SipSessionGateway::createBackplaneServices()
+{
+ // Include the base Component services.
+ 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)
+ {
+ lg(Critical) << getName() << " : " << BOOST_CURRENT_FUNCTION << " : " << e.what();
+ }
+}
+
+void SipSessionGateway::createReplicationStateListeners()
+{
+ try
+ {
+ // Create and publish our state replicator listener interface.
+ mReplicatorListener = new SipStateReplicatorListenerI(mEndpointFactory, mPJSipManager);
+ 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;
+ }
+}
+
+void SipSessionGateway::findRemoteServices()
+{
+ // Locate the Session Router so we can REALLY do routing.
+ locateSessionRouter();
+
+ // Locate the State Replicator so we can fail over.
+ locateStateReplicator();
+}
+
+/**
+ * Notification from the component that we're stopping.
+ */
+void SipSessionGateway::onStop()
+{
+ // Remove our endpoint locator from the routing service.
+ deregisterFromRoutingService();
+
+ //
+ // TODO: This is probably a mistake. Many things access the PJSipManager instance and will continue
+ // to do so until all of the threads have completed. It really should be reference counted.
+ //
+ delete mPJSipManager;
+}
+
+extern "C"
+{
+ASTERISK_SCF_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
+{
+ return new SipSessionGateway;
+}
+}
+
+}; // end SipSessionManager
+}; // end AsteriskSCF
diff --git a/src/SipSessionManagerApp.cpp b/src/SipSessionManagerApp.cpp
deleted file mode 100644
index 21dc803..0000000
--- a/src/SipSessionManagerApp.cpp
+++ /dev/null
@@ -1,636 +0,0 @@
-/*
- * 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 <pjlib.h>
-
-#include <Ice/Ice.h>
-#include <IceStorm/IceStorm.h>
-#include <IceBox/IceBox.h>
-#include <IceUtil/UUID.h>
-
-#include <boost/thread.hpp>
-#include <boost/shared_ptr.hpp>
-
-
-#include <AsteriskSCF/Core/Routing/RoutingIf.h>
-#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
-#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
-#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
-#include <AsteriskSCF/System/Component/ReplicaIf.h>
-#include <AsteriskSCF/Discovery/SmartProxy.h>
-#include <AsteriskSCF/System/Component/ConfigurationIf.h>
-
-#include <AsteriskSCF/Logger/IceLogger.h>
-#include <AsteriskSCF/logger.h>
-
-#include "SipSessionManagerEventPublisher.h"
-#include "SipSessionManagerEndpointLocator.h"
-#include "SipEndpointFactory.h"
-#include "PJSipSessionModule.h"
-#include "PJSipManager.h"
-#include "SipSession.h"
-#include "SipStateReplicator.h"
-#include "SipConfiguration.h"
-
-using namespace std;
-using namespace AsteriskSCF::SipSessionManager;
-using namespace AsteriskSCF::Core;
-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;
-
-namespace
-{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
-}
-
-namespace AsteriskSCF
-{
-namespace SipSessionManager
-{
-
-/**
- * This private class initializes the startup and controls the shutdown of the component.
- */
-class SipSessionManager : public IceBox::Service
-{
-public:
- SipSessionManager() : mDone(false) {}
- ~SipSessionManager()
- {
- // Smart pointers do your thing.
- mReplicaService = 0;
- mComponentService = 0;
- mConfigurationService = 0;
- mGlobalAdapter = 0;
- mLocalAdapter = 0;
- }
-
-public:
- // Overloads of IceBox::Service
- virtual void start(const string& name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
- virtual void stop();
-
-private:
- void initialize(const string& appName, const Ice::CommunicatorPtr& ic);
- void registerWithServiceLocator();
- void deregisterFromServiceLocator();
- void setCategory(const ServiceManagementPrx& serviceManagement, const string &category);
- void locateRoutingService();
- void locateSessionRouter();
- void locateStateReplicator();
- void registerWithStateReplicator();
- void registerWithRoutingService();
- void deregisterFromRoutingService();
- void configureEndpoints();
- void registerPJSipModules();
- void deregisterFromStateReplicator();
-
- bool mDone;
- std::string mAppName;
- Ice::CommunicatorPtr mCommunicator;
-
- std::string mRoutingId;
-
- // The global object adapter is for shared services that could be replicated from another server
- Ice::ObjectAdapterPtr mGlobalAdapter;
-
- // The local object adapter is for services unique to this instance of the service
- Ice::ObjectAdapterPtr mLocalAdapter;
-
- ServiceLocatorManagementPrx mServiceLocatorManagement;
-
- ServiceManagementPrx mComponentServiceManagement;
- ServiceManagementPrx mConfigurationManagement;
- std::string mConfigCompareGuid;
- ReplicaPtr mReplicaService;
- ComponentServicePtr mComponentService;
- ConfigurationServicePtr mConfigurationService;
- ConfigurationServicePrx mConfigurationServiceProxy;
- PJSipManager *mPJSipManager;
- SipStateReplicatorListenerPtr mReplicatorListener;
- SipStateReplicatorListenerPrx mReplicatorListenerProxy;
- boost::shared_ptr<SipEndpointFactory> mEndpointFactory;
- ServiceLocatorPrx mServiceLocator;
- AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> mStateReplicator;
- AsteriskSCF::Discovery::SmartProxy<SessionRouterPrx> mSessionRouter;
- AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> mRoutingServiceLocatorRegistry;
- boost::shared_ptr<SipSessionManagerEventPublisher> mEventPublisher;
- Routing::V1::EndpointLocatorPtr mEndpointLocator;
-};
-
-static const string ComponentServiceId("SipChannelComponent");
-static const string EndpointLocatorObjectId("SipChannelEndpointLocator");
-static const string ReplicaServiceId("SipChannelReplica");
-
-/**
- * This class provides implementation for the ComponentService interface, which
- * every Asterisk SCF component is expected to publish.
- */
-class ComponentServiceImpl : public ComponentService
-{
-public:
- ComponentServiceImpl(SipSessionManager &service) : mService(service) {}
-
-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:
- SipSessionManager& mService; // TODO reference?
-};
-
-/**
- * This class provides implementation for the Replica interface.
- */
-class ReplicaImpl : public Replica
-{
-public:
- ReplicaImpl(const Ice::ObjectAdapterPtr& adapter) : mAdapter(adapter), mPaused(false), mActive(true) { }
-
- bool isActive(const Ice::Current&)
- {
- return mActive;
- }
-
- bool activate(const Ice::Current&)
- {
- mActive = true;
-
- for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener =
- mListeners.begin(); listener != mListeners.end(); ++listener)
- {
- (*listener)->activated(ReplicaPrx::uncheckedCast(
- mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
- }
-
- return true;
- }
-
- void standby(const Ice::Current&)
- {
- mActive = false;
-
- for (vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx>::const_iterator listener =
- mListeners.begin(); listener != mListeners.end(); ++listener)
- {
- (*listener)->onStandby(ReplicaPrx::uncheckedCast(
- mAdapter->createDirectProxy(mAdapter->getCommunicator()->stringToIdentity(ReplicaServiceId))));
- }
- }
-
- void addListener(const AsteriskSCF::System::Component::V1::ReplicaListenerPrx& listener, const Ice::Current&)
- {
- mListeners.push_back(listener);
- }
-
- void removeListener(const AsteriskSCF::System::Component::V1::ReplicaListenerPrx& listener, const Ice::Current&)
- {
- mListeners.erase(std::remove(mListeners.begin(), mListeners.end(), listener), mListeners.end());
- }
-
-private:
- /**
- * Pointer to the object adapter we exist on.
- */
- Ice::ObjectAdapterPtr mAdapter;
-
- /**
- * Listeners that we need to push state change notifications out to.
- */
- vector<AsteriskSCF::System::Component::V1::ReplicaListenerPrx> mListeners;
-
- bool mPaused;
-
- bool mActive;
-};
-
-/**
- * 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 SipSessionManager::setCategory(const 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 SipSessionManager::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(
- mCommunicator->propertyToProxy("LocatorServiceManagement.Proxy"));
-
- if (mServiceLocatorManagement == 0)
- {
- lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected.";
- return;
- }
-
- // Get a proxy to our ComponentService interface and add it to the Service Locator.
- Ice::ObjectPrx componentServiceObjectPrx =
- mLocalAdapter->createDirectProxy(mCommunicator->stringToIdentity(ComponentServiceId));
- ComponentServicePrx componentServicePrx = ComponentServicePrx::checkedCast(componentServiceObjectPrx);
-
- // The GUID passed in to add service needs to be unique for reporting.
- string componentServiceGuid("SipSessionManager");
- mComponentServiceManagement = ServiceManagementPrx::uncheckedCast(
- mServiceLocatorManagement->addService(componentServicePrx, componentServiceGuid));
-
- setCategory(mComponentServiceManagement, AsteriskSCF::SIP::V1::ComponentServiceDiscoveryCategory);
-
- if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.Standalone", "false") == "true")
- {
- // Publish the configuration service IceStorm topic so everybody gets configuration
- mConfigurationManagement = ServiceManagementPrx::uncheckedCast(
- mServiceLocatorManagement->addService(mConfigurationServiceProxy, ""));
-
- // Populate the configuration parameters with details so we can be found
- ServiceLocatorParamsPtr configurationParams = new ServiceLocatorParams();
- configurationParams->category = ConfigurationDiscoveryCategory;
- configurationParams->service = mCommunicator->getProperties()->getPropertyWithDefault("SipConfiguration.Service", "");
- configurationParams->id = mCommunicator->getProperties()->getPropertyWithDefault("SipConfiguration.Id", "");
- mConfigurationManagement->addLocatorParams(configurationParams, "");
- }
-
- // TBD... We may have other interfaces to publish to the Service Locator.
- }
- catch(...)
- {
- lg(Error) << "Exception in " << mAppName << " registerWithServiceLocator()";
- }
-}
-
-/**
- * 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 SipSessionManager::registerWithRoutingService()
-{
- RegExSeq destinations;
-
- mEndpointFactory->generateRoutingDestinations(destinations);
-
- EndpointLocatorPrx locator = EndpointLocatorPrx::uncheckedCast(
- mGlobalAdapter->createDirectProxy(mCommunicator->stringToIdentity(EndpointLocatorObjectId)));
- mRoutingServiceLocatorRegistry->addEndpointLocator(mRoutingId, destinations, locator);
-}
-
-/**
- * Deregister our own Endpoint Locator from the Routing SErvice.
- */
-void SipSessionManager::deregisterFromRoutingService()
-{
- mRoutingServiceLocatorRegistry->removeEndpointLocator(mRoutingId);
-}
-
-/**
- * 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 SipSessionManager::locateRoutingService()
-{
- if (mServiceLocator == 0)
- {
- mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
- }
-
- ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
- genericparams->category = Routing::V1::RoutingServiceLocatorRegistryDiscoveryCategory;
-
- AsteriskSCF::Discovery::SmartProxy<LocatorRegistryPrx> pw(mServiceLocator, genericparams, lg);
- mRoutingServiceLocatorRegistry = pw;
-
- // This exists here since it may need to be known before actually contacting the routing service
- mRoutingId = mCommunicator->getProperties()->getPropertyWithDefault("Sip.RoutingId", "pjsip");
-}
-
-void SipSessionManager::locateStateReplicator()
-{
- if (mServiceLocator == 0)
- {
- mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
- }
-
- ServiceLocatorParamsPtr replicatorParams = new ServiceLocatorParams();
- replicatorParams->category = SIP::V1::StateReplicatorDiscoveryCategory;
- replicatorParams->service =
- mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorService", "default");
- replicatorParams->id =
- mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorName", "default");
-
- try
- {
- AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx> pw(mServiceLocator, replicatorParams, lg);
- mStateReplicator = pw;
- }
- catch (...)
- {
- lg(Error) << "State replicator could not be found, operating without.";
- }
-}
-
-void SipSessionManager::registerWithStateReplicator()
-{
- if (mStateReplicator == 0)
- {
- return;
- }
-
- if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.Standalone", "false") == "false")
- {
- ConfigurationReplicatorPrx configurationReplicator = ConfigurationReplicatorPrx::checkedCast(
- mStateReplicator.initialize(), ReplicatorFacet);
- configurationReplicator->registerConfigurationService(mConfigurationServiceProxy);
- }
-
- if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorListener", "no") == "yes")
- {
- mStateReplicator->addListener(mReplicatorListenerProxy);
- mReplicaService->standby();
- }
-}
-
-/**
- * Get a reference to the Session Routing Service interface that we care about, and cache it in the Data Model.
- * This will allow us to route sessions.
- */
-void SipSessionManager::locateSessionRouter()
-{
- if (mServiceLocator == 0)
- {
- mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
- }
-
- ServiceLocatorParamsPtr genericparams = new ServiceLocatorParams();
- genericparams->category = Routing::V1::SessionRouterDiscoveryCategory;
-
- AsteriskSCF::Discovery::SmartProxy<SessionRouterPrx> pw(mServiceLocator, genericparams, lg);
- mSessionRouter = pw;
-}
-
-/**
- * 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 SipSessionManager::deregisterFromServiceLocator()
-{
- try
- {
- mComponentServiceManagement->unregister();
- if (mConfigurationManagement)
- {
- mConfigurationManagement->unregister();
- }
- }
- catch(...)
- {
- lg(Error) << "Had trouble in deregisterFromServiceLocator().";
- }
-}
-
-void SipSessionManager::configureEndpoints()
-{
- Ice::PropertiesPtr props = mCommunicator->getProperties();
- Ice::StringSeq endpointNames = props->getPropertyAsList("Sip.Endpoints");
- for (Ice::StringSeq::iterator i = endpointNames.begin();
- i != endpointNames.end();
- ++i)
- {
- SipEndpointPtr endpoint = mEndpointFactory->createEndpoint(*i, props);
- }
-}
-
-void SipSessionManager::registerPJSipModules()
-{
- Ice::PropertiesPtr props = mCommunicator->getProperties();
- Ice::StringSeq moduleNames = props->getPropertyAsList("Sip.Modules");
- for (Ice::StringSeq::iterator i = moduleNames.begin();
- i != moduleNames.end();
- ++i)
- {
- //We should probably delegate the responsibility of mapping
- //module names to modules to the PJSIP session manager instead.
- //Since there's only a single configurable module at the moment,
- //we'll just do it here instead.
- if (*i == "Session")
- {
- mPJSipManager->registerSessionModule(mEndpointFactory,
- mSessionRouter, mServiceLocator, mStateReplicator, mReplicaService);
- }
- else if (*i == "Logging" || *i == "Logger")
- {
- mPJSipManager->registerLoggingModule();
- }
- }
- lg(Debug) << "Registered PJSIP modules";
-}
-
-void SipSessionManager::deregisterFromStateReplicator()
-{
- if (!mConfigCompareGuid.empty())
- {
- mServiceLocatorManagement->removeCompare(mConfigCompareGuid);
- }
-
- if (mConfigurationManagement)
- {
- mConfigurationManagement->unregister();
- }
-
- if (mReplicaService->isActive() == true)
- {
- return;
- }
-
- mStateReplicator->removeListener(mReplicatorListenerProxy);
-}
-
-/**
- * Create the primary functional objects of this component.
- * @param appName Name of the application or component.
- */
-void SipSessionManager::initialize(const string& appName, const Ice::CommunicatorPtr& ic)
-{
- try
- {
- mAppName = appName;
-
- // Initialize PJSIP
- mPJSipManager = new PJSipManager(ic->getProperties());
- lg(Debug) << "Created PJSIP manager";
-
- //As nice as it is of IceBox to provide us with a communicator,
- //we're going to create our own so that we can provide it with a threadhook.
- //Yes, this could be done via a plugin, but this is easier. Go away.
- Ice::InitializationData id;
- id.threadHook = new pjlibHook();
- id.properties = ic->getProperties();
-
- mCommunicator = Ice::initialize(id);
-
- // Create the global adapter.
- mGlobalAdapter = mCommunicator->createObjectAdapter("SipSessionManagerAdapter");
- lg(Debug) << "Created global object adapter";
-
- // Create the local adapter.
- mLocalAdapter = mCommunicator->createObjectAdapter("SipSessionManagerLocalAdapter");
- lg(Debug) << "Created local object adapter";
-
- mEventPublisher.reset(new SipSessionManagerEventPublisher(mLocalAdapter));
- lg(Debug) << "Created SIP Session Manager event publisher";
-
- // We're not actually registering with the service locator at this point, but
- // several components we create could really use the proxy, so we create
- // it now.
- mServiceLocator = ServiceLocatorPrx::checkedCast(mCommunicator->propertyToProxy("LocatorService.Proxy"));
-
- // Create and publish our Replica interface support.
- mReplicaService = new ReplicaImpl(mLocalAdapter);
- mLocalAdapter->add(mReplicaService, mCommunicator->stringToIdentity(ReplicaServiceId));
- lg(Debug) << "Created SIP Replica Implementation";
-
- mEndpointFactory.reset(new SipEndpointFactory(mGlobalAdapter, mPJSipManager, mServiceLocator, mReplicaService));
- 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.
- locateRoutingService();
-
- // Create and publish our Configuration interface support.
- mConfigurationService = createConfigurationServant(mPJSipManager, mEndpointFactory, mRoutingId, mRoutingServiceLocatorRegistry);
- mConfigurationServiceProxy = ConfigurationServicePrx::uncheckedCast(mLocalAdapter->addWithUUID(
- mConfigurationService));
- lg(Debug) << "Created SIP Configuration Implementation";
-
- // Create and configure our Endpoint Locator.
- mEndpointLocator = new SipSessionManagerEndpointLocator(mEndpointFactory);
- mGlobalAdapter->add(mEndpointLocator, mCommunicator->stringToIdentity(EndpointLocatorObjectId));
- lg(Debug) << "Got proxy to endpoint locator";
-
- // Create and publish our ComponentService interface support.
- mComponentService = new ComponentServiceImpl(*this);
- mLocalAdapter->add(mComponentService, mCommunicator->stringToIdentity(ComponentServiceId));
- lg(Debug) << "Added component service to object adapter";
-
- // Create and publish our state replicator listener interface.
- mReplicatorListener = new SipStateReplicatorListenerI(mEndpointFactory, mPJSipManager);
- mReplicatorListenerProxy =
- SipStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
- lg(Debug) << "Got proxy to SIP state replicator";
-
- mGlobalAdapter->activate();
- mLocalAdapter->activate();
- lg(Debug) << "Activated object adapters";
-
- configureEndpoints();
- lg(Debug) << "Endpoints configured";
- }
- catch(...)
- {
- lg(Critical) << "Major problems in " << mAppName << " initialization()";
- }
-}
-
-/**
- * Overload of the IceBox::Service::start method.
- */
-void SipSessionManager::start(const string& name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq&)
-{
- // Initialize this component.
- initialize(name, ic);
-
- // Plug into the Asterisk SCF discovery system so that the interfaces we provide
- // can be located.
- registerWithServiceLocator();
-
- // Locate the Session Router so we can REALLY do routing.
- locateSessionRouter();
-
- // Locate the State Replicator so we can fail over!
- locateStateReplicator();
-
- registerPJSipModules();
-
- // Register with the state replicator if we are a listener
- registerWithStateReplicator();
-
- // Register our Endpoint Locator so that we can provide endpoints to the
- // Routing Service for the endpoints we manage.
- if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorListener", "no") != "yes")
- {
- //Only register with the routing service if we're the primary SIP instance.
- registerWithRoutingService();
- }
-}
-
-/**
- * Overload of the IceBox::Service::stop method.
- */
-void SipSessionManager::stop()
-{
- // Remove our interfaces from the service locator.
- deregisterFromServiceLocator();
-
- // Remove our endpoint locator from the routing service.
- deregisterFromRoutingService();
-
- // Remove our state listener
- deregisterFromStateReplicator();
-
- //
- // TODO: This is probably a mistake. Many things access the PJSipManager instance and will continue
- // to do so until all of the threads have completed. It really should be reference counted.
- //
- delete mPJSipManager;
- mCommunicator->destroy();
-}
-
-extern "C"
-{
-ASTERISK_SCF_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
-{
- return new SipSessionManager;
-}
-}
-
-}; // end SipSessionManager
-}; // end AsteriskSCF
-----------------------------------------------------------------------
--
asterisk-scf/integration/sip.git
More information about the asterisk-scf-commits
mailing list