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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Jun 20 09:45:15 CDT 2011


branch "registrar" has been updated
       via  a6bfcd47c9f662ac6dd4a2318d96579737a12837 (commit)
      from  57993cd407779a00004dc426cb282f06bccb5bd5 (commit)

Summary of changes:
 src/PJSipRegistrarModule.cpp       |   19 +++++---
 src/PJSipRegistrarModule.h         |   88 ++++++++++++++++++------------------
 src/SipStateReplicatorListener.cpp |   10 ++--
 3 files changed, 60 insertions(+), 57 deletions(-)


- Log -----------------------------------------------------------------
commit a6bfcd47c9f662ac6dd4a2318d96579737a12837
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Jun 20 09:45:53 2011 -0500

    Replicate state on binding expiration.

diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index 8f816bb..4bc48df 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -38,15 +38,18 @@ static void registrationExpired(pj_timer_heap_t *, struct pj_timer_entry *entry)
     BindingWrapper *wrapper = static_cast<BindingWrapper *>(entry->user_data);
     lg(Debug) << "Detected expiration of binding " << wrapper->mBinding->contact;
     wrapper->cancelRegistrationExpiration();
-    BindingWrapperSeq& currentBindings = wrapper->mRegistrar->getAORBindingWrappers(wrapper->mAOR);
-    wrapper->mRegistrar->removeBinding(currentBindings, wrapper);
+    RegistrarIPtr registrar = wrapper->mRegModule->getRegistrar();
+    BindingWrapperSeq& currentBindings = registrar->getAORBindingWrappers(wrapper->mAOR);
+    registrar->removeBinding(currentBindings, wrapper);
     if (currentBindings.empty())
     {
-        wrapper->mRegistrar->removeAOR(wrapper->mAOR);
+        registrar->removeAOR(wrapper->mAOR);
     }
+    BindingWrapperSeq emptySeq;
+    BindingWrapperSeq toRemove;
+    toRemove.push_back(wrapper);
+    wrapper->mRegModule->replicateState(wrapper->mAOR, emptySeq, emptySeq, toRemove);
     delete wrapper;
-    //Note that we do not replicate state when a binding expires. This is because replicas
-    //maintain their own timers and will erase the bindings themselves when they expire.
 }
 
 static int expirationId;
@@ -54,10 +57,10 @@ static int expirationId;
 BindingWrapper::BindingWrapper(
         int expiration,
         const BindingPtr& binding,
-        const RegistrarIPtr& registrar,
+        const PJSipRegistrarModulePtr& regModule,
         pjsip_endpoint *endpt,
         const std::string& aor)
-    : mRegistrar(registrar), mBinding(binding), mEndpoint(endpt), mAOR(aor)
+    : mRegModule(regModule), mBinding(binding), mEndpoint(endpt), mAOR(aor)
 {
     pj_timer_entry_init(&mEntry, expirationId++, this, registrationExpired);
     pj_time_val delay = {expiration, 0};
@@ -464,7 +467,7 @@ BindingWrapper *PJSipRegistrarModule::createNewBinding(pjsip_contact_hdr *contac
         << ", and Expires: " << expiration;
 
     BindingPtr binding(new Binding(contactURIStr, callID, cSeq, time(NULL) + expiration));
-    BindingWrapper *wrapper(new BindingWrapper(expiration, binding, mRegistrar, mEndpoint, aor));
+    BindingWrapper *wrapper(new BindingWrapper(expiration, binding, this, mEndpoint, aor));
     //We could just return binding, but using wrapper here makes the compiler
     //not complain about an unused variable.
     return wrapper;
diff --git a/src/PJSipRegistrarModule.h b/src/PJSipRegistrarModule.h
index 7203ef3..885b9ad 100644
--- a/src/PJSipRegistrarModule.h
+++ b/src/PJSipRegistrarModule.h
@@ -28,50 +28,7 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-class RegistrarI;
-typedef IceUtil::Handle<RegistrarI> RegistrarIPtr;
-
-class BindingWrapper
-{
-public:
-    BindingWrapper(
-            int expiration,
-            const AsteriskSCF::SIP::Registration::V1::BindingPtr& binding,
-            const RegistrarIPtr& registrar,
-            pjsip_endpoint *endpt,
-            const std::string& aor);
-
-    ~BindingWrapper();
-
-    /**
-     * Called when a binding expires.
-     */
-    void expireRegistration();
-    /**
-     * Schedule expiration of a binding.
-     */
-    void scheduleRegistrationExpiration(int expiration);
-    /**
-     * Cancel the expiration of a binding.
-     */
-    void cancelRegistrationExpiration();
-
-    /**
-     * Update the binding in the wrapper with new information. This will
-     * result in rescheduling destruction of the binding.
-     */
-    void updateBinding(const std::string &callID, int cSeq, int expiration);
-
-    bool operator==(const BindingWrapper& rhs);
-    bool operator==(const AsteriskSCF::SIP::Registration::V1::BindingPtr& rhs);
-
-    RegistrarIPtr mRegistrar;
-    AsteriskSCF::SIP::Registration::V1::BindingPtr mBinding;
-    pjsip_endpoint *mEndpoint;
-    pj_timer_entry mEntry;
-    const std::string mAOR;
-};
-
+class BindingWrapper;
 typedef std::vector<BindingWrapper *> BindingWrapperSeq;
 typedef std::map<std::string, BindingWrapperSeq> BindingWrapperDict;
 
@@ -107,6 +64,8 @@ private:
     std::vector<AsteriskSCF::SIP::Registration::V1::RegistrarListenerPrx> mListeners;
 };
 
+typedef IceUtil::Handle<RegistrarI> RegistrarIPtr;
+
 class PJSipRegistrarModule : public PJSipModule
 {
 public:
@@ -171,5 +130,46 @@ private:
 
 typedef IceUtil::Handle<PJSipRegistrarModule> PJSipRegistrarModulePtr;
 
+class BindingWrapper
+{
+public:
+    BindingWrapper(
+            int expiration,
+            const AsteriskSCF::SIP::Registration::V1::BindingPtr& binding,
+            const PJSipRegistrarModulePtr& regModule,
+            pjsip_endpoint *endpt,
+            const std::string& aor);
+
+    ~BindingWrapper();
+
+    /**
+     * Called when a binding expires.
+     */
+    void expireRegistration();
+    /**
+     * Schedule expiration of a binding.
+     */
+    void scheduleRegistrationExpiration(int expiration);
+    /**
+     * Cancel the expiration of a binding.
+     */
+    void cancelRegistrationExpiration();
+
+    /**
+     * Update the binding in the wrapper with new information. This will
+     * result in rescheduling destruction of the binding.
+     */
+    void updateBinding(const std::string &callID, int cSeq, int expiration);
+
+    bool operator==(const BindingWrapper& rhs);
+    bool operator==(const AsteriskSCF::SIP::Registration::V1::BindingPtr& rhs);
+
+    PJSipRegistrarModulePtr mRegModule;
+    AsteriskSCF::SIP::Registration::V1::BindingPtr mBinding;
+    pjsip_endpoint *mEndpoint;
+    pj_timer_entry mEntry;
+    const std::string mAOR;
+};
+
 };
 };
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index 05be87f..d2bcdc0 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -72,14 +72,14 @@ public:
         }
     }
 
-    BindingWrapper *createBindingWrapper(const std::string& aor, const BindingPtr& binding, const RegistrarIPtr& registrar)
+    BindingWrapper *createBindingWrapper(const std::string& aor, const BindingPtr& binding, const PJSipRegistrarModulePtr& regModule)
     {
         int relativeExpiration = binding->expiration - time(NULL);
 
         BindingWrapper *wrapper(new BindingWrapper(
                     relativeExpiration,
                     binding,
-                    registrar,
+                    regModule,
                     mManager->getEndpoint(),
                     aor));
 
@@ -100,7 +100,7 @@ public:
             for (BindingSeq::iterator seqIter = bindings.begin();
                     seqIter != bindings.end(); ++seqIter)
             {
-                BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule->getRegistrar());
+                BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule);
                 wrapperSeq.push_back(wrapper);
             }
             regModule->getRegistrar()->updateBindings(dictIter->first, emptySeq, wrapperSeq);
@@ -140,7 +140,7 @@ public:
             for (BindingSeq::iterator seqIter = bindings.begin();
                     seqIter != bindings.end(); ++seqIter)
             {
-                BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule->getRegistrar());
+                BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule);
                 wrapperSeq.push_back(wrapper);
             }
             regModule->getRegistrar()->updateBindings(dictIter->first, wrapperSeq, emptySeq);
@@ -181,7 +181,7 @@ public:
                     //binding and removed it before the primary received the REGISTER to renew it.
                     //
                     //No biggie, just recreate the binding.
-                    BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule->getRegistrar());
+                    BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule);
                     newBindings.push_back(wrapper);
                 }
                 else

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list