~ubuntu-branches/ubuntu/trusty/indicator-session/trusty-updates

« back to all changes in this revision

Viewing changes to src/backend-dbus/utils.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Charles Kerr, Lars Uebernickel, Łukasz 'sil2100' Zemczak, Ubuntu daily release
  • Date: 2013-07-16 02:02:05 UTC
  • mfrom: (1.1.64)
  • Revision ID: package-import@ubuntu.com-20130716020205-84ig434y92hxi2g8
Tags: 12.10.5+13.10.20130716-0ubuntu1
[ Charles Kerr ]
* This is the GMenu, login1 version of indicator-session. This
  resubmission removes the prerequisite branch because the entire diff
  is contained in this ng-login1 branch.

[ Lars Uebernickel ]
* This is the GMenu, login1 version of indicator-session. This
  resubmission removes the prerequisite branch because the entire diff
  is contained in this ng-login1 branch.

[ Łukasz 'sil2100' Zemczak ]
* Add the python build-dep, as gdbus-codegen needs it to work
  properly.

[ Ubuntu daily release ]
* Automatic snapshot from revision 400

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *   Charles Kerr <charles.kerr@canonical.com>
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include "utils.h"
 
21
 
 
22
/***
 
23
**** indicator_session_util_get_session_proxies()
 
24
***/
 
25
 
 
26
struct session_proxy_data
 
27
{
 
28
  Login1Manager * login1_manager;
 
29
  Login1Seat * login1_seat;
 
30
  DisplayManagerSeat * dm_seat;
 
31
  Accounts * account_manager;
 
32
 
 
33
  GCancellable * cancellable;
 
34
  int pending;
 
35
 
 
36
  indicator_session_util_session_proxies_func callback;
 
37
  gpointer user_data;
 
38
};
 
39
 
 
40
 
 
41
static void
 
42
on_proxy_ready_impl (struct session_proxy_data * data,
 
43
                     gsize                       member_offset,
 
44
                     GError                    * err,
 
45
                     gpointer                    proxy)
 
46
{
 
47
  if (err != NULL)
 
48
    {
 
49
      if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
 
50
        g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, err->message);
 
51
 
 
52
      g_error_free (err);
 
53
    }
 
54
  else
 
55
    {
 
56
      *((gpointer*)G_STRUCT_MEMBER_P(data, member_offset)) = proxy;
 
57
    }
 
58
 
 
59
  if (!--data->pending)
 
60
    {
 
61
      data->callback (data->login1_manager,
 
62
                      data->login1_seat,
 
63
                      data->dm_seat,
 
64
                      data->account_manager,
 
65
                      data->cancellable,
 
66
                      data->user_data);
 
67
 
 
68
      g_clear_object (&data->login1_manager);
 
69
      g_clear_object (&data->login1_seat);
 
70
      g_clear_object (&data->dm_seat);
 
71
      g_clear_object (&data->account_manager);
 
72
      g_clear_object (&data->cancellable);
 
73
      g_free (data);
 
74
    }
 
75
}
 
76
    
 
77
static void
 
78
on_display_manager_seat_proxy_ready (GObject      * o G_GNUC_UNUSED,
 
79
                                     GAsyncResult * res,
 
80
                                     gpointer       gdata)
 
81
{
 
82
  gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, dm_seat);
 
83
  GError * err = NULL;
 
84
  gpointer proxy = display_manager_seat_proxy_new_for_bus_finish (res, &err);
 
85
  on_proxy_ready_impl (gdata, offset, err, proxy);
 
86
}
 
87
 
 
88
static void
 
89
on_login1_seat_ready (GObject      * o G_GNUC_UNUSED,
 
90
                      GAsyncResult * res,
 
91
                      gpointer       gdata)
 
92
{
 
93
  gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, login1_seat);
 
94
  GError * err = NULL;
 
95
  gpointer proxy = login1_seat_proxy_new_for_bus_finish (res,  &err);
 
96
  on_proxy_ready_impl (gdata, offset, err, proxy);
 
97
}
 
98
 
 
99
static void
 
100
on_login1_manager_ready (GObject      * o G_GNUC_UNUSED,
 
101
                         GAsyncResult * res,
 
102
                         gpointer       gdata)
 
103
{
 
104
  gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, login1_manager);
 
105
  GError * err = NULL;
 
106
  gpointer proxy = login1_manager_proxy_new_for_bus_finish (res, &err);
 
107
  on_proxy_ready_impl (gdata, offset, err, proxy);
 
108
}
 
109
 
 
110
static void
 
111
on_accounts_proxy_ready (GObject      * o G_GNUC_UNUSED,
 
112
                         GAsyncResult * res,
 
113
                         gpointer       gdata)
 
114
{
 
115
  gsize offset = G_STRUCT_OFFSET (struct session_proxy_data, account_manager);
 
116
  GError * err = NULL;
 
117
  gpointer proxy = accounts_proxy_new_for_bus_finish (res, &err);
 
118
  on_proxy_ready_impl (gdata, offset, err, proxy);
 
119
}
 
120
 
 
121
/* helper utility to get the dbus proxies used by the backend-dbus classes */
 
122
void
 
123
indicator_session_util_get_session_proxies (
 
124
                     indicator_session_util_session_proxies_func   func,
 
125
                     GCancellable                                * cancellable,
 
126
                     gpointer                                      user_data)
 
127
{
 
128
  struct session_proxy_data * data;
 
129
  const char * str;
 
130
 
 
131
  data = g_new0 (struct session_proxy_data, 1);
 
132
  data->callback = func;
 
133
  data->user_data = user_data;
 
134
  data->cancellable = g_object_ref (cancellable);
 
135
 
 
136
  /* login1 */
 
137
  data->pending++;
 
138
  login1_manager_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 
139
                                    G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
 
140
                                    "org.freedesktop.login1",
 
141
                                    "/org/freedesktop/login1",
 
142
                                    data->cancellable,
 
143
                                    on_login1_manager_ready, data);
 
144
 
 
145
  /* login1 seat */
 
146
  if ((str = g_getenv ("XDG_SEAT")))
 
147
    {
 
148
      char * path;
 
149
      data->pending++;
 
150
      path = g_strconcat ("/org/freedesktop/login1/seat/", str, NULL);
 
151
      login1_seat_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 
152
                                 G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
 
153
                                 "org.freedesktop.login1",
 
154
                                 path,
 
155
                                 data->cancellable,
 
156
                                 on_login1_seat_ready,
 
157
                                 data);
 
158
      g_free (path);
 
159
    }
 
160
 
 
161
  /* Accounts */
 
162
  data->pending++;
 
163
  accounts_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
 
164
                              G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
 
165
                              "org.freedesktop.Accounts",
 
166
                              "/org/freedesktop/Accounts",
 
167
                              data->cancellable,
 
168
                              on_accounts_proxy_ready, data);
 
169
 
 
170
  /* DisplayManager seat */
 
171
  if ((str = g_getenv ("XDG_SEAT_PATH")))
 
172
    {
 
173
      data->pending++;
 
174
      display_manager_seat_proxy_new_for_bus (
 
175
                               G_BUS_TYPE_SYSTEM,
 
176
                               G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
 
177
                               "org.freedesktop.DisplayManager",
 
178
                               str,
 
179
                               data->cancellable,
 
180
                               on_display_manager_seat_proxy_ready, data);
 
181
    }
 
182
}