2 * Copyright © 2010 Codethink Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Authors: Ryan Lortie <desrt@desrt.ca>
22 #include "gapplicationimpl.h"
24 #include "gactiongroup.h"
25 #include "gactiongroupexporter.h"
26 #include "gremoteactiongroup.h"
27 #include "gdbusactiongroup-private.h"
28 #include "gapplication.h"
30 #include "gdbusconnection.h"
31 #include "gdbusintrospection.h"
32 #include "gdbuserror.h"
33 #include "glib/gstdio.h"
38 #include "gapplicationcommandline.h"
39 #include "gdbusmethodinvocation.h"
42 #include "gunixinputstream.h"
43 #include "gunixfdlist.h"
46 /* DBus Interface definition {{{1 */
48 /* For documentation of these interfaces, see
49 * https://wiki.gnome.org/Projects/GLib/GApplication/DBusAPI
51 static const gchar org_gtk_Application_xml[] =
53 "<interface name='org.gtk.Application'>"
54 "<method name='Activate'>"
55 "<arg type='a{sv}' name='platform-data' direction='in'/>"
57 "<method name='Open'>"
58 "<arg type='as' name='uris' direction='in'/>"
59 "<arg type='s' name='hint' direction='in'/>"
60 "<arg type='a{sv}' name='platform-data' direction='in'/>"
62 "<method name='CommandLine'>"
63 "<arg type='o' name='path' direction='in'/>"
64 "<arg type='aay' name='arguments' direction='in'/>"
65 "<arg type='a{sv}' name='platform-data' direction='in'/>"
66 "<arg type='i' name='exit-status' direction='out'/>"
68 "<property name='Busy' type='b' access='read'/>"
72 static GDBusInterfaceInfo *org_gtk_Application;
74 static const gchar org_freedesktop_Application_xml[] =
76 "<interface name='org.freedesktop.Application'>"
77 "<method name='Activate'>"
78 "<arg type='a{sv}' name='platform-data' direction='in'/>"
80 "<method name='Open'>"
81 "<arg type='as' name='uris' direction='in'/>"
82 "<arg type='a{sv}' name='platform-data' direction='in'/>"
84 "<method name='ActivateAction'>"
85 "<arg type='s' name='action-name' direction='in'/>"
86 "<arg type='av' name='parameter' direction='in'/>"
87 "<arg type='a{sv}' name='platform-data' direction='in'/>"
92 static GDBusInterfaceInfo *org_freedesktop_Application;
94 static const gchar org_gtk_private_CommandLine_xml[] =
96 "<interface name='org.gtk.private.CommandLine'>"
97 "<method name='Print'>"
98 "<arg type='s' name='message' direction='in'/>"
100 "<method name='PrintError'>"
101 "<arg type='s' name='message' direction='in'/>"
106 static GDBusInterfaceInfo *org_gtk_private_CommandLine;
108 /* GApplication implementation {{{1 */
109 struct _GApplicationImpl
111 GDBusConnection *session_bus;
112 GActionGroup *exported_actions;
113 const gchar *bus_name;
114 guint name_lost_signal;
121 gboolean properties_live;
129 static GApplicationCommandLine *
130 g_dbus_command_line_new (GDBusMethodInvocation *invocation);
133 g_application_impl_get_property (GDBusConnection *connection,
135 const gchar *object_path,
136 const gchar *interface_name,
137 const gchar *property_name,
141 GApplicationImpl *impl = user_data;
143 if (strcmp (property_name, "Busy") == 0)
144 return g_variant_new_boolean (impl->busy);
146 g_assert_not_reached ();
152 send_property_change (GApplicationImpl *impl)
154 GVariantBuilder builder;
156 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
157 g_variant_builder_add (&builder,
159 "Busy", g_variant_new_boolean (impl->busy));
161 g_dbus_connection_emit_signal (impl->session_bus,
164 "org.freedesktop.DBus.Properties",
166 g_variant_new ("(sa{sv}as)",
167 "org.gtk.Application",
174 g_application_impl_method_call (GDBusConnection *connection,
176 const gchar *object_path,
177 const gchar *interface_name,
178 const gchar *method_name,
179 GVariant *parameters,
180 GDBusMethodInvocation *invocation,
183 GApplicationImpl *impl = user_data;
184 GApplicationClass *class;
186 class = G_APPLICATION_GET_CLASS (impl->app);
188 if (strcmp (method_name, "Activate") == 0)
190 GVariant *platform_data;
192 /* Completely the same for both freedesktop and gtk interfaces */
194 g_variant_get (parameters, "(@a{sv})", &platform_data);
196 class->before_emit (impl->app, platform_data);
197 g_signal_emit_by_name (impl->app, "activate");
198 class->after_emit (impl->app, platform_data);
199 g_variant_unref (platform_data);
201 g_dbus_method_invocation_return_value (invocation, NULL);
204 else if (strcmp (method_name, "Open") == 0)
206 GApplicationFlags flags;
207 GVariant *platform_data;
213 flags = g_application_get_flags (impl->app);
214 if ((flags & G_APPLICATION_HANDLES_OPEN) == 0)
216 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED, "Application does not open files");
220 /* freedesktop interface has no hint parameter */
221 if (g_str_equal (interface_name, "org.freedesktop.Application"))
223 g_variant_get (parameters, "(@as@a{sv})", &array, &platform_data);
227 g_variant_get (parameters, "(@as&s@a{sv})", &array, &hint, &platform_data);
229 n = g_variant_n_children (array);
230 files = g_new (GFile *, n + 1);
232 for (i = 0; i < n; i++)
236 g_variant_get_child (array, i, "&s", &uri);
237 files[i] = g_file_new_for_uri (uri);
239 g_variant_unref (array);
242 class->before_emit (impl->app, platform_data);
243 g_signal_emit_by_name (impl->app, "open", files, n, hint);
244 class->after_emit (impl->app, platform_data);
246 g_variant_unref (platform_data);
248 for (i = 0; i < n; i++)
249 g_object_unref (files[i]);
252 g_dbus_method_invocation_return_value (invocation, NULL);
255 else if (strcmp (method_name, "CommandLine") == 0)
257 GApplicationFlags flags;
258 GApplicationCommandLine *cmdline;
259 GVariant *platform_data;
262 flags = g_application_get_flags (impl->app);
263 if ((flags & G_APPLICATION_HANDLES_COMMAND_LINE) == 0)
265 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED,
266 "Application does not handle command line arguments");
270 /* Only on the GtkApplication interface */
272 cmdline = g_dbus_command_line_new (invocation);
273 platform_data = g_variant_get_child_value (parameters, 2);
274 class->before_emit (impl->app, platform_data);
275 g_signal_emit_by_name (impl->app, "command-line", cmdline, &status);
276 g_application_command_line_set_exit_status (cmdline, status);
277 class->after_emit (impl->app, platform_data);
278 g_variant_unref (platform_data);
279 g_object_unref (cmdline);
281 else if (g_str_equal (method_name, "ActivateAction"))
283 GVariant *parameter = NULL;
284 GVariant *platform_data;
288 /* Only on the freedesktop interface */
290 g_variant_get (parameters, "(&sav@a{sv})", &name, &iter, &platform_data);
291 g_variant_iter_next (iter, "v", ¶meter);
292 g_variant_iter_free (iter);
294 class->before_emit (impl->app, platform_data);
295 g_action_group_activate_action (impl->exported_actions, name, parameter);
296 class->after_emit (impl->app, platform_data);
299 g_variant_unref (parameter);
301 g_variant_unref (platform_data);
303 g_dbus_method_invocation_return_value (invocation, NULL);
306 g_assert_not_reached ();
310 application_path_from_appid (const gchar *appid)
312 gchar *appid_path, *iter;
315 /* this is a private implementation detail */
316 return g_strdup ("/org/gtk/Application/anonymous");
318 appid_path = g_strconcat ("/", appid, NULL);
319 for (iter = appid_path; *iter; iter++)
331 static void g_application_impl_stop_primary (GApplicationImpl *impl);
334 name_lost (GDBusConnection *bus,
335 const char *sender_name,
336 const char *object_path,
337 const char *interface_name,
338 const char *signal_name,
339 GVariant *parameters,
342 GApplicationImpl *impl = user_data;
345 impl->primary = FALSE;
346 g_application_impl_stop_primary (impl);
347 g_signal_emit_by_name (impl->app, "name-lost", &handled);
350 /* Attempt to become the primary instance.
352 * Returns %TRUE if everything went OK, regardless of if we became the
353 * primary instance or not. %FALSE is reserved for when something went
354 * seriously wrong (and @error will be set too, in that case).
356 * After a %TRUE return, impl->primary will be TRUE if we were
360 g_application_impl_attempt_primary (GApplicationImpl *impl,
361 GCancellable *cancellable,
364 const static GDBusInterfaceVTable vtable = {
365 g_application_impl_method_call,
366 g_application_impl_get_property,
367 NULL /* set_property */
369 GApplicationClass *app_class = G_APPLICATION_GET_CLASS (impl->app);
370 GBusRequestNameReplyFlags rval;
371 GBusNameOwnerFlags name_owner_flags;
372 GApplicationFlags app_flags;
374 if (org_gtk_Application == NULL)
376 GError *error = NULL;
379 info = g_dbus_node_info_new_for_xml (org_gtk_Application_xml, &error);
380 if G_UNLIKELY (info == NULL)
381 g_error ("%s", error->message);
382 org_gtk_Application = g_dbus_node_info_lookup_interface (info, "org.gtk.Application");
383 g_assert (org_gtk_Application != NULL);
384 g_dbus_interface_info_ref (org_gtk_Application);
385 g_dbus_node_info_unref (info);
387 info = g_dbus_node_info_new_for_xml (org_freedesktop_Application_xml, &error);
388 if G_UNLIKELY (info == NULL)
389 g_error ("%s", error->message);
390 org_freedesktop_Application = g_dbus_node_info_lookup_interface (info, "org.freedesktop.Application");
391 g_assert (org_freedesktop_Application != NULL);
392 g_dbus_interface_info_ref (org_freedesktop_Application);
393 g_dbus_node_info_unref (info);
396 /* We could possibly have been D-Bus activated as a result of incoming
397 * requests on either the application or actiongroup interfaces.
398 * Because of how GDBus dispatches messages, we need to ensure that
399 * both of those things are registered before we attempt to request
402 * The action group need not be populated yet, as long as it happens
403 * before we return to the mainloop. The reason for that is because
404 * GDBus does the check to make sure the object exists from the worker
405 * thread but doesn't actually dispatch the action invocation until we
406 * hit the mainloop in this thread. There is also no danger of
407 * receiving 'activate' or 'open' signals until after 'startup' runs,
408 * for the same reason.
410 impl->object_id = g_dbus_connection_register_object (impl->session_bus, impl->object_path,
411 org_gtk_Application, &vtable, impl, NULL, error);
413 if (impl->object_id == 0)
416 impl->fdo_object_id = g_dbus_connection_register_object (impl->session_bus, impl->object_path,
417 org_freedesktop_Application, &vtable, impl, NULL, error);
419 if (impl->fdo_object_id == 0)
422 impl->actions_id = g_dbus_connection_export_action_group (impl->session_bus, impl->object_path,
423 impl->exported_actions, error);
425 if (impl->actions_id == 0)
428 impl->registered = TRUE;
429 if (!app_class->dbus_register (impl->app,
435 if (impl->bus_name == NULL)
437 /* If this is a non-unique application then it is sufficient to
438 * have our object paths registered. We can return now.
440 * Note: non-unique applications always act as primary-instance.
442 impl->primary = TRUE;
446 /* If this is a unique application then we need to attempt to own
447 * the well-known name and fall back to remote mode (!is_primary)
448 * in the case that we can't do that.
450 name_owner_flags = G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE;
451 app_flags = g_application_get_flags (impl->app);
453 if (app_flags & G_APPLICATION_ALLOW_REPLACEMENT)
455 impl->name_lost_signal = g_dbus_connection_signal_subscribe (impl->session_bus,
456 "org.freedesktop.DBus",
457 "org.freedesktop.DBus",
459 "/org/freedesktop/DBus",
461 G_DBUS_SIGNAL_FLAGS_NONE,
466 name_owner_flags |= G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
468 if (app_flags & G_APPLICATION_REPLACE)
469 name_owner_flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
471 rval = g_dbus_request_name (impl->session_bus, impl->bus_name, name_owner_flags, error);
473 if (rval == G_BUS_REQUEST_NAME_FLAGS_ERROR)
476 /* DBUS_REQUEST_NAME_REPLY_EXISTS: 3 */
477 impl->primary = (rval != G_BUS_REQUEST_NAME_FLAGS_EXISTS);
479 if (!impl->primary && impl->name_lost_signal)
481 g_dbus_connection_signal_unsubscribe (impl->session_bus, impl->name_lost_signal);
482 impl->name_lost_signal = 0;
488 /* Stop doing the things that the primary instance does.
490 * This should be called if attempting to become the primary instance
491 * failed (in order to clean up any partial success) and should also
492 * be called when freeing the GApplication.
494 * It is safe to call this multiple times.
497 g_application_impl_stop_primary (GApplicationImpl *impl)
499 GApplicationClass *app_class = G_APPLICATION_GET_CLASS (impl->app);
501 if (impl->registered)
503 app_class->dbus_unregister (impl->app,
506 impl->registered = FALSE;
511 g_dbus_connection_unregister_object (impl->session_bus, impl->object_id);
515 if (impl->fdo_object_id)
517 g_dbus_connection_unregister_object (impl->session_bus, impl->fdo_object_id);
518 impl->fdo_object_id = 0;
521 if (impl->actions_id)
523 g_dbus_connection_unexport_action_group (impl->session_bus, impl->actions_id);
524 impl->actions_id = 0;
527 if (impl->name_lost_signal)
529 g_dbus_connection_signal_unsubscribe (impl->session_bus, impl->name_lost_signal);
530 impl->name_lost_signal = 0;
533 if (impl->primary && impl->bus_name)
535 g_dbus_release_name (impl->session_bus, impl->bus_name, NULL);
536 impl->primary = FALSE;
541 g_application_impl_set_busy_state (GApplicationImpl *impl,
544 if (impl->busy != busy)
547 send_property_change (impl);
552 g_application_impl_destroy (GApplicationImpl *impl)
554 g_application_impl_stop_primary (impl);
556 if (impl->session_bus)
557 g_object_unref (impl->session_bus);
559 g_free (impl->object_path);
561 g_slice_free (GApplicationImpl, impl);
565 g_application_impl_register (GApplication *application,
567 GApplicationFlags flags,
568 GActionGroup *exported_actions,
569 GRemoteActionGroup **remote_actions,
570 GCancellable *cancellable,
573 GDBusActionGroup *actions;
574 GApplicationImpl *impl;
576 g_assert ((flags & G_APPLICATION_NON_UNIQUE) || appid != NULL);
578 impl = g_slice_new0 (GApplicationImpl);
580 impl->app = application;
581 impl->exported_actions = exported_actions;
583 /* non-unique applications do not attempt to acquire a bus name */
584 if (~flags & G_APPLICATION_NON_UNIQUE)
585 impl->bus_name = appid;
587 impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, NULL);
589 if (impl->session_bus == NULL)
591 /* If we can't connect to the session bus, proceed as a normal
592 * non-unique application.
594 *remote_actions = NULL;
598 impl->object_path = application_path_from_appid (appid);
600 /* Only try to be the primary instance if
601 * G_APPLICATION_IS_LAUNCHER was not specified.
603 if (~flags & G_APPLICATION_IS_LAUNCHER)
605 if (!g_application_impl_attempt_primary (impl, cancellable, error))
607 g_application_impl_destroy (impl);
614 /* We didn't make it. Drop our service-side stuff. */
615 g_application_impl_stop_primary (impl);
617 if (flags & G_APPLICATION_IS_SERVICE)
619 g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
620 "Unable to acquire bus name '%s'", appid);
621 g_application_impl_destroy (impl);
627 /* We are non-primary. Try to get the primary's list of actions.
628 * This also serves as a mechanism to ensure that the primary exists
629 * (ie: DBus service files installed correctly, etc).
631 actions = g_dbus_action_group_get (impl->session_bus, impl->bus_name, impl->object_path);
632 if (!g_dbus_action_group_sync (actions, cancellable, error))
634 /* The primary appears not to exist. Fail the registration. */
635 g_application_impl_destroy (impl);
636 g_object_unref (actions);
641 *remote_actions = G_REMOTE_ACTION_GROUP (actions);
647 g_application_impl_activate (GApplicationImpl *impl,
648 GVariant *platform_data)
650 g_dbus_connection_call (impl->session_bus,
653 "org.gtk.Application",
655 g_variant_new ("(@a{sv})", platform_data),
656 NULL, 0, -1, NULL, NULL, NULL);
660 g_application_impl_open (GApplicationImpl *impl,
664 GVariant *platform_data)
666 GVariantBuilder builder;
669 g_variant_builder_init (&builder, G_VARIANT_TYPE ("(assa{sv})"));
670 g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
671 for (i = 0; i < n_files; i++)
673 gchar *uri = g_file_get_uri (files[i]);
674 g_variant_builder_add (&builder, "s", uri);
677 g_variant_builder_close (&builder);
678 g_variant_builder_add (&builder, "s", hint);
679 g_variant_builder_add_value (&builder, platform_data);
681 g_dbus_connection_call (impl->session_bus,
684 "org.gtk.Application",
686 g_variant_builder_end (&builder),
687 NULL, 0, -1, NULL, NULL, NULL);
691 g_application_impl_cmdline_method_call (GDBusConnection *connection,
693 const gchar *object_path,
694 const gchar *interface_name,
695 const gchar *method_name,
696 GVariant *parameters,
697 GDBusMethodInvocation *invocation,
700 const gchar *message;
702 g_variant_get_child (parameters, 0, "&s", &message);
704 if (strcmp (method_name, "Print") == 0)
705 g_print ("%s", message);
706 else if (strcmp (method_name, "PrintError") == 0)
707 g_printerr ("%s", message);
709 g_assert_not_reached ();
711 g_dbus_method_invocation_return_value (invocation, NULL);
721 g_application_impl_cmdline_done (GObject *source,
722 GAsyncResult *result,
725 CommandLineData *data = user_data;
726 GError *error = NULL;
730 reply = g_dbus_connection_call_with_unix_fd_list_finish (G_DBUS_CONNECTION (source), NULL, result, &error);
732 reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
738 g_variant_get (reply, "(i)", &data->status);
739 g_variant_unref (reply);
744 g_printerr ("%s\n", error->message);
745 g_error_free (error);
749 g_main_loop_quit (data->loop);
753 g_application_impl_command_line (GApplicationImpl *impl,
754 const gchar * const *arguments,
755 GVariant *platform_data)
757 const static GDBusInterfaceVTable vtable = {
758 g_application_impl_cmdline_method_call
760 const gchar *object_path = "/org/gtk/Application/CommandLine";
761 GMainContext *context;
762 CommandLineData data;
763 guint object_id G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
765 context = g_main_context_new ();
766 data.loop = g_main_loop_new (context, FALSE);
767 g_main_context_push_thread_default (context);
769 if (org_gtk_private_CommandLine == NULL)
771 GError *error = NULL;
774 info = g_dbus_node_info_new_for_xml (org_gtk_private_CommandLine_xml, &error);
775 if G_UNLIKELY (info == NULL)
776 g_error ("%s", error->message);
777 org_gtk_private_CommandLine = g_dbus_node_info_lookup_interface (info, "org.gtk.private.CommandLine");
778 g_assert (org_gtk_private_CommandLine != NULL);
779 g_dbus_interface_info_ref (org_gtk_private_CommandLine);
780 g_dbus_node_info_unref (info);
783 object_id = g_dbus_connection_register_object (impl->session_bus, object_path,
784 org_gtk_private_CommandLine,
785 &vtable, &data, NULL, NULL);
786 /* In theory we should try other paths... */
787 g_assert (object_id != 0);
791 GError *error = NULL;
792 GUnixFDList *fd_list;
794 /* send along the stdin in case
795 * g_application_command_line_get_stdin_data() is called
797 fd_list = g_unix_fd_list_new ();
798 g_unix_fd_list_append (fd_list, 0, &error);
799 g_assert_no_error (error);
801 g_dbus_connection_call_with_unix_fd_list (impl->session_bus, impl->bus_name, impl->object_path,
802 "org.gtk.Application", "CommandLine",
803 g_variant_new ("(o^aay@a{sv})", object_path, arguments, platform_data),
804 G_VARIANT_TYPE ("(i)"), 0, G_MAXINT, fd_list, NULL,
805 g_application_impl_cmdline_done, &data);
806 g_object_unref (fd_list);
809 g_dbus_connection_call (impl->session_bus, impl->bus_name, impl->object_path,
810 "org.gtk.Application", "CommandLine",
811 g_variant_new ("(o^aay@a{sv})", object_path, arguments, platform_data),
812 G_VARIANT_TYPE ("(i)"), 0, G_MAXINT, NULL,
813 g_application_impl_cmdline_done, &data);
816 g_main_loop_run (data.loop);
818 g_main_context_pop_thread_default (context);
819 g_main_context_unref (context);
820 g_main_loop_unref (data.loop);
826 g_application_impl_flush (GApplicationImpl *impl)
828 if (impl->session_bus)
829 g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
833 g_application_impl_get_dbus_connection (GApplicationImpl *impl)
835 return impl->session_bus;
839 g_application_impl_get_dbus_object_path (GApplicationImpl *impl)
841 return impl->object_path;
844 /* GDBusCommandLine implementation {{{1 */
846 typedef GApplicationCommandLineClass GDBusCommandLineClass;
847 static GType g_dbus_command_line_get_type (void);
850 GApplicationCommandLine parent_instance;
851 GDBusMethodInvocation *invocation;
853 GDBusConnection *connection;
854 const gchar *bus_name;
855 const gchar *object_path;
859 G_DEFINE_TYPE (GDBusCommandLine,
861 G_TYPE_APPLICATION_COMMAND_LINE)
864 g_dbus_command_line_print_literal (GApplicationCommandLine *cmdline,
865 const gchar *message)
867 GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
869 g_dbus_connection_call (gdbcl->connection,
872 "org.gtk.private.CommandLine", "Print",
873 g_variant_new ("(s)", message),
874 NULL, 0, -1, NULL, NULL, NULL);
878 g_dbus_command_line_printerr_literal (GApplicationCommandLine *cmdline,
879 const gchar *message)
881 GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
883 g_dbus_connection_call (gdbcl->connection,
886 "org.gtk.private.CommandLine", "PrintError",
887 g_variant_new ("(s)", message),
888 NULL, 0, -1, NULL, NULL, NULL);
891 static GInputStream *
892 g_dbus_command_line_get_stdin (GApplicationCommandLine *cmdline)
895 GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
896 GInputStream *result = NULL;
897 GDBusMessage *message;
898 GUnixFDList *fd_list;
900 message = g_dbus_method_invocation_get_message (gdbcl->invocation);
901 fd_list = g_dbus_message_get_unix_fd_list (message);
903 if (fd_list && g_unix_fd_list_get_length (fd_list))
907 fds = g_unix_fd_list_peek_fds (fd_list, NULL);
908 result = g_unix_input_stream_new (fds[0], FALSE);
909 g_object_weak_ref (G_OBJECT (result),
910 (GWeakNotify) g_object_unref,
911 g_object_ref (fd_list));
921 g_dbus_command_line_finalize (GObject *object)
923 GApplicationCommandLine *cmdline = G_APPLICATION_COMMAND_LINE (object);
924 GDBusCommandLine *gdbcl = (GDBusCommandLine *) object;
927 status = g_application_command_line_get_exit_status (cmdline);
929 g_dbus_method_invocation_return_value (gdbcl->invocation,
930 g_variant_new ("(i)", status));
931 g_object_unref (gdbcl->invocation);
933 G_OBJECT_CLASS (g_dbus_command_line_parent_class)
938 g_dbus_command_line_init (GDBusCommandLine *gdbcl)
943 g_dbus_command_line_class_init (GApplicationCommandLineClass *class)
945 GObjectClass *object_class = G_OBJECT_CLASS (class);
947 object_class->finalize = g_dbus_command_line_finalize;
948 class->printerr_literal = g_dbus_command_line_printerr_literal;
949 class->print_literal = g_dbus_command_line_print_literal;
950 class->get_stdin = g_dbus_command_line_get_stdin;
953 static GApplicationCommandLine *
954 g_dbus_command_line_new (GDBusMethodInvocation *invocation)
956 GDBusCommandLine *gdbcl;
958 GVariant *arguments, *platform_data;
960 args = g_dbus_method_invocation_get_parameters (invocation);
962 arguments = g_variant_get_child_value (args, 1);
963 platform_data = g_variant_get_child_value (args, 2);
964 gdbcl = g_object_new (g_dbus_command_line_get_type (),
965 "arguments", arguments,
966 "platform-data", platform_data,
968 g_variant_unref (arguments);
969 g_variant_unref (platform_data);
971 gdbcl->connection = g_dbus_method_invocation_get_connection (invocation);
972 gdbcl->bus_name = g_dbus_method_invocation_get_sender (invocation);
973 g_variant_get_child (args, 0, "&o", &gdbcl->object_path);
974 gdbcl->invocation = g_object_ref (invocation);
976 return G_APPLICATION_COMMAND_LINE (gdbcl);
981 /* vim:set foldmethod=marker: */