Add g_application_command_line_get_stdin()
[platform/upstream/glib.git] / gio / gapplicationimpl-dbus.c
1 /*
2  * Copyright © 2010 Codethink Limited
3  *
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 of the License, or (at your option) any later version.
8  *
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.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17  * Boston, MA 02111-1307, USA.
18  *
19  * Authors: Ryan Lortie <desrt@desrt.ca>
20  */
21
22 #include "config.h"
23
24 #include "gapplicationimpl.h"
25
26 #include "gactiongroup.h"
27 #include "gactiongroupexporter.h"
28 #include "gremoteactiongroup.h"
29 #include "gdbusactiongroup-private.h"
30 #include "gapplication.h"
31 #include "gfile.h"
32 #include "gdbusconnection.h"
33 #include "gdbusintrospection.h"
34 #include "gdbuserror.h"
35
36 #include <string.h>
37 #include <stdio.h>
38
39 #include "gapplicationcommandline.h"
40 #include "gdbusmethodinvocation.h"
41
42 #ifdef G_OS_UNIX
43 #include "gunixinputstream.h"
44 #include "gunixfdlist.h"
45 #endif
46
47 /* DBus Interface definition {{{1 */
48
49 /* For documentation of these interfaces, see
50  * http://live.gnome.org/GTK+/GApplication-dbus-apis
51  */
52 static const gchar org_gtk_Application_xml[] =
53   "<node>"
54     "<interface name='org.gtk.Application'>"
55       "<method name='Activate'>"
56         "<arg type='a{sv}' name='platform-data' direction='in'/>"
57       "</method>"
58       "<method name='Open'>"
59         "<arg type='as' name='uris' direction='in'/>"
60         "<arg type='s' name='hint' direction='in'/>"
61         "<arg type='a{sv}' name='platform-data' direction='in'/>"
62       "</method>"
63       "<method name='CommandLine'>"
64         "<arg type='o' name='path' direction='in'/>"
65         "<arg type='aay' name='arguments' direction='in'/>"
66         "<arg type='a{sv}' name='platform-data' direction='in'/>"
67         "<arg type='i' name='exit-status' direction='out'/>"
68       "</method>"
69     "</interface>"
70   "</node>";
71
72 static GDBusInterfaceInfo *org_gtk_Application;
73
74 static const gchar org_gtk_private_CommandLine_xml[] =
75   "<node>"
76     "<interface name='org.gtk.private.CommandLine'>"
77       "<method name='Print'>"
78         "<arg type='s' name='message' direction='in'/>"
79       "</method>"
80       "<method name='PrintError'>"
81         "<arg type='s' name='message' direction='in'/>"
82       "</method>"
83     "</interface>"
84   "</node>";
85
86 static GDBusInterfaceInfo *org_gtk_private_CommandLine;
87
88 /* GApplication implementation {{{1 */
89 struct _GApplicationImpl
90 {
91   GDBusConnection *session_bus;
92   GActionGroup    *exported_actions;
93   const gchar     *bus_name;
94
95   gchar           *object_path;
96   guint            object_id;
97   guint            actions_id;
98
99   gboolean         properties_live;
100   gboolean         primary;
101   GApplication    *app;
102 };
103
104
105 static GApplicationCommandLine *
106 g_dbus_command_line_new (GDBusMethodInvocation *invocation);
107
108
109 static void
110 g_application_impl_method_call (GDBusConnection       *connection,
111                                 const gchar           *sender,
112                                 const gchar           *object_path,
113                                 const gchar           *interface_name,
114                                 const gchar           *method_name,
115                                 GVariant              *parameters,
116                                 GDBusMethodInvocation *invocation,
117                                 gpointer               user_data)
118 {
119   GApplicationImpl *impl = user_data;
120   GApplicationClass *class;
121
122   class = G_APPLICATION_GET_CLASS (impl->app);
123
124   if (strcmp (method_name, "Activate") == 0)
125     {
126       GVariant *platform_data;
127
128       g_variant_get (parameters, "(@a{sv})", &platform_data);
129       class->before_emit (impl->app, platform_data);
130       g_signal_emit_by_name (impl->app, "activate");
131       class->after_emit (impl->app, platform_data);
132       g_variant_unref (platform_data);
133
134       g_dbus_method_invocation_return_value (invocation, NULL);
135     }
136
137   else if (strcmp (method_name, "Open") == 0)
138     {
139       GVariant *platform_data;
140       const gchar *hint;
141       GVariant *array;
142       GFile **files;
143       gint n, i;
144
145       g_variant_get (parameters, "(@ass@a{sv})",
146                      &array, &hint, &platform_data);
147
148       n = g_variant_n_children (array);
149       files = g_new (GFile *, n + 1);
150
151       for (i = 0; i < n; i++)
152         {
153           const gchar *uri;
154
155           g_variant_get_child (array, i, "&s", &uri);
156           files[i] = g_file_new_for_uri (uri);
157         }
158       g_variant_unref (array);
159       files[n] = NULL;
160
161       class->before_emit (impl->app, platform_data);
162       g_signal_emit_by_name (impl->app, "open", files, n, hint);
163       class->after_emit (impl->app, platform_data);
164
165       g_variant_unref (platform_data);
166
167       for (i = 0; i < n; i++)
168         g_object_unref (files[i]);
169       g_free (files);
170
171       g_dbus_method_invocation_return_value (invocation, NULL);
172     }
173
174   else if (strcmp (method_name, "CommandLine") == 0)
175     {
176       GApplicationCommandLine *cmdline;
177       GVariant *platform_data;
178       int status;
179
180       cmdline = g_dbus_command_line_new (invocation);
181       platform_data = g_variant_get_child_value (parameters, 2);
182       class->before_emit (impl->app, platform_data);
183       g_signal_emit_by_name (impl->app, "command-line", cmdline, &status);
184       g_application_command_line_set_exit_status (cmdline, status);
185       class->after_emit (impl->app, platform_data);
186       g_variant_unref (platform_data);
187       g_object_unref (cmdline);
188     }
189   else
190     g_assert_not_reached ();
191 }
192
193 static gchar *
194 application_path_from_appid (const gchar *appid)
195 {
196   gchar *appid_path, *iter;
197
198   if (appid == NULL)
199     /* this is a private implementation detail */
200     return g_strdup ("/org/gtk/Application/anonymous");
201
202   appid_path = g_strconcat ("/", appid, NULL);
203   for (iter = appid_path; *iter; iter++)
204     {
205       if (*iter == '.')
206         *iter = '/';
207
208       if (*iter == '-')
209         *iter = '_';
210     }
211
212   return appid_path;
213 }
214
215 /* Attempt to become the primary instance.
216  *
217  * Returns %TRUE if everything went OK, regardless of if we became the
218  * primary instance or not.  %FALSE is reserved for when something went
219  * seriously wrong (and @error will be set too, in that case).
220  *
221  * After a %TRUE return, impl->primary will be TRUE if we were
222  * successful.
223  */
224 static gboolean
225 g_application_impl_attempt_primary (GApplicationImpl  *impl,
226                                     GCancellable      *cancellable,
227                                     GError           **error)
228 {
229   const static GDBusInterfaceVTable vtable = {
230     g_application_impl_method_call,
231   };
232   GApplicationClass *app_class = G_APPLICATION_GET_CLASS (impl->app);
233   GVariant *reply;
234   guint32 rval;
235
236   if (org_gtk_Application == NULL)
237     {
238       GError *error = NULL;
239       GDBusNodeInfo *info;
240
241       info = g_dbus_node_info_new_for_xml (org_gtk_Application_xml, &error);
242       if G_UNLIKELY (info == NULL)
243         g_error ("%s", error->message);
244       org_gtk_Application = g_dbus_node_info_lookup_interface (info, "org.gtk.Application");
245       g_assert (org_gtk_Application != NULL);
246       g_dbus_interface_info_ref (org_gtk_Application);
247       g_dbus_node_info_unref (info);
248     }
249
250   /* We could possibly have been D-Bus activated as a result of incoming
251    * requests on either the application or actiongroup interfaces.
252    * Because of how GDBus dispatches messages, we need to ensure that
253    * both of those things are registered before we attempt to request
254    * our name.
255    *
256    * The action group need not be populated yet, as long as it happens
257    * before we return to the mainloop.  The reason for that is because
258    * GDBus does the check to make sure the object exists from the worker
259    * thread but doesn't actually dispatch the action invocation until we
260    * hit the mainloop in this thread.  There is also no danger of
261    * receiving 'activate' or 'open' signals until after 'startup' runs,
262    * for the same reason.
263    */
264   impl->object_id = g_dbus_connection_register_object (impl->session_bus, impl->object_path,
265                                                        org_gtk_Application, &vtable, impl, NULL, error);
266
267   if (impl->object_id == 0)
268     return FALSE;
269
270   impl->actions_id = g_dbus_connection_export_action_group (impl->session_bus, impl->object_path,
271                                                             impl->exported_actions, error);
272
273   if (impl->actions_id == 0)
274     return FALSE;
275
276   if (!app_class->dbus_register (impl->app,
277                                  impl->session_bus,
278                                  impl->object_path,
279                                  error))
280     return FALSE;
281
282   if (impl->bus_name == NULL)
283     {
284       /* If this is a non-unique application then it is sufficient to
285        * have our object paths registered. We can return now.
286        *
287        * Note: non-unique applications always act as primary-instance.
288        */
289       impl->primary = TRUE;
290       return TRUE;
291     }
292
293   /* If this is a unique application then we need to attempt to own
294    * the well-known name and fall back to remote mode (!is_primary)
295    * in the case that we can't do that.
296    */
297   /* DBUS_NAME_FLAG_DO_NOT_QUEUE: 0x4 */
298   reply = g_dbus_connection_call_sync (impl->session_bus, "org.freedesktop.DBus", "/org/freedesktop/DBus",
299                                        "org.freedesktop.DBus", "RequestName",
300                                        g_variant_new ("(su)", impl->bus_name, 0x4), G_VARIANT_TYPE ("(u)"),
301                                        0, -1, cancellable, error);
302
303   if (reply == NULL)
304     return FALSE;
305
306   g_variant_get (reply, "(u)", &rval);
307   g_variant_unref (reply);
308
309   /* DBUS_REQUEST_NAME_REPLY_EXISTS: 3 */
310   impl->primary = (rval != 3);
311
312   return TRUE;
313 }
314
315 /* Stop doing the things that the primary instance does.
316  *
317  * This should be called if attempting to become the primary instance
318  * failed (in order to clean up any partial success) and should also
319  * be called when freeing the GApplication.
320  *
321  * It is safe to call this multiple times.
322  */
323 static void
324 g_application_impl_stop_primary (GApplicationImpl *impl)
325 {
326   GApplicationClass *app_class = G_APPLICATION_GET_CLASS (impl->app);
327
328   app_class->dbus_unregister (impl->app,
329                               impl->session_bus,
330                               impl->object_path);
331
332   if (impl->object_id)
333     {
334       g_dbus_connection_unregister_object (impl->session_bus, impl->object_id);
335       impl->object_id = 0;
336     }
337
338   if (impl->actions_id)
339     {
340       g_dbus_connection_unexport_action_group (impl->session_bus, impl->actions_id);
341       impl->actions_id = 0;
342     }
343
344   if (impl->primary && impl->bus_name)
345     {
346       g_dbus_connection_call (impl->session_bus, "org.freedesktop.DBus",
347                               "/org/freedesktop/DBus", "org.freedesktop.DBus",
348                               "ReleaseName", g_variant_new ("(s)", impl->bus_name),
349                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
350       impl->primary = FALSE;
351     }
352 }
353
354 void
355 g_application_impl_destroy (GApplicationImpl *impl)
356 {
357   g_application_impl_stop_primary (impl);
358
359   if (impl->session_bus)
360     g_object_unref (impl->session_bus);
361
362   g_free (impl->object_path);
363
364   g_slice_free (GApplicationImpl, impl);
365 }
366
367 GApplicationImpl *
368 g_application_impl_register (GApplication        *application,
369                              const gchar         *appid,
370                              GApplicationFlags    flags,
371                              GActionGroup        *exported_actions,
372                              GRemoteActionGroup **remote_actions,
373                              GCancellable        *cancellable,
374                              GError             **error)
375 {
376   GDBusActionGroup *actions;
377   GApplicationImpl *impl;
378
379   g_assert ((flags & G_APPLICATION_NON_UNIQUE) || appid != NULL);
380
381   impl = g_slice_new0 (GApplicationImpl);
382
383   impl->app = application;
384   impl->exported_actions = exported_actions;
385
386   /* non-unique applications do not attempt to acquire a bus name */
387   if (~flags & G_APPLICATION_NON_UNIQUE)
388     impl->bus_name = appid;
389
390   impl->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, NULL);
391
392   if (impl->session_bus == NULL)
393     {
394       /* If we can't connect to the session bus, proceed as a normal
395        * non-unique application.
396        */
397       *remote_actions = NULL;
398       return impl;
399     }
400
401   impl->object_path = application_path_from_appid (appid);
402
403   /* Only try to be the primary instance if
404    * G_APPLICATION_IS_LAUNCHER was not specified.
405    */
406   if (~flags & G_APPLICATION_IS_LAUNCHER)
407     {
408       if (!g_application_impl_attempt_primary (impl, cancellable, error))
409         {
410           g_application_impl_destroy (impl);
411           return NULL;
412         }
413
414       if (impl->primary)
415         return impl;
416
417       /* We didn't make it.  Drop our service-side stuff. */
418       g_application_impl_stop_primary (impl);
419
420       if (flags & G_APPLICATION_IS_SERVICE)
421         {
422           g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
423                        "Unable to acquire bus name `%s'", appid);
424           g_application_impl_destroy (impl);
425
426           return NULL;
427         }
428     }
429
430   /* We are non-primary.  Try to get the primary's list of actions.
431    * This also serves as a mechanism to ensure that the primary exists
432    * (ie: DBus service files installed correctly, etc).
433    */
434   actions = g_dbus_action_group_get (impl->session_bus, impl->bus_name, impl->object_path);
435   if (!g_dbus_action_group_sync (actions, cancellable, error))
436     {
437       /* The primary appears not to exist.  Fail the registration. */
438       g_application_impl_destroy (impl);
439       g_object_unref (actions);
440
441       return NULL;
442     }
443
444   *remote_actions = G_REMOTE_ACTION_GROUP (actions);
445
446   return impl;
447 }
448
449 void
450 g_application_impl_activate (GApplicationImpl *impl,
451                              GVariant         *platform_data)
452 {
453   g_dbus_connection_call (impl->session_bus,
454                           impl->bus_name,
455                           impl->object_path,
456                           "org.gtk.Application",
457                           "Activate",
458                           g_variant_new ("(@a{sv})", platform_data),
459                           NULL, 0, -1, NULL, NULL, NULL);
460 }
461
462 void
463 g_application_impl_open (GApplicationImpl  *impl,
464                          GFile            **files,
465                          gint               n_files,
466                          const gchar       *hint,
467                          GVariant          *platform_data)
468 {
469   GVariantBuilder builder;
470   gint i;
471
472   g_variant_builder_init (&builder, G_VARIANT_TYPE ("(assa{sv})"));
473   g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
474   for (i = 0; i < n_files; i++)
475     {
476       gchar *uri = g_file_get_uri (files[i]);
477       g_variant_builder_add (&builder, "s", uri);
478       g_free (uri);
479     }
480   g_variant_builder_close (&builder);
481   g_variant_builder_add (&builder, "s", hint);
482   g_variant_builder_add_value (&builder, platform_data);
483
484   g_dbus_connection_call (impl->session_bus,
485                           impl->bus_name,
486                           impl->object_path,
487                           "org.gtk.Application",
488                           "Open",
489                           g_variant_builder_end (&builder),
490                           NULL, 0, -1, NULL, NULL, NULL);
491 }
492
493 static void
494 g_application_impl_cmdline_method_call (GDBusConnection       *connection,
495                                         const gchar           *sender,
496                                         const gchar           *object_path,
497                                         const gchar           *interface_name,
498                                         const gchar           *method_name,
499                                         GVariant              *parameters,
500                                         GDBusMethodInvocation *invocation,
501                                         gpointer               user_data)
502 {
503   const gchar *message;
504
505   g_variant_get_child (parameters, 0, "&s", &message);
506
507   if (strcmp (method_name, "Print") == 0)
508     g_print ("%s", message);
509   else if (strcmp (method_name, "PrintError") == 0)
510     g_printerr ("%s", message);
511   else
512     g_assert_not_reached ();
513
514   g_dbus_method_invocation_return_value (invocation, NULL);
515 }
516
517 typedef struct
518 {
519   GMainLoop *loop;
520   int status;
521 } CommandLineData;
522
523 static void
524 g_application_impl_cmdline_done (GObject      *source,
525                                  GAsyncResult *result,
526                                  gpointer      user_data)
527 {
528   CommandLineData *data = user_data;
529   GError *error = NULL;
530   GVariant *reply;
531
532 #ifdef G_OS_UNIX
533   reply = g_dbus_connection_call_with_unix_fd_list_finish (G_DBUS_CONNECTION (source), NULL, result, &error);
534 #else
535   reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
536 #endif
537
538
539   if (reply != NULL)
540     {
541       g_variant_get (reply, "(i)", &data->status);
542       g_variant_unref (reply);
543     }
544
545   else
546     {
547       g_printerr ("%s\n", error->message);
548       g_error_free (error);
549       data->status = 1;
550     }
551
552   g_main_loop_quit (data->loop);
553 }
554
555 int
556 g_application_impl_command_line (GApplicationImpl  *impl,
557                                  gchar            **arguments,
558                                  GVariant          *platform_data)
559 {
560   const static GDBusInterfaceVTable vtable = {
561     g_application_impl_cmdline_method_call
562   };
563   const gchar *object_path = "/org/gtk/Application/CommandLine";
564   GMainContext *context;
565   CommandLineData data;
566   guint object_id;
567
568   context = g_main_context_new ();
569   data.loop = g_main_loop_new (context, FALSE);
570   g_main_context_push_thread_default (context);
571
572   if (org_gtk_private_CommandLine == NULL)
573     {
574       GError *error = NULL;
575       GDBusNodeInfo *info;
576
577       info = g_dbus_node_info_new_for_xml (org_gtk_private_CommandLine_xml, &error);
578       if G_UNLIKELY (info == NULL)
579         g_error ("%s", error->message);
580       org_gtk_private_CommandLine = g_dbus_node_info_lookup_interface (info, "org.gtk.private.CommandLine");
581       g_assert (org_gtk_private_CommandLine != NULL);
582       g_dbus_interface_info_ref (org_gtk_private_CommandLine);
583       g_dbus_node_info_unref (info);
584     }
585
586   object_id = g_dbus_connection_register_object (impl->session_bus, object_path,
587                                                  org_gtk_private_CommandLine,
588                                                  &vtable, &data, NULL, NULL);
589   /* In theory we should try other paths... */
590   g_assert (object_id != 0);
591
592 #ifdef G_OS_UNIX
593   {
594     GError *error = NULL;
595     GUnixFDList *fd_list;
596
597     /* send along the stdin in case
598      * g_application_command_line_get_stdin_data() is called
599      */
600     fd_list = g_unix_fd_list_new ();
601     g_unix_fd_list_append (fd_list, 0, &error);
602     g_assert_no_error (error);
603
604     g_dbus_connection_call_with_unix_fd_list (impl->session_bus, impl->bus_name, impl->object_path,
605                                               "org.gtk.Application", "CommandLine",
606                                               g_variant_new ("(o^aay@a{sv})", object_path, arguments, platform_data),
607                                               G_VARIANT_TYPE ("(i)"), 0, G_MAXINT, fd_list, NULL,
608                                               g_application_impl_cmdline_done, &data);
609   }
610 #else
611   g_dbus_connection_call (impl->session_bus, impl->bus_name, impl->object_path,
612                           "org.gtk.Application", "CommandLine",
613                           g_variant_new ("(o^aay@a{sv})", object_path, arguments, platform_data),
614                           G_VARIANT_TYPE ("(i)"), 0, G_MAXINT, NULL,
615                           g_application_impl_cmdline_done, &data);
616 #endif
617
618   g_main_loop_run (data.loop);
619
620   g_main_context_pop_thread_default (context);
621   g_main_context_unref (context);
622   g_main_loop_unref (data.loop);
623
624   return data.status;
625 }
626
627 void
628 g_application_impl_flush (GApplicationImpl *impl)
629 {
630   if (impl->session_bus)
631     g_dbus_connection_flush_sync (impl->session_bus, NULL, NULL);
632 }
633
634 GDBusConnection *
635 g_application_impl_get_dbus_connection (GApplicationImpl *impl)
636 {
637   return impl->session_bus;
638 }
639
640 const gchar *
641 g_application_impl_get_dbus_object_path (GApplicationImpl *impl)
642 {
643   return impl->object_path;
644 }
645
646 /* GDBusCommandLine implementation {{{1 */
647
648 typedef GApplicationCommandLineClass GDBusCommandLineClass;
649 static GType g_dbus_command_line_get_type (void);
650 typedef struct
651 {
652   GApplicationCommandLine  parent_instance;
653   GDBusMethodInvocation   *invocation;
654
655   GDBusConnection *connection;
656   const gchar     *bus_name;
657   const gchar     *object_path;
658 } GDBusCommandLine;
659
660
661 G_DEFINE_TYPE (GDBusCommandLine,
662                g_dbus_command_line,
663                G_TYPE_APPLICATION_COMMAND_LINE)
664
665 static void
666 g_dbus_command_line_print_literal (GApplicationCommandLine *cmdline,
667                                    const gchar             *message)
668 {
669   GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
670
671   g_dbus_connection_call (gdbcl->connection,
672                           gdbcl->bus_name,
673                           gdbcl->object_path,
674                           "org.gtk.private.CommandLine", "Print",
675                           g_variant_new ("(s)", message),
676                           NULL, 0, -1, NULL, NULL, NULL);
677 }
678
679 static void
680 g_dbus_command_line_printerr_literal (GApplicationCommandLine *cmdline,
681                                       const gchar             *message)
682 {
683   GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
684
685   g_dbus_connection_call (gdbcl->connection,
686                           gdbcl->bus_name,
687                           gdbcl->object_path,
688                           "org.gtk.private.CommandLine", "PrintError",
689                           g_variant_new ("(s)", message),
690                           NULL, 0, -1, NULL, NULL, NULL);
691 }
692
693 static GInputStream *
694 g_dbus_command_line_get_stdin (GApplicationCommandLine *cmdline)
695 {
696 #ifdef G_OS_UNIX
697   GDBusCommandLine *gdbcl = (GDBusCommandLine *) cmdline;
698   GInputStream *result = NULL;
699   GDBusMessage *message;
700   GUnixFDList *fd_list;
701
702   message = g_dbus_method_invocation_get_message (gdbcl->invocation);
703   fd_list = g_dbus_message_get_unix_fd_list (message);
704
705   if (fd_list && g_unix_fd_list_get_length (fd_list))
706     {
707       gint *fds, n_fds, i;
708
709       fds = g_unix_fd_list_steal_fds (fd_list, &n_fds);
710       result = g_unix_input_stream_new (fds[0], TRUE);
711       for (i = 1; i < n_fds; i++)
712         close (fds[i]);
713       g_free (fds);
714     }
715
716   return result;
717 #else
718   return NULL;
719 #endif
720 }
721
722 static void
723 g_dbus_command_line_finalize (GObject *object)
724 {
725   GApplicationCommandLine *cmdline = G_APPLICATION_COMMAND_LINE (object);
726   GDBusCommandLine *gdbcl = (GDBusCommandLine *) object;
727   gint status;
728
729   status = g_application_command_line_get_exit_status (cmdline);
730
731   g_dbus_method_invocation_return_value (gdbcl->invocation,
732                                          g_variant_new ("(i)", status));
733   g_object_unref (gdbcl->invocation);
734
735   G_OBJECT_CLASS (g_dbus_command_line_parent_class)
736     ->finalize (object);
737 }
738
739 static void
740 g_dbus_command_line_init (GDBusCommandLine *gdbcl)
741 {
742 }
743
744 static void
745 g_dbus_command_line_class_init (GApplicationCommandLineClass *class)
746 {
747   GObjectClass *object_class = G_OBJECT_CLASS (class);
748
749   object_class->finalize = g_dbus_command_line_finalize;
750   class->printerr_literal = g_dbus_command_line_printerr_literal;
751   class->print_literal = g_dbus_command_line_print_literal;
752   class->get_stdin = g_dbus_command_line_get_stdin;
753 }
754
755 static GApplicationCommandLine *
756 g_dbus_command_line_new (GDBusMethodInvocation *invocation)
757 {
758   GDBusCommandLine *gdbcl;
759   GVariant *args;
760
761   args = g_dbus_method_invocation_get_parameters (invocation);
762
763   gdbcl = g_object_new (g_dbus_command_line_get_type (),
764                         "arguments", g_variant_get_child_value (args, 1),
765                         "platform-data", g_variant_get_child_value (args, 2),
766                         NULL);
767   gdbcl->connection = g_dbus_method_invocation_get_connection (invocation);
768   gdbcl->bus_name = g_dbus_method_invocation_get_sender (invocation);
769   g_variant_get_child (args, 0, "&o", &gdbcl->object_path);
770   gdbcl->invocation = g_object_ref (invocation);
771
772   return G_APPLICATION_COMMAND_LINE (gdbcl);
773 }
774
775 /* Epilogue {{{1 */
776
777 /* vim:set foldmethod=marker: */