mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-21 09:27:51 +02:00
Bug 621213 – GDBusProxy and well-known names
Allow constructing a GDBusProxy for well-known names as discussed here http://mail.gnome.org/archives/gtk-devel-list/2009-October/msg00075.html including test cases. Make it possible to create a GDBusProxy for a GBusType instead of a GDBusConnection. This requires G_BUS_TYPE_NONE so add that too. Nuke g_bus_watch_proxy() since one can now more or less use GDBusProxy for this. Port gdbus-example-watch-proxy to this new API and include this example in the GDBusProxy doc page. Also nuke the GType parameter from the GDBusProxy constructors as requested here: https://bugzilla.gnome.org/show_bug.cgi?id=621229 Also update the porting guide and other API docs for this change. Also fix a bug in the signal dispatching code so each subscriber only get notified once, not N times, for the same signal. Also add a test case for this. https://bugzilla.gnome.org/show_bug.cgi?id=621213 Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
@@ -349,93 +349,10 @@ accounts_user_frobnicate_finish (AccountsUser *user,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
/* Example usage of the AccountsUser type */
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
print_user (AccountsUser *user)
|
||||
{
|
||||
g_print (" user-name = `%s'\n", accounts_user_get_user_name (user));
|
||||
g_print (" real-name = `%s'\n", accounts_user_get_real_name (user));
|
||||
g_print (" automatic-login = %s\n", accounts_user_get_automatic_login (user) ? "true" : "false");
|
||||
}
|
||||
|
||||
static void
|
||||
on_changed (AccountsUser *user,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_print ("+++ Received the AccountsUser::changed signal\n");
|
||||
print_user (user);
|
||||
}
|
||||
|
||||
static void
|
||||
on_notify (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
AccountsUser *user = ACCOUNTS_USER (object);
|
||||
g_print ("+++ Received the GObject::notify signal for property `%s'\n",
|
||||
pspec->name);
|
||||
print_user (user);
|
||||
}
|
||||
|
||||
static void
|
||||
on_proxy_appeared (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
const gchar *name_owner,
|
||||
GDBusProxy *proxy,
|
||||
gpointer user_data)
|
||||
{
|
||||
AccountsUser *user = ACCOUNTS_USER (proxy);
|
||||
|
||||
g_print ("+++ Acquired proxy for user\n");
|
||||
print_user (user);
|
||||
|
||||
g_signal_connect (proxy,
|
||||
"notify",
|
||||
G_CALLBACK (on_notify),
|
||||
NULL);
|
||||
g_signal_connect (user,
|
||||
"changed",
|
||||
G_CALLBACK (on_changed),
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
on_proxy_vanished (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_print ("--- Cannot create proxy for user: no remote object\n");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
|
||||
gint
|
||||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
guint watcher_id;
|
||||
GMainLoop *loop;
|
||||
|
||||
g_type_init ();
|
||||
|
||||
watcher_id = g_bus_watch_proxy (G_BUS_TYPE_SYSTEM,
|
||||
"org.freedesktop.Accounts",
|
||||
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||
"/org/freedesktop/Accounts/User500",
|
||||
"org.freedesktop.Accounts.User",
|
||||
ACCOUNTS_TYPE_USER,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
on_proxy_appeared,
|
||||
on_proxy_vanished,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (loop);
|
||||
g_main_loop_unref (loop);
|
||||
g_bus_unwatch_proxy (watcher_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user