[gupnp] Make GUPnPContextManager an abstract base class
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp] Make GUPnPContextManager an abstract base class
- Date: Sat, 30 Jul 2011 10:57:43 +0000 (UTC)
commit 3537cce41f166446bc8c4464d92ba6a304e63f90
Author: Jens Georg <mail jensge org>
Date: Sat Jun 25 00:27:22 2011 +0200
Make GUPnPContextManager an abstract base class
gupnp_contxt_manager_new is renamed to gupnp_context_manager_create to
emphasize the factory-method character of it. It now only creates an
instance of the implementation.
The chained listening to the context-unavailable signal is now done by an
object signal handler run in first phase (G_SIGNAL_RUN_FIRST).
Previously, gupnp_context_manager_new was creating an instance of
GUPnPContextManager and the specific implementation, wrapping the
implementation in the GUPnPContextManager instance. The instance was
connecting to the context-unavailable signal of the implementation to take
care of the managed objects.
libgupnp/gupnp-context-manager.c | 143 +++++++++++--------------------------
libgupnp/gupnp-context-manager.h | 6 ++
2 files changed, 49 insertions(+), 100 deletions(-)
---
diff --git a/libgupnp/gupnp-context-manager.c b/libgupnp/gupnp-context-manager.c
index aae1b33..c2df9f1 100644
--- a/libgupnp/gupnp-context-manager.c
+++ b/libgupnp/gupnp-context-manager.c
@@ -44,9 +44,9 @@
#include "gupnp-unix-context-manager.h"
-G_DEFINE_TYPE (GUPnPContextManager,
- gupnp_context_manager,
- G_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE (GUPnPContextManager,
+ gupnp_context_manager,
+ G_TYPE_OBJECT);
struct _GUPnPContextManagerPrivate {
guint port;
@@ -60,7 +60,6 @@ enum {
PROP_0,
PROP_MAIN_CONTEXT,
PROP_PORT,
- PROP_CONTEXT_MANAGER
};
enum {
@@ -72,29 +71,12 @@ enum {
static guint signals[SIGNAL_LAST];
static void
-on_context_available (GUPnPContextManager *impl,
- GUPnPContext *context,
- gpointer *user_data)
-{
- GUPnPContextManager *manager = GUPNP_CONTEXT_MANAGER (user_data);
-
- /* Just proxy the signal */
- g_signal_emit (manager,
- signals[CONTEXT_AVAILABLE],
- 0,
- context);
-}
-
-static void
-on_context_unavailable (GUPnPContextManager *impl,
+on_context_unavailable (GUPnPContextManager *manager,
GUPnPContext *context,
gpointer *user_data)
{
- GUPnPContextManager *manager;
GList *l;
- manager = GUPNP_CONTEXT_MANAGER (user_data);
-
/* Make sure we don't send anything on now unavailable network */
g_object_set (context, "active", FALSE, NULL);
@@ -130,12 +112,6 @@ on_context_unavailable (GUPnPContextManager *impl,
l = l->next;
}
}
-
- /* Just proxy the signal */
- g_signal_emit (manager,
- signals[CONTEXT_UNAVAILABLE],
- 0,
- context);
}
static void
@@ -170,21 +146,6 @@ gupnp_context_manager_set_property (GObject *object,
"g_main_context_push_thread_default()"
"instead.");
break;
- case PROP_CONTEXT_MANAGER:
- priv->impl = g_value_get_object (value);
- if (priv->impl != NULL) {
- priv->impl = g_object_ref (priv->impl);
-
- g_signal_connect (priv->impl,
- "context-available",
- G_CALLBACK (on_context_available),
- manager);
- g_signal_connect (priv->impl,
- "context-unavailable",
- G_CALLBACK (on_context_unavailable),
- manager);
- }
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -212,9 +173,6 @@ gupnp_context_manager_get_property (GObject *object,
g_value_set_pointer (value,
g_main_context_get_thread_default ());
break;
- case PROP_CONTEXT_MANAGER:
- g_value_set_object (value, manager->priv->impl);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -229,15 +187,6 @@ gupnp_context_manager_dispose (GObject *object)
manager = GUPNP_CONTEXT_MANAGER (object);
- if (manager->priv->impl != NULL) {
- g_signal_handlers_disconnect_by_func (manager->priv->impl,
- on_context_available, manager);
- g_signal_handlers_disconnect_by_func (manager->priv->impl,
- on_context_unavailable, manager);
- g_object_unref (manager->priv->impl);
- manager->priv->impl = NULL;
- }
-
g_list_foreach (manager->priv->objects, (GFunc) g_object_unref, NULL);
g_list_free (manager->priv->objects);
manager->priv->objects = NULL;
@@ -301,27 +250,6 @@ gupnp_context_manager_class_init (GUPnPContextManagerClass *klass)
G_PARAM_STATIC_BLURB));
/**
- * GUPnPContextManager:context-manager:
- *
- * The actual GUPnPContextManager implementation used. This is an
- * internal property and therefore Application developer should just
- * ignore it.
- *
- **/
- g_object_class_install_property
- (object_class,
- PROP_CONTEXT_MANAGER,
- g_param_spec_object ("context-manager",
- "ContextManager",
- "ContextManager implemention",
- GUPNP_TYPE_CONTEXT_MANAGER,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
-
- /**
* GUPnPContextManager::context-available:
* @context_manager: The #GUPnPContextManager that received the signal
* @context: The now available #GUPnPContext
@@ -349,15 +277,16 @@ gupnp_context_manager_class_init (GUPnPContextManagerClass *klass)
*
**/
signals[CONTEXT_UNAVAILABLE] =
- g_signal_new ("context-unavailable",
- GUPNP_TYPE_CONTEXT_MANAGER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- GUPNP_TYPE_CONTEXT);
+ g_signal_new_class_handler
+ ("context-unavailable",
+ GUPNP_TYPE_CONTEXT_MANAGER,
+ G_SIGNAL_RUN_FIRST,
+ G_CALLBACK (on_context_unavailable),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GUPNP_TYPE_CONTEXT);
}
/**
@@ -367,23 +296,43 @@ gupnp_context_manager_class_init (GUPnPContextManagerClass *klass)
* g_main_context_push_thread_default() instead.
* @port: Port to create contexts for, or 0 if you don't care what port is used.
*
- * Create a new #GUPnPContextManager.
+ * Factory-method to create a new #GUPnPContextManager. The final type of the
+ * #GUPnPContextManager depends on the compile-time selection or - in case of
+ * NetworkManager - on its availability during runtime. If it is not available,
+ * the implementation falls back to the basic Unix context manager instead.
*
- * Return value: A new #GUPnPContextManager object.
+ * Returns: (transfer full): A new #GUPnPContextManager object.
+ * Deprecated: 0.17.2: Use gupnp_context_manager_create().
**/
+
GUPnPContextManager *
gupnp_context_manager_new (GMainContext *main_context,
guint port)
{
- GUPnPContextManager *manager;
+ if (main_context)
+ g_warning ("gupnp_context_manager_new::main_context is"
+ " deprecated. Use "
+ " g_main_context_push_thread_default() instead");
+
+ return gupnp_context_manager_create (port);
+}
+/**
+ * gupnp_context_manager_create:
+ * @port: Port to create contexts for, or 0 if you don't care what port is used.
+ *
+ * Factory-method to create a new #GUPnPContextManager. The final type of the
+ * #GUPnPContextManager depends on the compile-time selection or - in case of
+ * NetworkManager - on its availability during runtime. If it is not available,
+ * the implementation falls back to the basic Unix context manager instead.
+ *
+ * Returns: (transfer full): A new #GUPnPContextManager object.
+ **/
+GUPnPContextManager *
+gupnp_context_manager_create (guint port)
+{
GUPnPContextManager *impl;
GType impl_type = G_TYPE_INVALID;
- if (main_context)
- g_warning ("gupnp_context_manager_new::main_context is"
- " deprecated. Use "
- " g_main_context_push_thread_default() instead");
-
#ifdef USE_NETWORK_MANAGER
#include "gupnp-network-manager.h"
@@ -401,13 +350,7 @@ gupnp_context_manager_new (GMainContext *main_context,
"port", port,
NULL);
- manager = g_object_new (GUPNP_TYPE_CONTEXT_MANAGER,
- "port", port,
- "context-manager", impl,
- NULL);
- g_object_unref (impl);
-
- return manager;
+ return impl;
}
/**
diff --git a/libgupnp/gupnp-context-manager.h b/libgupnp/gupnp-context-manager.h
index 759ce8d..d1f24e6 100644
--- a/libgupnp/gupnp-context-manager.h
+++ b/libgupnp/gupnp-context-manager.h
@@ -79,9 +79,15 @@ struct _GUPnPContextManagerClass {
void (* _gupnp_reserved4) (void);
};
+
+#ifndef GUPNP_DISABLE_DEPRECATED
GUPnPContextManager *
gupnp_context_manager_new (GMainContext *main_context,
guint port);
+#endif
+
+GUPnPContextManager *
+gupnp_context_manager_create (guint port);
void
gupnp_context_manager_manage_control_point
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]