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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Sep 9 17:01:06 CDT 2011


branch "client-registration" has been updated
       via  6e3818ecf1213e1918454a129d1b49adcab0fc29 (commit)
       via  87a71b84f090c02df4091b65fb42f65dbf16e6d5 (commit)
      from  627496611f923896f9af9492d63b97c1eeb25b1d (commit)

Summary of changes:
 src/Component.cpp             |    9 ++++-
 src/SipClientRegistration.cpp |   58 ++++++++++++++++++++++++++++++--
 src/SipClientRegistration.h   |   19 ++++++++++-
 src/SipEndpoint.cpp           |   73 +++++++++++++++++++++++++++++++++++++----
 src/SipEndpoint.h             |   13 ++++++--
 src/SipEndpointFactory.cpp    |   11 +++++-
 src/SipEndpointFactory.h      |   21 +++++++++--
 7 files changed, 181 insertions(+), 23 deletions(-)


- Log -----------------------------------------------------------------
commit 6e3818ecf1213e1918454a129d1b49adcab0fc29
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Sep 9 16:19:54 2011 -0500

    Get activation and destruction in place.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index a7e9e1a..c7d7628 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -26,6 +26,7 @@ Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
 using namespace AsteriskSCF::SipSessionManager;
 using namespace AsteriskSCF::System::Hook::V1;
 using namespace AsteriskSCF::Configuration::SipSessionManager::V1;
+using namespace AsteriskSCF::System::Component::V1;
 
 void regCallback(struct pjsip_regc_cbparam *param)
 {
@@ -114,6 +115,28 @@ private:
 
 typedef IceUtil::Handle<RescheduleRegister> RescheduleRegisterPtr;
 
+class ClientRegistrationReplicaListener : public AsteriskSCF::System::Component::V1::ReplicaListener
+{
+public:
+    ClientRegistrationReplicaListener(const SipRegistrationClientPtr& client)
+        : mClient(client) { }
+
+    void activated(const ReplicaPrx&, const Ice::Current&)
+    {
+        mClient->sendRegister();
+    }
+
+    void onStandby(const ReplicaPrx&, const Ice::Current&)
+    {
+    }
+    void heartbeat(const ReplicaPrx&, bool, const Ice::Current&)
+    {
+    }
+
+private:
+    SipRegistrationClientPtr mClient;
+};
+
 using namespace AsteriskSCF::SIP::ExtensionPoint::V1;
 
 SipRegistrationClientManager::SipRegistrationClientManager()
@@ -154,7 +177,7 @@ SipRegistrationClient::SipRegistrationClient(
         const SipRegistrationClientManagerPtr& manager,
         const SipReplicationContextPtr& replicationContext,
         const Ice::ObjectAdapterPtr& backplaneAdapter,
-        const AsteriskSCF::System::Component::V1::ReplicaPrx& replica)
+        const ReplicaPrx& replica)
     : mEndpointName(sipEndpoint->getName()),
     mManager(manager),
     mTimer(new IceUtil::Timer()),
@@ -195,11 +218,24 @@ SipRegistrationClient::SipRegistrationClient(
     addContacts(confItem->contacts);
 }
 
-SipRegistrationClient::~SipRegistrationClient()
+void SipRegistrationClient::activate()
+{
+    ReplicaListenerPtr listener(new ClientRegistrationReplicaListener(this));
+    mReplicaListenerProxy = ReplicaListenerPrx::uncheckedCast(mBackplaneAdapter->addWithUUID(listener));
+    mReplica->addListener(mReplicaListenerProxy);
+}
+
+void SipRegistrationClient::destroy()
 {
+    mReplica->removeListener(mReplicaListenerProxy);
+    mBackplaneAdapter->remove(mReplicaListenerProxy->ice_getIdentity());
     pjsip_regc_destroy(mReg);
 }
 
+SipRegistrationClient::~SipRegistrationClient()
+{
+}
+
 void SipRegistrationClient::addContacts(const ContactInfoSeq& contacts)
 {
     unique_add(mContacts, contacts);
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index ce8745e..ca5581a 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -58,6 +58,7 @@ private:
 typedef IceUtil::Handle<SipRegistrationClientManager> SipRegistrationClientManagerPtr;
 
 class RescheduleRegister;
+class ClientRegistrationReplicaListener;
 
 /**
  * One of these exists per endpoint.
@@ -78,6 +79,10 @@ public:
 
     ~SipRegistrationClient();
 
+    void activate();
+
+    void destroy();
+
     void addContacts(const AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq& contacts);
 
     void removeContacts(const Ice::StringSeq& contacts);
@@ -104,7 +109,10 @@ private:
 
     AsteriskSCF::System::Component::V1::ReplicaPrx mReplica;
 
+    AsteriskSCF::System::Component::V1::ReplicaListenerPrx mReplicaListenerProxy;
+
     friend class RescheduleRegister;
+    friend class ClientRegistrationReplicaListener;
 };
 
 typedef IceUtil::Handle<SipRegistrationClient> SipRegistrationClientPtr;
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index bf953aa..c995952 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -328,9 +328,44 @@ void SipEndpoint::setDTMFMethod(AsteriskSCF::Configuration::SipSessionManager::V
     mImplPriv->mConfig.sessionConfig.dtmf = dtmf;
 }
 
+class MatchRegistration
+{
+public:
+    MatchRegistration(const std::string& aor)
+        : mAOR(aor) { }
+
+    bool operator()(const SipClientRegistrationItemPtr& item)
+    {
+        return item->aor == mAOR;
+    }
+private:
+    const std::string mAOR;
+};
+
 void SipEndpoint::updateClientRegistrations(SipClientRegistrationItemSeq& items)
 {
     lg(Debug) << "Updating client registrations for endpoint " << mImplPriv->mName;
+
+    //First step is to find registrations that exist for this endpoint but
+    //that no longer appear in configuration. These must be KILLED!!!!!
+    
+    for (std::map<std::string, SipRegistrationClientPtr>::iterator iter = mImplPriv->mClientRegistrations.begin(); 
+            iter != mImplPriv->mClientRegistrations.end(); )
+    {
+        SipClientRegistrationItemSeq::iterator toRemove = std::find_if(items.begin(), items.end(), MatchRegistration(iter->first));
+        if (toRemove != items.end())
+        {
+            iter->second->destroy();
+            mImplPriv->mClientRegistrations.erase(iter++);
+        }
+        else
+        {
+            ++iter;
+        }
+    }
+
+    //Next we go through the configured registrations and either update existing
+    //client registrations or create new ones.
     for (SipClientRegistrationItemSeq::iterator item = items.begin();
             item != items.end(); ++item)
     {
@@ -354,6 +389,8 @@ void SipEndpoint::updateClientRegistrations(SipClientRegistrationItemSeq& items)
                         mImplPriv->mReplicationContext,
                         mImplPriv->mBackplaneAdapter,
                         mImplPriv->mReplica);
+
+            mImplPriv->mClientRegistrations[(*item)->aor]->activate();
         }
     }
 }

commit 87a71b84f090c02df4091b65fb42f65dbf16e6d5
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Sep 9 12:26:14 2011 -0500

    Get the necessary pieces of stuff to the client registration for replication support.

diff --git a/src/Component.cpp b/src/Component.cpp
index ca64fe9..405ee50 100644
--- a/src/Component.cpp
+++ b/src/Component.cpp
@@ -524,8 +524,13 @@ void Component::createPrimaryServices()
         mEventPublisher.reset(new SipSessionManagerEventPublisher(getServiceAdapter()));
         lg(Debug) << "Created SIP Session Manager event publisher";
 
-        mEndpointFactory.reset(new SipEndpointFactory(getServiceAdapter(), 
-               mPJSipManager, getServiceLocator(), sipReplicationContext));
+        mEndpointFactory.reset(new SipEndpointFactory(
+                    getServiceAdapter(),
+                    getBackplaneAdapter(),
+                    mPJSipManager,
+                    getServiceLocator(),
+                    sipReplicationContext,
+                    getReplicaProxy()));
         lg(Debug) << "Created SIP endpoint factory";
 
 	    // Locate the Routing Service so that we can do routing. This is done here so it can be
diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index e389ff7..a7e9e1a 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -66,7 +66,6 @@ struct MakeContact
 
     pj_str_t operator() (const ContactInfo& info)
     {
-        lg(Debug) << "Making contact from " << info.contactURI << " and " << info.expiration;
         std::stringstream str;
         str << info.contactURI << ";expires=" << info.expiration;
         pj_str_t ret;
@@ -152,8 +151,16 @@ SipRegistrationClient::SipRegistrationClient(
         const SipClientRegistrationItemPtr& confItem,
         pjsip_endpoint* pjEndpoint,
         const SipEndpointPtr& sipEndpoint,
-        const SipRegistrationClientManagerPtr manager)
-    : mEndpointName(sipEndpoint->getName()), mManager(manager), mTimer(new IceUtil::Timer())
+        const SipRegistrationClientManagerPtr& manager,
+        const SipReplicationContextPtr& replicationContext,
+        const Ice::ObjectAdapterPtr& backplaneAdapter,
+        const AsteriskSCF::System::Component::V1::ReplicaPrx& replica)
+    : mEndpointName(sipEndpoint->getName()),
+    mManager(manager),
+    mTimer(new IceUtil::Timer()),
+    mReplicationContext(replicationContext),
+    mBackplaneAdapter(backplaneAdapter),
+    mReplica(replica)
 {
     pjsip_regc_create(pjEndpoint, this, regCallback, &mReg);
 
@@ -213,6 +220,12 @@ void SipRegistrationClient::removeContacts(const Ice::StringSeq& contacts)
 
 void SipRegistrationClient::sendRegister()
 {
+    //Replicas just hold onto the necessary information. They don't actually
+    //send registrations until they become active.
+    if (!mReplicationContext->isActive())
+    {
+        return;
+    }
 
     //There's a decent chance that there's no actual
     //scheduled task, but in case there is, we need
@@ -243,6 +256,7 @@ void SipRegistrationClient::handleRegisterResponse(pjsip_regc_cbparam *param)
         break;
     case 200:
         //This is a success!
+        lg(Debug) << "Endpoint " << mEndpointName << " registered successfully.";
         break;
     case 401:
     case 407:
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index 2941b36..ce8745e 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -71,7 +71,10 @@ public:
             const AsteriskSCF::Configuration::SipSessionManager::V1::SipClientRegistrationItemPtr& confItem,
             pjsip_endpoint* pjEndpoint,
             const SipEndpointPtr& sipEndpoint,
-            const SipRegistrationClientManagerPtr manager);
+            const SipRegistrationClientManagerPtr& manager,
+            const SipReplicationContextPtr& replicationContext,
+            const Ice::ObjectAdapterPtr& backplaneAdapter,
+            const AsteriskSCF::System::Component::V1::ReplicaPrx& replica);
 
     ~SipRegistrationClient();
 
@@ -95,6 +98,12 @@ private:
     IceUtil::TimerTaskPtr mTimerTask;
     IceUtil::TimerPtr mTimer;
 
+    SipReplicationContextPtr mReplicationContext;
+
+    Ice::ObjectAdapterPtr mBackplaneAdapter;
+
+    AsteriskSCF::System::Component::V1::ReplicaPrx mReplica;
+
     friend class RescheduleRegister;
 };
 
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index b39fcc7..bf953aa 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -38,6 +38,7 @@ using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Replication::SipSessionManager::V1;
 using namespace AsteriskSCF::Discovery;
 using namespace AsteriskSCF::Configuration::SipSessionManager::V1;
+using namespace AsteriskSCF::System::Component::V1;
 
 namespace
 {
@@ -179,12 +180,22 @@ public:
     /**
      * Constructor for the SipEndpointImplPriv class.
      */
-    SipEndpointImplPriv(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
-            const std::string& name, const PJSipManagerPtr& manager,
+    SipEndpointImplPriv(const Ice::ObjectAdapterPtr& adapter,
+            const Ice::ObjectAdapterPtr& backplaneAdapter,
+            const boost::shared_ptr<SipEndpointFactory>& factory,
+            const std::string& name,
+            const PJSipManagerPtr& manager,
             const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-            const SipReplicationContextPtr& replicationContext) :
-        mName(name), mAdapter(adapter), mEndpointFactory(factory), mManager(manager), mServiceLocator(serviceLocator),
+            const SipReplicationContextPtr& replicationContext,
+            const ReplicaPrx& replica) :
+        mName(name),
+        mAdapter(adapter),
+        mBackplaneAdapter(backplaneAdapter),
+        mEndpointFactory(factory),
+        mManager(manager),
+        mServiceLocator(serviceLocator),
         mReplicationContext(replicationContext),
+        mReplica(replica),
         mDefaultListeners(new AsteriskSCF::Collections::ProxySet<SessionListenerPrx>(adapter, lg, "Default Session Listeners")),
         mDefaultSessionCookies(new AsteriskSCF::Collections::HandleSet<SessionCookiePtr>(lg, "Default Cookies"))
     {
@@ -206,6 +217,7 @@ public:
      */
     Ice::ObjectAdapterPtr mAdapter;
 
+    Ice::ObjectAdapterPtr mBackplaneAdapter;
     /**
      * The endpoint factory that created us.
      */
@@ -238,6 +250,7 @@ public:
 
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
     SipReplicationContextPtr mReplicationContext;
+    ReplicaPrx mReplica;
     AsteriskSCF::Collections::ProxySet<SessionListenerPrx>::SetPtr mDefaultListeners;
     AsteriskSCF::Collections::HandleSet<SessionCookiePtr>::SetPtr mDefaultSessionCookies;
 
@@ -245,12 +258,14 @@ public:
 };
 
 SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, 
+    const Ice::ObjectAdapterPtr& backplaneAdapter,
     const boost::shared_ptr<SipEndpointFactory>& factory,
     std::string name, 
     const PJSipManagerPtr& manager, 
     const ServiceLocatorPrx& serviceLocator,
-    const SipReplicationContextPtr& replicationContext)
-    : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replicationContext))
+    const SipReplicationContextPtr& replicationContext,
+    const ReplicaPrx& replica)
+    : mImplPriv(new SipEndpointImplPriv(adapter, backplaneAdapter, factory, name, manager, serviceLocator, replicationContext, replica))
 {
     lg(Debug) << "Constructing SIP endpoint " << name;
 
@@ -331,7 +346,14 @@ void SipEndpoint::updateClientRegistrations(SipClientRegistrationItemSeq& items)
         {
             //New one!
             mImplPriv->mClientRegistrations[(*item)->aor] =
-                new SipRegistrationClient(*item, mImplPriv->mManager->getEndpoint(), this, mImplPriv->mManager->getClientRegistrationManager());
+                new SipRegistrationClient(
+                        *item,
+                        mImplPriv->mManager->getEndpoint(),
+                        this,
+                        mImplPriv->mManager->getClientRegistrationManager(),
+                        mImplPriv->mReplicationContext,
+                        mImplPriv->mBackplaneAdapter,
+                        mImplPriv->mReplica);
         }
     }
 }
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index 9ee243f..776f66c 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -34,6 +34,7 @@
 #include <AsteriskSCF/Media/RTP/MediaRTPIf.h>
 #include <AsteriskSCF/Media/SDP/MediaSDPIf.h>
 #include <AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.h>
+#include <AsteriskSCF/System/Component/ReplicaIf.h>
 
 #include "SipSession.h"
 #include "SipReplicationContext.h"
@@ -270,9 +271,15 @@ class SipEndpointImplPriv;
 class SipEndpoint : public AsteriskSCF::SessionCommunications::V1::SessionEndpoint
 {
 public:
-    SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory, std::string name, 
-        const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, 
-        const SipReplicationContextPtr& replicationContext);
+    SipEndpoint(
+            const Ice::ObjectAdapterPtr& adapter,
+            const Ice::ObjectAdapterPtr& backplaneAdapter,
+            const boost::shared_ptr<SipEndpointFactory>& factory,
+            std::string name,
+            const PJSipManagerPtr& manager,
+            const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+            const SipReplicationContextPtr& replicationContext,
+            const AsteriskSCF::System::Component::V1::ReplicaPrx& replica);
 
     bool operator==(const std::string &name) const;
 
diff --git a/src/SipEndpointFactory.cpp b/src/SipEndpointFactory.cpp
index ce8de77..2be256d 100644
--- a/src/SipEndpointFactory.cpp
+++ b/src/SipEndpointFactory.cpp
@@ -32,8 +32,15 @@ namespace SipSessionManager
 {
 SipEndpointPtr SipEndpointFactory::createEndpoint(std::string endpointName)
 {
-    SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), endpointName, mManager, 
-        mServiceLocator, mReplicationContext);
+    SipEndpointPtr endpoint = new SipEndpoint(
+            mAdapter,
+            mBackplaneAdapter,
+            shared_from_this(),
+            endpointName,
+            mManager,
+            mServiceLocator,
+            mReplicationContext,
+            mReplica);
     mEndpoints.push_back(endpoint);
     return endpoint;
 }
diff --git a/src/SipEndpointFactory.h b/src/SipEndpointFactory.h
index 13a63ed..fbefdd2 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
@@ -38,10 +38,19 @@ namespace SipSessionManager
 class SipEndpointFactory : public boost::enable_shared_from_this<SipEndpointFactory>
 {
 public:
-    SipEndpointFactory(const Ice::ObjectAdapterPtr& adapter, const PJSipManagerPtr& manager,
-        const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const SipReplicationContextPtr& replicationContext) :
-        mAdapter(adapter), mManager(manager), mServiceLocator(serviceLocator), mReplicationContext(replicationContext) {};
+    SipEndpointFactory(
+            const Ice::ObjectAdapterPtr& adapter,
+            const Ice::ObjectAdapterPtr& backplaneAdapter,
+            const PJSipManagerPtr& manager,
+            const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+            const SipReplicationContextPtr& replicationContext,
+            const AsteriskSCF::System::Component::V1::ReplicaPrx& replica) :
+        mAdapter(adapter),
+        mBackplaneAdapter(backplaneAdapter),
+        mManager(manager),
+        mServiceLocator(serviceLocator),
+        mReplicationContext(replicationContext),
+        mReplica(replica){};
 
     SipEndpointPtr createEndpoint(std::string);
 
@@ -57,6 +66,8 @@ private:
      */
     Ice::ObjectAdapterPtr mAdapter;
 
+    Ice::ObjectAdapterPtr mBackplaneAdapter;
+
     /**
      * A vector of endpoints that this factory has created.
      */
@@ -76,6 +87,8 @@ private:
      * A pointer to the replica information.
      */
     SipReplicationContextPtr mReplicationContext;
+
+    AsteriskSCF::System::Component::V1::ReplicaPrx mReplica;
 };
 
 }; // end SipSessionManager

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list