[ekiga] Opal::Account only keeps weak references to the endpoints



commit 06515956e2f1d07726dba5b9828d142f9febaccb
Author: Julien Puydt <jpuydt free fr>
Date:   Fri Jan 25 14:19:18 2013 +0100

    Opal::Account only keeps weak references to the endpoints

 lib/engine/components/opal/opal-account.cpp |   36 ++++++++++++++++++--------
 lib/engine/components/opal/opal-account.h   |    4 +-
 2 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 7c30ee0..32c4d23 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -331,11 +331,16 @@ void Opal::Account::enable ()
   state = Processing;
   status = _("Processing...");
 #ifdef HAVE_H323
-  if (type == Account::H323)
-    h323_endpoint->subscribe (*this, presentity);
+  boost::shared_ptr<Opal::H323::EndPoint> h323 = h323_endpoint.lock ();
+  if (type == Account::H323 && h323)
+    h323->subscribe (*this, presentity);
   else
 #endif
-    sip_endpoint->subscribe (*this, presentity);
+    {
+      boost::shared_ptr<Opal::Sip::EndPoint> sip = sip_endpoint.lock ();
+      if (sip)
+	sip->subscribe (*this, presentity);
+    }
 
   updated ();
   trigger_saving ();
@@ -355,13 +360,18 @@ void Opal::Account::disable ()
     }
   }
 #ifdef HAVE_H323
-  if (type == Account::H323)
-    h323_endpoint->unsubscribe (*this, presentity);
+  boost::shared_ptr<Opal::H323::EndPoint> h323 = h323_endpoint.lock ();
+  if (type == Account::H323 && h323)
+    h323->unsubscribe (*this, presentity);
   else
 #endif
     {
-      sip_endpoint->unsubscribe (*this, presentity);
-      sip_endpoint->Unsubscribe (SIPSubscribe::MessageSummary, get_aor ());
+      boost::shared_ptr<Opal::Sip::EndPoint> sip = sip_endpoint.lock ();
+      if (sip) {
+
+	sip->unsubscribe (*this, presentity);
+	sip->Unsubscribe (SIPSubscribe::MessageSummary, get_aor ());
+      }
     }
   // Translators: this is a state, not an action, i.e. it should be read as
   // "(you are) unregistered", and not as "(you have been) unregistered"
@@ -651,6 +661,7 @@ Opal::Account::handle_registration_event (RegistrationState state_,
       // "(you are) registered", and not as "(you have been) registered"
       status = _("Registered");
       if (presentity) {
+	boost::shared_ptr<Opal::Sip::EndPoint> sip = sip_endpoint.lock ();
         for (std::set<std::string>::iterator iter = watched_uris.begin ();
              iter != watched_uris.end (); ++iter) {
           PTRACE(4, "Ekiga\tSubscribeToPresence for " << iter->c_str () << " (Account Registered)");
@@ -658,7 +669,7 @@ Opal::Account::handle_registration_event (RegistrationState state_,
         }
         presentity->SetLocalPresence (personal_state, presence_status);
         if (type != Account::H323) {
-          sip_endpoint->Subscribe (SIPSubscribe::MessageSummary, 3600, get_aor ());
+          sip->Subscribe (SIPSubscribe::MessageSummary, 3600, get_aor ());
         }
       }
       boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
@@ -711,24 +722,27 @@ Opal::Account::handle_registration_event (RegistrationState state_,
     }
     else {
 #endif
+      boost::shared_ptr<Opal::Sip::EndPoint> sip = sip_endpoint.lock ();
+      if (!sip)
+	return;
       switch (compat_mode) {
       case SIPRegister::e_FullyCompliant:
         // FullyCompliant did not work, try next compat mode
         compat_mode = SIPRegister::e_CannotRegisterMultipleContacts;
         PTRACE (4, "Register failed in FullyCompliant mode, retrying in CannotRegisterMultipleContacts mode");
-        sip_endpoint->subscribe (*this, presentity);
+        sip->subscribe (*this, presentity);
         break;
       case SIPRegister::e_CannotRegisterMultipleContacts:
         // CannotRegMC did not work, try next compat mode
         compat_mode = SIPRegister::e_CannotRegisterPrivateContacts;
         PTRACE (4, "Register failed in CannotRegisterMultipleContacts mode, retrying in CannotRegisterPrivateContacts mode");
-        sip_endpoint->subscribe (*this, presentity);
+        sip->subscribe (*this, presentity);
         break;
       case SIPRegister::e_CannotRegisterPrivateContacts:
         // CannotRegMC did not work, try next compat mode
         compat_mode = SIPRegister::e_HasApplicationLayerGateway;
         PTRACE (4, "Register failed in CannotRegisterMultipleContacts mode, retrying in HasApplicationLayerGateway mode");
-        sip_endpoint->subscribe (*this, presentity);
+        sip->subscribe (*this, presentity);
         break;
       case SIPRegister::e_HasApplicationLayerGateway:
         // HasAppLG did not work, stop registration with error
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index a63b432..f4f1dbe 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -231,9 +231,9 @@ private:
 				  std::string presence,
 				  std::string status);
 
-    boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
+    boost::weak_ptr<Opal::Sip::EndPoint> sip_endpoint;
 #ifdef HAVE_H323
-    boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint;
+    boost::weak_ptr<Opal::H323::EndPoint> h323_endpoint;
 #endif
     boost::weak_ptr<Ekiga::PresenceCore> presence_core;
     boost::weak_ptr<Ekiga::NotificationCore> notification_core;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]