diff options
-rw-r--r-- | src/backend-dbus/backend-dbus.c | 34 | ||||
-rw-r--r-- | src/backend-dbus/utils.c | 384 | ||||
-rw-r--r-- | src/backend-dbus/utils.h | 16 |
3 files changed, 96 insertions, 338 deletions
diff --git a/src/backend-dbus/backend-dbus.c b/src/backend-dbus/backend-dbus.c index ea8f0ec..547c6ab 100644 --- a/src/backend-dbus/backend-dbus.c +++ b/src/backend-dbus/backend-dbus.c @@ -31,38 +31,36 @@ struct dbus_world_data IndicatorSessionGuestDbus * guest; }; -static void -on_proxies_ready (ConsoleKitManager * ck_manager, +static void +on_proxies_ready (Login1Manager * login1_manager, + Login1Seat * login1_seat, + DisplayManagerSeat * display_manager_seat, Accounts * account_manager, - DisplayManagerSeat * dm_seat, - ConsoleKitSeat * ck_seat, - ConsoleKitSession * ck_session, - AccountsUser * active_user G_GNUC_UNUSED, - const GError * error, + GCancellable * cancellable, gpointer gdata) { struct dbus_world_data * data = gdata; - if (error == NULL) + if (!g_cancellable_is_cancelled (cancellable)) { if (data->actions != NULL) indicator_session_actions_dbus_set_proxies (data->actions, - ck_manager, - dm_seat, - ck_seat); + login1_manager, + login1_seat, + display_manager_seat); if (data->users != NULL) indicator_session_users_dbus_set_proxies (data->users, - account_manager, - dm_seat, - ck_seat); + login1_manager, + login1_seat, + display_manager_seat, + account_manager); if (data->guest != NULL) indicator_session_guest_dbus_set_proxies (data->guest, - account_manager, - dm_seat, - ck_seat, - ck_session); + login1_manager, + login1_seat, + display_manager_seat); } g_free (data); diff --git a/src/backend-dbus/utils.c b/src/backend-dbus/utils.c index c8abc2b..25ac7c3 100644 --- a/src/backend-dbus/utils.c +++ b/src/backend-dbus/utils.c @@ -25,346 +25,100 @@ struct session_proxy_data { - ConsoleKitManager * ck_manager; - Accounts * account_manager; + Login1Manager * login1_manager; + Login1Seat * login1_seat; DisplayManagerSeat * dm_seat; - - ConsoleKitSeat * current_seat; - ConsoleKitSession * current_session; - AccountsUser * active_user; + Accounts * account_manager; GCancellable * cancellable; - GError * error; int pending; indicator_session_util_session_proxies_func callback; gpointer user_data; }; -static void -session_proxy_data_free (struct session_proxy_data * data) -{ - g_clear_object (&data->ck_manager); - g_clear_object (&data->account_manager); - g_clear_object (&data->dm_seat); - - g_clear_object (&data->current_seat); - g_clear_object (&data->current_session); - g_clear_object (&data->active_user); - - g_clear_object (&data->cancellable); - g_clear_error (&data->error); - - g_free (data); -} static void -finish_callback (struct session_proxy_data * data) +on_proxy_ready_impl (struct session_proxy_data * data, + gsize member_offset, + GError * err, + gpointer proxy) { - g_assert (data != NULL); - g_debug ("%s %s: pending is %d", G_STRLOC, G_STRFUNC, (data->pending-1)); - - if (!--data->pending) + if (err != NULL) { - data->callback (data->ck_manager, - data->account_manager, - data->dm_seat, - data->current_seat, - data->current_session, - data->active_user, - data->error, - data->user_data); + if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, err->message); - session_proxy_data_free (data); - } -} - -static void -on_user_proxy_ready (GObject * o G_GNUC_UNUSED, - GAsyncResult * res, - gpointer gdata) -{ - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - data->active_user = accounts_user_proxy_new_for_bus_finish (res, &data->error); - - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); + g_error_free (err); } else { - g_debug ("%s %s user proxy is %p", G_STRLOC, G_STRFUNC, (void*)data->active_user); - } - - finish_callback (data); -} - -static void -on_user_path_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata) -{ - char * path = NULL; - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - accounts_call_find_user_by_id_finish (data->account_manager, &path, res, &data->error); - - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - else if (path != NULL) - { - g_debug ("%s %s user path is %s", G_STRLOC, G_STRFUNC, path); - ++data->pending; - accounts_user_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, - "org.freedesktop.Accounts", - path, - data->cancellable, - on_user_proxy_ready, - data); + *((gpointer*)G_STRUCT_MEMBER_P(data, member_offset)) = proxy; } - finish_callback (data); - g_free (path); -} - -static void -on_uid_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata) -{ - guint uid = 0; - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - console_kit_session_call_get_unix_user_finish (data->current_session, &uid, res, &data->error); - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - else if (uid) - { - g_debug ("%s %s uid is %u", G_STRLOC, G_STRFUNC, uid); - ++data->pending; - accounts_call_find_user_by_id (data->account_manager, - uid, - data->cancellable, - on_user_path_ready, - data); - } - - finish_callback (data); -} - -static void -on_seat_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata) -{ - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - data->current_seat = console_kit_seat_proxy_new_for_bus_finish (res, &data->error); - - if (data->error && !g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - - finish_callback (data); -} - -static void -on_sid_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata) -{ - char * sid = NULL; - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - console_kit_session_call_get_seat_id_finish (data->current_session, &sid, res, &data->error); - - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - else if (sid != NULL) - { - g_debug ("%s %s sid is %s", G_STRLOC, G_STRFUNC, sid); - ++data->pending; - console_kit_seat_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, - "org.freedesktop.ConsoleKit", - sid, - data->cancellable, - on_seat_proxy_ready, - data); - } - - finish_callback (data); - g_free (sid); -} - -static void -on_session_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata) -{ - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - data->current_session = console_kit_session_proxy_new_finish (res, &data->error); - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - else + if (!--data->pending) { - ++data->pending; - console_kit_session_call_get_seat_id (data->current_session, - data->cancellable, - on_sid_ready, - data); + data->callback (data->login1_manager, + data->login1_seat, + data->dm_seat, + data->account_manager, + data->cancellable, + data->user_data); - ++data->pending; - console_kit_session_call_get_unix_user (data->current_session, - data->cancellable, - on_uid_ready, - data); + g_clear_object (&data->login1_manager); + g_clear_object (&data->login1_seat); + g_clear_object (&data->dm_seat); + g_clear_object (&data->account_manager); + g_clear_object (&data->cancellable); + g_free (data); } - - finish_callback (data); } - + static void -on_current_session_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata) +on_display_manager_seat_proxy_ready (GObject * o G_GNUC_UNUSED, + GAsyncResult * res, + gpointer gdata) { - char * ssid = NULL; - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - ssid = NULL; - console_kit_manager_call_get_current_session_finish (data->ck_manager, - &ssid, res, - &data->error); - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - else if (ssid) - { - g_debug ("%s %s ssid is %s", G_STRLOC, G_STRFUNC, ssid); - data->pending++; - console_kit_session_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, - "org.freedesktop.ConsoleKit", - ssid, - data->cancellable, - on_session_proxy_ready, - data); - - } - - finish_callback (data); - g_free (ssid); + gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, dm_seat); + GError * err = NULL; + gpointer proxy = display_manager_seat_proxy_new_for_bus_finish (res, &err); + on_proxy_ready_impl (gdata, offset, err, proxy); } static void -on_display_manager_seat_proxy_ready (GObject * o G_GNUC_UNUSED, - GAsyncResult * res, - gpointer gdata) +on_login1_seat_ready (GObject * o G_GNUC_UNUSED, + GAsyncResult * res, + gpointer gdata) { - DisplayManagerSeat * seat; - struct session_proxy_data * data = gdata; - - seat = display_manager_seat_proxy_new_for_bus_finish (res, &data->error); - - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - else if (seat != NULL) - { - data->dm_seat = g_object_ref (seat); - } - - finish_callback (data); - g_clear_object (&seat); + gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, login1_seat); + GError * err = NULL; + gpointer proxy = login1_seat_proxy_new_for_bus_finish (res, &err); + on_proxy_ready_impl (gdata, offset, err, proxy); } static void -on_console_kit_manager_proxy_ready (GObject * o G_GNUC_UNUSED, - GAsyncResult * res, - gpointer gdata) +on_login1_manager_ready (GObject * o G_GNUC_UNUSED, + GAsyncResult * res, + gpointer gdata) { - ConsoleKitManager * mgr; - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - if (data->error == NULL) - { - mgr = console_kit_manager_proxy_new_for_bus_finish (res, &data->error); - g_debug ("%s %s mgr is %p, err is %p", G_STRLOC, G_STRFUNC, (void*)mgr, (void*)data->error); - - if (data->error != NULL) - { - if (!g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - else - { - data->ck_manager = mgr; - - data->pending++; - console_kit_manager_call_get_current_session (mgr, - data->cancellable, - on_current_session_ready, - data); - - } - } - - finish_callback (data); + gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, login1_manager); + GError * err = NULL; + gpointer proxy = login1_manager_proxy_new_for_bus_finish (res, &err); + on_proxy_ready_impl (gdata, offset, err, proxy); } static void -on_accounts_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata) +on_accounts_proxy_ready (GObject * o G_GNUC_UNUSED, + GAsyncResult * res, + gpointer gdata) { - struct session_proxy_data * data = gdata; - g_debug ("%s %s", G_STRLOC, G_STRFUNC); - - if (data->error == NULL) - { - data->account_manager = accounts_proxy_new_for_bus_finish (res, &data->error); - - if (data->error && !g_error_matches (data->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message); - } - - finish_callback (data); + gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, account_manager); + GError * err = NULL; + gpointer proxy = accounts_proxy_new_for_bus_finish (res, &err); + on_proxy_ready_impl (gdata, offset, err, proxy); } -/** - * Getting all the proxies we want is kind of a pain -- - * especially without blocking (ie, using _sync() funcs) -- - * so it's farmed out to this wrapper utility. - * - * 1. in this func, start getting the ConsoleKit and Accounts proxies - * 2. when the accounts proxy is ready, stash it in data.account_manager - * 3. when the ck manager proxy is ready, stash it in data.ck_manager and - * ask it for the current session's ssid - * 4. when the ssid is ready, start getting a proxy for it - * 5. when the session's proxy is ready, stash it in data.current_session - * and ask it for both the current seat's sid and the active user's uid - * 6. When the current seat's sid is ready, start getting a proxy for it - * 7. When the current seat's proxy is ready, stash it in data.current_seat - * 8. when the active user's uid is ready, ask data.account_manager for the path - * 9. when the user path is ready, start getting an Accounts.User proxy for it - * 10. when the Accounts.User proxy is read, stash it in data.active_user - * - * When everything is done, or if there's an error, invoke the data.callback - */ +/* helper utility to get the dbus proxies used by the backend-dbus classes */ void indicator_session_util_get_session_proxies ( indicator_session_util_session_proxies_func func, @@ -372,6 +126,7 @@ indicator_session_util_get_session_proxies ( gpointer user_data) { struct session_proxy_data * data; + char * seat_path; data = g_new0 (struct session_proxy_data, 1); data->callback = func; @@ -379,6 +134,23 @@ indicator_session_util_get_session_proxies ( data->cancellable = g_object_ref (cancellable); data->pending++; + login1_manager_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, + "org.freedesktop.login1", + "/org/freedesktop/login1", + data->cancellable, + on_login1_manager_ready, data); + + data->pending++; + seat_path = g_strconcat ("/org/freedesktop/login1/seat/", g_getenv("XDG_SEAT"), NULL); + login1_seat_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, + "org.freedesktop.login1", + seat_path, + data->cancellable, + on_login1_seat_ready, + data); + data->pending++; accounts_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, "org.freedesktop.Accounts", @@ -387,15 +159,6 @@ indicator_session_util_get_session_proxies ( on_accounts_proxy_ready, data); data->pending++; - console_kit_manager_proxy_new_for_bus ( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, - "org.freedesktop.ConsoleKit", - "/org/freedesktop/ConsoleKit/Manager", - data->cancellable, - on_console_kit_manager_proxy_ready, data); - - data->pending++; display_manager_seat_proxy_new_for_bus ( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, @@ -404,4 +167,5 @@ indicator_session_util_get_session_proxies ( data->cancellable, on_display_manager_seat_proxy_ready, data); + g_free (seat_path); } diff --git a/src/backend-dbus/utils.h b/src/backend-dbus/utils.h index b4f26c3..802dd5e 100644 --- a/src/backend-dbus/utils.h +++ b/src/backend-dbus/utils.h @@ -25,19 +25,15 @@ #include "dbus-accounts.h" #include "dbus-display-manager.h" -#include "dbus-user.h" -#include "dbus-consolekit-seat.h" -#include "dbus-consolekit-session.h" -#include "dbus-consolekit-manager.h" +#include "dbus-login1-manager.h" +#include "dbus-login1-seat.h" typedef void (*indicator_session_util_session_proxies_func)( - ConsoleKitManager * ck_manager, + Login1Manager * login1_manager, + Login1Seat * login1_seat, + DisplayManagerSeat * display_manager_seat, Accounts * account_manager, - DisplayManagerSeat * dm_seat, - ConsoleKitSeat * current_ck_seat, - ConsoleKitSession * current_ck_session, - AccountsUser * active_user, - const GError * error, + GCancellable * cancellable, gpointer user_data); /** |