[gupnp] GUPnPContext derives from GInitable as well
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp] GUPnPContext derives from GInitable as well
- Date: Mon, 6 Jun 2011 14:27:26 +0000 (UTC)
commit 07772f4934cc0b3e15c039dc4e583c1c035ae147
Author: Jens Georg <mail jensge org>
Date: Thu Feb 3 22:58:38 2011 +0100
GUPnPContext derives from GInitable as well
libgupnp/gupnp-context.c | 66 +++++++++++++++++++++++----------
libgupnp/gupnp-network-manager.c | 28 +++++++------
libgupnp/gupnp-unix-context-manager.c | 14 +++---
3 files changed, 68 insertions(+), 40 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index b13c9ab..8934343 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -54,9 +54,18 @@
#include "gena-protocol.h"
#include "http-headers.h"
-G_DEFINE_TYPE (GUPnPContext,
- gupnp_context,
- GSSDP_TYPE_CLIENT);
+static void
+gupnp_context_initable_iface_init (gpointer g_iface,
+ gpointer iface_data);
+
+
+G_DEFINE_TYPE_EXTENDED (GUPnPContext,
+ gupnp_context,
+ GSSDP_TYPE_CLIENT,
+ 0,
+ G_IMPLEMENT_INTERFACE
+ (G_TYPE_INITABLE,
+ gupnp_context_initable_iface_init));
struct _GUPnPContextPrivate {
guint port;
@@ -92,6 +101,8 @@ typedef struct {
GList *user_agents;
} HostPathData;
+static GInitableIface* initable_parent_iface = NULL;
+
/*
* Generates the default server ID.
**/
@@ -123,18 +134,24 @@ gupnp_context_init (GUPnPContext *context)
g_free (server_id);
}
-static GObject *
-gupnp_context_constructor (GType type,
- guint n_props,
- GObjectConstructParam *props)
+static gboolean
+gupnp_context_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
- GObject *object;
- GUPnPContext *context;
char *user_agent;
+ GError *inner_error = NULL;
+ GUPnPContext *context;
- object = G_OBJECT_CLASS (gupnp_context_parent_class)->constructor
- (type, n_props, props);
- context = GUPNP_CONTEXT (object);
+ if (!initable_parent_iface->init(initable,
+ cancellable,
+ &inner_error)) {
+ g_propagate_error (error, inner_error);
+
+ return FALSE;
+ }
+
+ context = GUPNP_CONTEXT (initable);
context->priv->session = soup_session_async_new_with_options
(SOUP_SESSION_IDLE_TIMEOUT,
@@ -161,7 +178,16 @@ gupnp_context_constructor (GType type,
soup_session_add_feature_by_type (context->priv->session,
SOUP_TYPE_CONTENT_DECODER);
- return object;
+ return TRUE;
+}
+
+static void
+gupnp_context_initable_iface_init (gpointer g_iface,
+ gpointer iface_data)
+{
+ GInitableIface *iface = (GInitableIface *)g_iface;
+ initable_parent_iface = g_type_interface_peek_parent (iface);
+ iface->init = gupnp_context_initable_init;
}
static void
@@ -274,7 +300,6 @@ gupnp_context_class_init (GUPnPContextClass *klass)
object_class = G_OBJECT_CLASS (klass);
- object_class->constructor = gupnp_context_constructor;
object_class->set_property = gupnp_context_set_property;
object_class->get_property = gupnp_context_get_property;
object_class->dispose = gupnp_context_dispose;
@@ -475,12 +500,13 @@ gupnp_context_new (GMainContext *main_context,
guint port,
GError **error)
{
- return g_object_new (GUPNP_TYPE_CONTEXT,
- "main-context", main_context,
- "interface", interface,
- "port", port,
- "error", error,
- NULL);
+ return g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ error,
+ "main-context", main_context,
+ "interface", interface,
+ "port", port,
+ NULL);
}
/**
diff --git a/libgupnp/gupnp-network-manager.c b/libgupnp/gupnp-network-manager.c
index 1278f9e..0a1d70e 100644
--- a/libgupnp/gupnp-network-manager.c
+++ b/libgupnp/gupnp-network-manager.c
@@ -169,12 +169,13 @@ create_loopback_context (gpointer data)
"port", &port,
NULL);
- context = g_object_new (GUPNP_TYPE_CONTEXT,
- "main-context", main_context,
- "interface", LOOPBACK_IFACE,
- "port", port,
- "error", &error,
- NULL);
+ context = g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ &error,
+ "main-context", main_context,
+ "interface", LOOPBACK_IFACE,
+ "port", port,
+ NULL);
if (error) {
g_warning ("Error creating GUPnP context: %s\n",
error->message);
@@ -229,13 +230,14 @@ create_context_for_device (NMDevice *nm_device)
}
}
- nm_device->context = g_object_new (GUPNP_TYPE_CONTEXT,
- "main-context", main_context,
- "interface", iface,
- "network", ssid,
- "port", port,
- "error", &error,
- NULL);
+ nm_device->context = g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ &error,
+ "main-context", main_context,
+ "interface", iface,
+ "network", ssid,
+ "port", port,
+ NULL);
g_free (iface);
g_free (ssid);
diff --git a/libgupnp/gupnp-unix-context-manager.c b/libgupnp/gupnp-unix-context-manager.c
index 96ffb42..0d3e8d3 100644
--- a/libgupnp/gupnp-unix-context-manager.c
+++ b/libgupnp/gupnp-unix-context-manager.c
@@ -87,12 +87,13 @@ create_and_signal_context (GUPnPUnixContextManager *manager,
NULL);
error = NULL;
- context = g_object_new (GUPNP_TYPE_CONTEXT,
- "main-context", main_context,
- "interface", interface,
- "port", port,
- "error", &error,
- NULL);
+ context = g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ &error,
+ "main-context", main_context,
+ "interface", interface,
+ "port", port,
+ NULL);
if (error != NULL) {
if (!(error->domain == GSSDP_ERROR &&
error->code == GSSDP_ERROR_NO_IP_ADDRESS))
@@ -101,7 +102,6 @@ create_and_signal_context (GUPnPUnixContextManager *manager,
interface,
error->message);
- g_object_unref (context);
g_error_free (error);
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]