/* GIO - GLib Input, Output and Streaming Library
 *
 * Copyright (C) 2012 Colin Walters <walters@verbum.org>
 *
 * This library 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 License, 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.
 *
 * Author: Colin Walters <walters@verbum.org>
 */

#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
#error "Only <gio/gio.h> can be included directly."
#endif

#ifndef __G_SUBPROCESS_H__
#define __G_SUBPROCESS_H__

#include <gio/ginputstream.h>

G_BEGIN_DECLS

#define G_TYPE_SUBPROCESS         (g_subprocess_get_type ())
#define G_SUBPROCESS(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_SUBPROCESS, GSubprocess))
#define G_SUBPROCESS_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_SUBPROCESS, GSubprocessClass))
#define G_IS_SUBPROCESS(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_SUBPROCESS))
#define G_IS_SUBPROCESS_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_SUBPROCESS))
#define G_SUBPROCESS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_SUBPROCESS, GSubprocessClass))

typedef struct _GSubprocessClass   GSubprocessClass;

struct _GSubprocessClass
{
  GObjectClass parent_class;
};

GType            g_subprocess_get_type (void) G_GNUC_CONST;

GSubprocess *    g_subprocess_new (void);

GSubprocess *    g_subprocess_new_for_command_line (gchar **argv);

void             g_subprocess_set_environ (GSubprocess       *self,
					   gchar            **envp);

void             g_subprocess_set_spawn_flags (GSubprocess       *self,
					       GSpawnFlags        flags);

void             g_subprocess_set_working_directory (GSubprocess       *self,
						     const gchar       *working_directory);

void             g_subprocess_set_child_setup (GSubprocess           *self,
					       GSpawnChildSetupFunc   child_setup,
					       gpointer               user_data);

void             g_subprocess_set_standard_input_file_path (GSubprocess       *self,
							    const gchar       *file_path);

#ifdef G_OS_UNIX
void             g_subprocess_set_standard_input_unix_fd (GSubprocess       *self,
							  int                fd);
#endif

void             g_subprocess_set_standard_input_stream (GSubprocess       *self,
							 GInputStream      *input);

void             g_subprocess_set_standard_output_file_path (GSubprocess       *self,
							     const gchar       *file_path);

#ifdef G_OS_UNIX
void             g_subprocess_set_standard_output_unix_fd (GSubprocess       *self,
							   int                fd);
#endif

void             g_subprocess_set_standard_error_file_path (GSubprocess       *self,
							     const gchar       *file_path);

#ifdef G_OS_UNIX
void             g_subprocess_set_standard_error_unix_fd (GSubprocess       *self,
							   int                fd);
#endif

GInputStream    *g_subprocess_get_standard_output (GSubprocess  *self);
GInputStream    *g_subprocess_get_standard_error (GSubprocess  *self);

gboolean         g_subprocess_start (GSubprocess       *self,
				     GCancellable      *cancellable,
				     GError           **error);

GPid             g_subprocess_get_pid (GSubprocess     *self);

gboolean         g_subprocess_await_termination (GSubprocess   *self,
						 gint          *out_exit_code,
						 GCancellable  *cancellable,
						 GError       **error);

gint             g_subprocess_get_exit_code (GSubprocess   *self);

gboolean         g_subprocess_spawn_async_full (const gchar          *working_directory,
						gchar               **argv,
						gchar               **envp,
						GSpawnFlags           flags,
						GSpawnChildSetupFunc  child_setup,
						gpointer              user_data,
						GOutputStream       **standard_input,
						GInputStream        **standard_output,
						GInputStream        **standard_error,
						GCancellable         *cancellable,
						GError              **error);

gboolean         g_subprocess_spawn_sync_utf8_stdout (gchar        **argv,
						      gchar        **out_standard_output,
						      GCancellable  *cancellable,
						      GError       **error);

gboolean         g_subprocess_spawn_sync_utf8 (const gchar          *working_directory,
					       gchar               **argv,
					       gchar               **envp,
					       GSpawnFlags           flags,
					       GSpawnChildSetupFunc  child_setup,
					       gpointer              user_data,
					       GInputStream         *standard_input,                
					       gchar               **out_standard_output,
					       gchar               **out_standard_error,
					       gint                 *out_exit_status,
					       GCancellable         *cancellable,
					       GError              **error);

gboolean         g_subprocess_spawn_sync_bytes (const gchar          *working_directory,
						gchar               **argv,
						gchar               **envp,
						GSpawnFlags           flags,
						GSpawnChildSetupFunc  child_setup,
						gpointer              user_data,
						GInputStream         *standard_input,                
						GBytes              **out_standard_output,
						GBytes              **out_standard_error,
						gint                 *out_exit_status,
						GCancellable         *cancellable,
						GError              **error);

G_END_DECLS

#endif /* __G_SUBPROCESS_H__ */
