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