[ekiga/ds-fix-boost-leaks: 4/7] Call History: Migrated to the new framework.



commit 457700579953adc2fb687b2b8bcf42cc50461023
Author: Damien Sandras <dsandras seconix com>
Date:   Mon May 25 17:42:07 2015 +0200

    Call History: Migrated to the new framework.

 .../components/call-history/history-book.cpp       |  107 +++++++++++---------
 lib/engine/components/call-history/history-book.h  |   19 ++--
 .../components/call-history/history-contact.cpp    |   25 +++++
 .../components/call-history/history-contact.h      |   36 +++++--
 .../components/call-history/history-main.cpp       |    2 +-
 .../components/call-history/history-source.cpp     |   24 ++++-
 .../components/call-history/history-source.h       |    7 +-
 7 files changed, 148 insertions(+), 72 deletions(-)
---
diff --git a/lib/engine/components/call-history/history-book.cpp 
b/lib/engine/components/call-history/history-book.cpp
index c89d34b..c2bafaa 100644
--- a/lib/engine/components/call-history/history-book.cpp
+++ b/lib/engine/components/call-history/history-book.cpp
@@ -39,61 +39,36 @@
 
 #define CALL_HISTORY_KEY "call-history"
 
-History::Book::Book (Ekiga::ServiceCore& core):
-  contact_core(core.get<Ekiga::ContactCore>("contact-core")), doc()
-{
-  xmlNodePtr root = NULL;
 
-  contacts_settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (CONTACTS_SCHEMA));
-  std::string raw = contacts_settings->get_string (CALL_HISTORY_KEY);
-
-  if (!raw.empty ()) {
-
-    doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc);
-    if ( !doc)
-      doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
-
-    root = xmlDocGetRootElement (doc.get ());
-    if (root == NULL) {
-
-      root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
-      xmlDocSetRootElement (doc.get (), root);
-    }
-
-    for (xmlNodePtr child = root->children;
-        child != NULL;
-        child = child->next)
-      if (child->type == XML_ELEMENT_NODE
-         && child->name != NULL
-         && xmlStrEqual (BAD_CAST ("entry"), child->name))
-        add (child);
+boost::shared_ptr<History::Book>
+History::Book::create (Ekiga::ServiceCore & core)
+{
+  boost::shared_ptr<History::Book> book = boost::shared_ptr<History::Book> (new History::Book (core));
+  book->load ();
 
-  }
-  else {
+  return book;
+}
 
-    doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
-    root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
-    xmlDocSetRootElement (doc.get (), root);
-  }
 
+History::Book::Book (Ekiga::ServiceCore& core):
+  contact_core(core.get<Ekiga::ContactCore>("contact-core")), doc()
+{
   boost::shared_ptr<Ekiga::CallCore> call_core = core.get<Ekiga::CallCore> ("call-core");
 
   connections.add (call_core->missed_call.connect (boost::bind (&History::Book::on_missed_call, this, _1)));
   connections.add (call_core->cleared_call.connect (boost::bind (&History::Book::on_cleared_call, this, _1, 
_2)));
 
-  enforce_size_limit ();
-
-  /* Actor actions should be added */
   add_action (Ekiga::ActionPtr (new Ekiga::Action ("history_book_clear",
                                                    _("Clear History"),
                                                    boost::bind (&History::Book::clear,
                                                                 this))));
 }
 
+
 History::Book::~Book ()
 {
 #if DEBUG
-  std::cout << "History::Book: Destructor invoked" << std::endl;
+  std::cout << __FUNCTION__ << " invoked in " << __FILE__ << std::endl << std::flush;
 #endif
 }
 
@@ -116,7 +91,7 @@ void
 History::Book::add (xmlNodePtr node)
 {
   boost::shared_ptr<Ekiga::ContactCore> ccore = contact_core.lock ();
-  common_add (ContactPtr (new Contact (ccore, doc, node)));
+  common_add (History::Contact::create (ccore, doc, node));
 }
 
 void
@@ -132,8 +107,8 @@ History::Book::add (const std::string & name,
 
     xmlNodePtr root = xmlDocGetRootElement (doc.get ());
 
-    ContactPtr contact(new Contact (ccore, doc, name, uri,
-                                   call_start, call_duration, c_t));
+    boost::shared_ptr<History::Contact> contact =
+      History::Contact::create (ccore, doc, name, uri, call_start, call_duration, c_t);
 
     xmlAddChild (root, contact->get_node ());
 
@@ -141,7 +116,7 @@ History::Book::add (const std::string & name,
 
     common_add (contact);
 
-    enforce_size_limit();
+    enforce_size_limit ();
   }
 }
 
@@ -159,6 +134,46 @@ History::Book::get_status () const
 }
 
 void
+History::Book::load ()
+{
+  xmlNodePtr root = NULL;
+
+  contacts_settings = boost::shared_ptr<Ekiga::Settings> (new Ekiga::Settings (CONTACTS_SCHEMA));
+  std::string raw = contacts_settings->get_string (CALL_HISTORY_KEY);
+
+  if (!raw.empty ()) {
+
+    doc = boost::shared_ptr<xmlDoc> (xmlRecoverMemory (raw.c_str (), raw.length ()), xmlFreeDoc);
+    if ( !doc)
+      doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
+
+    root = xmlDocGetRootElement (doc.get ());
+    if (root == NULL) {
+
+      root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
+      xmlDocSetRootElement (doc.get (), root);
+    }
+
+    for (xmlNodePtr child = root->children;
+        child != NULL;
+        child = child->next)
+      if (child->type == XML_ELEMENT_NODE
+         && child->name != NULL
+         && xmlStrEqual (BAD_CAST ("entry"), child->name))
+        add (child);
+
+  }
+  else {
+
+    doc = boost::shared_ptr<xmlDoc> (xmlNewDoc (BAD_CAST "1.0"), xmlFreeDoc);
+    root = xmlNewDocNode (doc.get (), NULL, BAD_CAST "list", NULL);
+    xmlDocSetRootElement (doc.get (), root);
+  }
+
+  enforce_size_limit ();
+}
+
+void
 History::Book::save () const
 {
   xmlChar *buffer = NULL;
@@ -180,7 +195,7 @@ History::Book::clear ()
   ordered_contacts.clear ();
 
   cleared ();
-  updated ();
+  updated (this->shared_from_this ());
 
   for (std::list<ContactPtr>::iterator iter = old_contacts.begin ();
        iter != old_contacts.end();
@@ -225,7 +240,7 @@ History::Book::common_add (ContactPtr contact)
 
   ordered_contacts.push_back (contact);
   contact_added (contact);
-  updated ();
+  updated (this->shared_from_this ());
 }
 
 void
@@ -238,7 +253,7 @@ History::Book::enforce_size_limit()
     ContactPtr contact = ordered_contacts.front ();
     ordered_contacts.pop_front();
     xmlNodePtr node = contact->get_node ();
-    contact->removed();
+    contact->removed (contact);
     xmlUnlinkNode(node);
     xmlFreeNode(node);
     flag = true;
@@ -246,7 +261,7 @@ History::Book::enforce_size_limit()
 
   if (flag) {
 
-    save();
-    updated();
+    save ();
+    updated (this->shared_from_this ());
   }
 }
diff --git a/lib/engine/components/call-history/history-book.h 
b/lib/engine/components/call-history/history-book.h
index 2d7582f..2dea708 100644
--- a/lib/engine/components/call-history/history-book.h
+++ b/lib/engine/components/call-history/history-book.h
@@ -38,11 +38,12 @@
 #include "call-core.h"
 #include "call-manager.h"
 
-#include "book-impl.h"
 #include "history-contact.h"
 
 #include "ekiga-settings.h"
 #include "scoped-connections.h"
+#include "book-impl.h"
+#include "dynamic-object.h"
 
 namespace History
 {
@@ -53,14 +54,14 @@ namespace History
  * @{
  */
 
-  class Book:
-    public Ekiga::Book
+  class Book :
+      public Ekiga::BookImpl<Contact>,
+      public Ekiga::DynamicObject<Book>
   {
   public:
 
     /* generic api */
-
-    Book (Ekiga::ServiceCore &_core);
+    static boost::shared_ptr<Book> create (Ekiga::ServiceCore &_core);
 
     ~Book ();
 
@@ -73,7 +74,7 @@ namespace History
     const std::string get_status () const;
 
     const std::string get_icon () const
-    { return "document-open-recent-symbolic"; }
+      { return "document-open-recent-symbolic"; }
 
 
     /* more specific api */
@@ -89,10 +90,9 @@ namespace History
     boost::signals2::signal<void(void)> cleared;
 
   private:
+    Book (Ekiga::ServiceCore &_core);
 
-    Ekiga::scoped_connections connections;
-
-    void parse_entry (xmlNodePtr entry);
+    void load ();
 
     void save () const;
 
@@ -107,6 +107,7 @@ namespace History
 
     void enforce_size_limit();
 
+    Ekiga::scoped_connections connections;
     boost::weak_ptr<Ekiga::ContactCore> contact_core;
     boost::shared_ptr<xmlDoc> doc;
     std::list<ContactPtr> ordered_contacts;
diff --git a/lib/engine/components/call-history/history-contact.cpp 
b/lib/engine/components/call-history/history-contact.cpp
index c20a18c..da1f2f0 100644
--- a/lib/engine/components/call-history/history-contact.cpp
+++ b/lib/engine/components/call-history/history-contact.cpp
@@ -52,6 +52,28 @@ struct null_deleter
 };
 
 
+boost::shared_ptr<History::Contact>
+History::Contact::create (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
+                          boost::shared_ptr<xmlDoc> _doc,
+                          xmlNodePtr _node)
+{
+  return boost::shared_ptr<History::Contact> (new History::Contact (_contact_core, _doc, _node));
+}
+
+
+boost::shared_ptr<History::Contact>
+History::Contact::create (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
+                          boost::shared_ptr<xmlDoc> _doc,
+                          const std::string _name,
+                          const std::string _uri,
+                          time_t _call_start,
+                          const std::string _call_duration,
+                          call_type c_t)
+{
+  return boost::shared_ptr<History::Contact> (new History::Contact (_contact_core, _doc, _name, _uri, 
_call_start, _call_duration, c_t));
+}
+
+
 History::Contact::Contact (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
                           boost::shared_ptr<xmlDoc> _doc,
                           xmlNodePtr _node):
@@ -154,6 +176,9 @@ History::Contact::Contact (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
 
 History::Contact::~Contact ()
 {
+#if DEBUG
+  std::cout << __FUNCTION__ << " invoked in " << __FILE__ << std::endl << std::flush;
+#endif
 }
 
 const std::string
diff --git a/lib/engine/components/call-history/history-contact.h 
b/lib/engine/components/call-history/history-contact.h
index 8fe58ad..fb9f205 100644
--- a/lib/engine/components/call-history/history-contact.h
+++ b/lib/engine/components/call-history/history-contact.h
@@ -41,6 +41,7 @@
 
 #include "services.h"
 #include "contact-core.h"
+#include "dynamic-object.h"
 
 namespace History
 {
@@ -59,21 +60,22 @@ namespace History
   } call_type;
 
   class Contact:
-    public Ekiga::Contact
+      public Ekiga::Contact,
+      public Ekiga::DynamicObject<Contact>
   {
   public:
 
-    Contact (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
-            boost::shared_ptr<xmlDoc> _doc,
-            xmlNodePtr _node);
+    static boost::shared_ptr<Contact> create (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
+                                              boost::shared_ptr<xmlDoc> _doc,
+                                              xmlNodePtr _node);
 
-    Contact (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
-            boost::shared_ptr<xmlDoc> _doc,
-            const std::string _name,
-            const std::string _uri,
-             time_t call_start,
-             const std::string call_duration,
-            call_type c_t);
+    static boost::shared_ptr<Contact> create (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
+                                              boost::shared_ptr<xmlDoc> _doc,
+                                              const std::string _name,
+                                              const std::string _uri,
+                                              time_t call_start,
+                                              const std::string call_duration,
+                                              call_type c_t);
 
     ~Contact ();
 
@@ -98,6 +100,18 @@ namespace History
     const std::string get_uri () const;
 
   private:
+    Contact (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
+            boost::shared_ptr<xmlDoc> _doc,
+            xmlNodePtr _node);
+
+    Contact (boost::shared_ptr<Ekiga::ContactCore> _contact_core,
+            boost::shared_ptr<xmlDoc> _doc,
+            const std::string _name,
+            const std::string _uri,
+             time_t call_start,
+             const std::string call_duration,
+            call_type c_t);
+
 
     boost::weak_ptr<Ekiga::ContactCore> contact_core;
 
diff --git a/lib/engine/components/call-history/history-main.cpp 
b/lib/engine/components/call-history/history-main.cpp
index 02cd0a2..15484b4 100644
--- a/lib/engine/components/call-history/history-main.cpp
+++ b/lib/engine/components/call-history/history-main.cpp
@@ -53,7 +53,7 @@ struct HISTORYSpark: public Ekiga::Spark
 
     if (contact_core && call_core) {
 
-      boost::shared_ptr<History::Source> source (new History::Source (core));
+      boost::shared_ptr<History::Source> source = History::Source::create (core);
       if (core.add (source)) {
 
        contact_core->add_source (source);
diff --git a/lib/engine/components/call-history/history-source.cpp 
b/lib/engine/components/call-history/history-source.cpp
index f80bf3e..3eab14a 100644
--- a/lib/engine/components/call-history/history-source.cpp
+++ b/lib/engine/components/call-history/history-source.cpp
@@ -36,17 +36,24 @@
 
 #include "history-source.h"
 
-History::Source::Source (Ekiga::ServiceCore &_core): core(_core)
+boost::shared_ptr<History::Source>
+History::Source::create (Ekiga::ServiceCore &_core)
 {
-  book = boost::shared_ptr<Book>(new Book (core));
+  boost::shared_ptr<History::Source> source = boost::shared_ptr<History::Source> (new History::Source 
(_core));
+  source->load ();
 
-  add_book (book);
+  return source;
+}
+
+
+History::Source::Source (Ekiga::ServiceCore &_core): core(_core)
+{
 }
 
 History::Source::~Source ()
 {
 #if DEBUG
-  std::cout << "History::Source: Destructor invoked" << std::endl;
+  std::cout << __FUNCTION__ << " invoked in " << __FILE__ << std::endl << std::flush;
 #endif
 }
 
@@ -61,3 +68,12 @@ History::Source::get_book () const
 {
   return book;
 }
+
+void
+History::Source::load ()
+{
+  book = History::Book::create (core);
+
+  add_book (book);
+}
+
diff --git a/lib/engine/components/call-history/history-source.h 
b/lib/engine/components/call-history/history-source.h
index 491ceea..960a4bc 100644
--- a/lib/engine/components/call-history/history-source.h
+++ b/lib/engine/components/call-history/history-source.h
@@ -37,6 +37,7 @@
 
 #include "source-impl.h"
 #include "history-book.h"
+#include "dynamic-object.h"
 
 namespace History
 {
@@ -49,11 +50,12 @@ namespace History
 
   class Source :
     public Ekiga::SourceImpl<Book>,
+    public Ekiga::DynamicObject<Source>,
     public Ekiga::Service
   {
   public:
 
-    Source (Ekiga::ServiceCore &_core);
+    static boost::shared_ptr<Source> create (Ekiga::ServiceCore &_core);
 
     ~Source ();
 
@@ -70,6 +72,9 @@ namespace History
     BookPtr get_book () const;
 
   private:
+    Source (Ekiga::ServiceCore &_core);
+
+    void load ();
 
     Ekiga::ServiceCore &core;
     BookPtr book;


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