[ekiga/ds-fix-boost-leaks] Opal::Account: Ported to the new framework.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga/ds-fix-boost-leaks] Opal::Account: Ported to the new framework.
- Date: Sun, 21 Jun 2015 13:35:39 +0000 (UTC)
commit 4c37d3a39313d959c6d8f3079f6c6c960c305591
Author: Damien Sandras <dsandras seconix com>
Date: Sun Jun 21 15:29:57 2015 +0200
Opal::Account: Ported to the new framework.
lib/engine/components/opal/opal-account.cpp | 129 +++++++++++++++------------
lib/engine/components/opal/opal-account.h | 50 +++++++----
2 files changed, 101 insertions(+), 78 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-account.cpp b/lib/engine/components/opal/opal-account.cpp
index 41d46e3..53ed5ea 100644
--- a/lib/engine/components/opal/opal-account.cpp
+++ b/lib/engine/components/opal/opal-account.cpp
@@ -147,6 +147,38 @@ Opal::Account::build_node(Opal::Account::Type typus,
}
+boost::shared_ptr<Opal::Account>
+Opal::Account::create (Bank & bank,
+ boost::weak_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,
+ EndPoint& _endpoint,
+#ifdef HAVE_H323
+ H323::EndPoint* _h323_endpoint,
+#endif
+ Sip::EndPoint* _sip_endpoint,
+ boost::function0<std::list<std::string> > _existing_groups,
+ xmlNodePtr _node)
+{
+ boost::shared_ptr<Opal::Account> account =
+ boost::shared_ptr<Opal::Account> (new Opal::Account (bank,
+ _presence_core,
+ _notification_core,
+ _personal_details,
+ _audiooutput_core,
+ _endpoint,
+#ifdef HAVE_H323
+ _h323_endpoint,
+#endif
+ _sip_endpoint,
+ _existing_groups,
+ _node));
+
+ return account;
+}
+
+
Opal::Account::Account (Opal::Bank & _bank,
boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
boost::shared_ptr<Ekiga::NotificationCore> _notification_core,
@@ -185,20 +217,8 @@ Opal::Account::Account (Opal::Bank & _bank,
if (child->type == XML_ELEMENT_NODE && child->name != NULL && xmlStrEqual (BAD_CAST "roster",
child->name)) {
roster_node = child;
- for (xmlNodePtr presnode = roster_node->children; presnode != NULL; presnode = presnode->next) {
-
- Opal::PresentityPtr pres(new Presentity (*this,
- presence_core,
- existing_groups,
- presnode));
-
- pres->trigger_saving.connect (boost::ref (trigger_saving));
- pres->removed.connect (boost::bind (&Opal::Account::when_presentity_removed, this, pres));
- pres->updated.connect (boost::bind (&Opal::Account::when_presentity_updated, this, pres));
- pres->questions.connect (boost::ref (Ekiga::Heap::questions));
- add_object (pres);
- presentity_added (pres);
- }
+ for (xmlNodePtr presnode = roster_node->children; presnode != NULL; presnode = presnode->next)
+ load_presentity (presence_core, existing_groups, presnode);
}
}
@@ -262,7 +282,9 @@ Opal::Account::get_groups () const
{
std::list<std::string> result;
- for (Ekiga::RefLister< Presentity >::const_iterator iter = Ekiga::RefLister< Presentity >::begin (); iter
!= Ekiga::RefLister< Presentity >::end (); ++iter) {
+ for (Ekiga::HeapImpl<Opal::Presentity>::const_iterator iter = Ekiga::HeapImpl<Opal::Presentity>::begin ();
+ iter != Ekiga::HeapImpl<Opal::Presentity>::end ();
+ ++iter) {
std::list<std::string> groups = (*iter)->get_groups ();
result.merge (groups);
@@ -544,7 +566,7 @@ Opal::Account::enable ()
sip_endpoint->EnableAccount (*this);
break;
}
- updated ();
+ updated (this->shared_from_this ());
disable_action ("enable-account");
enable_action ("disable-account");
@@ -571,10 +593,9 @@ Opal::Account::disable ()
default:
if (opal_presentity) {
- for (Ekiga::RefLister< Presentity >::iterator iter = Ekiga::RefLister< Presentity >::begin ();
- iter != Ekiga::RefLister< Presentity >::end ();
+ for (Ekiga::HeapImpl<Opal::Presentity>::iterator iter = Ekiga::HeapImpl<Opal::Presentity>::begin ();
+ iter != Ekiga::HeapImpl<Opal::Presentity>::end ();
++iter) {
-
(*iter)->set_presence ("unknown");
(*iter)->set_status ("");
}
@@ -597,7 +618,7 @@ Opal::Account::disable ()
status = _("Unregistered");
state = Unregistered;
- updated ();
+ updated (this->shared_from_this ());
enable_action ("enable-account");
disable_action ("disable-account");
@@ -660,8 +681,7 @@ Opal::Account::remove ()
xmlFreeNode (node);
trigger_saving ();
- Ekiga::Heap::removed ();
- Ekiga::Account::removed ();
+ removed (this->shared_from_this ());
}
@@ -854,7 +874,7 @@ Opal::Account::on_edit_form_submitted (bool submitted,
else if (should_disable)
disable ();
- updated ();
+ updated (this->shared_from_this ());
trigger_saving ();
}
@@ -902,13 +922,7 @@ Opal::Account::on_add_contact_form_submitted (bool submitted,
xmlAddChild (roster_node, presnode);
trigger_saving ();
- Opal::PresentityPtr pres(new Presentity (*this, presence_core, existing_groups, presnode));
- pres->trigger_saving.connect (boost::ref (trigger_saving));
- pres->removed.connect (boost::bind (boost::ref (presentity_removed), pres));
- pres->updated.connect (boost::bind (boost::ref (presentity_updated), pres));
- pres->questions.connect (boost::ref (Ekiga::Heap::questions));
- add_object (pres);
- presentity_added (pres);
+ boost::shared_ptr<Opal::Presentity> pres = load_presentity (presence_core, existing_groups, presnode);
fetch (pres->get_uri ());
return true;
@@ -947,6 +961,25 @@ Opal::Account::publish (const Ekiga::PersonalDetails& details)
}
+boost::shared_ptr<Opal::Presentity>
+Opal::Account::load_presentity (boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
+ boost::function0<std::list<std::string> > _existing_groups,
+ xmlNodePtr _node)
+{
+ Opal::PresentityPtr pres = Opal::Presentity::create (*this, _presence_core, _existing_groups, _node);
+
+ // When the presentity emits trigger_saving, we relay it "upstream" so that the
+ // Bank can save everything.
+ std::cout << "FIXME: Use add_connection here" << std::endl;
+ pres->trigger_saving.connect (boost::ref (trigger_saving));
+ pres->removed.connect (boost::bind (&Opal::Account::unfetch, this, pres->get_uri ()));
+ pres->updated.connect (boost::bind (&Opal::Account::fetch, this, pres->get_uri ()));
+ add_presentity (pres);
+
+ return pres;
+}
+
+
void
Opal::Account::fetch (const std::string uri)
{
@@ -1025,8 +1058,8 @@ Opal::Account::handle_registration_event (Ekiga::Account::RegistrationState stat
opal_presentity->Open ();
- for (Ekiga::RefLister<Presentity>::iterator iter = Ekiga::RefLister<Presentity>::begin ();
- iter != Ekiga::RefLister<Presentity>::end ();
+ for (Ekiga::HeapImpl<Opal::Presentity>::iterator iter = Ekiga::HeapImpl<Opal::Presentity>::begin ();
+ iter != Ekiga::HeapImpl<Opal::Presentity>::end ();
++iter)
fetch ((*iter)->get_uri());
@@ -1052,7 +1085,7 @@ Opal::Account::handle_registration_event (Ekiga::Account::RegistrationState stat
/* delay destruction of this account until the
unsubscriber thread has called back */
if (dead)
- removed ();
+ removed (this->shared_from_this ());
break;
case UnregistrationFailed:
@@ -1092,7 +1125,7 @@ Opal::Account::handle_registration_event (Ekiga::Account::RegistrationState stat
break;
}
- updated ();
+ updated (this->shared_from_this ());
}
@@ -1111,7 +1144,7 @@ Opal::Account::handle_message_waiting_information (const std::string info)
if (audiooutput)
audiooutput->play_event ("new-voicemail-sound");
}
- updated ();
+ updated (this->shared_from_this ());
}
}
@@ -1293,8 +1326,8 @@ Opal::Account::presence_status_in_main (std::string uri,
std::string uri_presence,
std::string uri_status) const
{
- for (Ekiga::RefLister< Presentity >::const_iterator iter = Ekiga::RefLister< Presentity >::begin ();
- iter != Ekiga::RefLister< Presentity >::end ();
+ for (Ekiga::HeapImpl<Opal::Presentity>::const_iterator iter = Ekiga::HeapImpl<Opal::Presentity>::begin ();
+ iter != Ekiga::HeapImpl<Opal::Presentity>::end ();
++iter) {
if ((*iter)->has_uri (uri)) {
@@ -1307,28 +1340,6 @@ Opal::Account::presence_status_in_main (std::string uri,
status_received (uri, uri_status);
}
-void
-Opal::Account::when_presentity_removed (Opal::PresentityPtr pres)
-{
- unfetch (pres->get_uri ());
- presentity_removed (pres);
-}
-
-void
-Opal::Account::when_presentity_updated (Opal::PresentityPtr pres)
-{
- // we don't unfetch the previous uri here...
- fetch (pres->get_uri ());
- presentity_updated (pres);
-}
-
-
-void
-Opal::Account::visit_presentities (boost::function1<bool, Ekiga::PresentityPtr > visitor) const
-{
- visit_objects (visitor);
-}
-
void
Opal::Account::on_rename_group (Opal::PresentityPtr pres)
diff --git a/lib/engine/components/opal/opal-account.h b/lib/engine/components/opal/opal-account.h
index 588bf9f..0fa59e4 100644
--- a/lib/engine/components/opal/opal-account.h
+++ b/lib/engine/components/opal/opal-account.h
@@ -42,12 +42,13 @@
#include <opal/pres_ent.h>
#include <sip/sippdu.h>
+#include "account.h"
#include "notification-core.h"
#include "presence-core.h"
#include "personal-details.h"
#include "audiooutput-core.h"
-#include "bank-impl.h"
+#include "heap-impl.h"
#include "opal-presentity.h"
@@ -68,10 +69,10 @@ namespace Opal
*/
class Account:
public Ekiga::Account,
- public Ekiga::Heap,
- protected Ekiga::RefLister<Presentity>,
public Ekiga::PresencePublisher,
- public Ekiga::PresenceFetcher
+ public Ekiga::PresenceFetcher,
+ public Ekiga::HeapImpl<Presentity>,
+ public Ekiga::DynamicObject<Account>
{
friend class Presentity;
public:
@@ -105,18 +106,18 @@ public:
* that Opal is taking care of deleting them. They are not deleted when
* the last object having a reference to them is deleted.
*/
- Account (Bank & bank,
- boost::weak_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,
- EndPoint& _endpoint,
+ static boost::shared_ptr<Account> create (Bank & bank,
+ boost::weak_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,
+ EndPoint& _endpoint,
#ifdef HAVE_H323
- H323::EndPoint* _h323_endpoint,
+ H323::EndPoint* _h323_endpoint,
#endif
- Sip::EndPoint* _sip_endpoint,
- boost::function0<std::list<std::string> > _existing_groups,
- xmlNodePtr node_);
+ Sip::EndPoint* _sip_endpoint,
+ boost::function0<std::list<std::string> > _existing_groups,
+ xmlNodePtr node_);
~Account ();
@@ -207,15 +208,28 @@ public:
*/
void handle_message_waiting_information (const std::string info);
- /* This part of the api is the implementation of Ekiga::Heap */
- void visit_presentities (boost::function1<bool, Ekiga::PresentityPtr > visitor) const;
-
const PString get_full_uri (const PString & uri) const;
protected:
void on_rename_group (Opal::PresentityPtr pres);
private:
+ Account (Bank & bank,
+ boost::weak_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,
+ EndPoint& _endpoint,
+#ifdef HAVE_H323
+ H323::EndPoint* _h323_endpoint,
+#endif
+ Sip::EndPoint* _sip_endpoint,
+ boost::function0<std::list<std::string> > _existing_groups,
+ xmlNodePtr node_);
+ boost::shared_ptr<Presentity> load_presentity (boost::weak_ptr<Ekiga::PresenceCore> _presence_core,
+ boost::function0<std::list<std::string> >
_existing_groups,
+ xmlNodePtr _node);
+
void fetch (const std::string uri);
void unfetch (const std::string uri);
bool is_supported_uri (const std::string & uri);
@@ -261,8 +275,6 @@ private:
void presence_status_in_main (std::string uri,
std::string presence,
std::string status) const;
- void when_presentity_removed (boost::shared_ptr<Presentity> pres);
- void when_presentity_updated (boost::shared_ptr<Presentity> pres);
Bank & bank;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]