[ekiga/ds-fix-boost-leaks: 3/7] Addressbook: Fixed boost leaks and simplified API.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga/ds-fix-boost-leaks: 3/7] Addressbook: Fixed boost leaks and simplified API.
- Date: Mon, 25 May 2015 15:45:01 +0000 (UTC)
commit 12a7dd0654a109d20fc0e2c724a29a302a46ec0a
Author: Damien Sandras <dsandras seconix com>
Date: Mon May 25 17:16:08 2015 +0200
Addressbook: Fixed boost leaks and simplified API.
Here is the list of changes:
- We now "use" the DynamicObjectStore object everywhere instead of
inheriting from it (or from RefLister). We should avoir inheriting
from STL containers.
- Signals relay has been simplified. Signals should not have the
emitting object as a parameter. When using Boost shared pointers, you
cannot bind them as the "emitting object" parameter to slots. That's
because the shared pointer will be copied into the object's slot list,
keeping it in memory indefinitely.
lib/engine/addressbook/book-impl.h | 35 ++++++++++-----------
lib/engine/addressbook/book.h | 8 ++--
lib/engine/addressbook/contact-core.cpp | 9 -----
lib/engine/addressbook/contact-core.h | 32 ++----------------
lib/engine/addressbook/contact.h | 5 +--
lib/engine/addressbook/source-impl.h | 52 ++++++------------------------
lib/engine/addressbook/source.h | 31 +++++-------------
7 files changed, 45 insertions(+), 127 deletions(-)
---
diff --git a/lib/engine/addressbook/book-impl.h b/lib/engine/addressbook/book-impl.h
index 4281731..957db35 100644
--- a/lib/engine/addressbook/book-impl.h
+++ b/lib/engine/addressbook/book-impl.h
@@ -36,7 +36,7 @@
#ifndef __BOOK_IMPL_H__
#define __BOOK_IMPL_H__
-#include "reflister.h"
+#include "dynamic-object-store.h"
#include "book.h"
@@ -70,15 +70,13 @@ namespace Ekiga
* backend.
*/
template<typename ContactType = Contact>
- class BookImpl:
- public Book,
- protected RefLister<ContactType>
- {
+ class BookImpl: public Book
+{
public:
- typedef typename RefLister<ContactType>::iterator iterator;
- typedef typename RefLister<ContactType>::const_iterator const_iterator;
+ typedef typename DynamicObjectStore<ContactType>::iterator iterator;
+ typedef typename DynamicObjectStore<ContactType>::const_iterator const_iterator;
/** The constructor
*/
@@ -130,7 +128,8 @@ namespace Ekiga
*/
void remove_contact (boost::shared_ptr<ContactType> contact);
- using RefLister<ContactType>::add_connection;
+ protected:
+ DynamicObjectStore<ContactType> contacts;
};
/**
@@ -146,9 +145,9 @@ template<typename ContactType>
Ekiga::BookImpl<ContactType>::BookImpl ()
{
/* this is signal forwarding */
- RefLister<ContactType>::object_added.connect (contact_added);
- RefLister<ContactType>::object_removed.connect (contact_removed);
- RefLister<ContactType>::object_updated.connect (contact_updated);
+ contacts.object_added.connect (boost::bind (boost::ref (contact_added), _1));
+ contacts.object_updated.connect (boost::bind (boost::ref (contact_updated), _1));
+ contacts.object_removed.connect (boost::bind (boost::ref (contact_removed), _1));
}
@@ -162,7 +161,7 @@ template<typename ContactType>
void
Ekiga::BookImpl<ContactType>::visit_contacts (boost::function1<bool, ContactPtr > visitor) const
{
- RefLister<ContactType>::visit_objects (visitor);
+ contacts.visit_objects (visitor);
}
@@ -170,7 +169,7 @@ template<typename ContactType>
typename Ekiga::BookImpl<ContactType>::iterator
Ekiga::BookImpl<ContactType>::begin ()
{
- return RefLister<ContactType>::begin ();
+ return contacts.begin ();
}
@@ -178,7 +177,7 @@ template<typename ContactType>
typename Ekiga::BookImpl<ContactType>::iterator
Ekiga::BookImpl<ContactType>::end ()
{
- return RefLister<ContactType>::end ();
+ return contacts.end ();
}
@@ -186,7 +185,7 @@ template<typename ContactType>
typename Ekiga::BookImpl<ContactType>::const_iterator
Ekiga::BookImpl<ContactType>::begin () const
{
- return RefLister<ContactType>::begin ();
+ return contacts.begin ();
}
@@ -194,7 +193,7 @@ template<typename ContactType>
typename Ekiga::BookImpl<ContactType>::const_iterator
Ekiga::BookImpl<ContactType>::end () const
{
- return RefLister<ContactType>::end ();
+ return contacts.end ();
}
@@ -203,7 +202,7 @@ void
Ekiga::BookImpl<ContactType>::add_contact (boost::shared_ptr<ContactType> contact)
{
contact->questions.connect (boost::ref (questions));
- this->add_object (contact);
+ contacts.add_object (contact);
}
@@ -211,7 +210,7 @@ template<typename ContactType>
void
Ekiga::BookImpl<ContactType>::remove_contact (boost::shared_ptr<ContactType> contact)
{
- this->remove_object (contact);
+ contacts.remove_object (contact);
}
#endif
diff --git a/lib/engine/addressbook/book.h b/lib/engine/addressbook/book.h
index 24ec52d..0eaaf4d 100644
--- a/lib/engine/addressbook/book.h
+++ b/lib/engine/addressbook/book.h
@@ -40,9 +40,10 @@
namespace Ekiga {
- class Book:
- public Actor,
- public virtual LiveObject
+ class Book;
+ typedef boost::shared_ptr<Book> BookPtr;
+
+ class Book: public Actor
{
public:
@@ -106,7 +107,6 @@ namespace Ekiga {
boost::signals2::signal<void(ContactPtr)> contact_updated;
};
- typedef boost::shared_ptr<Book> BookPtr;
};
#endif
diff --git a/lib/engine/addressbook/contact-core.cpp b/lib/engine/addressbook/contact-core.cpp
index 5c5b1eb..6e54ad9 100644
--- a/lib/engine/addressbook/contact-core.cpp
+++ b/lib/engine/addressbook/contact-core.cpp
@@ -58,16 +58,7 @@ Ekiga::ContactCore::add_source (SourcePtr source)
{
sources.push_back (source);
source_added (source);
- conns.add (source->updated.connect (boost::ref (updated)));
- conns.add (source->book_added.connect (boost::bind (boost::ref (book_added), _1)));
- conns.add (source->book_removed.connect (boost::bind (boost::ref (book_removed), _1)));
- conns.add (source->book_updated.connect (boost::bind (boost::ref (book_updated), _1)));
- conns.add (source->contact_added.connect (boost::bind (boost::ref (contact_added), _1, _2)));
- conns.add (source->contact_removed.connect (boost::bind (boost::ref (contact_removed), _1, _2)));
- conns.add (source->contact_updated.connect (boost::bind (boost::ref (contact_updated), _1, _2)));
source->questions.connect (boost::ref (questions));
-
- updated ();
}
void
diff --git a/lib/engine/addressbook/contact-core.h b/lib/engine/addressbook/contact-core.h
index 70a6403..343bde3 100644
--- a/lib/engine/addressbook/contact-core.h
+++ b/lib/engine/addressbook/contact-core.h
@@ -39,6 +39,8 @@
#include "source.h"
#include "scoped-connections.h"
#include "action-provider.h"
+#include "chain-of-responsibility.h"
+#include "form-request.h"
/* declaration of a few helper classes */
namespace Ekiga
@@ -56,7 +58,6 @@ namespace Ekiga
* be freed here : it's up to you to free them somehow.
*/
class ContactCore:
- public virtual LiveObject,
public URIActionProviderStore,
public Service
{
@@ -106,35 +107,10 @@ namespace Ekiga
*/
boost::signals2::signal<void(SourcePtr)> source_added;
- /** This signal is emitted when a book has been added to one of
- * the sources
- */
- boost::signals2::signal<void(BookPtr)> book_added;
-
- /** This signal is emitted when a book has been removed from one of
- * the sources
- */
- boost::signals2::signal<void(BookPtr )> book_removed;
-
- /** This signal is emitted when a book has been updated in one of
- * the sources
- */
- boost::signals2::signal<void(BookPtr )> book_updated;
-
- /** This signal is emitted when a contact has been added to one of
- * the book of one of the sources
- */
- boost::signals2::signal<void(BookPtr, ContactPtr )> contact_added;
-
- /** This signal is emitted when a contact has been removed from one of
- * the book of one of the sources
- */
- boost::signals2::signal<void(BookPtr, ContactPtr )> contact_removed;
- /** This signal is emitted when a contact has been updated in one of
- * the book of one of the sources
+ /** This chain allows the core to present forms to the user
*/
- boost::signals2::signal<void(BookPtr, ContactPtr )> contact_updated;
+ ChainOfResponsibility<FormRequestPtr> questions;
private:
diff --git a/lib/engine/addressbook/contact.h b/lib/engine/addressbook/contact.h
index c69b02b..281aeb3 100644
--- a/lib/engine/addressbook/contact.h
+++ b/lib/engine/addressbook/contact.h
@@ -42,7 +42,6 @@
#include <boost/smart_ptr.hpp>
-#include "live-object.h"
#include "actor.h"
namespace Ekiga
@@ -53,9 +52,7 @@ namespace Ekiga
* @{
*/
- class Contact:
- public virtual LiveObject,
- public Ekiga::Actor
+ class Contact: public Actor
{
public:
diff --git a/lib/engine/addressbook/source-impl.h b/lib/engine/addressbook/source-impl.h
index 594b585..5d2eeca 100644
--- a/lib/engine/addressbook/source-impl.h
+++ b/lib/engine/addressbook/source-impl.h
@@ -37,7 +37,7 @@
#ifndef __SOURCE_IMPL_H__
#define __SOURCE_IMPL_H__
-#include "reflister.h"
+#include "dynamic-object-store.h"
#include "source.h"
@@ -76,8 +76,7 @@ namespace Ekiga
* the appropriate api function to delete the Book in your backend.
*/
template<typename BookType = Book>
- class SourceImpl:
- public Source
+ class SourceImpl: public Source
{
public:
@@ -118,8 +117,8 @@ namespace Ekiga
void remove_book (boost::shared_ptr<BookType> book);
public:
- typedef typename RefLister<BookType>::const_iterator const_iterator;
- typedef typename RefLister<BookType>::iterator iterator;
+ typedef typename DynamicObjectStore<BookType>::const_iterator const_iterator;
+ typedef typename DynamicObjectStore<BookType>::iterator iterator;
/** Returns an iterator to the first Book of the collection
*/
@@ -137,33 +136,8 @@ namespace Ekiga
*/
const_iterator end () const;
-
- private:
-
- /** Disconnects the signals for the Ekiga::Book, emits the 'book_removed'
- * signal on the Ekiga::Source and takes care of the release of that
- * Ekiga::Book.
- * @param: The Book to remove.
- */
- void common_removal_steps (boost::shared_ptr<BookType> book);
-
-
- /** This callback is triggered when the 'updated' signal is emitted on an
- * Ekiga::Book. Emits the Ekiga::Source 'book_updated' signal for that
- * Ekiga::Book.
- * @param: The updated book.
- */
- void on_book_updated (boost::shared_ptr<BookType> book);
-
-
- /** This callback is triggered when the 'removed' signal is emitted on an
- * Ekiga::Book. Emits the Ekiga::Source 'book_removed' signal for that book
- * and takes care of the deletion of the book.
- * @param: The removed book.
- */
- void on_book_removed (boost::shared_ptr<BookType> book);
-
- RefLister<BookType> books;
+ protected:
+ DynamicObjectStore<BookType> books;
};
@@ -180,16 +154,16 @@ namespace Ekiga
template<typename BookType>
Ekiga::SourceImpl<BookType>::SourceImpl ()
{
- /* signal forwarding */
- books.object_added.connect (boost::ref (book_added));
- books.object_removed.connect (boost::ref (book_removed));
- books.object_updated.connect (boost::ref (book_updated));
+ /* this is signal forwarding */
+ books.object_added.connect (boost::bind (boost::ref (book_added), _1));
+ books.object_updated.connect (boost::bind (boost::ref (book_updated), _1));
+ books.object_removed.connect (boost::bind (boost::ref (book_removed), _1));
}
+
template<typename BookType>
Ekiga::SourceImpl<BookType>::~SourceImpl ()
{
- books.remove_all_objects ();
}
@@ -206,10 +180,6 @@ void
Ekiga::SourceImpl<BookType>::add_book (boost::shared_ptr<BookType> book)
{
books.add_object (book);
-
- books.add_connection (book, book->contact_added.connect (boost::bind (boost::ref (contact_added), book,
_1)));
- books.add_connection (book, book->contact_removed.connect (boost::bind (boost::ref (contact_removed),
book, _1)));
- books.add_connection (book, book->contact_updated.connect (boost::bind (boost::ref (contact_updated),
book, _1)));
books.add_connection (book, book->questions.connect (boost::ref (questions)));
}
diff --git a/lib/engine/addressbook/source.h b/lib/engine/addressbook/source.h
index eaa05bd..aed6892 100644
--- a/lib/engine/addressbook/source.h
+++ b/lib/engine/addressbook/source.h
@@ -41,9 +41,11 @@
namespace Ekiga {
+ class Source;
+ typedef boost::shared_ptr<Source> SourcePtr;
+
class Source:
- public Actor,
- public virtual LiveObject
+ public Actor
{
public:
@@ -65,34 +67,17 @@ namespace Ekiga {
/** This signal is emitted when a Book has been added to the Source.
*/
boost::signals2::signal<void(BookPtr)> book_added;
-
-
+
+
/** This signal is emitted when a Book has been updated in the Source.
*/
boost::signals2::signal<void(BookPtr)> book_updated;
-
-
- /** This signal is emitted when a Book has been removed in the Source.
- */
- boost::signals2::signal<void(BookPtr)> book_removed;
- /** This signal is emitted when a Contact has been added to a book in
- * this source.
- */
- boost::signals2::signal<void(BookPtr, ContactPtr )> contact_added;
-
- /** This signal is emitted when a Contact has been removed from a book in
- * this source.
- */
- boost::signals2::signal<void(BookPtr, ContactPtr )> contact_removed;
- /** This signal is emitted when a Contact has been updated in a book in
- * this source
+ /** This signal is emitted when a Book has been removed in the Source.
*/
- boost::signals2::signal<void(BookPtr, ContactPtr )> contact_updated;
+ boost::signals2::signal<void(BookPtr)> book_removed;
};
-
- typedef boost::shared_ptr<Source> SourcePtr;
};
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]