[gnome-settings-daemon/gnome-3-18] color: Use GCancellable for all async operations
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/gnome-3-18] color: Use GCancellable for all async operations
- Date: Tue, 15 Mar 2016 23:41:29 +0000 (UTC)
commit a0c85f91821ae181c7ceedc6f7d82043b2c19444
Author: Richard Hughes <richard hughsie com>
Date: Tue Mar 15 11:18:12 2016 +0000
color: Use GCancellable for all async operations
Make sure to cancel any async operations when stopping the color plugin.
Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=763382
plugins/color/gsd-color-manager.c | 3 ++
plugins/color/gsd-color-profiles.c | 31 ++++++++++++++++++++++------
plugins/color/gsd-color-profiles.h | 1 +
plugins/color/gsd-color-state.c | 39 ++++++++++++++++++++++++++---------
plugins/color/gsd-color-state.h | 1 +
5 files changed, 58 insertions(+), 17 deletions(-)
---
diff --git a/plugins/color/gsd-color-manager.c b/plugins/color/gsd-color-manager.c
index dd6ec5c..ae1bc0d 100644
--- a/plugins/color/gsd-color-manager.c
+++ b/plugins/color/gsd-color-manager.c
@@ -85,7 +85,10 @@ out:
void
gsd_color_manager_stop (GsdColorManager *manager)
{
+ GsdColorManagerPrivate *priv = manager->priv;
g_debug ("Stopping color manager");
+ gsd_color_state_stop (priv->state);
+ gsd_color_profiles_stop (priv->profiles);
}
static void
diff --git a/plugins/color/gsd-color-profiles.c b/plugins/color/gsd-color-profiles.c
index 88558c0..8251d38 100644
--- a/plugins/color/gsd-color-profiles.c
+++ b/plugins/color/gsd-color-profiles.c
@@ -29,6 +29,7 @@
struct GsdColorProfilesPrivate
{
+ GCancellable *cancellable;
CdClient *client;
CdIccStore *icc_store;
};
@@ -78,7 +79,7 @@ gcm_session_client_connect_cb (GObject *source_object,
ret = cd_icc_store_search_kind (priv->icc_store,
CD_ICC_STORE_SEARCH_KIND_USER,
CD_ICC_STORE_SEARCH_FLAGS_CREATE_LOCATION,
- NULL,
+ profiles->priv->cancellable,
&error);
if (!ret) {
g_warning ("failed to add user icc: %s", error->message);
@@ -90,14 +91,28 @@ gboolean
gsd_color_profiles_start (GsdColorProfiles *profiles,
GError **error)
{
- cd_client_connect (profiles->priv->client,
- NULL,
+ GsdColorProfilesPrivate *priv = profiles->priv;
+
+ /* use a fresh cancellable for each start->stop operation */
+ g_cancellable_cancel (priv->cancellable);
+ g_clear_object (&priv->cancellable);
+ priv->cancellable = g_cancellable_new ();
+
+ cd_client_connect (priv->client,
+ priv->cancellable,
gcm_session_client_connect_cb,
profiles);
return TRUE;
}
+void
+gsd_color_profiles_stop (GsdColorProfiles *profiles)
+{
+ GsdColorProfilesPrivate *priv = profiles->priv;
+ g_cancellable_cancel (priv->cancellable);
+}
+
static void
gcm_session_create_profile_cb (GObject *object,
GAsyncResult *res,
@@ -128,7 +143,7 @@ gcm_session_icc_store_added_cb (CdIccStore *icc_store,
cd_client_create_profile_for_icc (priv->client,
icc,
CD_OBJECT_SCOPE_TEMP,
- NULL,
+ priv->cancellable,
gcm_session_create_profile_cb,
profiles);
#else
@@ -155,7 +170,7 @@ gcm_session_icc_store_added_cb (CdIccStore *icc_store,
profile_id,
CD_OBJECT_SCOPE_TEMP,
profile_props,
- NULL,
+ priv->cancellable,
gcm_session_create_profile_cb,
profiles);
g_free (profile_id);
@@ -200,7 +215,7 @@ gcm_session_find_profile_by_filename_cb (GObject *object,
/* remove it from colord */
cd_client_delete_profile (profiles->priv->client,
profile,
- NULL,
+ profiles->priv->cancellable,
gcm_session_delete_profile_cb,
profiles);
out:
@@ -217,7 +232,7 @@ gcm_session_icc_store_removed_cb (CdIccStore *icc_store,
g_debug ("filename %s removed", cd_icc_get_filename (icc));
cd_client_find_profile_by_filename (profiles->priv->client,
cd_icc_get_filename (icc),
- NULL,
+ profiles->priv->cancellable,
gcm_session_find_profile_by_filename_cb,
profiles);
}
@@ -251,6 +266,8 @@ gsd_color_profiles_finalize (GObject *object)
profiles = GSD_COLOR_PROFILES (object);
+ g_cancellable_cancel (profiles->priv->cancellable);
+ g_clear_object (&profiles->priv->cancellable);
g_clear_object (&profiles->priv->icc_store);
g_clear_object (&profiles->priv->client);
diff --git a/plugins/color/gsd-color-profiles.h b/plugins/color/gsd-color-profiles.h
index c7c305a..df87a39 100644
--- a/plugins/color/gsd-color-profiles.h
+++ b/plugins/color/gsd-color-profiles.h
@@ -48,6 +48,7 @@ GQuark gsd_color_profiles_error_quark (void);
GsdColorProfiles * gsd_color_profiles_new (void);
gboolean gsd_color_profiles_start (GsdColorProfiles *profiles,
GError **error);
+void gsd_color_profiles_stop (GsdColorProfiles *profiles);
G_END_DECLS
diff --git a/plugins/color/gsd-color-state.c b/plugins/color/gsd-color-state.c
index aa8138b..643da60 100644
--- a/plugins/color/gsd-color-state.c
+++ b/plugins/color/gsd-color-state.c
@@ -45,6 +45,7 @@
struct GsdColorStatePrivate
{
+ GCancellable *cancellable;
GsdSessionManager *session;
CdClient *client;
GnomeRRScreen *state_screen;
@@ -890,7 +891,7 @@ gcm_session_device_assign_connect_cb (GObject *object,
helper->state = g_object_ref (state);
helper->device = g_object_ref (device);
cd_profile_connect (profile,
- NULL,
+ priv->cancellable,
gcm_session_device_assign_profile_connect_cb,
helper);
out:
@@ -921,7 +922,7 @@ gcm_session_device_assign (GsdColorState *state, CdDevice *device)
g_strdup (key),
GINT_TO_POINTER (TRUE));
cd_device_connect (device,
- NULL,
+ state->priv->cancellable,
gcm_session_device_assign_connect_cb,
state);
}
@@ -1060,7 +1061,7 @@ gcm_session_add_state_output (GsdColorState *state, GnomeRROutput *output)
device_id,
CD_OBJECT_SCOPE_TEMP,
device_props,
- NULL,
+ priv->cancellable,
gcm_session_create_device_cb,
state);
g_free (device_id);
@@ -1116,7 +1117,7 @@ gcm_session_screen_removed_find_device_cb (GObject *object, GAsyncResult *res, g
cd_device_get_object_path (device));
cd_client_delete_device (state->priv->client,
device,
- NULL,
+ state->priv->cancellable,
gcm_session_screen_removed_delete_device_cb,
state);
g_object_unref (device);
@@ -1134,7 +1135,7 @@ gnome_rr_screen_output_removed_cb (GnomeRRScreen *screen,
cd_client_find_device_by_property (state->priv->client,
CD_DEVICE_METADATA_XRANDR_NAME,
gnome_rr_output_get_name (output),
- NULL,
+ state->priv->cancellable,
gcm_session_screen_removed_find_device_cb,
state);
}
@@ -1186,7 +1187,7 @@ gcm_session_profile_gamma_find_device_cb (GObject *object,
/* get properties */
cd_device_connect (device,
- NULL,
+ state->priv->cancellable,
gcm_session_device_assign_connect_cb,
state);
out:
@@ -1216,7 +1217,7 @@ gnome_rr_screen_output_changed_cb (GnomeRRScreen *screen,
cd_client_find_device_by_property (state->priv->client,
CD_DEVICE_METADATA_XRANDR_NAME,
gnome_rr_output_get_name (outputs[i]),
- NULL,
+ priv->cancellable,
gcm_session_profile_gamma_find_device_cb,
state);
}
@@ -1266,7 +1267,8 @@ gcm_session_active_changed_cb (GDBusProxy *session,
*/
if (is_active && !priv->session_is_active) {
g_debug ("Done switch to new account, reload devices");
- cd_client_get_devices (state->priv->client, NULL,
+ cd_client_get_devices (priv->client,
+ priv->cancellable,
gcm_session_get_devices_cb,
state);
}
@@ -1341,7 +1343,8 @@ gcm_session_client_connect_cb (GObject *source_object,
state);
/* set for each device that already exist */
- cd_client_get_devices (priv->client, NULL,
+ cd_client_get_devices (priv->client,
+ priv->cancellable,
gcm_session_get_devices_cb,
state);
out:
@@ -1364,7 +1367,7 @@ on_rr_screen_acquired (GObject *object,
priv->state_screen = screen;
cd_client_connect (priv->client,
- NULL,
+ priv->cancellable,
gcm_session_client_connect_cb,
state);
}
@@ -1372,12 +1375,26 @@ on_rr_screen_acquired (GObject *object,
void
gsd_color_state_start (GsdColorState *state)
{
+ GsdColorStatePrivate *priv = state->priv;
+
+ /* use a fresh cancellable for each start->stop operation */
+ g_cancellable_cancel (priv->cancellable);
+ g_clear_object (&priv->cancellable);
+ priv->cancellable = g_cancellable_new ();
+
/* coldplug the list of screens */
gnome_rr_screen_new_async (gdk_screen_get_default (),
on_rr_screen_acquired,
state);
}
+void
+gsd_color_state_stop (GsdColorState *state)
+{
+ GsdColorStatePrivate *priv = state->priv;
+ g_cancellable_cancel (priv->cancellable);
+}
+
static void
gsd_color_state_class_init (GsdColorStateClass *klass)
{
@@ -1428,6 +1445,8 @@ gsd_color_state_finalize (GObject *object)
state = GSD_COLOR_STATE (object);
+ g_cancellable_cancel (state->priv->cancellable);
+ g_clear_object (&state->priv->cancellable);
g_clear_object (&state->priv->client);
g_clear_object (&state->priv->session);
g_clear_pointer (&state->priv->edid_cache, g_hash_table_destroy);
diff --git a/plugins/color/gsd-color-state.h b/plugins/color/gsd-color-state.h
index 27443b0..ebe5850 100644
--- a/plugins/color/gsd-color-state.h
+++ b/plugins/color/gsd-color-state.h
@@ -47,6 +47,7 @@ GQuark gsd_color_state_error_quark (void);
GsdColorState * gsd_color_state_new (void);
void gsd_color_state_start (GsdColorState *state);
+void gsd_color_state_stop (GsdColorState *state);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]