< Previous by Date | Date Index | Next by Date > |
< Previous in Thread | Thread Index | Next in Thread > |
In general you should not be deleting AppDialogSets – DUM manages their lifetime and will delete them, when they are no longer required.
When your app shuts down you should end() all subscriptions and execute a dum->shutdown while running the process loop, when all dialogs are destroyed the shutdown callback will be called.
From: resiprocate-devel-bounces@xxxxxxxxxxxxxxxxxxxx [mailto:resiprocate-devel-bounces@xxxxxxxxxxxxxxxxxxxx] On Behalf Of Dien Ba Quang
Sent: Thursday, May 03, 2007 11:35 AM
To: resiprocate-devel@xxxxxxxxxxxxxxxxxxxx
Subject: [reSIProcate] How to maintain SUBSCRIBE AppDialogSets?
Hi,
In my soft phone, I implemented SUBSCRIBE and NOTIFY messages to maintain a buddy list. But I have some problems with the SUBSCRIBE AppDialogSets, it crashed sometimes. Below is my implementation:
After received 200 OK for REGISTER messages, send SUBSCRIBE messages for every contacts in my buddy list (code below).
1. The problem is when I try to delete all the AppDialogSets (when closing soft phone), it crashed my app. So do you know how DUM deletes the AppDialogSet? and What's the good ways to maintain the SUBSCRIBE AppDialogSets?
2. When I repeated sending SUBSCRIBE messages from another instant (the same code) to the soft phone, it crashed (just sometime). I don't know what's the problem with DUM? It's always crash at line 775 in dialogset.cxx
AppDialog* appDialog = mAppDialogSet->createAppDialog(msg);
Best regards,
DBQ.
void SendSubscribe(char* contact, int exp_time)
{
try {
string validContact = validateSipAddress(contact);
NameAddr uasAor(validContact.c_str());
Data mevent("presence");
//Check if the contact already has the AppDialogSet or not
testAppDialogSet *m_pADS = uac.getSubscribeDialog(uasAor.uri());
if (m_pADS == NULL) //if not -> create a new one and store into a list(contact, group, AppDialogSet)
{
testAppDialogSet *m_pADS = new testAppDialogSet(*(clientDum), "UAC(SUBSCRIBE)");
uac.addBuddy(uasAor.uri(), "Friends", m_pADS);
}
SharedPtr<SipMessage> SubscribeMessage = clientDum->makeSubscription(uasAor, mevent, exp_time, m_pADS);
clientDum->send(SubscribeMessage);
}
catch (BaseException& e) {
return;
}
//delete all SUBSCRIBE AppDialogSets
void TestUac::deleteSubscribeDialog()
{
TestUac::BuddyIterator i;
i = mBuddies.begin ();
while ( i != mBuddies.end() )
{
if ( i->presDialog != NULL )
{
delete i->presDialog;
i->presDialog = NULL;
}
i = mBuddies.erase (i);
}
}
//Subscription Callbacks
void TestUac::onUpdateActive(ClientSubscriptionHandle is, const SipMessage& notify, bool outOfOrder)
{
if (notify.header(h_Event).value() == Data("message-summary"))
{
is->acceptUpdate();
//TODO:check voice message
return;
}
is->acceptUpdate();
Contents *body = notify.getContents();
//Received NOTIFY message event with no contents
if (!body){
return;
}
Pidf* pidf = dynamic_cast<Pidf*>(body);
Uri uri = pidf->getEntity();
//update status of uri as Online
PresenceNotify((char*)uri.user().c_str(), 1, 0);
}
void TestUac::onNewSubscription(ServerSubscriptionHandle is, const SipMessage& sub)
{
SharedPtr<SipMessage> sipmsg = is->accept();
is->send(sipmsg);
Data fromAor(sub.header(h_From).uri().getAor());
string name = str_get_username(fromAor.c_str());
if (sub.header(h_Expires).value() != 0){
Token state;
state.value() = Data("active");
Pidf *doc = new Pidf(Mime("application", "pidf-xml"));
doc->setEntity(myUri);
doc->setSimpleStatus(true);
sipmsg = is->update(doc);
sipmsg->header(h_SubscriptionState) = state;
is->send(sipmsg);
delete doc;
//check if the name is not online --> resend SUBSCRIBE message
PresenceNotify((char*)name.c_str(), 1, 1);
}
else {
//in case Unsubscribe expire = 0
PresenceNotify((char*)name.c_str(), 0, 0);
}
}