2
* Copyright 2013 Canonical Ltd.
5
* Charles Kerr <charles.kerr@canonical.com>
7
* This program is free software: you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 3, as published
9
* by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranties of
13
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
* PURPOSE. See the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
23
**** indicator_session_util_get_session_proxies()
26
struct session_proxy_data
28
ConsoleKitManager * ck_manager;
29
Accounts * account_manager;
30
DisplayManagerSeat * dm_seat;
32
ConsoleKitSeat * current_seat;
33
ConsoleKitSession * current_session;
34
AccountsUser * active_user;
36
GCancellable * cancellable;
40
indicator_session_util_session_proxies_func callback;
45
session_proxy_data_free (struct session_proxy_data * data)
47
g_clear_object (&data->ck_manager);
48
g_clear_object (&data->account_manager);
49
g_clear_object (&data->dm_seat);
51
g_clear_object (&data->current_seat);
52
g_clear_object (&data->current_session);
53
g_clear_object (&data->active_user);
55
g_clear_object (&data->cancellable);
56
g_clear_error (&data->error);
62
finish_callback (struct session_proxy_data * data)
64
g_assert (data != NULL);
65
g_debug ("%s %s: pending is %d", G_STRLOC, G_STRFUNC, (data->pending-1));
69
data->callback (data->ck_manager,
70
data->account_manager,
73
data->current_session,
78
session_proxy_data_free (data);
83
on_user_proxy_ready (GObject * o G_GNUC_UNUSED,
87
struct session_proxy_data * data = gdata;
88
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
90
data->active_user = accounts_user_proxy_new_for_bus_finish (res, &data->error);
92
if (data->error != NULL)
94
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
98
g_debug ("%s %s user proxy is %p", G_STRLOC, G_STRFUNC, (void*)data->active_user);
101
finish_callback (data);
105
on_user_path_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata)
108
struct session_proxy_data * data = gdata;
109
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
111
accounts_call_find_user_by_id_finish (data->account_manager, &path, res, &data->error);
113
if (data->error != NULL)
115
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
117
else if (path != NULL)
119
g_debug ("%s %s user path is %s", G_STRLOC, G_STRFUNC, path);
121
accounts_user_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
122
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
123
"org.freedesktop.Accounts",
130
finish_callback (data);
135
on_uid_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata)
138
struct session_proxy_data * data = gdata;
139
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
141
console_kit_session_call_get_unix_user_finish (data->current_session, &uid, res, &data->error);
142
if (data->error != NULL)
144
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
148
g_debug ("%s %s uid is %u", G_STRLOC, G_STRFUNC, uid);
150
accounts_call_find_user_by_id (data->account_manager,
157
finish_callback (data);
161
on_seat_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata)
163
struct session_proxy_data * data = gdata;
164
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
166
data->current_seat = console_kit_seat_proxy_new_for_bus_finish (res, &data->error);
168
if (data->error != NULL)
169
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
171
finish_callback (data);
175
on_sid_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata)
178
struct session_proxy_data * data = gdata;
179
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
181
console_kit_session_call_get_seat_id_finish (data->current_session, &sid, res, &data->error);
183
if (data->error != NULL)
185
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
187
else if (sid != NULL)
189
g_debug ("%s %s sid is %s", G_STRLOC, G_STRFUNC, sid);
191
console_kit_seat_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
192
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
193
"org.freedesktop.ConsoleKit",
200
finish_callback (data);
205
on_session_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata)
207
struct session_proxy_data * data = gdata;
208
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
210
data->current_session = console_kit_session_proxy_new_finish (res, &data->error);
211
if (data->error != NULL)
213
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
218
console_kit_session_call_get_seat_id (data->current_session,
224
console_kit_session_call_get_unix_user (data->current_session,
230
finish_callback (data);
234
on_current_session_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata)
237
struct session_proxy_data * data = gdata;
238
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
241
console_kit_manager_call_get_current_session_finish (data->ck_manager,
244
if (data->error != NULL)
246
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
250
g_debug ("%s %s ssid is %s", G_STRLOC, G_STRFUNC, ssid);
252
console_kit_session_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
253
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
254
"org.freedesktop.ConsoleKit",
257
on_session_proxy_ready,
262
finish_callback (data);
267
on_display_manager_seat_proxy_ready (GObject * o G_GNUC_UNUSED,
271
DisplayManagerSeat * seat;
272
struct session_proxy_data * data = gdata;
274
seat = display_manager_seat_proxy_new_for_bus_finish (res, &data->error);
276
if (data->error != NULL)
278
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
280
else if (seat != NULL)
282
data->dm_seat = g_object_ref (seat);
285
finish_callback (data);
286
g_clear_object (&seat);
290
on_console_kit_manager_proxy_ready (GObject * o G_GNUC_UNUSED,
294
ConsoleKitManager * mgr;
295
struct session_proxy_data * data = gdata;
296
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
298
if (data->error == NULL)
300
mgr = console_kit_manager_proxy_new_for_bus_finish (res, &data->error);
301
g_debug ("%s %s mgr is %p, err is %p", G_STRLOC, G_STRFUNC, (void*)mgr, (void*)data->error);
303
if (data->error != NULL)
305
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
309
data->ck_manager = mgr;
312
console_kit_manager_call_get_current_session (mgr,
314
on_current_session_ready,
320
finish_callback (data);
324
on_accounts_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gdata)
326
struct session_proxy_data * data = gdata;
327
g_debug ("%s %s", G_STRLOC, G_STRFUNC);
329
if (data->error == NULL)
331
data->account_manager = accounts_proxy_new_for_bus_finish (res, &data->error);
333
if (data->error != NULL)
334
g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, data->error->message);
337
finish_callback (data);
341
* Getting all the proxies we want is kind of a pain --
342
* especially without blocking (ie, using _sync() funcs) --
343
* so it's farmed out to this wrapper utility.
345
* 1. in this func, start getting the ConsoleKit and Accounts proxies
346
* 2. when the accounts proxy is ready, stash it in data.account_manager
347
* 3. when the ck manager proxy is ready, stash it in data.ck_manager and
348
* ask it for the current session's ssid
349
* 4. when the ssid is ready, start getting a proxy for it
350
* 5. when the session's proxy is ready, stash it in data.current_session
351
* and ask it for both the current seat's sid and the active user's uid
352
* 6. When the current seat's sid is ready, start getting a proxy for it
353
* 7. When the current seat's proxy is ready, stash it in data.current_seat
354
* 8. when the active user's uid is ready, ask data.account_manager for the path
355
* 9. when the user path is ready, start getting an Accounts.User proxy for it
356
* 10. when the Accounts.User proxy is read, stash it in data.active_user
358
* When everything is done, or if there's an error, invoke the data.callback
361
indicator_session_util_get_session_proxies (
362
indicator_session_util_session_proxies_func func,
363
GCancellable * cancellable,
366
struct session_proxy_data * data;
368
data = g_new0 (struct session_proxy_data, 1);
369
data->callback = func;
370
data->user_data = user_data;
371
data->cancellable = g_object_ref (cancellable);
374
accounts_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
375
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
376
"org.freedesktop.Accounts",
377
"/org/freedesktop/Accounts",
379
on_accounts_proxy_ready, data);
382
console_kit_manager_proxy_new_for_bus (
384
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
385
"org.freedesktop.ConsoleKit",
386
"/org/freedesktop/ConsoleKit/Manager",
388
on_console_kit_manager_proxy_ready, data);
391
display_manager_seat_proxy_new_for_bus (
393
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
394
"org.freedesktop.DisplayManager",
395
g_getenv ("XDG_SEAT_PATH"),
397
on_display_manager_seat_proxy_ready, data);