[grilo-plugins] upnp: use GUPnPContextManager
- From: Iago Toral Quiroga <itoral src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] upnp: use GUPnPContextManager
- Date: Thu, 13 Jan 2011 13:40:38 +0000 (UTC)
commit da4926e683f1089ed3e5e5e75c1ce38cbf8a751a
Author: Jussi Kukkonen <jku linux intel com>
Date: Thu Jan 13 13:53:43 2011 +0200
upnp: use GUPnPContextManager
ContextManager makes managing control points easier and also
makes non-default contexts visible to the plugin.
This raises dependency to gupnp-1.0 >= 0.13
Signed-off-by: Iago Toral Quiroga <itoral igalia com>
configure.ac | 2 +-
src/upnp/grl-upnp.c | 72 +++++++++++++++++++++++++++------------------------
2 files changed, 39 insertions(+), 35 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ba91484..e0241a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,7 +106,7 @@ PKG_CHECK_MODULES(XML, libxml-2.0, HAVE_XML=yes, HAVE_XML=no)
PKG_CHECK_MODULES(GIO, gio-2.0, HAVE_GIO=yes, HAVE_GIO=no)
-PKG_CHECK_MODULES(GUPNP, gupnp-1.0, HAVE_GUPNP=yes, HAVE_GUPNP=no)
+PKG_CHECK_MODULES(GUPNP, gupnp-1.0 >= 0.13, HAVE_GUPNP=yes, HAVE_GUPNP=no)
PKG_CHECK_MODULES(GUPNPAV, gupnp-av-1.0, HAVE_GUPNPAV=yes, HAVE_GUPNPAV=no)
diff --git a/src/upnp/grl-upnp.c b/src/upnp/grl-upnp.c
index 1845a4f..02ae960 100644
--- a/src/upnp/grl-upnp.c
+++ b/src/upnp/grl-upnp.c
@@ -120,6 +120,9 @@ static void grl_upnp_source_metadata (GrlMediaSource *source,
static GrlSupportedOps grl_upnp_source_supported_operations (GrlMetadataSource *source);
+static void context_available_cb (GUPnPContextManager *context_manager,
+ GUPnPContext *context,
+ gpointer user_data);
static void device_available_cb (GUPnPControlPoint *cp,
GUPnPDeviceProxy *device,
gpointer user_data);
@@ -131,8 +134,7 @@ static void device_unavailable_cb (GUPnPControlPoint *cp,
static GHashTable *key_mapping = NULL;
static GHashTable *filter_key_mapping = NULL;
-static GUPnPControlPoint *cp = NULL;
-static GUPnPContext *context = NULL;
+static GUPnPContextManager *context_manager = NULL;
/* =================== UPnP Plugin =============== */
@@ -141,8 +143,6 @@ grl_upnp_plugin_init (GrlPluginRegistry *registry,
const GrlPluginInfo *plugin,
GList *configs)
{
- GError *error = NULL;
-
GRL_LOG_DOMAIN_INIT (upnp_log_domain, "upnp");
GRL_DEBUG ("grl_upnp_plugin_init");
@@ -152,28 +152,11 @@ grl_upnp_plugin_init (GrlPluginRegistry *registry,
g_thread_init (NULL);
}
- context = gupnp_context_new (NULL, NULL, 0, &error);
- if (error) {
- g_critical ("Failed to create GUPnP context: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
-
- cp = gupnp_control_point_new (context, "ssdp:all");
- if (!cp) {
- g_critical ("Failed to create control point");
- return FALSE;
- }
- g_signal_connect (cp,
- "device-proxy-available",
- G_CALLBACK (device_available_cb),
- (gpointer) plugin);
- g_signal_connect (cp,
- "device-proxy-unavailable",
- G_CALLBACK (device_unavailable_cb),
- NULL);
-
- gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
+ context_manager = gupnp_context_manager_new (NULL, 0);
+ g_signal_connect (context_manager,
+ "context-available",
+ G_CALLBACK (context_available_cb),
+ (gpointer)plugin);
return TRUE;
}
@@ -182,15 +165,10 @@ static void
grl_upnp_plugin_deinit (void)
{
GRL_DEBUG ("grl_upnp_plugin_deinit");
- if (cp != NULL) {
- gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), FALSE);
- g_object_unref (cp);
- cp = NULL;
- }
- if (context != NULL) {
- g_object_unref ( context);
- context = NULL;
+ if (context_manager != NULL) {
+ g_object_unref (context_manager);
+ context_manager = NULL;
}
}
@@ -347,6 +325,32 @@ gupnp_search_caps_cb (GUPnPServiceProxy *service,
}
static void
+context_available_cb (GUPnPContextManager *context_manager,
+ GUPnPContext *context,
+ gpointer user_data)
+{
+ GUPnPControlPoint *cp;
+
+ GRL_DEBUG ("%s", __func__);
+
+ cp = gupnp_control_point_new (context, "ssdp:all");
+ g_signal_connect (cp,
+ "device-proxy-available",
+ G_CALLBACK (device_available_cb),
+ user_data);
+ g_signal_connect (cp,
+ "device-proxy-unavailable",
+ G_CALLBACK (device_unavailable_cb),
+ NULL);
+
+ gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
+
+ /* Let context manager take care of the control point life cycle */
+ gupnp_context_manager_manage_control_point (context_manager, cp);
+ g_object_unref (cp);
+}
+
+static void
device_available_cb (GUPnPControlPoint *cp,
GUPnPDeviceProxy *device,
gpointer user_data)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]