[gupnp/wip/phako/initable: 4/4] Context: Use port property from GSSDP.Client




commit daeac1a7ff1b5bbbb6e80235eb128175970260f6
Author: Jens Georg <mail jensge org>
Date:   Wed Oct 27 11:24:38 2021 +0200

    Context: Use port property from GSSDP.Client
    
    Part of #54

 libgupnp/gupnp-context.c                       | 81 ++++----------------------
 libgupnp/meson.build                           |  6 +-
 meson.build                                    |  2 +-
 subprojects/{gssdp-1.2.wrap => gssdp-1.6.wrap} |  2 +-
 vala/gupnp-1.6.deps                            |  2 +-
 vala/meson.build                               |  6 +-
 6 files changed, 19 insertions(+), 80 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index efec13f..7ec29cd 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -63,8 +63,6 @@ gupnp_context_initable_iface_init (gpointer g_iface,
                                    gpointer iface_data);
 
 struct _GUPnPContextPrivate {
-        guint        port;
-
         guint        subscription_timeout;
 
         SoupSession *session;
@@ -90,7 +88,6 @@ G_DEFINE_TYPE_EXTENDED (GUPnPContext,
 
 enum {
         PROP_0,
-        PROP_PORT,
         PROP_SERVER,
         PROP_SESSION,
         PROP_SUBSCRIPTION_TIMEOUT,
@@ -203,7 +200,9 @@ gupnp_context_initable_init (GInitable     *initable,
         }
 
         /* Create the server already if the port is not null*/
-        if (priv->port != 0) {
+        guint port = gssdp_client_get_port (GSSDP_CLIENT (context));
+        if (port != 0) {
+                // Create the server
                 gupnp_context_get_server (context);
 
                 if (priv->server == NULL) {
@@ -214,7 +213,7 @@ gupnp_context_initable_init (GInitable     *initable,
                                      GUPNP_SERVER_ERROR,
                                      GUPNP_SERVER_ERROR_OTHER,
                                      "Could not create HTTP server on port %d",
-                                     priv->port);
+                                     port);
 
                         return FALSE;
                 }
@@ -245,9 +244,6 @@ gupnp_context_set_property (GObject      *object,
         priv = gupnp_context_get_instance_private (context);
 
         switch (property_id) {
-        case PROP_PORT:
-                priv->port = g_value_get_uint (value);
-                break;
         case PROP_SUBSCRIPTION_TIMEOUT:
                 priv->subscription_timeout = g_value_get_uint (value);
                 break;
@@ -356,43 +352,6 @@ gupnp_context_finalize (GObject *object)
         object_class->finalize (object);
 }
 
-static GObject *
-gupnp_context_constructor (GType                  type,
-                           guint                  n_construct_params,
-                           GObjectConstructParam *construct_params)
-{
-        GObjectClass *object_class;
-        guint port = 0, msearch_port = 0;
-        guint i;
-        int msearch_idx = -1;
-
-        for (i = 0; i < n_construct_params; i++) {
-                const char *par_name;
-
-                par_name = construct_params[i].pspec->name;
-
-                if (strcmp (par_name, "port") == 0)
-                        port = g_value_get_uint (construct_params[i].value);
-                else if (strcmp (par_name, "msearch-port") == 0) {
-                        msearch_idx = i;
-                        msearch_port = g_value_get_uint
-                                        (construct_params[i].value);
-                }
-        }
-
-        object_class = G_OBJECT_CLASS (gupnp_context_parent_class);
-
-        /* Override msearch-port property if port is set, the property exists
-         * and wasn't provided otherwise */
-        if (port != 0 && msearch_idx != -1 && msearch_port == 0) {
-                g_value_set_uint (construct_params[msearch_idx].value, port);
-        }
-
-        return object_class->constructor (type,
-                                          n_construct_params,
-                                          construct_params);
-}
-
 
 static void
 gupnp_context_class_init (GUPnPContextClass *klass)
@@ -405,25 +364,6 @@ gupnp_context_class_init (GUPnPContextClass *klass)
         object_class->get_property = gupnp_context_get_property;
         object_class->dispose      = gupnp_context_dispose;
         object_class->finalize     = gupnp_context_finalize;
-        object_class->constructor  = gupnp_context_constructor;
-
-        /**
-         * GUPnPContext:port:
-         *
-         * The port to run on. Set to 0 if you don't care what port to run on.
-         **/
-        g_object_class_install_property
-                (object_class,
-                 PROP_PORT,
-                 g_param_spec_uint ("port",
-                                    "Port",
-                                    "Port to run on",
-                                    0, G_MAXUINT, SOUP_ADDRESS_ANY_PORT,
-                                    G_PARAM_READWRITE |
-                                    G_PARAM_CONSTRUCT_ONLY |
-                                    G_PARAM_STATIC_NAME |
-                                    G_PARAM_STATIC_NICK |
-                                    G_PARAM_STATIC_BLURB));
 
         /**
          * GUPnPContext:server:
@@ -590,25 +530,24 @@ gupnp_context_get_server (GUPnPContext *context)
 
                 ip = gssdp_client_get_host_ip (GSSDP_CLIENT (context));
                 inet_addr = gssdp_client_get_address (GSSDP_CLIENT (context));
+                guint port = gssdp_client_get_port (GSSDP_CLIENT (context));
                 if (g_inet_address_get_family (inet_addr) == G_SOCKET_FAMILY_IPV6 &&
                     g_inet_address_get_is_link_local (inet_addr)) {
-                        guint scope;
-
-                        scope = gssdp_client_get_index (GSSDP_CLIENT (context));
+                        guint scope =
+                                gssdp_client_get_index (GSSDP_CLIENT (context));
                         addr = g_object_new (G_TYPE_INET_SOCKET_ADDRESS,
                                              "address", inet_addr,
-                                             "port", priv->port,
+                                             "port", port,
                                              "scope-id", scope,
                                              NULL);
                 } else {
-                        addr = g_inet_socket_address_new (inet_addr,
-                                                          priv->port);
+                        addr = g_inet_socket_address_new (inet_addr, port);
                 }
                 g_object_unref (inet_addr);
 
                 if (! soup_server_listen (priv->server,
                                           addr, (SoupServerListenOptions) 0, &error)) {
-                        g_warning ("GUPnPContext: Unable to listen on %s:%u %s", ip, priv->port, 
error->message);
+                        g_warning ("GUPnPContext: Unable to listen on %s:%u %s", ip, port, error->message);
                         g_error_free (error);
                 }
 
diff --git a/libgupnp/meson.build b/libgupnp/meson.build
index 043a510..af74d94 100644
--- a/libgupnp/meson.build
+++ b/libgupnp/meson.build
@@ -129,7 +129,7 @@ pkg.generate(
     libgupnp,
     subdirs: GUPNP_API_NAME,
     name : GUPNP_API_NAME,
-    requires : ['glib-2.0', 'gio-2.0', 'gssdp-1.2'],
+    requires : ['glib-2.0', 'gio-2.0', 'gssdp-1.6'],
     description : 'GObject-based UPnP library',
     version : meson.project_version(),
     filebase : GUPNP_API_NAME
@@ -138,9 +138,9 @@ pkg.generate(
 if get_option('introspection')
     gir_includes = ['GObject-2.0', 'Gio-2.0', 'Soup-2.4', 'libxml2-2.0']
     if gssdp_dep.type_name() == 'internal'
-        gir_includes += subproject('gssdp-1.2').get_variable('gir').get(0)
+        gir_includes += subproject('gssdp-1.6').get_variable('gir').get(0)
     else
-        gir_includes += 'GSSDP-1.2'
+        gir_includes += 'GSSDP-1.6'
     endif
     gir = gnome.generate_gir(
         libgupnp,
diff --git a/meson.build b/meson.build
index 0eb0cc7..fbd244e 100644
--- a/meson.build
+++ b/meson.build
@@ -27,7 +27,7 @@ conf.set('GLIB_VERSION_MAX_ALLOWED', 'GLIB_VERSION_' + glib_version.underscorify
 subdir('internal')
 guul = subproject('guul', default_options : ['default_library=static'])
 
-gssdp_dep = dependency('gssdp-1.2', version : '>= 1.3.0', default_options: ['sniffer=false'], fallback: 
'gssdp-1.2')
+gssdp_dep = dependency('gssdp-1.6', version : '>= 1.5.0', default_options: ['sniffer=false'], fallback: 
'gssdp-1.6')
 
 gio_unix = dependency('gio-unix-2.0', version: '>= 2.44', required: host_machine.system() != 'windows')
 
diff --git a/subprojects/gssdp-1.2.wrap b/subprojects/gssdp-1.6.wrap
similarity index 78%
rename from subprojects/gssdp-1.2.wrap
rename to subprojects/gssdp-1.6.wrap
index 34d9b0b..b0b6504 100644
--- a/subprojects/gssdp-1.2.wrap
+++ b/subprojects/gssdp-1.6.wrap
@@ -4,5 +4,5 @@ revision = master
 depth = 1
  
 [provides]
-dependency_name = gssdp-1.2
+dependency_name = gssdp-1.6
 
diff --git a/vala/gupnp-1.6.deps b/vala/gupnp-1.6.deps
index 48dcf61..c353320 100644
--- a/vala/gupnp-1.6.deps
+++ b/vala/gupnp-1.6.deps
@@ -1,3 +1,3 @@
-gssdp-1.2
+gssdp-1.6
 libsoup-2.4
 libxml-2.0
diff --git a/vala/meson.build b/vala/meson.build
index 7117bb1..107c908 100644
--- a/vala/meson.build
+++ b/vala/meson.build
@@ -1,8 +1,8 @@
 if gssdp_dep.type_name() == 'internal'
-    gssdp_vala_package = subproject('gssdp-1.2').get_variable('vapi')
-    gssdp_gir_dirs = subproject('gssdp-1.2').get_variable('gssdp_gir_dir')
+    gssdp_vala_package = subproject('gssdp-1.6').get_variable('vapi')
+    gssdp_gir_dirs = subproject('gssdp-1.6').get_variable('gssdp_gir_dir')
 else
-    gssdp_vala_package = 'gssdp-1.2'
+    gssdp_vala_package = 'gssdp-1.6'
     gssdp_gir_dirs = []
 endif
 


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