1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-07-28 04:43:28 +02:00
Files
build
debian
docs
gio
fam
fen
gvdb
inotify
libasyncns
tests
schema-tests
.gitignore
Makefile.am
appinfo-test.c
appinfo-test.desktop
appinfo.c
application.c
async-close-output-stream.c
buffered-input-stream.c
contexts.c
converter-stream.c
data-input-stream.c
data-output-stream.c
de.po
desktop-app-info.c
echo-server.c
filter-cat.c
filter-streams.c
g-file-info.c
g-file.c
g-icon.c
gdbus-addresses.c
gdbus-connection.c
gdbus-error.c
gdbus-example-export.c
gdbus-example-own-name.c
gdbus-example-peer.c
gdbus-example-proxy-subclass.c
gdbus-example-server.c
gdbus-example-subtree.c
gdbus-example-unix-fd-client.c
gdbus-example-watch-name.c
gdbus-example-watch-proxy.c
gdbus-exit-on-close.c
gdbus-export.c
gdbus-introspection.c
gdbus-names.c
gdbus-peer.c
gdbus-proxy-well-known-name.c
gdbus-proxy.c
gdbus-serialization.c
gdbus-sessionbus.c
gdbus-sessionbus.h
gdbus-tests.c
gdbus-tests.h
gdbus-testserver.py
gdbus-threading.c
gschema-compile.c
gsettings.c
httpd.c
live-g-file.c
live-g-file.txt
memory-input-stream.c
memory-output-stream.c
org.gtk.test.gschema
org.gtk.test.gschema.xml
readwrite.c
resolver.c
send-data.c
simple-async-result.c
sleepy-stream.c
socket-client.c
socket-common.c
socket-server.c
srvtarget.c
testapp.c
testapps.c
unix-fd.c
unix-streams.c
win32-streams.c
win32
xdgmime
.gitignore
ChangeLog
Makefile.am
abicheck.sh
gappinfo.c
gappinfo.h
gapplication.c
gapplication.h
gasynchelper.c
gasynchelper.h
gasyncinitable.c
gasyncinitable.h
gasyncresult.c
gasyncresult.h
gbufferedinputstream.c
gbufferedinputstream.h
gbufferedoutputstream.c
gbufferedoutputstream.h
gcancellable.c
gcancellable.h
gcharsetconverter.c
gcharsetconverter.h
gcontenttype.c
gcontenttype.h
gcontenttypeprivate.h
gconverter.c
gconverter.h
gconverterinputstream.c
gconverterinputstream.h
gconverteroutputstream.c
gconverteroutputstream.h
gcredentials.c
gcredentials.h
gdatainputstream.c
gdatainputstream.h
gdataoutputstream.c
gdataoutputstream.h
gdbus-bash-completion.sh
gdbus-tool.c
gdbusaddress.c
gdbusaddress.h
gdbusapplication.c
gdbusauth.c
gdbusauth.h
gdbusauthmechanism.c
gdbusauthmechanism.h
gdbusauthmechanismanon.c
gdbusauthmechanismanon.h
gdbusauthmechanismexternal.c
gdbusauthmechanismexternal.h
gdbusauthmechanismsha1.c
gdbusauthmechanismsha1.h
gdbusauthobserver.c
gdbusauthobserver.h
gdbusconnection.c
gdbusconnection.h
gdbuserror.c
gdbuserror.h
gdbusintrospection.c
gdbusintrospection.h
gdbusmessage.c
gdbusmessage.h
gdbusmethodinvocation.c
gdbusmethodinvocation.h
gdbusnameowning.c
gdbusnameowning.h
gdbusnamewatching.c
gdbusnamewatching.h
gdbusprivate.c
gdbusprivate.h
gdbusproxy.c
gdbusproxy.h
gdbusserver.c
gdbusserver.h
gdbusutils.c
gdbusutils.h
gdelayedsettingsbackend.c
gdelayedsettingsbackend.h
gdesktopappinfo.c
gdesktopappinfo.h
gdrive.c
gdrive.h
gdummyfile.c
gdummyfile.h
gemblem.c
gemblem.h
gemblemedicon.c
gemblemedicon.h
gfile.c
gfile.h
gfileattribute-priv.h
gfileattribute.c
gfileattribute.h
gfiledescriptorbased.c
gfiledescriptorbased.h
gfileenumerator.c
gfileenumerator.h
gfileicon.c
gfileicon.h
gfileinfo-priv.h
gfileinfo.c
gfileinfo.h
gfileinputstream.c
gfileinputstream.h
gfileiostream.c
gfileiostream.h
gfilemonitor.c
gfilemonitor.h
gfilenamecompleter.c
gfilenamecompleter.h
gfileoutputstream.c
gfileoutputstream.h
gfilterinputstream.c
gfilterinputstream.h
gfilteroutputstream.c
gfilteroutputstream.h
gicon.c
gicon.h
ginetaddress.c
ginetaddress.h
ginetsocketaddress.c
ginetsocketaddress.h
ginitable.c
ginitable.h
ginputstream.c
ginputstream.h
gio-marshal.list
gio-querymodules.c
gio.h
gio.rc.in
gio.symbols
gioenums.h
gioenumtypes.c.template
gioenumtypes.h.template
gioerror.c
gioerror.h
giomodule-priv.h
giomodule.c
giomodule.h
gioscheduler.c
gioscheduler.h
giostream.c
giostream.h
giotypes.h
gkeyfilesettingsbackend.c
gkeyfilesettingsbackend.h
gloadableicon.c
gloadableicon.h
glocaldirectorymonitor.c
glocaldirectorymonitor.h
glocalfile.c
glocalfile.h
glocalfileenumerator.c
glocalfileenumerator.h
glocalfileinfo.c
glocalfileinfo.h
glocalfileinputstream.c
glocalfileinputstream.h
glocalfileiostream.c
glocalfileiostream.h
glocalfilemonitor.c
glocalfilemonitor.h
glocalfileoutputstream.c
glocalfileoutputstream.h
glocalvfs.c
glocalvfs.h
gmemoryinputstream.c
gmemoryinputstream.h
gmemoryoutputstream.c
gmemoryoutputstream.h
gmemorysettingsbackend.c
gmemorysettingsbackend.h
gmount.c
gmount.h
gmountoperation.c
gmountoperation.h
gmountprivate.h
gnativevolumemonitor.c
gnativevolumemonitor.h
gnetworkaddress.c
gnetworkaddress.h
gnetworkingprivate.h
gnetworkservice.c
gnetworkservice.h
gnullapplication.c
gnullsettingsbackend.c
gnullsettingsbackend.h
goutputstream.c
goutputstream.h
gpermission.c
gpermission.h
gpollfilemonitor.c
gpollfilemonitor.h
gresolver.c
gresolver.h
gschema-compile.c
gschema.dtd
gseekable.c
gseekable.h
gsettings-mapping.c
gsettings-mapping.h
gsettings-schema-convert
gsettings-tool.c
gsettings.c
gsettings.h
gsettingsbackend.c
gsettingsbackend.h
gsettingsbackendinternal.h
gsettingsschema.c
gsettingsschema.h
gsimpleasyncresult.c
gsimpleasyncresult.h
gsimplepermission.c
gsimplepermission.h
gsocket.c
gsocket.h
gsocketaddress.c
gsocketaddress.h
gsocketaddressenumerator.c
gsocketaddressenumerator.h
gsocketclient.c
gsocketclient.h
gsocketconnectable.c
gsocketconnectable.h
gsocketconnection.c
gsocketconnection.h
gsocketcontrolmessage.c
gsocketcontrolmessage.h
gsocketinputstream.c
gsocketinputstream.h
gsocketlistener.c
gsocketlistener.h
gsocketoutputstream.c
gsocketoutputstream.h
gsocketservice.c
gsocketservice.h
gsrvtarget.c
gsrvtarget.h
gtcpconnection.c
gtcpconnection.h
gthemedicon.c
gthemedicon.h
gthreadedresolver.c
gthreadedresolver.h
gthreadedsocketservice.c
gthreadedsocketservice.h
gunionvolumemonitor.c
gunionvolumemonitor.h
gunixconnection.c
gunixconnection.h
gunixcredentialsmessage.c
gunixcredentialsmessage.h
gunixfdlist.c
gunixfdlist.h
gunixfdmessage.c
gunixfdmessage.h
gunixinputstream.c
gunixinputstream.h
gunixmount.c
gunixmount.h
gunixmounts.c
gunixmounts.h
gunixoutputstream.c
gunixoutputstream.h
gunixresolver.c
gunixresolver.h
gunixsocketaddress.c
gunixsocketaddress.h
gunixvolume.c
gunixvolume.h
gunixvolumemonitor.c
gunixvolumemonitor.h
gvfs.c
gvfs.h
gvolume.c
gvolume.h
gvolumemonitor.c
gvolumemonitor.h
gwin32appinfo.c
gwin32appinfo.h
gwin32inputstream.c
gwin32inputstream.h
gwin32mount.c
gwin32mount.h
gwin32outputstream.c
gwin32outputstream.h
gwin32resolver.c
gwin32resolver.h
gwin32volumemonitor.c
gwin32volumemonitor.h
gzlibcompressor.c
gzlibcompressor.h
gzlibdecompressor.c
gzlibdecompressor.h
makefile.msc
makegioalias.pl
pltcheck.sh
glib
gmodule
gobject
gthread
m4macros
po
tests
.gitignore
AUTHORS
COPYING
ChangeLog.pre-1-2
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-14
ChangeLog.pre-2-16
ChangeLog.pre-2-18
ChangeLog.pre-2-2
ChangeLog.pre-2-20
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
HACKING
INSTALL.in
MAINTAINERS
Makefile.am
Makefile.decl
NEWS
NEWS.pre-1-3
README.commits
README.in
README.win32
acglib.m4
acinclude.m4
autogen.sh
config.h.win32.in
configure.in
gio-2.0-uninstalled.pc.in
gio-2.0.pc.in
gio-unix-2.0-uninstalled.pc.in
gio-unix-2.0.pc.in
gio-windows-2.0.pc.in
glib-2.0-uninstalled.pc.in
glib-2.0.pc.in
glib-gettextize.in
glib-zip.in
glibconfig.h.win32.in
gmodule-2.0-uninstalled.pc.in
gmodule-2.0.pc.in
gmodule-export-2.0.pc.in
gmodule-no-export-2.0-uninstalled.pc.in
gmodule-no-export-2.0.pc.in
gobject-2.0-uninstalled.pc.in
gobject-2.0.pc.in
gthread-2.0-uninstalled.pc.in
gthread-2.0.pc.in
makefile.msc
mkinstalldirs
msvc_recommended_pragmas.h
sanity_check
win32-fixup.pl
glib/gio/tests/gdbus-example-watch-proxy.c
David Zeuthen 32f2e9a85b 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>
2010-06-11 18:21:27 -04:00

233 lines
7.1 KiB
C

#include <gio/gio.h>
static gchar *opt_name = NULL;
static gchar *opt_object_path = NULL;
static gchar *opt_interface = NULL;
static gboolean opt_system_bus = FALSE;
static gboolean opt_no_auto_start = FALSE;
static gboolean opt_no_properties = FALSE;
static GOptionEntry opt_entries[] =
{
{ "name", 'n', 0, G_OPTION_ARG_STRING, &opt_name, "Name of the remote object to watch", NULL },
{ "object-path", 'o', 0, G_OPTION_ARG_STRING, &opt_object_path, "Object path of the remote object", NULL },
{ "interface", 'i', 0, G_OPTION_ARG_STRING, &opt_interface, "D-Bus interface of remote object", NULL },
{ "system-bus", 's', 0, G_OPTION_ARG_NONE, &opt_system_bus, "Use the system-bus instead of the session-bus", NULL },
{ "no-auto-start", 'a', 0, G_OPTION_ARG_NONE, &opt_no_auto_start, "Don't instruct the bus to launch an owner for the name", NULL},
{ "no-properties", 'p', 0, G_OPTION_ARG_NONE, &opt_no_properties, "Do not load properties", NULL},
{ NULL}
};
static GMainLoop *loop = NULL;
static void
print_properties (GDBusProxy *proxy)
{
gchar **property_names;
guint n;
g_print (" properties:\n");
property_names = g_dbus_proxy_get_cached_property_names (proxy);
for (n = 0; property_names != NULL && property_names[n] != NULL; n++)
{
const gchar *key = property_names[n];
GVariant *value;
gchar *value_str;
value = g_dbus_proxy_get_cached_property (proxy, key);
value_str = g_variant_print (value, TRUE);
g_print (" %s -> %s\n", key, value_str);
g_variant_unref (value);
g_free (value_str);
}
g_strfreev (property_names);
}
static void
on_properties_changed (GDBusProxy *proxy,
GVariant *changed_properties,
const gchar* const *invalidated_properties,
gpointer user_data)
{
/* Note that we are guaranteed that changed_properties and
* invalidated_properties are never NULL
*/
if (g_variant_n_children (changed_properties) > 0)
{
GVariantIter *iter;
const gchar *key;
GVariant *value;
g_print (" *** Properties Changed:\n");
g_variant_get (changed_properties,
"a{sv}",
&iter);
while (g_variant_iter_loop (iter, "{&sv}", &key, &value))
{
gchar *value_str;
value_str = g_variant_print (value, TRUE);
g_print (" %s -> %s\n", key, value_str);
g_free (value_str);
}
g_variant_iter_free (iter);
}
if (g_strv_length ((GStrv) invalidated_properties) > 0)
{
guint n;
g_print (" *** Properties Invalidated:\n");
for (n = 0; invalidated_properties[n] != NULL; n++)
{
const gchar *key = invalidated_properties[n];
g_print (" %s\n", key);
}
}
}
static void
on_signal (GDBusProxy *proxy,
gchar *sender_name,
gchar *signal_name,
GVariant *parameters,
gpointer user_data)
{
gchar *parameters_str;
parameters_str = g_variant_print (parameters, TRUE);
g_print (" *** Received Signal: %s: %s\n",
signal_name,
parameters_str);
g_free (parameters_str);
}
static void
print_proxy (GDBusProxy *proxy)
{
gchar *name_owner;
name_owner = g_dbus_proxy_get_name_owner (proxy);
if (name_owner != NULL)
{
g_print ("+++ Proxy object points to remote object owned by %s\n"
" bus: %s\n"
" name: %s\n"
" object path: %s\n"
" interface: %s\n",
name_owner,
opt_system_bus ? "System Bus" : "Session Bus",
opt_name,
opt_object_path,
opt_interface);
print_properties (proxy);
}
else
{
g_print ("--- Proxy object is inert - there is no name owner for the name\n"
" bus: %s\n"
" name: %s\n"
" object path: %s\n"
" interface: %s\n",
opt_system_bus ? "System Bus" : "Session Bus",
opt_name,
opt_object_path,
opt_interface);
}
g_free (name_owner);
}
static void
on_name_owner_notify (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
GDBusProxy *proxy = G_DBUS_PROXY (object);
print_proxy (proxy);
}
int
main (int argc, char *argv[])
{
GOptionContext *opt_context;
GError *error;
GDBusProxyFlags flags;
GDBusProxy *proxy;
g_type_init ();
loop = NULL;
proxy = NULL;
opt_context = g_option_context_new ("g_bus_watch_proxy() example");
g_option_context_set_summary (opt_context,
"Example: to watch the object of gdbus-example-server, use:\n"
"\n"
" ./gdbus-example-watch-proxy -n org.gtk.GDBus.TestServer \\\n"
" -o /org/gtk/GDBus/TestObject \\\n"
" -i org.gtk.GDBus.TestInterface");
g_option_context_add_main_entries (opt_context, opt_entries, NULL);
error = NULL;
if (!g_option_context_parse (opt_context, &argc, &argv, &error))
{
g_printerr ("Error parsing options: %s\n", error->message);
goto out;
}
if (opt_name == NULL || opt_object_path == NULL || opt_interface == NULL)
{
g_printerr ("Incorrect usage, try --help.\n");
goto out;
}
flags = G_DBUS_PROXY_FLAGS_NONE;
if (opt_no_properties)
flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES;
if (opt_no_auto_start)
flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START;
loop = g_main_loop_new (NULL, FALSE);
error = NULL;
proxy = g_dbus_proxy_new_for_bus_sync (opt_system_bus ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
flags,
NULL, /* GDBusInterfaceInfo */
opt_name,
opt_object_path,
opt_interface,
NULL, /* GCancellable */
&error);
if (proxy == NULL)
{
g_printerr ("Error creating proxy: %s\n", error->message);
g_error_free (error);
goto out;
}
g_signal_connect (proxy,
"g-properties-changed",
G_CALLBACK (on_properties_changed),
NULL);
g_signal_connect (proxy,
"g-signal",
G_CALLBACK (on_signal),
NULL);
g_signal_connect (proxy,
"notify::g-name-owner",
G_CALLBACK (on_name_owner_notify),
NULL);
print_proxy (proxy);
g_main_loop_run (loop);
out:
if (proxy != NULL)
g_object_unref (proxy);
if (loop != NULL)
g_main_loop_unref (loop);
g_option_context_free (opt_context);
g_free (opt_name);
g_free (opt_object_path);
g_free (opt_interface);
return 0;
}