Commit 07772f49 authored by Jens Georg's avatar Jens Georg

GUPnPContext derives from GInitable as well

parent 63cfce88
......@@ -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);
}
/**
......
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment