[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
Wed Jun 22 14:23:34 CDT 2011
branch "registrar" has been updated
via 1dda9776c5a1f55037ac61f5290593e25a5677cb (commit)
from 34797f06098f619838f094d9af7ec1a8c3ad4724 (commit)
Summary of changes:
src/PJSipRegistrarModule.cpp | 29 +++++++++++++++--------------
src/PJSipRegistrarModule.h | 13 +++++++------
src/SipStateReplicatorListener.cpp | 10 +++++-----
3 files changed, 27 insertions(+), 25 deletions(-)
- Log -----------------------------------------------------------------
commit 1dda9776c5a1f55037ac61f5290593e25a5677cb
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Jun 22 14:23:26 2011 -0500
Switch to using smart pointers for BindingWrappers.
As suggested by Brent Eagles in CR-ASTSCR-106
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index dd6be8c..44498a4 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -36,20 +36,22 @@ namespace SipSessionManager
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();
- RegistrarIPtr registrar = wrapper->mRegModule->getRegistrar();
- BindingWrapperSeq& currentBindings = registrar->getAORBindingWrappers(wrapper->mAOR);
- registrar->removeBinding(currentBindings, wrapper);
+ //Create a BindingWrapperPtr so that when we remove the wrapper from the
+ //registrar, it doesn't get deleted.
+ BindingWrapperPtr wrapperPtr(new BindingWrapper(*wrapper));
+ lg(Debug) << "Detected expiration of binding " << wrapperPtr->mBinding->contact;
+ wrapperPtr->cancelRegistrationExpiration();
+ RegistrarIPtr registrar = wrapperPtr->mRegModule->getRegistrar();
+ BindingWrapperSeq& currentBindings = registrar->getAORBindingWrappers(wrapperPtr->mAOR);
+ registrar->removeBinding(currentBindings, wrapperPtr);
if (currentBindings.empty())
{
- registrar->removeAOR(wrapper->mAOR);
+ registrar->removeAOR(wrapperPtr->mAOR);
}
BindingWrapperSeq emptySeq;
BindingWrapperSeq toRemove;
- toRemove.push_back(wrapper);
- wrapper->mRegModule->replicateState(wrapper->mAOR, emptySeq, emptySeq, toRemove);
- delete wrapper;
+ toRemove.push_back(wrapperPtr);
+ wrapperPtr->mRegModule->replicateState(wrapperPtr->mAOR, emptySeq, emptySeq, toRemove);
}
static int expirationId;
@@ -179,7 +181,7 @@ BindingWrapperSeq& RegistrarI::getAORBindingWrappers(const std::string &aor)
}
}
-void RegistrarI::removeBinding(BindingWrapperSeq& currentBindings, BindingWrapper *wrapper)
+void RegistrarI::removeBinding(BindingWrapperSeq& currentBindings, BindingWrapperPtr wrapper)
{
lg(Debug) << "Removing binding " << wrapper->mBinding->contact;
currentBindings.erase(std::remove(currentBindings.begin(), currentBindings.end(), wrapper), currentBindings.end());
@@ -288,7 +290,6 @@ void RegistrarI::updateBindings(const std::string &aor, BindingWrapperSeq& newBi
for (BindingWrapperSeq::iterator iter = removedBindings.begin(); iter != removedBindings.end(); ++iter)
{
removeBinding(currentBindings, *iter);
- delete *iter;
}
if (currentBindings.empty())
{
@@ -449,7 +450,7 @@ int PJSipRegistrarModule::getExpiration(pjsip_contact_hdr *contact, pjsip_rx_dat
}
}
-BindingWrapper *PJSipRegistrarModule::createNewBinding(pjsip_contact_hdr *contact, const std::string &callID, int cSeq, int expiration, const std::string& aor)
+BindingWrapperPtr PJSipRegistrarModule::createNewBinding(pjsip_contact_hdr *contact, const std::string &callID, int cSeq, int expiration, const std::string& aor)
{
char buf[512];
pjsip_sip_uri *contactURI = (pjsip_sip_uri *)pjsip_uri_get_uri(contact->uri);
@@ -462,7 +463,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, this, mEndpoint, aor));
+ BindingWrapperPtr 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;
@@ -536,7 +537,7 @@ pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
}
else
{
- BindingWrapper *wrapper = createNewBinding(*iter, callID, cSeq, expiration, aor);
+ BindingWrapperPtr wrapper = createNewBinding(*iter, callID, cSeq, expiration, aor);
lg(Debug) << "Adding " << wrapper->mBinding->contact << " to our bindings to add";
newBindings.push_back(wrapper);
}
diff --git a/src/PJSipRegistrarModule.h b/src/PJSipRegistrarModule.h
index e56a321..ab7ed34 100644
--- a/src/PJSipRegistrarModule.h
+++ b/src/PJSipRegistrarModule.h
@@ -29,7 +29,8 @@ namespace SipSessionManager
{
class BindingWrapper;
-typedef std::vector<BindingWrapper *> BindingWrapperSeq;
+typedef boost::shared_ptr<BindingWrapper> BindingWrapperPtr;
+typedef std::vector<BindingWrapperPtr> BindingWrapperSeq;
typedef std::map<std::string, BindingWrapperSeq> BindingWrapperDict;
class RegistrarI : public AsteriskSCF::SIP::Registration::V1::Registrar
@@ -43,7 +44,7 @@ public:
BindingWrapperSeq& getAORBindingWrappers(const std::string &aor);
- void removeBinding(BindingWrapperSeq& currentBindings, BindingWrapper *wrapper);
+ void removeBinding(BindingWrapperSeq& currentBindings, BindingWrapperPtr wrapper);
void removeAOR(const std::string& aor);
void updateBindings(
@@ -94,9 +95,9 @@ public:
*/
void replicateState(
const std::string &aor,
- BindingWrapperSeq& existingBindings,
- BindingWrapperSeq& newBindings,
- BindingWrapperSeq& removedBindings);
+ const BindingWrapperSeq& existingBindings,
+ const BindingWrapperSeq& newBindings,
+ const BindingWrapperSeq& removedBindings);
private:
/**
@@ -121,7 +122,7 @@ private:
* Create a new BindingWrapper based on information extracted from a
* REGISTER request
*/
- BindingWrapper *createNewBinding(pjsip_contact_hdr *contact,
+ BindingWrapperPtr createNewBinding(pjsip_contact_hdr *contact,
const std::string& callID, int cSeq, int expiration, const std::string& aor);
pjsip_endpoint *mEndpoint;
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index 61df232..26e4402 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -72,11 +72,11 @@ public:
}
}
- BindingWrapper *createBindingWrapper(const std::string& aor, const BindingPtr& binding, const PJSipRegistrarModulePtr& regModule)
+ BindingWrapperPtr createBindingWrapper(const std::string& aor, const BindingPtr& binding, const PJSipRegistrarModulePtr& regModule)
{
int relativeExpiration = binding->expiration - time(NULL);
- BindingWrapper *wrapper(new BindingWrapper(
+ BindingWrapperPtr wrapper(new BindingWrapper(
relativeExpiration,
binding,
regModule,
@@ -90,7 +90,7 @@ public:
{
BindingFinder(const BindingPtr& binding)
: mBinding(binding) { }
- bool operator()(BindingWrapper *wrapper)
+ bool operator()(const BindingWrapperPtr& wrapper)
{
return *wrapper == mBinding;
}
@@ -163,7 +163,7 @@ public:
for (BindingSeq::iterator seqIter = bindings.begin();
seqIter != bindings.end(); ++seqIter)
{
- BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule);
+ BindingWrapperPtr wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule);
wrapperSeq.push_back(wrapper);
}
regModule->getRegistrar()->updateBindings(dictIter->first, wrapperSeq, emptySeq);
@@ -193,7 +193,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);
+ BindingWrapperPtr 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