[gupnp-igd] Restore the "main-context" property as read-only



commit 9864bdcfe5c7c88aeaf53a127c741481a5cdf84d
Author: Olivier CrÃte <olivier crete collabora com>
Date:   Mon Nov 7 17:41:20 2011 -0500

    Restore the "main-context" property as read-only
    
    Farsight2 used it to put a timer in the thread's context

 doc/gupnp-igd-sections.txt      |    5 +++-
 libgupnp-igd/gupnp-simple-igd.c |   47 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/doc/gupnp-igd-sections.txt b/doc/gupnp-igd-sections.txt
index 149661d..9c33684 100644
--- a/doc/gupnp-igd-sections.txt
+++ b/doc/gupnp-igd-sections.txt
@@ -4,10 +4,12 @@
 GUPnPSimpleIgd
 GUPnPSimpleIgdClass
 GUPNP_SIMPLE_IGD_ERROR
+GUPNP_TYPE_SIMPLE_IGD_ERROR
 GUPnPSimpleIgdError
 gupnp_simple_igd_new
 gupnp_simple_igd_add_port
 gupnp_simple_igd_remove_port
+gupnp_simple_igd_delete_all_mappings
 <SUBSECTION Standard>
 GUPNP_SIMPLE_IGD
 GUPNP_SIMPLE_IGD_CLASS
@@ -17,8 +19,9 @@ GUPNP_IS_SIMPLE_IGD
 GUPNP_TYPE_SIMPLE_IGD
 gupnp_simple_igd_get_type
 GUPNP_IS_SIMPLE_IGD_CLASS
+gupnp_simple_igd_error_get_type
+gupnp_simple_igd_error_quark
 <SUBSECTION Private>
-gupnp_simple_igd_get_error_domain
 GUPnPSimpleIgdPrivate
 </SECTION>
 
diff --git a/libgupnp-igd/gupnp-simple-igd.c b/libgupnp-igd/gupnp-simple-igd.c
index db56d45..ff4ece3 100644
--- a/libgupnp-igd/gupnp-simple-igd.c
+++ b/libgupnp-igd/gupnp-simple-igd.c
@@ -48,6 +48,8 @@
 
 struct _GUPnPSimpleIgdPrivate
 {
+  GMainContext *main_context;
+
   GUPnPContextManager *gupnp_context_manager;
 
   GPtrArray *service_proxies;
@@ -99,8 +101,14 @@ enum
   LAST_SIGNAL
 };
 
+/* props */
+enum
+{
+  PROP_0,
+  PROP_MAIN_CONTEXT
+};
 
-static guint signals[LAST_SIGNAL] = { 0 };
+guint signals[LAST_SIGNAL] = { 0 };
 
 
 #define GUPNP_SIMPLE_IGD_GET_PRIVATE(o)                                 \
@@ -114,6 +122,8 @@ G_DEFINE_TYPE (GUPnPSimpleIgd, gupnp_simple_igd, G_TYPE_OBJECT);
 static void gupnp_simple_igd_constructed (GObject *object);
 static void gupnp_simple_igd_dispose (GObject *object);
 static void gupnp_simple_igd_finalize (GObject *object);
+static void gupnp_simple_igd_get_property (GObject *object, guint prop_id,
+    GValue *value, GParamSpec *pspec);
 
 static void gupnp_simple_igd_gather (GUPnPSimpleIgd *self,
     struct Proxy *prox);
@@ -154,10 +164,18 @@ gupnp_simple_igd_class_init (GUPnPSimpleIgdClass *klass)
   gobject_class->constructed = gupnp_simple_igd_constructed;
   gobject_class->dispose = gupnp_simple_igd_dispose;
   gobject_class->finalize = gupnp_simple_igd_finalize;
+  gobject_class->get_property = gupnp_simple_igd_get_property;
 
   klass->add_port = gupnp_simple_igd_add_port_real;
   klass->remove_port = gupnp_simple_igd_remove_port_real;
 
+  g_object_class_install_property (gobject_class,
+      PROP_MAIN_CONTEXT,
+      g_param_spec_pointer ("main-context",
+          "The GMainContext to use",
+          "This GMainContext will be used for all async activities",
+          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   /**
    * GUPnPSimpleIgd::mapped-external-port
    * @self: #GUPnPSimpleIgd that emitted the signal
@@ -403,6 +421,8 @@ gupnp_simple_igd_finalize (GObject *object)
 {
   GUPnPSimpleIgd *self = GUPNP_SIMPLE_IGD_CAST (object);
 
+  g_main_context_unref (self->priv->main_context);
+
   g_warn_if_fail (self->priv->mappings->len == 0);
   g_ptr_array_free (self->priv->mappings, TRUE);
 
@@ -410,6 +430,24 @@ gupnp_simple_igd_finalize (GObject *object)
 }
 
 static void
+gupnp_simple_igd_get_property (GObject *object, guint prop_id,
+    GValue *value, GParamSpec *pspec)
+{
+  GUPnPSimpleIgd *self = GUPNP_SIMPLE_IGD_CAST (object);
+
+  switch (prop_id) {
+    case PROP_MAIN_CONTEXT:
+      g_value_set_pointer (value, self->priv->main_context);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+
+}
+
+
+static void
 _cp_service_avail (GUPnPControlPoint *cp,
     GUPnPServiceProxy *proxy,
     GUPnPSimpleIgd *self)
@@ -502,6 +540,11 @@ gupnp_simple_igd_constructed (GObject *object)
   GUPnPSimpleIgd *self = GUPNP_SIMPLE_IGD_CAST (object);
   SoupSession *session;
 
+  self->priv->main_context = g_main_context_get_thread_default ();
+  if (!self->priv->main_context)
+    self->priv->main_context = g_main_context_default ();
+  g_main_context_ref (self->priv->main_context);
+
   self->priv->gupnp_context_manager = gupnp_context_manager_create (0);
 
   g_signal_connect (self->priv->gupnp_context_manager, "context-available",
@@ -710,7 +753,7 @@ _service_proxy_added_port_mapping (GUPnPServiceProxy *proxy,
         g_timeout_source_new_seconds (pm->mapping->lease_duration / 2);
       g_source_set_callback (pm->renew_src,
           _renew_mapping_timeout, pm, NULL);
-      g_source_attach (pm->renew_src, g_main_context_get_thread_default ());
+      g_source_attach (pm->renew_src, self->priv->main_context);
     }
   }
   else



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]