[ekiga] Opal bank&account: shuffled a little the way services are managed, still leaky though :-/



commit 374337472f72310c93a1dd19db8ebff9bf842e09
Author: Julien Puydt <jpuydt free fr>
Date:   Fri Jan 25 07:51:36 2013 +0100

    Opal bank&account: shuffled a little the way services are managed, still leaky though :-/

 lib/engine/components/opal/opal-account.cpp |   82 ++++++++++++++++++---------
 lib/engine/components/opal/opal-account.h   |   35 ++++++++---
 lib/engine/components/opal/opal-bank.cpp    |   55 +++++++++++++++---
 lib/engine/components/opal/opal-bank.h      |   10 +++-
 4 files changed, 135 insertions(+), 47 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 2d6434d..7c30ee0 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -60,10 +60,26 @@
 #include "h323-endpoint.h"
 #endif
 
-Opal::Account::Account (Ekiga::ServiceCore& core,
-                        const std::string & account)
+Opal::Account::Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
+#ifdef HAVE_H323
+			boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint,
+#endif
+			boost::shared_ptr<Ekiga::PresenceCore> _presence_core,
+			boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
+			boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
+			boost::shared_ptr<Ekiga::AudioOutputCore> _audiooutput_core,
+			boost::shared_ptr<CallManager> _opal_component,
+			const std::string & account):
+  sip_endpoint(_sip_endpoint),
+#ifdef HAVE_H323
+  h323_endpoint(_h323_endpoint),
+#endif
+  presence_core(_presence_core),
+  notification_core(_notification_core),
+  personal_details(_personal_details),
+  audiooutput_core(_audiooutput_core),
+  opal_component(_opal_component)
 {
-  fetch_services_on_startup (core);
   state = Unregistered;
   status = _("Unregistered");
   message_waiting_number = 0;
@@ -146,18 +162,33 @@ Opal::Account::Account (Ekiga::ServiceCore& core,
 }
 
 
-Opal::Account::Account (Ekiga::ServiceCore& core,
-                        Type t,
+Opal::Account::Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
+#ifdef HAVE_H323
+			boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint,
+#endif
+			boost::shared_ptr<Ekiga::PresenceCore> _presence_core,
+			boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
+			boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
+			boost::shared_ptr<Ekiga::AudioOutputCore> _audiooutput_core,
+			boost::shared_ptr<CallManager> _opal_component,
+			Type t,
                         std::string _name,
                         std::string _host,
                         std::string _username,
                         std::string _auth_username,
                         std::string _password,
                         bool _enabled,
-                        unsigned _timeout)
+                        unsigned _timeout):
+  sip_endpoint(_sip_endpoint),
+#ifdef HAVE_H323
+  h323_endpoint(_h323_endpoint),
+#endif
+  presence_core(_presence_core),
+  notification_core(_notification_core),
+  personal_details(_personal_details),
+  audiooutput_core(_audiooutput_core),
+  opal_component(_opal_component)
 {
-  fetch_services_on_startup (core);
-
   state = Unregistered;
   status = "";
   message_waiting_number = 0;
@@ -630,8 +661,10 @@ Opal::Account::handle_registration_event (RegistrationState state_,
           sip_endpoint->Subscribe (SIPSubscribe::MessageSummary, 3600, get_aor ());
         }
       }
-      if (presence_core && personal_details)
-	presence_core->publish (personal_details);
+      boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
+      boost::shared_ptr<Ekiga::PersonalDetails> details = personal_details.lock ();
+      if (pcore && details)
+	pcore->publish (details);
 
       state = state_;
       failed_registration_already_notified = false;
@@ -672,7 +705,9 @@ Opal::Account::handle_registration_event (RegistrationState state_,
         std::stringstream msg;
         msg << _("Could not register to ") << get_name ();
         boost::shared_ptr<Ekiga::Notification> notif (new Ekiga::Notification (Ekiga::Notification::Warning, msg.str (), info, _("Edit"), boost::bind (&Opal::Account::edit, (Opal::Account*) this)));
-        notification_core->push_notification (notif);
+	boost::shared_ptr<Ekiga::NotificationCore> ncore = notification_core.lock ();
+	if (ncore)
+	  ncore->push_notification (notif);
     }
     else {
 #endif
@@ -706,7 +741,9 @@ Opal::Account::handle_registration_event (RegistrationState state_,
           std::stringstream msg;
           msg << _("Could not register to ") << get_name ();
           boost::shared_ptr<Ekiga::Notification> notif (new Ekiga::Notification (Ekiga::Notification::Warning, msg.str (), info, _("Edit"), boost::bind (&Opal::Account::edit, (Opal::Account*) this)));
-          notification_core->push_notification (notif);
+	boost::shared_ptr<Ekiga::NotificationCore> ncore = notification_core.lock ();
+	if (ncore)
+          ncore->push_notification (notif);
         }
         updated ();
         failed_registration_already_notified = true;
@@ -745,8 +782,11 @@ Opal::Account::handle_message_waiting_information (const std::string info)
     std::stringstream new_messages;
     new_messages << info.substr (0, loc);
     new_messages >> message_waiting_number;
-    if (message_waiting_number > 0)
-      audiooutput_core->play_event ("new_voicemail_sound");
+    if (message_waiting_number > 0) {
+      boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput = audiooutput_core.lock ();
+      if (audiooutput)
+	audiooutput->play_event ("new_voicemail_sound");
+    }
     updated ();
   }
 }
@@ -944,17 +984,3 @@ Opal::Account::presence_status_in_main (std::string uri,
   presence_received (uri, uri_presence);
   status_received (uri, uri_status);
 }
-
-void
-Opal::Account::fetch_services_on_startup (Ekiga::ServiceCore& core)
-{
-  sip_endpoint = core.get<Sip::EndPoint> ("opal-sip-endpoint");
-#ifdef HAVE_H323
-  h323_endpoint = core.get<H323::EndPoint> ("opal-h323-endpoint");
-#endif
-  notification_core = core.get<Ekiga::NotificationCore> ("notification-core");
-  presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
-  personal_details = core.get<Ekiga::PersonalDetails> ("personal-details");
-  audiooutput_core = core.get<Ekiga::AudioOutputCore> ("audiooutput-core");
-  opal_component = core.get<CallManager> ("opal-component");
-}
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index 2f2ff3a..a63b432 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -75,11 +75,27 @@ public:
 
     typedef enum { Processing, Registered, Unregistered, RegistrationFailed, UnregistrationFailed } RegistrationState;
 
-    Account (Ekiga::ServiceCore & core,
-             const std::string & account);
-
-    Account (Ekiga::ServiceCore & core,
-             Type t,
+    Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
+#ifdef HAVE_H323
+	     boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint,
+#endif
+	     boost::shared_ptr<Ekiga::PresenceCore> _presence_core,
+	     boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
+	     boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
+	     boost::shared_ptr<Ekiga::AudioOutputCore> _audiooutput_core,
+	     boost::shared_ptr<CallManager> _opal_component,
+	     const std::string & account);
+
+    Account (boost::shared_ptr<Opal::Sip::EndPoint> _sip_endpoint,
+#ifdef HAVE_H323
+	     boost::shared_ptr<Opal::H323::EndPoint> _h323_endpoint,
+#endif
+	     boost::shared_ptr<Ekiga::PresenceCore> _presence_core,
+	     boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
+	     boost::shared_ptr<Ekiga::PersonalDetails> _personal_details,
+	     boost::shared_ptr<Ekiga::AudioOutputCore> _audiooutput_core,
+	     boost::shared_ptr<CallManager> _opal_component,
+	     Type t,
              std::string name,
              std::string host,
              std::string user,
@@ -215,15 +231,14 @@ private:
 				  std::string presence,
 				  std::string status);
 
-    void fetch_services_on_startup (Ekiga::ServiceCore& core);
     boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
 #ifdef HAVE_H323
     boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint;
 #endif
-    boost::shared_ptr<Ekiga::PresenceCore> presence_core;
-    boost::shared_ptr<Ekiga::NotificationCore> notification_core;
-    boost::shared_ptr<Ekiga::PersonalDetails> personal_details;
-    boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core;
+    boost::weak_ptr<Ekiga::PresenceCore> presence_core;
+    boost::weak_ptr<Ekiga::NotificationCore> notification_core;
+    boost::weak_ptr<Ekiga::PersonalDetails> personal_details;
+    boost::weak_ptr<Ekiga::AudioOutputCore> audiooutput_core;
     boost::weak_ptr<CallManager> opal_component;
   };
 
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 4300209..c9251f4 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -45,18 +45,45 @@
 
 #include "gmconf.h"
 #include "menu-builder.h"
-
-#include "opal-bank.h"
 #include "form-request-simple.h"
 
-Opal::Bank::Bank (Ekiga::ServiceCore &_core): core(_core)
+#include "opal-bank.h"
+#include "sip-endpoint.h"
+#ifdef HAVE_H323
+#include "h323-endpoint.h"
+#endif
+
+Opal::Bank::Bank (Ekiga::ServiceCore& core):
+  sip_endpoint(core.get<Opal::Sip::EndPoint> ("opal-sip-endpoint")),
+#ifdef HAVE_H323
+  h323_endpoint(core.get<Opal::H323::EndPoint> ("opal-h323-endpoint")),
+#endif
+  presence_core(core.get<Ekiga::PresenceCore> ("presence-core")),
+  notification_core(core.get<Ekiga::NotificationCore> ("notification-core")),
+  personal_details(core.get<Ekiga::PersonalDetails> ("personal-details")),
+  audiooutput_core(core.get<Ekiga::AudioOutputCore> ("audiooutput-core")),
+  opal_component(core.get<CallManager> ("opal-component"))
 {
+  boost::shared_ptr<CallManager> opal = opal_component.lock ();
+  if (!opal)
+    return;
+
   GSList *accounts = gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
   GSList *accounts_iter = accounts;
 
   while (accounts_iter) {
 
-    boost::shared_ptr<Account> account = boost::shared_ptr<Account> (new Account (core, (char *)accounts_iter->data));
+    boost::shared_ptr<Account> account
+      = boost::shared_ptr<Account> (new Account (sip_endpoint,
+#ifdef HAVE_H323
+						 h323_endpoint,
+#endif
+						 presence_core,
+						 notification_core,
+						 personal_details,
+						 audiooutput_core,
+						 opal,
+						 (char *)accounts_iter->data));
 
     add_account (account);
     Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind (&Opal::Bank::save, this)));
@@ -203,10 +230,22 @@ void Opal::Bank::add (Account::Type acc_type,
                       bool enabled,
                       unsigned timeout)
 {
-  AccountPtr account = AccountPtr(new Opal::Account (core, acc_type, name,
-						     host, user, auth_user,
-						     password, enabled,
-						     timeout));
+  boost::shared_ptr<CallManager> opal = opal_component.lock ();
+  if (!opal)
+    return;
+  AccountPtr account
+    = AccountPtr(new Opal::Account (sip_endpoint,
+#ifdef HAVE_H323
+				    h323_endpoint,
+#endif
+				    presence_core,
+				    notification_core,
+				    personal_details,
+				    audiooutput_core,
+				    opal, acc_type, name,
+				    host, user, auth_user,
+				    password, enabled,
+				    timeout));
   add_account (account);
   Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind (&Opal::Bank::save, this)));
   Ekiga::BankImpl<Account>::add_connection (account, account->presence_received.connect (boost::ref (presence_received)));
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index a491d6e..e6de2d4 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -92,7 +92,15 @@ public:
     void call_manager_ready ();
 
 private:
-    Ekiga::ServiceCore &core;
+    boost::shared_ptr<Opal::Sip::EndPoint> sip_endpoint;
+#ifdef HAVE_H323
+    boost::shared_ptr<Opal::H323::EndPoint> h323_endpoint;
+#endif
+    boost::shared_ptr<Ekiga::PresenceCore> presence_core;
+    boost::shared_ptr<Ekiga::NotificationCore> notification_core;
+    boost::shared_ptr<Ekiga::PersonalDetails> personal_details;
+    boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core;
+    boost::weak_ptr<CallManager> opal_component;
 
     void on_new_account_form_submitted (bool submitted,
 					Ekiga::Form& form,



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