[vte] widget: Move some public API to its own file



commit 015a1e45484fc28f235d0753cf4442acae2f92e3
Author: Christian Persch <chpe gnome org>
Date:   Wed Nov 18 21:15:46 2015 +0100

    widget: Move some public API to its own file

 src/vte.cc         |  102 ++++++++++++-------------------------------
 src/vtegtk.cc      |  121 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/vteinternal.hh |   12 +++++
 3 files changed, 162 insertions(+), 73 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 5b5be3e..395b019 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -3737,40 +3737,8 @@ _vte_terminal_disconnect_pty_write(VteTerminal *terminal)
        }
 }
 
-/**
- * vte_terminal_pty_new_sync:
- * @terminal: a #VteTerminal
- * @flags: flags from #VtePtyFlags
- * @cancellable: (allow-none): a #GCancellable, or %NULL
- * @error: (allow-none): return location for a #GError, or %NULL
- *
- * Creates a new #VtePty, and sets the emulation property
- * from #VteTerminal:emulation.
- *
- * See vte_pty_new() for more information.
- *
- * Returns: (transfer full): a new #VtePty
- */
-VtePty *
-vte_terminal_pty_new_sync(VteTerminal *terminal,
-                          VtePtyFlags flags,
-                          GCancellable *cancellable,
-                          GError **error)
-{
-        VtePty *pty;
-
-        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
-
-        pty = vte_pty_new_sync(flags, cancellable, error);
-        if (pty == NULL)
-                return NULL;
-
-        return pty;
-}
-
-/**
- * vte_terminal_watch_child:
- * @terminal: a #VteTerminal
+/*
+ * VteTerminalPrivate::watch_child:
  * @child_pid: a #GPid
  *
  * Watches @child_pid. When the process exists, the #VteTerminal::child-exited
@@ -3788,45 +3756,35 @@ vte_terminal_pty_new_sync(VteTerminal *terminal,
  * the %G_SPAWN_DO_NOT_REAP_CHILD flag MUST have been passed.
  */
 void
-vte_terminal_watch_child (VteTerminal *terminal,
-                          GPid child_pid)
+VteTerminalPrivate::watch_child (GPid child_pid)
 {
-        VteTerminalPrivate *pvt;
-        GObject *object;
-
-        g_return_if_fail(VTE_IS_TERMINAL(terminal));
-        g_return_if_fail(child_pid != -1);
-
-        pvt = terminal->pvt;
-        g_return_if_fail(pvt->pty != NULL);
-
         // FIXMEchpe: support passing child_pid = -1 to remove the wathch
+        g_assert(child_pid != -1);
+        g_assert(m_pty != nullptr);
 
-        object = G_OBJECT(terminal);
-
+        GObject *object = G_OBJECT(m_terminal);
         g_object_freeze_notify(object);
 
         /* Set this as the child's pid. */
-        pvt->pty_pid = child_pid;
+        m_pty_pid = child_pid;
 
         /* Catch a child-exited signal from the child pid. */
-        if (terminal->pvt->child_watch_source != 0) {
-                g_source_remove (terminal->pvt->child_watch_source);
+        if (m_child_watch_source != 0) {
+                g_source_remove (m_child_watch_source);
         }
-        terminal->pvt->child_watch_source =
+        m_child_watch_source =
                 g_child_watch_add_full(G_PRIORITY_HIGH,
                                        child_pid,
                                        (GChildWatchFunc)vte_terminal_child_watch_cb,
-                                       terminal, NULL);
+                                       m_terminal, NULL);
 
         /* FIXMEchpe: call vte_terminal_set_size here? */
 
         g_object_thaw_notify(object);
 }
 
-/**
- * vte_terminal_spawn_sync:
- * @terminal: a #VteTerminal
+/*
+ * VteTerminalPrivate::spawn_sync:
  * @pty_flags: flags from #VtePtyFlags
  * @working_directory: (allow-none): the name of a directory the command should start
  *   in, or %NULL to use the current working directory
@@ -3856,9 +3814,8 @@ vte_terminal_watch_child (VteTerminal *terminal,
  *
  * Returns: %TRUE on success, or %FALSE on error with @error filled in
  */
-gboolean
-vte_terminal_spawn_sync(VteTerminal *terminal,
-                               VtePtyFlags pty_flags,
+bool
+VteTerminalPrivate::spawn_sync(VtePtyFlags pty_flags,
                                const char *working_directory,
                                char **argv,
                                char **envv,
@@ -3870,22 +3827,21 @@ vte_terminal_spawn_sync(VteTerminal *terminal,
                                GError **error)
 {
         guint spawn_flags = (guint)spawn_flags_;
-        VtePty *pty;
+        VtePty *new_pty;
         GPid pid;
 
-        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
-        g_return_val_if_fail(argv != NULL, FALSE);
-        g_return_val_if_fail(child_setup_data == NULL || child_setup, FALSE);
-        g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
+        g_assert(argv != nullptr);
+        g_assert(child_setup_data == nullptr || child_setup != nullptr);
+        g_assert(error == nullptr || *error == nullptr);
 
-        pty = vte_terminal_pty_new_sync(terminal, pty_flags, cancellable, error);
-        if (pty == NULL)
-                return FALSE;
+        new_pty = vte_terminal_pty_new_sync(m_terminal, pty_flags, cancellable, error);
+        if (new_pty == nullptr)
+                return false;
 
         /* FIXMEchpe: is this flag needed */
         spawn_flags |= G_SPAWN_CHILD_INHERITS_STDIN;
 
-        if (!__vte_pty_spawn(pty,
+        if (!__vte_pty_spawn(new_pty,
                              working_directory,
                              argv,
                              envv,
@@ -3893,18 +3849,18 @@ vte_terminal_spawn_sync(VteTerminal *terminal,
                              child_setup, child_setup_data,
                              &pid,
                              error)) {
-                g_object_unref(pty);
-                return FALSE;
+                g_object_unref(new_pty);
+                return false;
         }
 
-        vte_terminal_set_pty(terminal, pty);
-        vte_terminal_watch_child(terminal, pid);
-        g_object_unref (pty);
+        vte_terminal_set_pty(m_terminal, new_pty);
+        vte_terminal_watch_child(m_terminal, pid);
+        g_object_unref (new_pty);
 
         if (child_pid)
                 *child_pid = pid;
 
-        return TRUE;
+        return true;
 }
 
 /* Handle an EOF from the client. */
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index a714352..b869f63 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2074,6 +2074,127 @@ vte_terminal_get_cursor_position(VteTerminal *terminal,
 }
 
 /**
+ * vte_terminal_pty_new_sync:
+ * @terminal: a #VteTerminal
+ * @flags: flags from #VtePtyFlags
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @error: (allow-none): return location for a #GError, or %NULL
+ *
+ * Creates a new #VtePty, and sets the emulation property
+ * from #VteTerminal:emulation.
+ *
+ * See vte_pty_new() for more information.
+ *
+ * Returns: (transfer full): a new #VtePty
+ */
+VtePty *
+vte_terminal_pty_new_sync(VteTerminal *terminal,
+                          VtePtyFlags flags,
+                          GCancellable *cancellable,
+                          GError **error)
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
+
+        VtePty *pty = vte_pty_new_sync(flags, cancellable, error);
+        if (pty == NULL)
+                return NULL;
+
+        return pty;
+}
+
+/**
+ * vte_terminal_watch_child:
+ * @terminal: a #VteTerminal
+ * @child_pid: a #GPid
+ *
+ * Watches @child_pid. When the process exists, the #VteTerminal::child-exited
+ * signal will be called with the child's exit status.
+ *
+ * Prior to calling this function, a #VtePty must have been set in @terminal
+ * using vte_terminal_set_pty().
+ * When the child exits, the terminal's #VtePty will be set to %NULL.
+ *
+ * Note: g_child_watch_add() or g_child_watch_add_full() must not have
+ * been called for @child_pid, nor a #GSource for it been created with
+ * g_child_watch_source_new().
+ *
+ * Note: when using the g_spawn_async() family of functions,
+ * the %G_SPAWN_DO_NOT_REAP_CHILD flag MUST have been passed.
+ */
+void
+vte_terminal_watch_child (VteTerminal *terminal,
+                          GPid child_pid)
+{
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(child_pid != -1);
+        g_return_if_fail(terminal->pvt->pty != NULL);
+
+        terminal->pvt->watch_child(child_pid);
+}
+
+/**
+ * vte_terminal_spawn_sync:
+ * @terminal: a #VteTerminal
+ * @pty_flags: flags from #VtePtyFlags
+ * @working_directory: (allow-none): the name of a directory the command should start
+ *   in, or %NULL to use the current working directory
+ * @argv: (array zero-terminated=1) (element-type filename): child's argument vector
+ * @envv: (allow-none) (array zero-terminated=1) (element-type filename): a list of environment
+ *   variables to be added to the environment before starting the process, or %NULL
+ * @spawn_flags: flags from #GSpawnFlags
+ * @child_setup: (allow-none) (scope call): an extra child setup function to run in the child just before 
exec(), or %NULL
+ * @child_setup_data: user data for @child_setup
+ * @child_pid: (out) (allow-none) (transfer full): a location to store the child PID, or %NULL
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @error: (allow-none): return location for a #GError, or %NULL
+ *
+ * Starts the specified command under a newly-allocated controlling
+ * pseudo-terminal.  The @argv and @envv lists should be %NULL-terminated.
+ * The "TERM" environment variable is automatically set to a default value,
+ * but can be overridden from @envv.
+ * @pty_flags controls logging the session to the specified system log files.
+ *
+ * Note that %G_SPAWN_DO_NOT_REAP_CHILD will always be added to @spawn_flags.
+ *
+ * Note that unless @spawn_flags contains %G_SPAWN_LEAVE_DESCRIPTORS_OPEN, all file
+ * descriptors except stdin/stdout/stderr will be closed before calling exec()
+ * in the child.
+ *
+ * See vte_pty_new(), g_spawn_async() and vte_terminal_watch_child() for more information.
+ *
+ * Returns: %TRUE on success, or %FALSE on error with @error filled in
+ */
+gboolean
+vte_terminal_spawn_sync(VteTerminal *terminal,
+                        VtePtyFlags pty_flags,
+                        const char *working_directory,
+                        char **argv,
+                        char **envv,
+                        GSpawnFlags spawn_flags_,
+                        GSpawnChildSetupFunc child_setup,
+                        gpointer child_setup_data,
+                        GPid *child_pid /* out */,
+                        GCancellable *cancellable,
+                        GError **error)
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
+        g_return_val_if_fail(argv != NULL, FALSE);
+        g_return_val_if_fail(child_setup_data == NULL || child_setup, FALSE);
+        g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
+
+        return terminal->pvt->spawn_sync(pty_flags,
+                                         working_directory,
+                                         argv,
+                                         envv,
+                                         spawn_flags_,
+                                         child_setup,
+                                         child_setup_data,
+                                         child_pid,
+                                         cancellable,
+                                         error);
+}
+
+/**
  * VteSelectionFunc:
  * @terminal: terminal in which the cell is.
  * @column: column in which the cell is.
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 5a5e4a4..6ebe49c 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -483,6 +483,18 @@ public:
                                          int *natural_height);
         void widget_size_allocate(GtkAllocation *allocation);
 
+        void watch_child (GPid child_pid);
+        bool spawn_sync(VtePtyFlags pty_flags,
+                        const char *working_directory,
+                        char **argv,
+                        char **envv,
+                        GSpawnFlags spawn_flags_,
+                        GSpawnChildSetupFunc child_setup,
+                        gpointer child_setup_data,
+                        GPid *child_pid /* out */,
+                        GCancellable *cancellable,
+                        GError **error);
+
         void select_all();
         void deselect_all();
 


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