[libchamplain] NetworkTileSrc: Make max-conns settable



commit 498f2e6924a4733bd122f417a0a0cceac107f7f5
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Wed Aug 3 21:17:23 2016 +0200

    NetworkTileSrc: Make max-conns settable
    
    Make it possible to set the maximum allowed simultaneous connections on
    the underlying soup session.
    
    This makes it possible for NetworkTileSources that allow more
    simultanoeus connections than 2 to take advantage of that, making the
    map viewing experience much nicer.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768890

 champlain/champlain-network-tile-source.c |   92 ++++++++++++++++++++++++++++-
 champlain/champlain-network-tile-source.h |    5 ++
 2 files changed, 94 insertions(+), 3 deletions(-)
---
diff --git a/champlain/champlain-network-tile-source.c b/champlain/champlain-network-tile-source.c
index b993b19..7fb9ec2 100644
--- a/champlain/champlain-network-tile-source.c
+++ b/champlain/champlain-network-tile-source.c
@@ -61,7 +61,8 @@ enum
   PROP_0,
   PROP_URI_FORMAT,
   PROP_OFFLINE,
-  PROP_PROXY_URI
+  PROP_PROXY_URI,
+  PROP_MAX_CONNS
 };
 
 G_DEFINE_TYPE (ChamplainNetworkTileSource, champlain_network_tile_source, CHAMPLAIN_TYPE_TILE_SOURCE);
@@ -75,6 +76,7 @@ struct _ChamplainNetworkTileSourcePrivate
   gchar *uri_format;
   gchar *proxy_uri;
   SoupSession *soup_session;
+  gint max_conns;
 };
 
 typedef struct
@@ -130,6 +132,10 @@ champlain_network_tile_source_get_property (GObject *object,
       g_value_set_string (value, priv->proxy_uri);
       break;
 
+    case PROP_MAX_CONNS:
+      g_value_set_int (value, priv->max_conns);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -158,6 +164,10 @@ champlain_network_tile_source_set_property (GObject *object,
       champlain_network_tile_source_set_proxy_uri (tile_source, g_value_get_string (value));
       break;
 
+    case PROP_MAX_CONNS:
+      champlain_network_tile_source_set_max_conns (tile_source, g_value_get_int (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -257,6 +267,29 @@ champlain_network_tile_source_class_init (ChamplainNetworkTileSourceClass *klass
         "",
         G_PARAM_READWRITE);
   g_object_class_install_property (object_class, PROP_PROXY_URI, pspec);
+
+  /**
+   * ChamplainNetworkTileSource:max-conns:
+   *
+   * Specifies the max number of allowed simultaneous connections for this tile
+   * source.
+   *
+   * Before changing this remember to verify how many simultaneous connections
+   * your tile provider allows you to make.
+   *
+   * Since: 0.12.15
+   */
+  pspec = g_param_spec_int ("max-conns",
+        "Max Connection Count",
+        "The maximum number of allowed simultaneous connections "
+        "for this tile source.",
+        1,
+        G_MAXINT,
+        2,
+        G_PARAM_READWRITE);
+
+  g_object_class_install_property (object_class, PROP_MAX_CONNS, pspec);
+
 }
 
 
@@ -270,6 +303,7 @@ champlain_network_tile_source_init (ChamplainNetworkTileSource *tile_source)
   priv->proxy_uri = NULL;
   priv->uri_format = NULL;
   priv->offline = FALSE;
+  priv->max_conns = 2;
 
   priv->soup_session = soup_session_new_with_options (
         "proxy-uri", NULL,
@@ -282,8 +316,9 @@ champlain_network_tile_source_init (ChamplainNetworkTileSource *tile_source)
   g_object_set (G_OBJECT (priv->soup_session),
       "user-agent", 
       "libchamplain/" CHAMPLAIN_VERSION_S,
-      "max-conns-per-host", 2,    /* This is as required by OSM */ 
-      NULL); 
+      "max-conns-per-host", 2,    /* This is as required by OSM */
+      "max-conns", 2,
+      NULL);
 }
 
 
@@ -482,6 +517,57 @@ champlain_network_tile_source_set_offline (ChamplainNetworkTileSource *tile_sour
 }
 
 
+/**
+ * champlain_network_tile_source_get_max_conns:
+ * @tile_source: the #ChamplainNetworkTileSource
+ *
+ * Gets the max number of allowed simultaneous connections for this tile
+ * source.
+ *
+ * Returns: the max number of allowed simultaneous connections for this tile
+ * source.
+ *
+ * Since: 0.12.15
+ */
+gint
+champlain_network_tile_source_get_max_conns (ChamplainNetworkTileSource *tile_source)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_NETWORK_TILE_SOURCE (tile_source), 0);
+
+  return tile_source->priv->max_conns;
+}
+
+
+/**
+ * champlain_network_tile_source_set_max_conns:
+ * @tile_source: the #ChamplainNetworkTileSource
+ * @max_conns: the number of allowed simultaneous connections
+ *
+ * Sets the max number of allowed simultaneous connections for this tile source.
+ *
+ * Before changing this remember to verify how many simultaneous connections
+ * your tile provider allows you to make.
+ *
+ * Since: 0.12.15
+ */
+void
+champlain_network_tile_source_set_max_conns (ChamplainNetworkTileSource *tile_source,
+    gint max_conns)
+{
+  g_return_if_fail (CHAMPLAIN_IS_NETWORK_TILE_SOURCE (tile_source));
+  g_return_if_fail (SOUP_IS_SESSION (tile_source->priv->soup_session));
+
+  tile_source->priv->max_conns = max_conns;
+
+  g_object_set (G_OBJECT (tile_source->priv->soup_session),
+      "max-conns-per-host", max_conns,
+      "max-conns", max_conns,
+      NULL);
+
+  g_object_notify (G_OBJECT (tile_source), "max_conns");
+}
+
+
 #define SIZE 8
 static gchar *
 get_tile_uri (ChamplainNetworkTileSource *tile_source,
diff --git a/champlain/champlain-network-tile-source.h b/champlain/champlain-network-tile-source.h
index 7fabb1a..7c29b3e 100644
--- a/champlain/champlain-network-tile-source.h
+++ b/champlain/champlain-network-tile-source.h
@@ -96,6 +96,11 @@ const gchar *champlain_network_tile_source_get_proxy_uri (ChamplainNetworkTileSo
 void champlain_network_tile_source_set_proxy_uri (ChamplainNetworkTileSource *tile_source,
     const gchar *proxy_uri);
 
+gint champlain_network_tile_source_get_max_conns (ChamplainNetworkTileSource *tile_source);
+void champlain_network_tile_source_set_max_conns (ChamplainNetworkTileSource *tile_source,
+    gint max_conns);
+
+
 G_END_DECLS
 
 #endif /* _CHAMPLAIN_NETWORK_TILE_SOURCE_H_ */


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