[glib/application: 1/2] it's a start



commit e00c5a111f49aa6ce2e9f466a9b71455c8f4ada0
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Jul 21 15:51:08 2010 -0400

    it's a start

 gio/Makefile.am                  |    1 +
 gio/gapplication.c               |  288 +++++++++++---------------------------
 gio/gapplication.h               |   78 ++++++----
 gio/gapplicationinvocation.c     |  291 ++++++++++++++++++++++++++++++++++++++
 gio/gapplicationinvocation.h     |  115 +++++++++++++++
 gio/gdbusapplicationinvocation.c |   41 ++++++
 6 files changed, 577 insertions(+), 237 deletions(-)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index dd6bb9e..dea09d4 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -259,6 +259,7 @@ SUBDIRS += tests
 
 libgio_2_0_la_SOURCES =		\
 	gappinfo.c 		\
+	gapplicationinvocation.c\
 	gapplication.c		\
 	gapplication.h		\
 	gasynchelper.c 		\
diff --git a/gio/gapplication.c b/gio/gapplication.c
index c4b2b24..6c5e45b 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -178,11 +178,7 @@ enum
   PROP_0,
 
   PROP_APPLICATION_ID,
-  PROP_REGISTER,
-  PROP_DEFAULT_QUIT,
-  PROP_IS_REMOTE,
-  PROP_ARGV,
-  PROP_PLATFORM_DATA
+  PROP_IS_REMOTE
 };
 
 enum
@@ -217,7 +213,6 @@ struct _GApplicationPrivate
   guint registration_tried : 1;
 
   guint actions_changed_id;
-
 #ifdef G_OS_UNIX
   gchar *dbus_path;
   GDBusConnection *session_bus;
@@ -310,13 +305,17 @@ g_application_default_quit_with_data (GApplication *application,
   return TRUE;
 }
 
-static void
-g_application_default_run (GApplication *application)
+static gint
+g_application_default_run (GApplication *application,
+                           GVariant     *arguments,
+                           GVariant     *platform_data)
 {
   if (application->priv->mainloop == NULL)
     application->priv->mainloop = g_main_loop_new (NULL, TRUE);
 
   g_main_loop_run (application->priv->mainloop);
+
+  return 0;
 }
 
 static GVariant *
@@ -443,34 +442,13 @@ g_application_action_free (gpointer data)
  * Since: 2.26
  */
 GApplication *
-g_application_new (const gchar *appid,
-		   int          argc,
-		   char       **argv)
+g_application_new (const gchar *appid)
 {
-  const gchar * const *args = (const gchar **) argv;
-  GObject *app;
-  GError *error = NULL;
-  GVariant *argv_variant;
-
   g_type_init ();
 
-  g_return_val_if_fail (appid != NULL, NULL);
-  
-  argv_variant = g_variant_new_bytestring_array (args, argc);
-  
-  app = g_initable_new (G_TYPE_APPLICATION, 
-			NULL,
-			&error,
-			"application-id", appid, 
-			"argv", argv_variant, 
-			NULL);
-  if (!app)
-    {
-      g_error ("%s", error->message);
-      g_clear_error (&error);
-      return NULL;
-    }
-  return G_APPLICATION (app);
+  return g_object_new (G_TYPE_APPLICATION,
+                       "application-id", appid,
+                       NULL);
 }
 
 /**
@@ -489,65 +467,15 @@ g_application_new (const gchar *appid,
  * Since: 2.26
  */
 GApplication *
-g_application_try_new (const gchar *appid,
-		       int          argc,
-		       char       **argv,
-		       GError     **error)
+g_application_try_new (const gchar *appid)
 {
-  const gchar * const *args = (const gchar **) argv;
-  GVariant *argv_variant;
-
   g_type_init ();
 
-  g_return_val_if_fail (appid != NULL, NULL);
-  
-  argv_variant = g_variant_new_bytestring_array (args, argc);
-  
-  return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION, 
-					NULL,
-					error,
-					"application-id", appid, 
-					"argv", argv_variant, 
-					NULL));
-}
-
-/**
- * g_application_unregistered_try_new:
- * @appid: System-dependent application identifier
- * @argc: Number of arguments in @argv
- * @argv: (allow-none) (array length=argc): Argument vector, usually from the <parameter>argv</parameter> parameter of main() 
- * @error: a #GError
- *
- * This function is similar to g_application_try_new(), but also
- * sets the GApplication:register property to %FALSE.  You can later
- * call g_application_register() to complete initialization.
- *
- * Returns: (transfer full): An application instance
- *
- * Since: 2.26
- */
-GApplication *
-g_application_unregistered_try_new (const gchar *appid,
-				    int          argc,
-				    char       **argv,
-				    GError     **error)
-{
-  const gchar * const *args = (const gchar **) argv;
-  GVariant *argv_variant;
-
-  g_type_init ();
+  /* XXX do the check for required functionality */
 
-  g_return_val_if_fail (appid != NULL, NULL);
-  
-  argv_variant = g_variant_new_bytestring_array (args, argc);
-  
-  return G_APPLICATION (g_initable_new (G_TYPE_APPLICATION, 
-					NULL,
-					error,
-					"application-id", appid, 
-					"argv", argv_variant, 
-					"register", FALSE,
-					NULL));
+  return g_object_new (G_TYPE_APPLICATION,
+                       "application-id", appid,
+                       NULL);
 }
 
 /**
@@ -877,13 +805,18 @@ g_application_get_action_enabled (GApplication *application,
  *
  * Since: 2.26
  */
-void
-g_application_run (GApplication *application)
+int
+g_application_run (GApplication  *application,
+                   int            argc,
+                   char         **argv)
 {
-  g_return_if_fail (G_IS_APPLICATION (application));
-  g_return_if_fail (!application->priv->is_remote);
+  GVariant *arguments;
 
-  G_APPLICATION_GET_CLASS (application)->run (application);
+  g_return_val_if_fail (G_IS_APPLICATION (application), 1);
+
+  arguments = g_variant_new_bytestring_array ((const gchar **) argv, argc);
+
+  return G_APPLICATION_GET_CLASS (application)->run (application, arguments);
 }
 
 /**
@@ -1017,26 +950,10 @@ g_application_get_property (GObject    *object,
       g_value_set_string (value, g_application_get_id (app));
       break;
 
-    case PROP_DEFAULT_QUIT:
-      g_value_set_boolean (value, app->priv->default_quit);
-      break;
-
     case PROP_IS_REMOTE:
       g_value_set_boolean (value, g_application_is_remote (app));
       break;
 
-    case PROP_REGISTER:
-      g_value_set_boolean (value, app->priv->do_register);
-      break;
-
-    case PROP_ARGV:
-      g_value_set_variant (value, app->priv->argv);
-      break;
-
-    case PROP_PLATFORM_DATA:
-      g_value_set_variant (value, app->priv->platform_data);
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -1057,30 +974,6 @@ g_application_set_property (GObject      *object,
       app->priv->appid = g_value_dup_string (value);
       break;
 
-    case PROP_DEFAULT_QUIT:
-      app->priv->default_quit = g_value_get_boolean (value);
-      break;
-
-    case PROP_REGISTER:
-      app->priv->do_register = g_value_get_boolean (value);
-      /* If we're not registering, the default_quit no longer applies */
-      if (!app->priv->do_register)
-	app->priv->default_quit = FALSE;
-      break;
-
-    case PROP_ARGV:
-      app->priv->argv = g_value_dup_variant (value);
-      break;
-
-    case PROP_PLATFORM_DATA:
-      {
-	GVariant *platform_data = g_value_get_variant (value);
-	if (app->priv->platform_data)
-	  g_variant_unref (app->priv->platform_data);
-	app->priv->platform_data = g_variant_ref_sink (append_cwd_to_platform_data (platform_data));
-      }
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -1248,62 +1141,6 @@ g_application_class_init (GApplicationClass *klass)
                                                         G_PARAM_STATIC_STRINGS));
 
   /**
-   * GApplication:argv:
-   *
-   * The argument vector given to this application.  It must be a #GVariant
-   * with a type signature "aay".
-   *
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_ARGV,
-                                   g_param_spec_variant ("argv",
-						        P_("Argument vector"),
-						        P_("System argument vector with type signature aay"),
-						        G_VARIANT_TYPE ("aay"),
-                                                        NULL,
-						        G_PARAM_READWRITE |
-						        G_PARAM_CONSTRUCT_ONLY |
-						        G_PARAM_STATIC_STRINGS));
-
-  /**
-   * GApplication:platform-data:
-   *
-   * Platform-specific data retrieved from the operating system
-   * environment.  It must be a #GVariant with type signature "a{sv}".
-   *
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_PLATFORM_DATA,
-                                   g_param_spec_variant ("platform-data",
-						         P_("Platform data"),
-						         P_("Environmental data, must have type signature a{sv}"),
-						         G_VARIANT_TYPE ("a{sv}"),
-                                                         NULL,
-						         G_PARAM_READWRITE |
-						         G_PARAM_CONSTRUCT_ONLY |
-						         G_PARAM_STATIC_STRINGS));
-
-  /**
-   * GApplication:default-quit:
-   *
-   * By default, if the GApplication:register property is %TRUE, and a
-   * different process is running this application, the process will
-   * be exited.  Set this property to %FALSE to allow custom
-   * interaction with the remote process.
-   *
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_DEFAULT_QUIT,
-                                   g_param_spec_boolean ("default-quit",
-                                                         P_("Default Quit"),
-                                                         P_("Exit the process by default"),
-                                                         TRUE,
-                                                         G_PARAM_READWRITE |
-                                                         G_PARAM_CONSTRUCT_ONLY |
-                                                         G_PARAM_STATIC_STRINGS));
-
-
-  /**
    * GApplication:is-remote:
    *
    * This property is %TRUE if this application instance represents a proxy
@@ -1317,21 +1154,62 @@ g_application_class_init (GApplicationClass *klass)
                                                          P_("Whether this application is a proxy for another process"),
                                                          TRUE,
                                                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+}
 
-  /**
-   * GApplication:register:
-   *
-   * If this property is %FALSE, the application construction will not attempt
-   * to ensure process uniqueness, and the application is guaranteed to be in the
-   * remote state.  See GApplication:is-remote.
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_REGISTER,
-                                   g_param_spec_boolean ("register",
-                                                         P_("Register"),
-                                                         P_("If false, do not "),
-                                                         TRUE,
-                                                         G_PARAM_READWRITE | 
-							 G_PARAM_CONSTRUCT_ONLY |
-							 G_PARAM_STATIC_STRINGS));
+
+int
+g_application_run_variant (GApplication *application,
+                           GVariant     *arguments)
+{
+  GApplicationClass *class = G_APPLICATION_GET_CLASS (application);
+  int exit_status;
+
+  g_variant_ref_sink (arguments);
+
+  if (class->preprocess_args (application, &arguments, &exit_status))
+    {
+      g_variant_unref (arguments);
+      return exit_status;
+    }
+
+  g_application_register (application);
+
+  if (g_application_is_remote (application))
+    {
+      GVariantBuilder *builder;
+      GVariant *platform_data;
+
+      builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+      class->add_platform_data (application, builder);
+      platform_data = g_variant_builder_end (builder);
+      g_variant_builder_free (builder);
+
+      status = remote_impl_run (arguments, platform_data);
+    }
+  else
+    {
+      GApplicationInvocation *invocation;
+
+      invocation = class->create_invocation (application, arguments, NULL);
+      class->prepare_invocation (application, invocation);
+      exit_status = class->invoked (application, invocation);
+      g_object_unref (invocation);
+
+      if (exit_status == 0)
+        class->run_mainloop (application);
+    }
+
+  g_variant_unref (arguments);
+
+  return exit_status;
+}
+
+int
+g_application_run (GApplication *application,
+                   int argc, char **argv)
+{
+  GVariant *args;
+
+  args = g_variant_bytestring_array_new ((const gchar **) argv, argc);
+  return g_application_run_variant (args);
 }
diff --git a/gio/gapplication.h b/gio/gapplication.h
index 20cc4ea..e31aa4d 100644
--- a/gio/gapplication.h
+++ b/gio/gapplication.h
@@ -79,42 +79,53 @@ struct _GApplicationClass
 
   /*< public >*/
   /* signals */
-  void        (* action_with_data) (GApplication *application,
-				    const gchar  *action_name,
-				    GVariant     *platform_data);
-  gboolean    (* quit_with_data)   (GApplication *application,
-				    GVariant     *platform_data);
-  void        (* prepare_activation)   (GApplication  *application,
-                                        GVariant      *arguments,
-                                        GVariant      *platform_data);
+  void                     (* startup)            (GApplication            *application);
+
+  void                     (* open)               (GApplication            *application,
+                                                   GFile                   *file);
+
+  void                     (* activate)           (GApplication            *application);
+
+  gint                     (* invoke)             (GApplication            *application,
+                                                   GApplicationInvocation  *invocation);
+
+  gboolean                 (* action)             (GApplication            *application,
+                                                   const gchar             *action_name);
+
 
   /* vfuncs */
-  void        (* run)    (GApplication *application);
+  void                     (* add_platform_data)  (GApplication            *application,
+                                                   GVariantBuilder         *builder);
+  gboolean                 (* preprocess_args)    (GApplication            *application,
+                                                   GVariant               **arguments,
+                                                   gint                    *exit_status);
+
+  GApplicationInvocation * (* create_invocation)  (GApplication            *application,
+                                                   GVariant                *arguments,
+                                                   GVariant                *platform_data);
+
+  void                     (* emit_invocation)    (GApplication            *application,
+                                                   GApplicationInvocation  *invocation);
+  void                     (* emit_open)          (GApplication            *application,
+                                                   GFile                   *file,
+                                                   GVariant                *platform_data);
+  void                     (* emit_activate)      (GApplication            *application,
+                                                   GVariant                *platform_data);
+  void                     (* emit_action)        (GApplication            *application,
+                                                   const gchar             *action_name,
+                                                   GVariant                *platform_data);
+
+  void                     (* quit_mainloop)      (GApplication            *application);
+  int                      (* run_mainloop)       (GApplication            *application);
 
   /*< private >*/
-  /* Padding for future expansion */
-  void (*_g_reserved1) (void);
-  void (*_g_reserved2) (void);
-  void (*_g_reserved3) (void);
-  void (*_g_reserved4) (void);
-  void (*_g_reserved5) (void);
-  void (*_g_reserved6) (void);
+  gpointer padding[12];
 };
 GType                   g_application_get_type                  (void) G_GNUC_CONST;
 
-GApplication *          g_application_new                       (const gchar      *appid,
-								 int               argc,
-								 char            **argv);
+gboolean                g_application_is_supported              (void);
 
-GApplication *          g_application_try_new                   (const gchar      *appid,
-								 int               argc,
-								 char            **argv,
-								 GError          **error);
-
-GApplication *          g_application_unregistered_try_new      (const gchar      *appid,
-								 int               argc,
-								 char            **argv,
-								 GError          **error);
+GApplication *          g_application_new                       (const gchar      *appid);
 
 gboolean                g_application_register                  (GApplication      *application);
 
@@ -135,12 +146,15 @@ gboolean                g_application_get_action_enabled        (GApplication
 G_CONST_RETURN gchar *  g_application_get_action_description    (GApplication      *application,
                                                                  const gchar       *name);
 void                    g_application_invoke_action             (GApplication      *application,
-                                                                 const gchar       *name,
-                                                                 GVariant          *platform_data);
+                                                                 const gchar       *name);
+
+int                     g_application_invoke_variant            (GApplication      *application,
+                                                                 GVariant          *arguments);
+int                     g_application_invoke                    (GApplication      *application,
+                                                                 int                argc,
+                                                                 char             **argv);
 
 void                    g_application_run                       (GApplication      *application);
-gboolean                g_application_quit_with_data            (GApplication      *application,
-                                                                 GVariant          *platform_data);
 
 gboolean                g_application_is_remote                 (GApplication      *application);
 
diff --git a/gio/gapplicationinvocation.c b/gio/gapplicationinvocation.c
new file mode 100644
index 0000000..f180465
--- /dev/null
+++ b/gio/gapplicationinvocation.c
@@ -0,0 +1,291 @@
+#include "gapplicationinvocation.h"
+
+#include <string.h>
+#include <stdio.h>
+
+G_DEFINE_TYPE (GApplicationInvocation, g_application_invocation, G_TYPE_OBJECT)
+
+enum
+{
+  PROP_NONE,
+  PROP_ARGUMENTS,
+  PROP_PLATFORM_DATA,
+  PROP_IS_REMOTE
+};
+
+typedef struct _RemoteImpl RemoteImpl;
+
+static void     remote_impl_init                (RemoteImpl    *remote_impl,
+                                                 gpointer       remote_handle);
+static void     remote_impl_stdout_write        (RemoteImpl    *remote_impl,
+                                                 gconstpointer  buf,
+                                                 gsize          length);
+static void     remote_impl_stderr_write        (RemoteImpl    *remote_impl,
+                                                 gconstpointer  buf,
+                                                 gsize          length);
+static void     remote_impl_exit                (RemoteImpl    *remote_impl,
+                                                 int            status);
+
+
+#include "gdbusapplicationinvocation.c"
+
+struct _GApplicationInvocationPrivate
+{
+  GVariant *platform_data;
+  GVariant *arguments;
+  GVariant *cwd;
+  gint exit_status;
+
+  RemoteImpl remote_impl;
+};
+
+#define IS_REMOTE(invocation) ((invocation)->priv->platform_data != NULL)
+
+void
+g_application_invocation_get_argc_argv (GApplicationInvocation *invocation,
+                                        int *argc, char ***argv)
+{
+  gsize len;
+
+  g_return_if_fail (G_IS_APPLICATION_INVOCATION (invocation));
+  g_return_if_fail (argc != NULL && argv != NULL);
+
+  *argv = g_variant_dup_bytestring_array (invocation->priv->arguments, &len);
+  *argc = len;
+}
+
+GVariant *
+g_application_invocation_get_arguments (GApplicationInvocation *invocation)
+{
+  return g_variant_ref (invocation->priv->arguments);
+}
+
+const gchar *
+g_application_invocation_get_cwd (GApplicationInvocation *invocation)
+{
+  if (invocation->priv->cwd)
+    return g_variant_get_bytestring (invocation->priv->cwd);
+  else
+    return NULL;
+}
+
+GVariant *
+g_application_invocation_get_cwd_variant (GApplicationInvocation *invocation)
+{
+  if (invocation->priv->cwd)
+    return g_variant_ref (invocation->priv->cwd);
+  else
+    return NULL;
+}
+
+gboolean
+g_application_invocation_get_is_remote (GApplicationInvocation *invocation)
+{
+  return IS_REMOTE (invocation);
+}
+
+void
+g_application_invocation_stdout_write (GApplicationInvocation *invocation,
+                                       gconstpointer           buf,
+                                       gssize                  length)
+{
+  if (length < 0)
+    length = strlen (buf);
+
+  if (IS_REMOTE (invocation))
+    remote_impl_stdout_write (&invocation->priv->remote_impl, buf, length);
+  else
+    fwrite (buf, length, 1, stdout);
+}
+
+void
+g_application_invocation_stderr_write (GApplicationInvocation *invocation,
+                                       gconstpointer           buf,
+                                       gssize                  length)
+{
+  if (length < 0)
+    length = strlen (buf);
+
+  if (IS_REMOTE (invocation))
+    remote_impl_stderr_write (&invocation->priv->remote_impl, buf, length);
+  else
+    fwrite (buf, length, 1, stderr);
+}
+
+void
+g_application_invocation_stdout_print (GApplicationInvocation *invocation,
+                                       const gchar            *format,
+                                       ...)
+{
+  gchar *message;
+  va_list ap;
+
+  g_return_if_fail (G_IS_APPLICATION_INVOCATION (invocation));
+  g_return_if_fail (format != NULL);
+
+  va_start (ap, format);
+  message = g_strdup_vprintf (format, ap);
+  va_end (ap);
+
+  g_application_invocation_stdout_write (invocation, message, -1);
+}
+
+void
+g_application_invocation_stderr_print (GApplicationInvocation *invocation,
+                                       const gchar            *format,
+                                       ...)
+{
+  gchar *message;
+  va_list ap;
+
+  g_return_if_fail (G_IS_APPLICATION_INVOCATION (invocation));
+  g_return_if_fail (format != NULL);
+
+  va_start (ap, format);
+  message = g_strdup_vprintf (format, ap);
+  va_end (ap);
+
+  g_application_invocation_stderr_write (invocation, message, -1);
+}
+
+void
+g_application_invocation_set_exit_status (GApplicationInvocation *invocation,
+                                          int                     exit_status)
+{
+  g_return_if_fail (G_IS_APPLICATION_INVOCATION (invocation));
+
+  invocation->priv->exit_status = exit_status;
+}
+
+static void
+grok_platform_data (GApplicationInvocation *invocation)
+{
+  GVariantIter iter;
+  const gchar *key;
+  GVariant *value;
+
+  g_variant_iter_init (&iter, invocation->priv->platform_data);
+
+  while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
+    if (strcmp (key, "cwd") == 0)
+      {
+        if (!invocation->priv->cwd)
+          invocation->priv->cwd = g_variant_ref (value);
+      }
+}
+
+static void
+g_application_invocation_get_property (GObject *object, guint prop_id,
+                                       GValue *value, GParamSpec *pspec)
+{
+  GApplicationInvocation *invocation = G_APPLICATION_INVOCATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_ARGUMENTS:
+      g_value_set_variant (value, invocation->priv->arguments);
+      break;
+
+    case PROP_PLATFORM_DATA:
+      g_value_set_variant (value, invocation->priv->platform_data);
+      break;
+
+    case PROP_IS_REMOTE:
+      g_value_set_boolean (value, IS_REMOTE (invocation));
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+static void
+g_application_invocation_set_property (GObject *object, guint prop_id,
+                                       const GValue *value, GParamSpec *pspec)
+{
+  GApplicationInvocation *invocation = G_APPLICATION_INVOCATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_ARGUMENTS:
+      g_assert (invocation->priv->arguments == NULL);
+      invocation->priv->arguments = g_value_dup_variant (value);
+      break;
+
+    case PROP_PLATFORM_DATA:
+      g_assert (invocation->priv->platform_data == NULL);
+      invocation->priv->platform_data = g_value_dup_variant (value);
+      grok_platform_data (invocation);
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+static void
+g_application_invocation_finalize (GObject *object)
+{
+  GApplicationInvocation *invocation = G_APPLICATION_INVOCATION (object);
+
+  remote_impl_exit (&invocation->priv->remote_impl,
+                    invocation->priv->exit_status);
+
+  if (invocation->priv->platform_data)
+    g_variant_unref (invocation->priv->platform_data);
+  if (invocation->priv->arguments)
+    g_variant_unref (invocation->priv->arguments);
+  if (invocation->priv->cwd)
+    g_variant_unref (invocation->priv->cwd);
+
+  G_OBJECT_CLASS (g_application_invocation_parent_class)
+    ->finalize (object);
+}
+
+static void
+g_application_invocation_init (GApplicationInvocation *invocation)
+{
+}
+
+static void
+g_application_invocation_class_init (GApplicationInvocationClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->get_property = g_application_invocation_get_property;
+  object_class->set_property = g_application_invocation_set_property;
+  object_class->finalize = g_application_invocation_finalize;
+
+  g_object_class_install_property (object_class, PROP_ARGUMENTS,
+    g_param_spec_variant ("arguments", "commandline arguments",
+                          "the commandline that caused this invocation",
+                          G_VARIANT_TYPE_BYTESTRING_ARRAY, NULL,
+                          G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class, PROP_PLATFORM_DATA,
+    g_param_spec_variant ("platform-data", "platform data",
+                          "platform-specific data for the invocation",
+                          G_VARIANT_TYPE ("a{sv}"), NULL,
+                          G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (object_class, PROP_IS_REMOTE,
+    g_param_spec_boolean ("is-remote", "is remote",
+                          "TRUE if this is a remote invocation", FALSE,
+                          G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+}
+
+GVariant *
+g_application_invocation_get_platform_data (GApplicationInvocation *invocation)
+{
+  g_return_val_if_fail (G_IS_APPLICATION_INVOCATION (invocation), NULL);
+  g_return_val_if_fail (IS_REMOTE (invocation), NULL);
+
+  return g_variant_ref (invocation->priv->platform_data);
+}
+
+void
+g_application_invocation_setup_remote (GApplicationInvocation *invocation,
+                                       gpointer                remote_handle)
+{
+  remote_impl_init (&invocation->priv->remote_impl, remote_handle);
+}
diff --git a/gio/gapplicationinvocation.h b/gio/gapplicationinvocation.h
new file mode 100644
index 0000000..f918984
--- /dev/null
+++ b/gio/gapplicationinvocation.h
@@ -0,0 +1,115 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
+#error "Only <gio/gio.h> can be included directly."
+#endif
+
+#ifndef __G_APPLICATION_INVOCATION_H__
+#define __G_APPLICATION_INVOCATION_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define G_TYPE_APPLICATION_INVOCATION                       (g_application_invocation_get_type ())
+#define G_APPLICATION_INVOCATION(inst)                      (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
+                                                             G_TYPE_APPLICATION_INVOCATION,                          \
+                                                             GApplicationInvocation))
+#define G_APPLICATION_INVOCATION_CLASS(class)               (G_TYPE_CHECK_CLASS_CAST ((class),                       \
+                                                             G_TYPE_APPLICATION_INVOCATION,                          \
+                                                             GApplicationInvocationClass))
+#define G_IS_APPLICATION_INVOCATION(inst)                   (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
+                                                             G_TYPE_APPLICATION_INVOCATION))
+#define G_IS_APPLICATION_INVOCATION_CLASS(class)            (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
+                                                             G_TYPE_APPLICATION_INVOCATION))
+#define G_APPLICATION_INVOCATION_GET_CLASS(inst)            (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
+                                                             G_TYPE_APPLICATION_INVOCATION,                          \
+                                                             GApplicationInvocationClass))
+
+typedef struct _GApplicationInvocation                      GApplicationInvocation;
+typedef struct _GApplicationInvocationPrivate               GApplicationInvocationPrivate;
+typedef struct _GApplicationInvocationClass                 GApplicationInvocationClass;
+
+/**
+ * GApplicationInvocation:
+ *
+ * The <structname>GApplicationInvocation</structname> structure contains private
+ * data and should only be accessed using the provided API
+ *
+ * Since: 2.26
+ */
+struct _GApplicationInvocation
+{
+  /*< private >*/
+  GObject parent_instance;
+
+  GApplicationInvocationPrivate *priv;
+};
+
+/**
+ * GApplicationInvocationClass:
+ *
+ * The <structname>GApplicationInvocationClass</structname> structure contains
+ * private data only
+ *
+ * Since: 2.26
+ */
+struct _GApplicationInvocationClass
+{
+  /*< private >*/
+  GObjectClass parent_class;
+  gpointer padding[12];
+};
+
+GType                   g_application_invocation_get_type               (void) G_GNUC_CONST;
+
+void                    g_application_invocation_get_argc_argv          (GApplicationInvocation *invocation,
+                                                                         int *argc, char ***argv);
+GVariant *              g_application_invocation_get_arguments          (GApplicationInvocation *invocation);
+
+const gchar *           g_application_invocation_get_cwd                (GApplicationInvocation *invocation);
+GVariant *              g_application_invocation_get_cwd_variant        (GApplicationInvocation *invocation);
+
+gboolean                g_application_invocation_get_is_remote          (GApplicationInvocation *invocation);
+
+void                    g_application_invocation_stdout_write           (GApplicationInvocation *invocation,
+                                                                         gconstpointer           buf,
+                                                                         gssize                  length);
+void                    g_application_invocation_stderr_write           (GApplicationInvocation *invocation,
+                                                                         gconstpointer           buf,
+                                                                         gssize                  length);
+void                    g_application_invocation_stdout_print           (GApplicationInvocation *invocation,
+                                                                         const gchar            *format,
+                                                                         ...);
+void                    g_application_invocation_stderr_print           (GApplicationInvocation *invocation,
+                                                                         const gchar            *format,
+                                                                         ...);
+
+void                    g_application_invocation_set_exit_status        (GApplicationInvocation *invocation,
+                                                                         int                     exit_status);
+
+GVariant *              g_application_invocation_get_platform_data      (GApplicationInvocation *invocation);
+
+G_END_DECLS
+
+#endif /* __G_APPLICATION_INVOCATION_H__ */
diff --git a/gio/gdbusapplicationinvocation.c b/gio/gdbusapplicationinvocation.c
new file mode 100644
index 0000000..6cb1ebb
--- /dev/null
+++ b/gio/gdbusapplicationinvocation.c
@@ -0,0 +1,41 @@
+#include "gdbusconnection.h"
+
+struct _RemoteImpl {
+  GDBusConnection *session;
+  gchar *remote_name;
+};
+
+void
+remote_impl_init (RemoteImpl *remote_impl,
+                  gpointer    remote_handle)
+{
+  /* won't block, won't fail */
+  g_assert (remote_impl->session == NULL);
+  remote_impl->session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+  g_assert (remote_impl->session != NULL);
+
+  remote_impl->remote_name = g_strdup (remote_handle);
+}
+
+void
+remote_impl_stdout_write (RemoteImpl    *remote_impl,
+                          gconstpointer  buf,
+                          gsize          length)
+{
+}
+
+
+void
+remote_impl_stderr_write (RemoteImpl    *remote_impl,
+                          gconstpointer  buf,
+                          gsize          length)
+{
+}
+
+void
+remote_impl_exit (RemoteImpl *remote_impl,
+                  int         status)
+{
+  g_object_unref (remote_impl->session);
+  g_free (remote_impl->remote_name);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]