[gssdp] Deprecate main_context property.
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gssdp] Deprecate main_context property.
- Date: Wed, 20 Jul 2011 18:13:25 +0000 (UTC)
commit 541f3752f89899c6ecd775abcfbd89afbb6fc403
Author: Jens Georg <mail jensge org>
Date: Sun Jun 26 09:15:31 2011 +0200
Deprecate main_context property.
Use g_main_context_get_thread_default() instead
libgssdp/gssdp-client.c | 59 ++++++++++--------------------------
libgssdp/gssdp-client.h | 2 +
libgssdp/gssdp-resource-browser.c | 13 ++-----
libgssdp/gssdp-resource-group.c | 18 ++++-------
libgssdp/gssdp-socket-source.c | 6 ++--
libgssdp/gssdp-socket-source.h | 3 +-
tests/test-browser.c | 6 +++-
tests/test-publish.c | 6 +++-
tools/gssdp-device-sniffer.c | 5 ++-
9 files changed, 47 insertions(+), 71 deletions(-)
---
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index 16a6da5..8b8e3f9 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -85,8 +85,6 @@ G_DEFINE_TYPE_EXTENDED (GSSDPClient,
gssdp_client_initable_iface_init));
struct _GSSDPClientPrivate {
- GMainContext *main_context;
-
char *server_id;
char *iface;
char *host_ip;
@@ -116,10 +114,6 @@ enum {
static guint signals[LAST_SIGNAL];
-/* Function prototypes */
-static void
-gssdp_client_set_main_context (GSSDPClient *client,
- GMainContext *context);
static char *
make_server_id (void);
static gboolean
@@ -259,14 +253,9 @@ gssdp_client_initable_init (GInitable *initable,
return FALSE;
}
- gssdp_socket_source_attach (client->priv->request_socket,
- client->priv->main_context);
-
- gssdp_socket_source_attach (client->priv->multicast_socket,
- client->priv->main_context);
-
- gssdp_socket_source_attach (client->priv->search_socket,
- client->priv->main_context);
+ gssdp_socket_source_attach (client->priv->request_socket);
+ gssdp_socket_source_attach (client->priv->multicast_socket);
+ gssdp_socket_source_attach (client->priv->search_socket);
return TRUE;
}
@@ -288,10 +277,12 @@ gssdp_client_get_property (GObject *object,
gssdp_client_get_server_id (client));
break;
case PROP_MAIN_CONTEXT:
+ g_warning ("GSSDPClient:main-context is deprecated."
+ " Please use g_main_context_push_thread_default()");
g_value_set_pointer
(value,
(gpointer)
- gssdp_client_get_main_context (client));
+ g_main_context_get_thread_default ());
break;
case PROP_IFACE:
g_value_set_string (value,
@@ -330,8 +321,8 @@ gssdp_client_set_property (GObject *object,
g_value_get_string (value));
break;
case PROP_MAIN_CONTEXT:
- gssdp_client_set_main_context (client,
- g_value_get_pointer (value));
+ g_warning ("GSSDPClient:main-context is deprecated."
+ " Please use g_main_context_push_thread_default()");
break;
case PROP_IFACE:
client->priv->iface = g_value_dup_string (value);
@@ -371,12 +362,6 @@ gssdp_client_dispose (GObject *object)
client->priv->search_socket = NULL;
}
- /* Unref the context */
- if (client->priv->main_context) {
- g_main_context_unref (client->priv->main_context);
- client->priv->main_context = NULL;
- }
-
G_OBJECT_CLASS (gssdp_client_parent_class)->dispose (object);
}
@@ -433,6 +418,7 @@ gssdp_client_class_init (GSSDPClientClass *klass)
* GSSDPClient:main-context
*
* The #GMainContext to use. Set to NULL to use the default.
+ * Deprecated: 0.11.1: Use g_main_context_push_thread_default().
**/
g_object_class_install_property
(object_class,
@@ -552,7 +538,8 @@ gssdp_client_class_init (GSSDPClientClass *klass)
/**
* gssdp_client_new
- * @main_context: The #GMainContext to associate with, or NULL
+ * @main_context: Deprecated: 0.11.1: Always set to NULL. If you want to
+ * specify a context use g_main_context_push_thread_default()
* @iface: The name of the network interface, or %NULL for auto-detection.
* @error: Location to store error, or NULL
*
@@ -563,42 +550,30 @@ gssdp_client_new (GMainContext *main_context,
const char *iface,
GError **error)
{
+ if (main_context) {
+ g_warning ("GSSDPClient:main-context is deprecated."
+ " Please use g_main_context_push_thread_default()");
+ }
return g_initable_new (GSSDP_TYPE_CLIENT,
NULL,
error,
- "main-context", main_context,
"interface", iface,
NULL);
}
/*
- * Sets the GMainContext @client is associated with to @main_context
- */
-static void
-gssdp_client_set_main_context (GSSDPClient *client,
- GMainContext *main_context)
-{
- g_return_if_fail (GSSDP_IS_CLIENT (client));
-
- /* A NULL main_context is fine */
- if (main_context)
- client->priv->main_context = g_main_context_ref (main_context);
-
- g_object_notify (G_OBJECT (client), "main-context");
-}
-
-/**
* gssdp_client_get_main_context
* @client: A #GSSDPClient
*
* Returns: (transfer none): The #GMainContext @client is associated with, or NULL.
+ * Deprecated: 0.11.1: Returns g_main_context_get_thread_default()
**/
GMainContext *
gssdp_client_get_main_context (GSSDPClient *client)
{
g_return_val_if_fail (GSSDP_IS_CLIENT (client), NULL);
- return client->priv->main_context;
+ return g_main_context_get_thread_default ();
}
/**
diff --git a/libgssdp/gssdp-client.h b/libgssdp/gssdp-client.h
index ff2b2c2..32ba9d3 100644
--- a/libgssdp/gssdp-client.h
+++ b/libgssdp/gssdp-client.h
@@ -75,8 +75,10 @@ gssdp_client_new (GMainContext *main_context,
const char *iface,
GError **error);
+#ifndef GSSDP_DISABLE_DEPRECATED
GMainContext *
gssdp_client_get_main_context (GSSDPClient *client);
+#endif
void
gssdp_client_set_server_id (GSSDPClient *client,
diff --git a/libgssdp/gssdp-resource-browser.c b/libgssdp/gssdp-resource-browser.c
index 77b25b7..1199a25 100644
--- a/libgssdp/gssdp-resource-browser.c
+++ b/libgssdp/gssdp-resource-browser.c
@@ -614,7 +614,6 @@ resource_available (GSSDPResourceBrowser *resource_browser,
gboolean was_cached;
guint timeout;
GList *locations;
- GMainContext *context;
usn = soup_message_headers_get_one (headers, "USN");
if (!usn)
@@ -709,9 +708,8 @@ resource_available (GSSDPResourceBrowser *resource_browser,
resource_expire,
resource, NULL);
- context = gssdp_client_get_main_context
- (resource_browser->priv->client);
- g_source_attach (resource->timeout_src, context);
+ g_source_attach (resource->timeout_src,
+ g_main_context_get_thread_default ());
g_source_unref (resource->timeout_src);
@@ -962,8 +960,6 @@ discovery_timeout (gpointer data)
static void
start_discovery (GSSDPResourceBrowser *resource_browser)
{
- GMainContext *context;
-
/* Send one now */
send_discovery_request (resource_browser);
@@ -975,9 +971,8 @@ start_discovery (GSSDPResourceBrowser *resource_browser)
discovery_timeout,
resource_browser, NULL);
- context = gssdp_client_get_main_context
- (resource_browser->priv->client);
- g_source_attach (resource_browser->priv->timeout_src, context);
+ g_source_attach (resource_browser->priv->timeout_src,
+ g_main_context_get_thread_default ());
g_source_unref (resource_browser->priv->timeout_src);
}
diff --git a/libgssdp/gssdp-resource-group.c b/libgssdp/gssdp-resource-group.c
index db6e2bf..e5b852b 100644
--- a/libgssdp/gssdp-resource-group.c
+++ b/libgssdp/gssdp-resource-group.c
@@ -522,7 +522,6 @@ gssdp_resource_group_set_available (GSSDPResourceGroup *resource_group,
resource_group->priv->available = available;
if (available) {
- GMainContext *context;
int timeout;
/* We want to re-announce at least 3 times before the resource
@@ -542,9 +541,8 @@ gssdp_resource_group_set_available (GSSDPResourceGroup *resource_group,
resource_group_timeout,
resource_group, NULL);
- context = gssdp_client_get_main_context
- (resource_group->priv->client);
- g_source_attach (resource_group->priv->timeout_src, context);
+ g_source_attach (resource_group->priv->timeout_src,
+ g_main_context_get_thread_default ());
g_source_unref (resource_group->priv->timeout_src);
@@ -805,7 +803,6 @@ message_received_cb (GSSDPClient *client,
/* Match. */
guint timeout;
DiscoveryResponse *response;
- GMainContext *context;
/* Get a random timeout from the interval [0, mx] */
timeout = g_random_int_range (0, mx * 1000);
@@ -828,8 +825,8 @@ message_received_cb (GSSDPClient *client,
discovery_response_timeout,
response, NULL);
- context = gssdp_client_get_main_context (client);
- g_source_attach (response->timeout_src, context);
+ g_source_attach (response->timeout_src,
+ g_main_context_get_thread_default ());
g_source_unref (response->timeout_src);
@@ -1005,16 +1002,13 @@ queue_message (GSSDPResourceGroup *resource_group,
if (resource_group->priv->message_src == NULL) {
/* nothing in the queue: process message immediately
and add a timeout for (possible) next message */
- GMainContext *context;
-
process_queue (resource_group);
resource_group->priv->message_src = g_timeout_source_new (
resource_group->priv->message_delay);
g_source_set_callback (resource_group->priv->message_src,
process_queue, resource_group, NULL);
- context = gssdp_client_get_main_context (
- resource_group->priv->client);
- g_source_attach (resource_group->priv->message_src, context);
+ g_source_attach (resource_group->priv->message_src,
+ g_main_context_get_thread_default ());
g_source_unref (resource_group->priv->message_src);
}
}
diff --git a/libgssdp/gssdp-socket-source.c b/libgssdp/gssdp-socket-source.c
index 720061e..e8409a6 100644
--- a/libgssdp/gssdp-socket-source.c
+++ b/libgssdp/gssdp-socket-source.c
@@ -337,13 +337,13 @@ gssdp_socket_source_set_callback (GSSDPSocketSource *self,
}
void
-gssdp_socket_source_attach (GSSDPSocketSource *self,
- GMainContext *context)
+gssdp_socket_source_attach (GSSDPSocketSource *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (GSSDP_IS_SOCKET_SOURCE (self));
- g_source_attach (self->priv->source, context);
+ g_source_attach (self->priv->source,
+ g_main_context_get_thread_default ());
}
static void
diff --git a/libgssdp/gssdp-socket-source.h b/libgssdp/gssdp-socket-source.h
index c464aeb..39b2932 100644
--- a/libgssdp/gssdp-socket-source.h
+++ b/libgssdp/gssdp-socket-source.h
@@ -84,8 +84,7 @@ gssdp_socket_source_set_callback (GSSDPSocketSource *socket_source,
gpointer user_data);
G_GNUC_INTERNAL void
-gssdp_socket_source_attach (GSSDPSocketSource *socket_source,
- GMainContext *context);
+gssdp_socket_source_attach (GSSDPSocketSource *socket_source);
G_END_DECLS
diff --git a/tests/test-browser.c b/tests/test-browser.c
index 0b88ba5..4157fca 100644
--- a/tests/test-browser.c
+++ b/tests/test-browser.c
@@ -20,6 +20,7 @@
*/
#include <libgssdp/gssdp.h>
+#include <gio/gio.h>
#include <stdlib.h>
static void
@@ -58,7 +59,10 @@ main (int argc,
g_type_init ();
error = NULL;
- client = gssdp_client_new (NULL, NULL, &error);
+ client = g_initable_new (GSSDP_TYPE_CLIENT,
+ NULL,
+ &error,
+ NULL);
if (error) {
g_printerr ("Error creating the GSSDP client: %s\n",
error->message);
diff --git a/tests/test-publish.c b/tests/test-publish.c
index 89c62cc..52889fb 100644
--- a/tests/test-publish.c
+++ b/tests/test-publish.c
@@ -20,6 +20,7 @@
*/
#include <libgssdp/gssdp.h>
+#include <gio/gio.h>
#include <stdlib.h>
int
@@ -34,7 +35,10 @@ main (int argc,
g_type_init ();
error = NULL;
- client = gssdp_client_new (NULL, NULL, &error);
+ client = g_initable_new (GSSDP_TYPE_CLIENT,
+ NULL,
+ &error,
+ NULL);
if (error) {
g_printerr ("Error creating the GSSDP client: %s\n",
error->message);
diff --git a/tools/gssdp-device-sniffer.c b/tools/gssdp-device-sniffer.c
index 833bb07..4ae3943 100644
--- a/tools/gssdp-device-sniffer.c
+++ b/tools/gssdp-device-sniffer.c
@@ -601,7 +601,10 @@ init_upnp (void)
GError *error;
error = NULL;
- client = gssdp_client_new (NULL, NULL, &error);
+ client = g_initable_new (GSSDP_TYPE_CLIENT,
+ NULL,
+ &error,
+ NULL);
if (error) {
g_printerr ("Error creating the GSSDP client: %s\n",
error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]