[gnome-builder/wip/gtk4-port] libide/foundry: add helper to create stdin/stdout stream



commit e76e842eb82842dbd382cd9819953a5cfa268478
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 24 16:16:55 2022 -0700

    libide/foundry: add helper to create stdin/stdout stream

 src/libide/foundry/ide-run-context.c | 29 +++++++++++++++++++++++++++++
 src/libide/foundry/ide-run-context.h |  3 +++
 2 files changed, 32 insertions(+)
---
diff --git a/src/libide/foundry/ide-run-context.c b/src/libide/foundry/ide-run-context.c
index 736f5956b..58ed61ce3 100644
--- a/src/libide/foundry/ide-run-context.c
+++ b/src/libide/foundry/ide-run-context.c
@@ -1145,3 +1145,32 @@ ide_run_context_set_pty (IdeRunContext *self,
   if (consumer_fd != -1)
     ide_run_context_set_pty_fd (self, consumer_fd);
 }
+
+/**
+ * ide_run_context_create_stdio_stream:
+ * @self: a #IdeRunContext
+ * @error: a location for a #GError
+ *
+ * Creates a stream to communicate with the subprocess using stdin/stdout.
+ *
+ * The stream is created using UNIX pipes which are attached to the
+ * stdin/stdout of the child process.
+ *
+ * Returns: (transfer full): a #GIOStream if successful; otherwise
+ *   %NULL and @error is set.
+ */
+GIOStream *
+ide_run_context_create_stdio_stream (IdeRunContext  *self,
+                                     GError        **error)
+{
+  IdeRunContextLayer *layer;
+
+  g_return_val_if_fail (IDE_IS_RUN_CONTEXT (self), NULL);
+
+  layer = ide_run_context_current_layer (self);
+
+  return ide_unix_fd_map_create_stream (layer->unix_fd_map,
+                                        STDIN_FILENO,
+                                        STDOUT_FILENO,
+                                        error);
+}
diff --git a/src/libide/foundry/ide-run-context.h b/src/libide/foundry/ide-run-context.h
index 51bcf13a8..9171f05f4 100644
--- a/src/libide/foundry/ide-run-context.h
+++ b/src/libide/foundry/ide-run-context.h
@@ -127,6 +127,9 @@ IDE_AVAILABLE_IN_ALL
 void                   ide_run_context_unsetenv                (IdeRunContext         *self,
                                                                 const char            *key);
 IDE_AVAILABLE_IN_ALL
+GIOStream             *ide_run_context_create_stdio_stream     (IdeRunContext         *self,
+                                                                GError               **error);
+IDE_AVAILABLE_IN_ALL
 IdeSubprocessLauncher *ide_run_context_end                     (IdeRunContext         *self,
                                                                 GError               **error);
 IDE_AVAILABLE_IN_ALL


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