ekiga r7187 - in trunk: . lib lib/gmref src src/gui



Author: jpuydt
Date: Thu Oct  9 18:37:38 2008
New Revision: 7187
URL: http://svn.gnome.org/viewvc/ekiga?rev=7187&view=rev

Log:
gmref is in

Added:
   trunk/lib/gmref/
   trunk/lib/gmref/Makefile.am
   trunk/lib/gmref/gmref.cpp
   trunk/lib/gmref/gmref.h
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/lib/Makefile.am
   trunk/src/Makefile.am
   trunk/src/gui/main.cpp

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Thu Oct  9 18:37:38 2008
@@ -754,6 +754,7 @@
 AC_PACKAGE_NAME.desktop.in
 lib/Makefile
 lib/gmconf/Makefile
+lib/gmref/Makefile
 lib/gui/Makefile
 lib/pixops/Makefile
 lib/toolbox/Makefile

Modified: trunk/lib/Makefile.am
==============================================================================
--- trunk/lib/Makefile.am	(original)
+++ trunk/lib/Makefile.am	Thu Oct  9 18:37:38 2008
@@ -1,4 +1,4 @@
-SUBDIRS = gmconf gui toolbox platform
+SUBDIRS = gmconf gmref gui toolbox platform
 
 if !WIN32
 SUBDIRS += pixops
@@ -21,10 +21,12 @@
 	-I$(top_srcdir)					
 
 libekiga_la_LDFLAGS = -export-dynamic
-libekiga_la_LIBADD = gmconf/libgmconf.la \
-		     gui/libgmwidgets.la \
-		     toolbox/libtoolbox.la \
-		     platform/libgmplatform.la
+libekiga_la_LIBADD = \
+	gmconf/libgmconf.la \
+	gmref/libgmref.la \
+	gui/libgmwidgets.la \
+	toolbox/libtoolbox.la \
+	platform/libgmplatform.la
 
 if !WIN32
 libekiga_la_LIBADD += pixops/libpixops.la

Added: trunk/lib/gmref/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/lib/gmref/Makefile.am	Thu Oct  9 18:37:38 2008
@@ -0,0 +1,6 @@
+noinst_LTLIBRARIES = libgmref.la
+
+libgmref_la_SOURCES = gmref.h gmref.cpp
+
+libgmref_la_LDFLAGS = -export-dynamic $(AM_LIBS)
+

Added: trunk/lib/gmref/gmref.cpp
==============================================================================
--- (empty file)
+++ trunk/lib/gmref/gmref.cpp	Thu Oct  9 18:37:38 2008
@@ -0,0 +1,71 @@
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * 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.
+ */
+
+
+/*
+ *                         gmref.cpp  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : Reference-counted memory management helpers
+ *
+ */
+
+#include "gmref.h"
+
+#include <map>
+
+static std::map<GmRefCounted*, int> refcounts;
+
+void
+gmref_init ()
+{
+  /* the goal is to prevent the static initialization fiasco */
+  refcounts.clear ();
+}
+
+void
+gmref_inc (GmRefCounted* obj)
+{
+  std::map<GmRefCounted*, int>::iterator iter = refcounts.find (obj);
+  if (iter == refcounts.end ()) {
+
+    refcounts[obj] = 1;
+  } else
+    refcounts[obj]++;
+}
+
+void
+gmref_dec (GmRefCounted* obj)
+{
+  refcounts[obj]--;
+
+  if (refcounts[obj] <= 0) {
+
+    refcounts.erase (obj);
+    delete obj;
+  }
+}

Added: trunk/lib/gmref/gmref.h
==============================================================================
--- (empty file)
+++ trunk/lib/gmref/gmref.h	Thu Oct  9 18:37:38 2008
@@ -0,0 +1,203 @@
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * 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.
+ */
+
+
+/*
+ *                         gmref.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2008 by Julien Puydt
+ *   copyright            : (c) 2008 by Julien Puydt
+ *   description          : Reference-counted memory management helpers
+ *
+ */
+
+#ifndef __GMREF_H__
+#define __GMREF_H__
+
+/* base class */
+struct GmRefCounted
+{
+  virtual ~GmRefCounted ()
+  {}
+};
+
+
+/* base api */
+
+void gmref_init ();
+void gmref_inc (GmRefCounted* obj);
+void gmref_dec (GmRefCounted* obj);
+
+/* reference-counted pointer class */
+
+template<typename T>
+class gmref_ptr
+{
+public:
+
+  gmref_ptr (T* obj_);
+
+  gmref_ptr (const gmref_ptr<T>& ptr);
+
+  template<typename Tprim> gmref_ptr (const gmref_ptr<Tprim>& ptr);
+
+  ~gmref_ptr ();
+
+  gmref_ptr<T>& operator= (const gmref_ptr<T>& other);
+
+  T* operator-> () const;
+
+  T& operator* () const;
+
+  operator bool () const;
+
+  bool operator==(const gmref_ptr<T>& other) const;
+
+  bool operator!=(const gmref_ptr<T>& other) const;
+
+private:
+
+  template<typename Tprim> friend class gmref_ptr;
+  template<typename Tprim> friend void gmref_inc (gmref_ptr<Tprim> ptr);
+  template<typename Tprim> friend void gmref_dec (gmref_ptr<Tprim> ptr);
+
+  void reset ();
+  void inc ();
+
+  T* obj;
+};
+
+/* extended api */
+
+template<typename T>
+void gmref_inc (gmref_ptr<T> ptr)
+{
+  gmref_inc (ptr.obj);
+}
+
+template<typename T>
+void gmref_dec (gmref_ptr<T> ptr)
+{
+  gmref_dec (ptr.obj);
+}
+
+
+/* implementation of the templates */
+
+template<typename T>
+gmref_ptr<T>::gmref_ptr (T* obj_ = 0)
+{
+  obj = obj_;
+  inc ();
+}
+
+template<typename T>
+gmref_ptr<T>::gmref_ptr (const gmref_ptr<T>& ptr)
+{
+  obj = ptr.obj;
+  inc ();
+}
+
+template<typename T>
+template<typename Tprim>
+gmref_ptr<T>::gmref_ptr (const gmref_ptr<Tprim>& ptr)
+{
+  obj = dynamic_cast<T*>(ptr.obj);
+  inc ();
+}
+
+template<typename T>
+gmref_ptr<T>::~gmref_ptr ()
+{
+  reset ();
+}
+
+template<typename T>
+gmref_ptr<T>&
+gmref_ptr<T>::operator= (const gmref_ptr<T>& other)
+{
+  if (this != &other) {
+
+    reset ();
+    obj = other.obj;
+    inc ();
+  }
+
+  return *this;
+}
+
+template<typename T>
+T*
+gmref_ptr<T>::operator-> () const
+{
+  return obj;
+}
+
+template<typename T>
+T&
+gmref_ptr<T>::operator* () const
+{
+  return *obj;
+}
+
+template<typename T>
+gmref_ptr<T>::operator bool () const
+{
+  return obj != 0;
+}
+
+template<typename T>
+bool
+gmref_ptr<T>::operator==(const gmref_ptr<T>& other) const
+{
+  return obj == other.obj;
+}
+
+template<typename T>
+bool
+gmref_ptr<T>::operator!=(const gmref_ptr<T>& other) const
+{
+  return !operator==(other);
+}
+
+template<typename T>
+void
+gmref_ptr<T>::reset ()
+{
+  if (obj != 0)
+    gmref_dec (obj);
+  obj = 0;
+}
+
+template<typename T>
+void
+gmref_ptr<T>::inc ()
+{
+  if (obj != 0)
+    gmref_inc (obj);
+}
+
+#endif

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Thu Oct  9 18:37:38 2008
@@ -1,6 +1,7 @@
 INCLUDES = \
 	-I$(top_srcdir)/lib				\
 	-I$(top_srcdir)/lib/gmconf			\
+	-I$(top_srcdir)/lib/gmref			\
 	-I$(top_srcdir)/lib/toolbox			\
 	-I$(top_srcdir)/lib/gui				\
 	-I$(top_srcdir)/lib/engine/			\

Modified: trunk/src/gui/main.cpp
==============================================================================
--- trunk/src/gui/main.cpp	(original)
+++ trunk/src/gui/main.cpp	Thu Oct  9 18:37:38 2008
@@ -55,6 +55,7 @@
 #include "gmconnectbutton.h"
 #include "gmstockicons.h"
 #include "gmconf.h"
+#include "gmref.h"
 #include "gmwindow.h"
 #include "gmmenuaddon.h"
 #include "gmlevelmeter.h"
@@ -4268,6 +4269,9 @@
   /* initialize platform-specific code */
   gm_platform_init ();
 
+  /* Memory management helpers */
+  gmref_init ();
+
   /* Configuration backend initialization */
   gm_conf_init ();
 



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