4 /* ---------------------------------------------------------------------------------------------------- */
5 /* The D-Bus interface definition we want to create a GDBusProxy-derived type for: */
6 /* ---------------------------------------------------------------------------------------------------- */
8 static const gchar introspection_xml
[] =
10 " <interface name='org.freedesktop.Accounts.User'>"
11 " <method name='Frobnicate'>"
12 " <arg name='flux' type='s' direction='in'/>"
13 " <arg name='baz' type='s' direction='in'/>"
14 " <arg name='result' type='s' direction='out'/>"
16 " <signal name='Changed'/>"
17 " <property name='AutomaticLogin' type='b' access='readwrite'/>"
18 " <property name='RealName' type='s' access='read'/>"
19 " <property name='UserName' type='s' access='read'/>"
23 /* ---------------------------------------------------------------------------------------------------- */
24 /* Definition of the AccountsUser type */
25 /* ---------------------------------------------------------------------------------------------------- */
27 #define ACCOUNTS_TYPE_USER (accounts_user_get_type ())
28 #define ACCOUNTS_USER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ACCOUNTS_TYPE_USER, AccountsUser))
29 #define ACCOUNTS_USER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), ACCOUNTS_TYPE_USER, AccountsUserClass))
30 #define ACCOUNTS_USER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ACCOUNTS_TYPE_USER, AccountsUserClass))
31 #define ACCOUNTS_IS_USER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ACCOUNTS_TYPE_USER))
32 #define ACCOUNTS_IS_USER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ACCOUNTS_TYPE_USER))
34 typedef struct _AccountsUser AccountsUser
;
35 typedef struct _AccountsUserClass AccountsUserClass
;
36 typedef struct _AccountsUserPrivate AccountsUserPrivate
;
41 GDBusProxy parent_instance
;
42 AccountsUserPrivate
*priv
;
45 struct _AccountsUserClass
48 GDBusProxyClass parent_class
;
49 void (*changed
) (AccountsUser
*user
);
52 GType
accounts_user_get_type (void) G_GNUC_CONST
;
54 const gchar
*accounts_user_get_user_name (AccountsUser
*user
);
55 const gchar
*accounts_user_get_real_name (AccountsUser
*user
);
56 gboolean
accounts_user_get_automatic_login (AccountsUser
*user
);
58 void accounts_user_frobnicate (AccountsUser
*user
,
61 GCancellable
*cancellable
,
62 GAsyncReadyCallback callback
,
64 gchar
*accounts_user_frobnicate_finish (AccountsUser
*user
,
67 gchar
*accounts_user_frobnicate_sync (AccountsUser
*user
,
70 GCancellable
*cancellable
,
73 /* ---------------------------------------------------------------------------------------------------- */
74 /* Implementation of the AccountsUser type */
75 /* ---------------------------------------------------------------------------------------------------- */
77 /* A more efficient approach than parsing XML is to use const static
78 * GDBusInterfaceInfo, GDBusMethodInfo, ... structures
80 static GDBusInterfaceInfo
*
81 accounts_user_get_interface_info (void)
83 static gsize has_info
= 0;
84 static GDBusInterfaceInfo
*info
= NULL
;
85 if (g_once_init_enter (&has_info
))
87 GDBusNodeInfo
*introspection_data
;
88 introspection_data
= g_dbus_node_info_new_for_xml (introspection_xml
, NULL
);
89 info
= introspection_data
->interfaces
[0];
90 g_once_init_leave (&has_info
, 1);
100 PROP_AUTOMATIC_LOGIN
,
109 static guint signals
[LAST_SIGNAL
] = {0};
111 G_DEFINE_TYPE (AccountsUser
, accounts_user
, G_TYPE_DBUS_PROXY
);
114 accounts_user_finalize (GObject
*object
)
116 G_GNUC_UNUSED AccountsUser
*user
= ACCOUNTS_USER (object
);
118 if (G_OBJECT_CLASS (accounts_user_parent_class
)->finalize
!= NULL
)
119 G_OBJECT_CLASS (accounts_user_parent_class
)->finalize (object
);
123 accounts_user_init (AccountsUser
*user
)
125 /* Sets the expected interface */
126 g_dbus_proxy_set_interface_info (G_DBUS_PROXY (user
), accounts_user_get_interface_info ());
130 accounts_user_get_property (GObject
*object
,
135 AccountsUser
*user
= ACCOUNTS_USER (object
);
140 g_value_set_string (value
, accounts_user_get_user_name (user
));
144 g_value_set_string (value
, accounts_user_get_real_name (user
));
147 case PROP_AUTOMATIC_LOGIN
:
148 g_value_set_boolean (value
, accounts_user_get_automatic_login (user
));
152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
158 accounts_user_get_user_name (AccountsUser
*user
)
162 g_return_val_if_fail (ACCOUNTS_IS_USER (user
), NULL
);
163 value
= g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user
), "UserName");
164 ret
= g_variant_get_string (value
, NULL
);
165 g_variant_unref (value
);
170 accounts_user_get_real_name (AccountsUser
*user
)
174 g_return_val_if_fail (ACCOUNTS_IS_USER (user
), NULL
);
175 value
= g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user
), "RealName");
176 ret
= g_variant_get_string (value
, NULL
);
177 g_variant_unref (value
);
182 accounts_user_get_automatic_login (AccountsUser
*user
)
186 g_return_val_if_fail (ACCOUNTS_IS_USER (user
), FALSE
);
187 value
= g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user
), "AutomaticLogin");
188 ret
= g_variant_get_boolean (value
);
189 g_variant_unref (value
);
194 accounts_user_g_signal (GDBusProxy
*proxy
,
195 const gchar
*sender_name
,
196 const gchar
*signal_name
,
197 GVariant
*parameters
)
199 AccountsUser
*user
= ACCOUNTS_USER (proxy
);
200 if (g_strcmp0 (signal_name
, "Changed") == 0)
201 g_signal_emit (user
, signals
[CHANGED_SIGNAL
], 0);
205 accounts_user_g_properties_changed (GDBusProxy
*proxy
,
206 GVariant
*changed_properties
,
207 const gchar
* const *invalidated_properties
)
209 AccountsUser
*user
= ACCOUNTS_USER (proxy
);
213 if (changed_properties
!= NULL
)
215 g_variant_get (changed_properties
, "a{sv}", &iter
);
216 while (g_variant_iter_next (iter
, "{&sv}", &key
, NULL
))
218 if (g_strcmp0 (key
, "AutomaticLogin") == 0)
219 g_object_notify (G_OBJECT (user
), "automatic-login");
220 else if (g_strcmp0 (key
, "RealName") == 0)
221 g_object_notify (G_OBJECT (user
), "real-name");
222 else if (g_strcmp0 (key
, "UserName") == 0)
223 g_object_notify (G_OBJECT (user
), "user-name");
225 g_variant_iter_free (iter
);
230 accounts_user_class_init (AccountsUserClass
*klass
)
232 GObjectClass
*gobject_class
;
233 GDBusProxyClass
*proxy_class
;
235 gobject_class
= G_OBJECT_CLASS (klass
);
236 gobject_class
->get_property
= accounts_user_get_property
;
237 gobject_class
->finalize
= accounts_user_finalize
;
239 proxy_class
= G_DBUS_PROXY_CLASS (klass
);
240 proxy_class
->g_signal
= accounts_user_g_signal
;
241 proxy_class
->g_properties_changed
= accounts_user_g_properties_changed
;
243 g_object_class_install_property (gobject_class
,
245 g_param_spec_string ("user-name",
247 "The user name of the user",
250 G_PARAM_STATIC_STRINGS
));
252 g_object_class_install_property (gobject_class
,
254 g_param_spec_string ("real-name",
256 "The real name of the user",
259 G_PARAM_STATIC_STRINGS
));
261 g_object_class_install_property (gobject_class
,
262 PROP_AUTOMATIC_LOGIN
,
263 g_param_spec_boolean ("automatic-login",
265 "Whether the user is automatically logged in",
268 G_PARAM_STATIC_STRINGS
));
270 signals
[CHANGED_SIGNAL
] = g_signal_new ("changed",
273 G_STRUCT_OFFSET (AccountsUserClass
, changed
),
276 g_cclosure_marshal_VOID__VOID
,
282 accounts_user_frobnicate_sync (AccountsUser
*user
,
285 GCancellable
*cancellable
,
291 g_return_val_if_fail (ACCOUNTS_IS_USER (user
), NULL
);
295 value
= g_dbus_proxy_call_sync (G_DBUS_PROXY (user
),
297 g_variant_new ("(si)",
300 G_DBUS_CALL_FLAGS_NONE
,
306 g_variant_get (value
, "(s)", &ret
);
307 g_variant_unref (value
);
313 accounts_user_frobnicate (AccountsUser
*user
,
316 GCancellable
*cancellable
,
317 GAsyncReadyCallback callback
,
320 g_return_if_fail (ACCOUNTS_IS_USER (user
));
321 g_dbus_proxy_call (G_DBUS_PROXY (user
),
323 g_variant_new ("(si)",
326 G_DBUS_CALL_FLAGS_NONE
,
335 accounts_user_frobnicate_finish (AccountsUser
*user
,
343 value
= g_dbus_proxy_call_finish (G_DBUS_PROXY (user
), res
, error
);
346 g_variant_get (value
, "(s)", &ret
);
347 g_variant_unref (value
);
352 /* ---------------------------------------------------------------------------------------------------- */
355 main (gint argc
, gchar
*argv
[])