[ekiga/ds-opal-refactoring] DynamicObject: Added replacement for RefLister and LiveObject.



commit ac5cf02ec43709651f25a95e954513188906e328
Author: Damien Sandras <dsandras seconix com>
Date:   Tue Mar 31 18:07:24 2015 +0200

    DynamicObject: Added replacement for RefLister and LiveObject.
    
    The new replacement is working around the crossed references problem
    preventing boost to release memory.
    
    The problem is due to signal relay: we connect signals of an object so
    that they are relayed by another object using the first object as
    argument.
    
    The solution is to pass the object itself to the signal instead of
    binding to it.

 lib/Makefile.am                             |    2 +
 lib/engine/framework/dynamic-object-store.h |  185 +++++++++++++++++++++++++++
 lib/engine/framework/dynamic-object.h       |   75 +++++++++++
 3 files changed, 262 insertions(+), 0 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 8fcbf5f..6dbe119 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -145,6 +145,7 @@ libekiga_la_SOURCES += \
        engine/framework/map-key-iterator.h \
        engine/framework/map-key-const-iterator.h \
        engine/framework/reflister.h \
+       engine/framework/dynamic-object-store.h \
        engine/framework/chain-of-responsibility.h \
        engine/framework/device-def.h \
        engine/framework/form-builder.h \
@@ -176,6 +177,7 @@ libekiga_la_SOURCES += \
        engine/framework/ptr_array_iterator.h \
        engine/framework/ptr_array_const_iterator.h \
        engine/framework/live-object.h \
+       engine/framework/dynamic-object.h \
        engine/framework/filterable.h \
        engine/framework/scoped-connections.h
 
diff --git a/lib/engine/framework/dynamic-object-store.h b/lib/engine/framework/dynamic-object-store.h
new file mode 100644
index 0000000..ebaf5cb
--- /dev/null
+++ b/lib/engine/framework/dynamic-object-store.h
@@ -0,0 +1,185 @@
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+
+ * This program is free software; you can  redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ *                         dynamic-object-store.h  -  description
+ *                         --------------------------------------
+ *   begin                : 28 March 2015
+ *   authors              : (c) 2008 Julien Puydt
+ *                          (c) 2015 Damien SANDRAS
+ *   description          : declaration of an object able to store objects.
+ *
+ */
+
+#ifndef __DYNAMIC_OBJECT_STORE_H__
+#define __DYNAMIC_OBJECT_STORE_H__
+
+#include <boost/signals2.hpp>
+#include <boost/bind.hpp>
+#include <list>
+
+#include <boost/smart_ptr.hpp>
+
+#include "live-object.h"
+#include "map-key-iterator.h"
+#include "map-key-const-iterator.h"
+#include "scoped-connections.h"
+
+namespace Ekiga
+{
+  template<typename ObjectType>
+  class DynamicObjectStore
+  {
+  public:
+
+    typedef std::map<boost::shared_ptr<ObjectType>, boost::shared_ptr<scoped_connections> > container_type;
+    typedef Ekiga::map_key_iterator<container_type> iterator;
+    typedef Ekiga::map_key_const_iterator<container_type> const_iterator;
+
+    ~DynamicObjectStore ();
+
+    void visit_objects (boost::function1<bool, boost::shared_ptr<ObjectType> > visitor) const;
+
+    void add_object (boost::shared_ptr<ObjectType> obj);
+
+    void add_connection (boost::shared_ptr<ObjectType> obj,
+                        boost::signals2::connection connection);
+
+    void remove_object (boost::shared_ptr<ObjectType> obj);
+
+    void remove_all_objects ();
+
+    int size () const;
+
+    iterator begin ();
+    iterator end ();
+
+    const_iterator begin () const;
+    const_iterator end () const;
+
+    boost::signals2::signal<void(boost::shared_ptr<ObjectType>)> object_added;
+    boost::signals2::signal<void(boost::shared_ptr<ObjectType>)> object_removed;
+    boost::signals2::signal<void(boost::shared_ptr<ObjectType>)> object_updated;
+
+  private:
+    container_type objects;
+  };
+
+};
+
+
+template<typename ObjectType>
+Ekiga::DynamicObjectStore<ObjectType>::~DynamicObjectStore ()
+{
+  remove_all_objects ();
+}
+
+
+template<typename ObjectType>
+void
+Ekiga::DynamicObjectStore<ObjectType>::visit_objects (boost::function1<bool, boost::shared_ptr<ObjectType> > 
visitor) const
+{
+  bool go_on = true;
+  for (typename container_type::const_iterator iter = objects.begin ();
+       go_on && iter != objects.end ();
+       ++iter)
+    go_on = visitor (iter->first);
+}
+
+template<typename ObjectType>
+void
+Ekiga::DynamicObjectStore<ObjectType>::add_object (boost::shared_ptr<ObjectType> obj)
+{
+  typename container_type::iterator iter = objects.find (obj);
+  if (iter == objects.end ()) {
+    objects[obj] = boost::shared_ptr<scoped_connections> (new scoped_connections);
+    object_added (obj);
+  }
+}
+
+template<typename ObjectType>
+void
+Ekiga::DynamicObjectStore<ObjectType>::add_connection (boost::shared_ptr<ObjectType> obj,
+                                             boost::signals2::connection connection)
+{
+  typename container_type::iterator iter = objects.find (obj);
+  if (iter == objects.end ())
+    objects[obj] = boost::shared_ptr<scoped_connections> (new scoped_connections);
+  objects[obj]->add (connection);
+}
+
+template<typename ObjectType>
+void
+Ekiga::DynamicObjectStore<ObjectType>::remove_object (boost::shared_ptr<ObjectType> obj)
+{
+  object_removed (obj);
+  objects.erase (objects.find (obj));
+}
+
+template<typename ObjectType>
+void
+Ekiga::DynamicObjectStore<ObjectType>::remove_all_objects ()
+{
+  /* iterators get invalidated as we go, hence the strange loop */
+  while ( !objects.empty ())
+    remove_object (objects.begin ()->first);
+}
+
+template<typename ObjectType>
+int
+Ekiga::DynamicObjectStore<ObjectType>::size () const
+{
+  return objects.size ();
+}
+
+template<typename ObjectType>
+typename Ekiga::DynamicObjectStore<ObjectType>::iterator
+Ekiga::DynamicObjectStore<ObjectType>::begin ()
+{
+  return iterator (objects.begin ());
+}
+
+template<typename ObjectType>
+typename Ekiga::DynamicObjectStore<ObjectType>::iterator
+Ekiga::DynamicObjectStore<ObjectType>::end ()
+{
+  return iterator (objects.end ());
+}
+
+template<typename ObjectType>
+typename Ekiga::DynamicObjectStore<ObjectType>::const_iterator
+Ekiga::DynamicObjectStore<ObjectType>::begin () const
+{
+  return const_iterator (objects.begin ());
+}
+
+template<typename ObjectType>
+typename Ekiga::DynamicObjectStore<ObjectType>::const_iterator
+Ekiga::DynamicObjectStore<ObjectType>::end () const
+{
+  return const_iterator (objects.end ());
+}
+
+#endif
diff --git a/lib/engine/framework/dynamic-object.h b/lib/engine/framework/dynamic-object.h
new file mode 100644
index 0000000..fdc99e8
--- /dev/null
+++ b/lib/engine/framework/dynamic-object.h
@@ -0,0 +1,75 @@
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+
+ * This program is free software; you can  redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ *                         dynamic-object.h  -  description
+ *                         --------------------------------
+ *   copyright            : (c) 2009 by Julien Puydt
+ *                          (c) 2015 by Damien SANDRAS
+ *   description          : common class for objects which are somehow 'dynamic'
+ *
+ */
+
+#ifndef __DYNAMIC_OBJECT_H__
+#define __DYNAMIC_OBJECT_H__
+
+#include <boost/smart_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+
+#include "chain-of-responsibility.h"
+#include "form-request.h"
+#include "menu-builder.h"
+
+namespace Ekiga
+{
+
+  template<typename ObjectType>
+  class DynamicObject : public virtual boost::enable_shared_from_this<ObjectType>
+  {
+  public:
+
+    virtual ~DynamicObject () { }
+
+    boost::shared_ptr<ObjectType> get_shared_ptr () { return this->shared_from_this (); };
+
+    /**
+     * Signals on that object
+     */
+
+    /** This signal is emitted when the object has been updated.
+     */
+    boost::signals2::signal<void(boost::shared_ptr<ObjectType>)> updated;
+
+
+    /** This signal is emitted when the object has been removed.
+     */
+    boost::signals2::signal<void(boost::shared_ptr<ObjectType>)> removed;
+
+    /** This chain allows the object to present forms to the user
+     */
+    ChainOfResponsibility<FormRequestPtr> questions;
+  };
+};
+#endif


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