[ekiga/ds-fix-boost-leaks] Opal::Bank: Ported to the new framework.



commit 92c3530e97e18216fd280cb809fb55cf19277aae
Author: Damien Sandras <dsandras seconix com>
Date:   Sun Jun 21 15:30:17 2015 +0200

    Opal::Bank: Ported to the new framework.

 lib/engine/components/opal/opal-bank.cpp |  173 +++++++++++++-----------------
 lib/engine/components/opal/opal-bank.h   |   32 ++++--
 2 files changed, 97 insertions(+), 108 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-bank.cpp b/lib/engine/components/opal/opal-bank.cpp
index 3c998cd..debc7eb 100644
--- a/lib/engine/components/opal/opal-bank.cpp
+++ b/lib/engine/components/opal/opal-bank.cpp
@@ -48,6 +48,28 @@
 #include "opal-presentity.h"
 
 
+boost::shared_ptr<Opal::Bank>
+Opal::Bank::create (Ekiga::ServiceCore& core,
+                    Opal::EndPoint& _endpoint,
+#ifdef HAVE_H323
+                    Opal::H323::EndPoint* _h323_endpoint,
+#endif
+                    Opal::Sip::EndPoint* _sip_endpoint)
+{
+  boost::shared_ptr<Opal::Bank> bank =
+    boost::shared_ptr<Opal::Bank> (new Opal::Bank (core,
+                                                   _endpoint,
+#ifdef HAVE_H323
+                                                   _h323_endpoint,
+#endif
+                                                   _sip_endpoint));
+
+  bank->load ();
+
+  return bank;
+}
+
+
 Opal::Bank::Bank (Ekiga::ServiceCore& core,
                   Opal::EndPoint& _endpoint,
 #ifdef HAVE_H323
@@ -64,7 +86,49 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
 #endif
   sip_endpoint(_sip_endpoint)
 {
-  std::list<std::string> accounts;
+  // FIXME
+  sip_endpoint->mwi_event.connect (boost::bind(&Opal::Bank::on_mwi_event, this, _1, _2));
+}
+
+
+Opal::Bank::~Bank ()
+{
+  delete protocols_settings;
+}
+
+
+boost::shared_ptr<Opal::Account>
+Opal::Bank::load_account (boost::function0<std::list<std::string> > _existing_groups,
+                          xmlNodePtr _node)
+{
+  boost::shared_ptr<Opal::Account> account = Opal::Account::create (*this,
+                                                                    presence_core,
+                                                                    notification_core,
+                                                                    personal_details,
+                                                                    audiooutput_core,
+                                                                    endpoint,
+#ifdef HAVE_H323
+                                                                    h323_endpoint,
+#endif
+                                                                    sip_endpoint,
+                                                                    _existing_groups,
+                                                                    _node);
+
+  std::cout << "FIXME: Use add_connection here" << std::endl;
+  account->trigger_saving.connect (boost::bind (&Opal::Bank::save, this));
+  account->removed.connect (boost::bind (&Opal::Bank::on_account_removed, this, _1));
+  add_account (account);
+  add_heap (account);
+
+  activate (account);
+
+  return account;
+}
+
+
+void
+Opal::Bank::load ()
+{
   protocols_settings = new Ekiga::Settings (PROTOCOLS_SCHEMA);
 
   const std::string raw = protocols_settings->get_string ("accounts");
@@ -88,47 +152,9 @@ Opal::Bank::Bank (Ekiga::ServiceCore& core,
 
     if (child->type == XML_ELEMENT_NODE
         && child->name != NULL
-        && xmlStrEqual(BAD_CAST "account", child->name)) {
-
-      boost::shared_ptr<Account> account(new Account (*this,
-                                                      presence_core,
-                                                      notification_core,
-                                                      personal_details,
-                                                      audiooutput_core,
-                                                      endpoint,
-#ifdef HAVE_H323
-                                                      _h323_endpoint,
-#endif
-                                                      _sip_endpoint,
-                                                      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)));
-      Ekiga::BankImpl<Account>::add_connection (account, account->presentity_updated.connect (boost::bind 
(boost::ref(presentity_updated), account, _1)));
-      Ekiga::BankImpl<Account>::add_connection (account, account->presentity_removed.connect (boost::bind 
(boost::ref(presentity_removed), account, _1)));
-
-      // We have several questions to relay following we are a Cluster or a Bank.
-      // Clusters will relay questions from Heaps. Banks will relay questions from Accounts.
-      Ekiga::BankImpl<Account>::add_connection (account, account->Heap::questions.connect 
(boost::ref(Ekiga::Cluster::questions)));
-      Ekiga::BankImpl<Account>::add_connection (account, account->Account::questions.connect 
(boost::ref(Ekiga::Bank::questions)));
-
-      Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
-      Ekiga::BankImpl<Account>::add_connection (account, account->removed.connect (boost::bind 
(&Opal::Bank::on_account_removed, this, account)));
-      add_account (account);
-      heap_added (account);
-
-      activate (account);
-    }
+        && xmlStrEqual(BAD_CAST "account", child->name))
+      boost::shared_ptr<Opal::Account> account = load_account (boost::bind(&Opal::Bank::existing_groups, 
this), child);
   }
-
-  // FIXME
-  sip_endpoint->mwi_event.connect (boost::bind(&Opal::Bank::on_mwi_event, this, _1, _2));
-}
-
-
-Opal::Bank::~Bank ()
-{
-  delete protocols_settings;
 }
 
 
@@ -281,33 +307,7 @@ Opal::Bank::add (Account::Type acc_type,
   save ();
 
 
-  AccountPtr account
-    = AccountPtr(new Opal::Account (*this,
-                                   presence_core,
-                                   notification_core,
-                                   personal_details,
-                                   audiooutput_core,
-                                    endpoint,
-#ifdef HAVE_H323
-                                    h323_endpoint,
-#endif
-                                    sip_endpoint,
-                                   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)));
-  Ekiga::BankImpl<Account>::add_connection (account, account->presentity_updated.connect (boost::bind 
(boost::ref(presentity_updated), account, _1)));
-  Ekiga::BankImpl<Account>::add_connection (account, account->presentity_removed.connect (boost::bind 
(boost::ref(presentity_removed), account, _1)));
-  Ekiga::BankImpl<Account>::add_connection (account, account->trigger_saving.connect (boost::bind 
(&Opal::Bank::save, this)));
-  Ekiga::BankImpl<Account>::add_connection (account, account->removed.connect (boost::bind 
(&Opal::Bank::on_account_removed, this, account)));
-  add_account (account);
-  heap_added (account);
-
-  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
-  if (pcore)
-    pcore->add_presence_fetcher (account);
-
-  if (enabled)
-    account->enable ();
+  AccountPtr account = load_account (boost::bind(&Opal::Bank::existing_groups, this), child);
 }
 
 
@@ -321,8 +321,8 @@ Opal::Bank::find_account (const std::string& _aor)
   if (t != std::string::npos)
     aor = aor.substr (0, t);
 
-  for (iterator iter = begin ();
-       iter != end ();
+  for (Ekiga::BankImpl<Opal::Account>::iterator iter = Ekiga::BankImpl<Opal::Account>::begin ();
+       iter != Ekiga::BankImpl<Opal::Account>::end ();
        ++iter) {
     if (aor.find ("@") != std::string::npos && (*iter)->get_aor () == aor)  // find by account name+host 
(aor)
         return *iter;
@@ -334,13 +334,6 @@ Opal::Bank::find_account (const std::string& _aor)
 
 
 void
-Opal::Bank::clear ()
-{
-  Ekiga::RefLister<Opal::Account>::remove_all_objects ();
-}
-
-
-void
 Opal::Bank::save () const
 {
   xmlChar *buffer = NULL;
@@ -359,17 +352,14 @@ Opal::Bank::on_account_removed (boost::shared_ptr<Account> account)
   boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
   if (pcore)
     pcore->remove_presence_fetcher (account);
-
-  heap_removed (account);
-  remove_account (account);
 }
 
 
 void
 Opal::Bank::publish (const Ekiga::PersonalDetails& details)
 {
-  for (iterator iter = begin ();
-       iter != end ();
+  for (Ekiga::BankImpl<Opal::Account>::iterator iter = Ekiga::BankImpl<Opal::Account>::begin ();
+       iter != Ekiga::BankImpl<Opal::Account>::end ();
        iter++)
     (*iter)->publish (details);
 }
@@ -386,20 +376,13 @@ Opal::Bank::on_mwi_event (std::string aor,
 }
 
 
-void
-Opal::Bank::visit_heaps (boost::function1<bool, Ekiga::HeapPtr> visitor) const
-{
-  visit_objects (visitor);
-}
-
-
 const std::list<std::string>
 Opal::Bank::existing_groups () const
 {
   std::list<std::string> result;
 
-  for (const_iterator iter = begin ();
-       iter != end ();
+  for (Ekiga::BankImpl<Opal::Account>::const_iterator iter = Ekiga::BankImpl<Opal::Account>::begin ();
+       iter != Ekiga::BankImpl<Opal::Account>::end ();
        ++iter) {
 
     std::list<std::string> groups = (*iter)->get_groups ();
@@ -458,12 +441,10 @@ Opal::Bank::find_presentity_for_uri (const std::string uri) const
 {
   find_presentity_helper helper(uri);
 
-  for (const_iterator iter = begin ();
-       iter != end () && !helper.result;
-       ++iter) {
-
+  for (Ekiga::ClusterImpl<Opal::Account>::const_iterator iter = Ekiga::ClusterImpl<Opal::Account>::begin ();
+       iter != Ekiga::ClusterImpl<Opal::Account>::end () && !helper.result;
+       ++iter)
     (*iter)->visit_presentities(boost::ref(helper));
-  }
 
   return helper.result;
 }
diff --git a/lib/engine/components/opal/opal-bank.h b/lib/engine/components/opal/opal-bank.h
index 5c0f742..205de89 100644
--- a/lib/engine/components/opal/opal-bank.h
+++ b/lib/engine/components/opal/opal-bank.h
@@ -49,6 +49,9 @@
 #include "sip-endpoint.h"
 #include "h323-endpoint.h"
 
+#include "cluster-impl.h"
+#include "bank-impl.h"
+
 namespace Opal
 {
   /**
@@ -58,8 +61,9 @@ namespace Opal
    */
   class Bank:
       public Ekiga::BankImpl<Account>,
-      public Ekiga::Cluster,
+      public Ekiga::ClusterImpl<Account>,
       public Ekiga::PresencePublisher,
+      public Ekiga::DynamicObject<Bank>,
       public Ekiga::Service
   {
     friend class Account;
@@ -82,12 +86,12 @@ public:
      * that Opal is taking care of deleting them. They are not deleted when
      * the last object having a reference to them is deleted.
      */
-    Bank (Ekiga::ServiceCore& _core,
-          Opal::EndPoint& _endpoint,
+    static boost::shared_ptr<Bank> create (Ekiga::ServiceCore& _core,
+                                           Opal::EndPoint& _endpoint,
 #ifdef HAVE_H323
-          Opal::H323::EndPoint* _h323_endpoint,
+                                           Opal::H323::EndPoint* _h323_endpoint,
 #endif
-          Opal::Sip::EndPoint* _sip_endpoint);
+                                           Opal::Sip::EndPoint* _sip_endpoint);
 
     ~Bank ();
 
@@ -115,13 +119,6 @@ public:
      */
     AccountPtr find_account (const std::string& aor);
 
-    /** Clear all Accounts
-     */
-    void clear ();
-
-    /* this object is an Ekiga::Cluster */
-    void visit_heaps (boost::function1<bool, Ekiga::HeapPtr> visitor) const;
-
     const std::list<std::string> existing_groups () const;
 
     /* this is useful when we want to do something with some uri and
@@ -132,6 +129,17 @@ public:
     static void migrate_from_gconf (const std::list<std::string> old);
 
 private:
+    Bank (Ekiga::ServiceCore& _core,
+          Opal::EndPoint& _endpoint,
+#ifdef HAVE_H323
+          Opal::H323::EndPoint* _h323_endpoint,
+#endif
+          Opal::Sip::EndPoint* _sip_endpoint);
+
+    boost::shared_ptr<Account> load_account (boost::function0<std::list<std::string> > _existing_groups,
+                                             xmlNodePtr _node);
+
+    void load ();
     void set_ready ();
     bool is_ready;
 


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