[ekiga] Opal: Use weak_ptr where possible.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] Opal: Use weak_ptr where possible.
- Date: Sat, 24 Jan 2015 14:57:49 +0000 (UTC)
commit 0d509a0fa56583ebcc58d4bc9855aaa43c95299a
Author: Damien Sandras <dsandras seconix com>
Date: Sat Jan 24 15:56:55 2015 +0100
Opal: Use weak_ptr where possible.
This avoids cyclic references. That's not a perfect solution though.
lib/engine/components/opal/opal-account.cpp | 20 ++++++++++++++------
lib/engine/components/opal/opal-account.h | 2 +-
lib/engine/components/opal/opal-bank.cpp | 15 ++++++++++++---
lib/engine/components/opal/opal-bank.h | 2 +-
4 files changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 83b9c1d..bf44c15 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -238,8 +238,11 @@ Opal::Account::Account (Opal::Bank & _bank,
}
/* We will directly use the OPAL SIP and H.323 EndPoints */
- sip_endpoint = (Opal::Sip::EndPoint*) call_manager->FindEndPoint ("sip");
- h323_endpoint = (Opal::H323::EndPoint*) call_manager->FindEndPoint ("h323");
+ boost::shared_ptr<Opal::CallManager> cmanager = call_manager.lock ();
+ if (cmanager) {
+ sip_endpoint = (Opal::Sip::EndPoint*) cmanager->FindEndPoint ("sip");
+ h323_endpoint = (Opal::H323::EndPoint*) cmanager->FindEndPoint ("h323");
+ }
}
@@ -548,8 +551,10 @@ Opal::Account::disable ()
presentity->Close ();
}
- // Register the given aor to the given registrar
- sip_endpoint->disable_account (*this);
+ if (sip_endpoint) {
+ // Register the given aor to the given registrar
+ sip_endpoint->disable_account (*this);
+ }
break;
}
@@ -921,8 +926,11 @@ Opal::Account::handle_registration_event (Ekiga::Account::RegistrationState stat
state = state_;
failed_registration_already_notified = false;
- PURL url = PString (get_transaction_aor (get_aor ()));
- presentity = call_manager->AddPresentity (url);
+ boost::shared_ptr<Opal::CallManager> cmanager = call_manager.lock ();
+ if (cmanager) {
+ PURL url = PString (get_transaction_aor (get_aor ()));
+ presentity = cmanager->AddPresentity (url);
+ }
if (presentity) {
presentity->SetPresenceChangeNotifier (PCREATE_PresenceChangeNotifier (OnPresenceChange));
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index a8584c6..8fe1f9e 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -248,7 +248,7 @@ private:
boost::weak_ptr<Ekiga::PersonalDetails> personal_details;
boost::weak_ptr<Ekiga::AudioOutputCore> audiooutput_core;
- boost::shared_ptr<Opal::CallManager> call_manager;
+ boost::weak_ptr<Opal::CallManager> call_manager;
};
typedef boost::shared_ptr<Account> AccountPtr;
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index a1fc869..e04a8ad 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -59,6 +59,10 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
personal_details(core.get<Ekiga::PersonalDetails> ("personal-details")),
audiooutput_core(core.get<Ekiga::AudioOutputCore> ("audiooutput-core"))
{
+ boost::shared_ptr<Opal::CallManager> cmanager = call_manager.lock ();
+ if (!cmanager)
+ return;
+
is_ready = false;
std::list<std::string> accounts;
@@ -92,7 +96,7 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
notification_core,
personal_details,
audiooutput_core,
- call_manager,
+ cmanager,
boost::bind(&Opal::Bank::existing_groups, this),
child));
@@ -120,7 +124,7 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
//sip_endpoint.mwi_event.connect (boost::bind(&Opal::Bank::on_mwi_event, this, _1, _2));
// Enable accounts when the manager is ready
- call_manager->ready.connect (boost::bind (&Opal::Bank::set_ready, this));
+ cmanager->ready.connect (boost::bind (&Opal::Bank::set_ready, this));
}
@@ -254,19 +258,24 @@ Opal::Bank::add (Account::Type acc_type,
bool enabled,
unsigned timeout)
{
+ boost::shared_ptr<Opal::CallManager> cmanager = call_manager.lock ();
+ if (!cmanager)
+ return;
+
xmlNodePtr child = Opal::Account::build_node (acc_type, name, host, user, auth_user, password, enabled,
timeout);
xmlAddChild (node, child);
save ();
+
AccountPtr account
= AccountPtr(new Opal::Account (*this,
presence_core,
notification_core,
personal_details,
audiooutput_core,
- call_manager,
+ cmanager,
boost::bind(&Opal::Bank::existing_groups, this),
child));
Ekiga::BankImpl<Account>::add_connection (account, account->presentity_added.connect (boost::bind
(boost::ref(presentity_added), account, _1)));
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index fef9902..62c302f 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -106,7 +106,7 @@ private:
void set_ready ();
bool is_ready;
- boost::shared_ptr<Opal::CallManager> call_manager;
+ boost::weak_ptr<Opal::CallManager> call_manager;
boost::weak_ptr<Ekiga::PresenceCore> presence_core;
boost::shared_ptr<Ekiga::NotificationCore> notification_core;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]