2 * Copyright © 2010 Red Hat, Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2 of the licence or (at
7 * your option) any later version.
9 * See the included COPYING file for more information.
11 * Author: David Zeuthen <davidz@redhat.com>
17 #include <sys/types.h>
24 /* see gdbus-example-server.c for the server implementation */
26 get_server_stdout (GDBusConnection *connection,
27 const gchar *name_owner,
30 GDBusMessage *method_call_message;
31 GDBusMessage *method_reply_message;
36 method_call_message = NULL;
37 method_reply_message = NULL;
39 method_call_message = g_dbus_message_new_method_call (name_owner,
40 "/org/gtk/GDBus/TestObject",
41 "org.gtk.GDBus.TestInterface",
43 method_reply_message = g_dbus_connection_send_message_with_reply_sync (connection,
46 NULL, /* out_serial */
47 NULL, /* cancellable */
49 if (method_reply_message == NULL)
52 if (g_dbus_message_get_type (method_reply_message) == G_DBUS_MESSAGE_TYPE_ERROR)
54 g_dbus_message_to_gerror (method_reply_message, error);
58 fd_list = g_dbus_message_get_unix_fd_list (method_reply_message);
59 fd = g_unix_fd_list_get (fd_list, 0, error);
62 g_object_unref (method_call_message);
63 g_object_unref (method_reply_message);
69 on_name_appeared (GDBusConnection *connection,
71 const gchar *name_owner,
78 fd = get_server_stdout (connection, name_owner, &error);
81 g_printerr ("Error invoking GimmeStdout(): %s\n",
99 str = g_strdup_printf ("On %s, gdbus-example-unix-fd-client with pid %d was here!\n",
103 g_warn_if_fail (write (fd, str, len) == len);
106 g_print ("Wrote the following on server's stdout:\n%s", str);
114 on_name_vanished (GDBusConnection *connection,
118 g_printerr ("Failed to get name owner for %s\n"
119 "Is ./gdbus-example-server running?\n",
125 main (int argc, char *argv[])
132 watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
133 "org.gtk.GDBus.TestServer",
134 G_BUS_NAME_WATCHER_FLAGS_NONE,
140 loop = g_main_loop_new (NULL, FALSE);
141 g_main_loop_run (loop);
143 g_bus_unwatch_name (watcher_id);