[ekiga/ds-fix-boost-leaks] Avahi: Ported code to DynamicObject.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga/ds-fix-boost-leaks] Avahi: Ported code to DynamicObject.
- Date: Sun, 21 Jun 2015 13:34:28 +0000 (UTC)
commit 413ce22a4639a2af74ce38d50b9dfddc86134fa7
Author: Damien Sandras <dsandras seconix com>
Date: Sun May 31 17:24:59 2015 +0200
Avahi: Ported code to DynamicObject.
plugins/avahi/Makefile.am | 4 ++-
plugins/avahi/avahi-cluster.cpp | 25 +++++++++++--
plugins/avahi/avahi-cluster.h | 9 ++++-
plugins/avahi/avahi-heap.cpp | 38 +++++++++++++++-----
plugins/avahi/avahi-heap.h | 26 +++++++++-----
plugins/avahi/avahi-main.cpp | 3 +-
plugins/avahi/avahi-presentity.cpp | 60 +++++++++++++++++++++++++++++++
plugins/avahi/avahi-presentity.h | 68 ++++++++++++++++++++++++++++++++++++
8 files changed, 206 insertions(+), 27 deletions(-)
---
diff --git a/plugins/avahi/Makefile.am b/plugins/avahi/Makefile.am
index 455e023..bf5ac61 100644
--- a/plugins/avahi/Makefile.am
+++ b/plugins/avahi/Makefile.am
@@ -18,7 +18,9 @@ libgmavahi_la_SOURCES = \
avahi-heap.h \
avahi-heap.cpp \
avahi-cluster.h \
- avahi-cluster.cpp
+ avahi-cluster.cpp \
+ avahi-presentity.h \
+ avahi-presentity.cpp
libgmavahi_la_LDFLAGS = $(PLUGINS_LIBTOOL_FLAGS)
libgmavahi_la_LIBADD = \
diff --git a/plugins/avahi/avahi-cluster.cpp b/plugins/avahi/avahi-cluster.cpp
index 994e44b..5742d33 100644
--- a/plugins/avahi/avahi-cluster.cpp
+++ b/plugins/avahi/avahi-cluster.cpp
@@ -36,21 +36,40 @@
#include "avahi-cluster.h"
-Avahi::Cluster::Cluster (Ekiga::ServiceCore &_core): core(_core)
+boost::shared_ptr<Avahi::Cluster>
+Avahi::Cluster::create (Ekiga::ServiceCore & core)
+{
+ boost::shared_ptr<Avahi::Cluster> cluster =
+ boost::shared_ptr<Avahi::Cluster> (new Avahi::Cluster (core));
+
+ cluster->load ();
+
+ return cluster;
+}
+
+
+void
+Avahi::Cluster::load ()
{
- heap = HeapPtr(new Heap (core));
+ heap = Avahi::Heap::create (core);
add_heap (heap);
- /* don't check the cast: it has been checked already by avahi-main! */
boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
presence_core->add_presence_fetcher (heap);
}
+
+Avahi::Cluster::Cluster (Ekiga::ServiceCore &_core): core(_core)
+{
+}
+
+
Avahi::Cluster::~Cluster ()
{
}
+
bool
Avahi::Cluster::populate_menu (Ekiga::MenuBuilder &/*builder*/)
{
diff --git a/plugins/avahi/avahi-cluster.h b/plugins/avahi/avahi-cluster.h
index cc0613d..58a2bfc 100644
--- a/plugins/avahi/avahi-cluster.h
+++ b/plugins/avahi/avahi-cluster.h
@@ -39,6 +39,7 @@
#include "cluster-impl.h"
#include "avahi-heap.h"
+#include "dynamic-object.h"
namespace Avahi
{
@@ -51,11 +52,12 @@ namespace Avahi
class Cluster:
public Ekiga::Service,
- public Ekiga::ClusterImpl<Heap>
+ public Ekiga::ClusterImpl<Heap>,
+ public Ekiga::DynamicObject<Cluster>
{
public:
- Cluster (Ekiga::ServiceCore &_core);
+ static boost::shared_ptr<Cluster> create (Ekiga::ServiceCore &_core);
~Cluster ();
@@ -71,6 +73,9 @@ namespace Avahi
private:
+ void load ();
+ Cluster (Ekiga::ServiceCore &_core);
+
Ekiga::ServiceCore &core;
HeapPtr heap;
};
diff --git a/plugins/avahi/avahi-heap.cpp b/plugins/avahi/avahi-heap.cpp
index 0bdc410..ad5aa4a 100644
--- a/plugins/avahi/avahi-heap.cpp
+++ b/plugins/avahi/avahi-heap.cpp
@@ -37,6 +37,7 @@
#include <cstdlib>
#include <glib/gi18n.h>
+#include "avahi-presentity.h"
#include "avahi-heap.h"
#define DEBUG 0
@@ -87,13 +88,24 @@ avahi_resolver_callback (AvahiServiceResolver *resolver,
}
-Avahi::Heap::Heap (Ekiga::ServiceCore& core)
+boost::shared_ptr<Avahi::Heap>
+Avahi::Heap::create (Ekiga::ServiceCore & core)
+{
+ boost::shared_ptr<Avahi::Heap> heap =
+ boost::shared_ptr<Avahi::Heap> (new Avahi::Heap (core));
+
+ heap->load ();
+
+ return heap;
+}
+
+
+void
+Avahi::Heap::load ()
{
const AvahiPoll *poll_api = NULL;
int error;
- presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
-
/* let's make sure those are sanely initialized */
poll = NULL;
client = NULL;
@@ -114,6 +126,12 @@ Avahi::Heap::Heap (Ekiga::ServiceCore& core)
#endif
}
+
+Avahi::Heap::Heap (Ekiga::ServiceCore & _core) : core(_core)
+{
+}
+
+
Avahi::Heap::~Heap ()
{
if (client != NULL)
@@ -234,7 +252,7 @@ Avahi::Heap::BrowserCallback (AvahiServiceBrowser *browser,
iter != end ();
++iter)
if ((*iter)->get_name () == name) {
- (*iter)->removed ();
+ (*iter)->removed (*iter);
break;
}
break;
@@ -275,7 +293,7 @@ public:
bool operator() (Ekiga::PresentityPtr pres_)
{
- boost::shared_ptr<Ekiga::URIPresentity> presentity_ = boost::dynamic_pointer_cast<Ekiga::URIPresentity>
(pres_);
+ boost::shared_ptr<Avahi::Presentity> presentity_ = boost::dynamic_pointer_cast<Avahi::Presentity>
(pres_);
bool result = true;
if (presentity_ && presentity_->get_name () == name) {
@@ -286,11 +304,11 @@ public:
return result;
}
- boost::shared_ptr<Ekiga::URIPresentity> found_presentity () const
+ boost::shared_ptr<Avahi::Presentity> found_presentity () const
{ return presentity; }
private:
- boost::shared_ptr<Ekiga::URIPresentity> presentity;
+ boost::shared_ptr<Avahi::Presentity> presentity;
const std::string name;
};
@@ -369,14 +387,14 @@ Avahi::Heap::ResolverCallback (AvahiServiceResolver *resolver,
/* ok, this is a new contact */
gchar** broken = NULL;
broken = g_strsplit_set (typ, "._", 0);
- boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
- if (broken != NULL && broken[0] != NULL && broken[1] != NULL && pcore) {
+ boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
+ if (broken != NULL && broken[0] != NULL && broken[1] != NULL) {
std::list<std::string> groups;
groups.push_back (_("Neighbours"));
url = g_strdup_printf ("%s:neighbour %s:%d", broken[1], host_name, port);
- boost::shared_ptr<Ekiga::URIPresentity> presentity (new Ekiga::URIPresentity (pcore, name, url,
groups));
+ boost::shared_ptr<Avahi::Presentity> presentity = Avahi::Presentity::create (presence_core, name,
url, groups);
status_received (url, status);
presence_received (url, presence);
add_presentity (presentity);
diff --git a/plugins/avahi/avahi-heap.h b/plugins/avahi/avahi-heap.h
index e957774..d012a9b 100644
--- a/plugins/avahi/avahi-heap.h
+++ b/plugins/avahi/avahi-heap.h
@@ -37,16 +37,19 @@
#ifndef __AVAHI_HEAP_H__
#define __AVAHI_HEAP_H__
-#include "presence-core.h"
-#include "heap-impl.h"
-#include "uri-presentity.h"
-
#include <avahi-client/client.h>
#include <avahi-client/lookup.h>
#include <avahi-common/error.h>
#include <avahi-glib/glib-watch.h>
#include <avahi-glib/glib-malloc.h>
+
+#include "heap-impl.h"
+#include "dynamic-object.h"
+
+#include "presence-core.h"
+#include "avahi-presentity.h"
+
namespace Avahi
{
@@ -58,11 +61,12 @@ namespace Avahi
class Heap:
public Ekiga::PresenceFetcher,
- public Ekiga::HeapImpl<Ekiga::URIPresentity>
+ public Ekiga::HeapImpl<Presentity>,
+ public Ekiga::DynamicObject<Heap>
{
public:
- Heap (Ekiga::ServiceCore &_core);
+ static boost::shared_ptr<Heap> create (Ekiga::ServiceCore &_core);
~Heap ();
@@ -73,13 +77,14 @@ namespace Avahi
bool populate_menu_for_group (const std::string name,
Ekiga::MenuBuilder& builder);
- /* the PresenceFetcher interface : we don't do what we're told ;-) */
+
+ /* The PresenceFetcher interface: we don't do what we're told ;-) */
void fetch (std::string) {}
void unfetch (std::string) {}
bool is_supported_uri (const std::string &) { return true; }
- /* these should be private but are called from C code */
+ /* These should be private but are called from C code */
void ClientCallback (AvahiClient *client,
AvahiClientState state);
@@ -106,11 +111,14 @@ namespace Avahi
AvahiLookupResultFlags flags);
private:
+ void load ();
+ Heap (Ekiga::ServiceCore &_core);
- boost::weak_ptr<Ekiga::PresenceCore> presence_core;
AvahiGLibPoll *poll;
AvahiClient *client;
+ Ekiga::ServiceCore &core;
+
bool remover (Ekiga::PresentityPtr presentity,
const std::string name);
};
diff --git a/plugins/avahi/avahi-main.cpp b/plugins/avahi/avahi-main.cpp
index 211cae0..758cdf0 100644
--- a/plugins/avahi/avahi-main.cpp
+++ b/plugins/avahi/avahi-main.cpp
@@ -60,9 +60,8 @@ struct AVAHISpark: public Ekiga::Spark
result = true;
}
- boost::shared_ptr<Avahi::Cluster> cluster (new Avahi::Cluster (core));
+ boost::shared_ptr<Avahi::Cluster> cluster = Avahi::Cluster::create (core);
if (core.add (cluster)) {
-
presence_core->add_cluster (cluster);
result = true;
}
diff --git a/plugins/avahi/avahi-presentity.cpp b/plugins/avahi/avahi-presentity.cpp
new file mode 100644
index 0000000..3136989
--- /dev/null
+++ b/plugins/avahi/avahi-presentity.cpp
@@ -0,0 +1,60 @@
+/* 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.
+ */
+
+
+/*
+ * avahi-presentity.cpp - description
+ * ------------------------------------
+ * begin : written in 2015 by Damien Sandras
+ * copyright : (c) 2015 Damien Sandras
+ * description : implementation of the avahi presentity
+ *
+ */
+
+#include "avahi-presentity.h"
+
+
+boost::shared_ptr<Avahi::Presentity>
+Avahi::Presentity::create (boost::shared_ptr<Ekiga::PresenceCore> _presence_core,
+ std::string _name,
+ std::string _uri,
+ std::list<std::string> _groups)
+{
+ return boost::shared_ptr<Avahi::Presentity> (new Avahi::Presentity (_presence_core, _name, _uri, _groups));
+}
+
+
+Avahi::Presentity::Presentity (boost::shared_ptr<Ekiga::PresenceCore> _presence_core,
+ std::string _name,
+ std::string _uri,
+ std::list<std::string> _groups) : URIPresentity (_presence_core, _name, _uri,
_groups)
+{
+}
+
+
+Avahi::Presentity::~Presentity ()
+{
+}
diff --git a/plugins/avahi/avahi-presentity.h b/plugins/avahi/avahi-presentity.h
new file mode 100644
index 0000000..7c6502d
--- /dev/null
+++ b/plugins/avahi/avahi-presentity.h
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+
+/*
+ * avahi-presentity.h - description
+ * ----------------------------------
+ * begin : written in 2015 by Damien Sandras
+ * copyright : (c) 2015 by Damien Sandras
+ * description : declaration of Avahi::Presentity
+ *
+ */
+
+
+
+#ifndef __AVAHI_PRESENTITY_H__
+#define __AVAHI_PRESENTITY_H__
+
+#include "dynamic-object.h"
+#include "uri-presentity.h"
+
+#include "presence-core.h"
+
+namespace Avahi
+{
+ class Presentity:
+ public Ekiga::URIPresentity,
+ public Ekiga::DynamicObject<Presentity>
+ {
+
+public:
+ static boost::shared_ptr<Presentity> create (boost::shared_ptr<Ekiga::PresenceCore> presence_core,
+ std::string name,
+ std::string uri,
+ std::list<std::string> groups);
+
+ ~Presentity ();
+
+private:
+ Presentity (boost::shared_ptr<Ekiga::PresenceCore> presence_core,
+ std::string name,
+ std::string uri,
+ std::list<std::string> groups);
+ };
+};
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]