#ifndef _ECORE_EXE_EO_H_
#define _ECORE_EXE_EO_H_

#ifndef _ECORE_EXE_EO_CLASS_TYPE
#define _ECORE_EXE_EO_CLASS_TYPE

typedef Eo Ecore_Exe;

#endif

#ifndef _ECORE_EXE_EO_TYPES
#define _ECORE_EXE_EO_TYPES

/** A structure that stores information of lines data from a child process.
 *
 * @ingroup Ecore_Exe_Event_Data
 */
typedef struct _Ecore_Exe_Event_Data_Line
{
  char *line; /** The bytes of a line of buffered data */
  int size; /** The size of the line buffer in bytes */
} Ecore_Exe_Event_Data_Line;

typedef struct _Ecore_Exe_Event_Data
{
  Eo_Base *exe; /** The handle to the process. FIXME: should actually be
                 * Ecore.Exe, workaround cyclic */
  void *data; /** the raw binary data from the child process that was received
               */
  int size; /** the size of this data in bytes */
  Ecore_Exe_Event_Data_Line *lines; /** an array of line data if line buffered,
                                     * the last one has it's line member set to
                                     * @c NULL */
} Ecore_Exe_Event_Data;

/** Flags for executing a child with its stdin and/or stdout piped back.
 *
 * @ingroup Ecore
 */
typedef enum
{
  ECORE_EXE_NONE = 0, /** No exe flags at all */
  ECORE_EXE_PIPE_READ = 1 /* 0 */, /** Exe Pipe Read mask */
  ECORE_EXE_PIPE_WRITE = 2 /* 0 */, /** Exe Pipe Write mask */
  ECORE_EXE_PIPE_ERROR = 4 /* 0 */, /** Exe Pipe error mask */
  ECORE_EXE_PIPE_READ_LINE_BUFFERED = 8 /* 0 */, /** Reads are buffered until a
                                                  * newline and split 1 line
                                                  * per
                                                  * Ecore_Exe_Event_Data_Line
                                                  */
  ECORE_EXE_PIPE_ERROR_LINE_BUFFERED = 16 /* 0 */, /** Errors are buffered
                                                    * until a newline and split
                                                    * 1 line per
                                                    * Ecore_Exe_Event_Data_Line
                                                    */
  ECORE_EXE_PIPE_AUTO = 32 /* 0 */, /** stdout and stderr are buffered
                                     * automatically */
  ECORE_EXE_RESPAWN = 64 /* 0 */, /** FIXME: Exe is restarted if it dies */
  ECORE_EXE_USE_SH = 128 /* 0 */, /** Use /bin/sh to run the command. */
  ECORE_EXE_NOT_LEADER = 256 /* 0 */, /** Do not use setsid() to have the
                                       * executed process be its own session
                                       * leader */
  ECORE_EXE_TERM_WITH_PARENT = 512 /* 0 */ /** Makes child receive SIGTERM when
                                            * parent dies. */
} Ecore_Exe_Flags;


#endif
/**
 * @brief Ecore.Exe is responsible for managing portable process spawning.
 *
 * With this module you are able to spawn, pause and quit the spawned
 * processes. An interaction between your process and those spawned is possible
 * using pipes or signals.
 *
 * @ingroup Ecore_Exe
 */
#define ECORE_EXE_CLASS ecore_exe_class_get()

EWAPI const Eo_Class *ecore_exe_class_get(void);

/**
 * @brief Control the command that's executed. FIXME: May need a split/rename.
 *
 * @param[in] exe_cmd The command to execute.
 * @param[in] flags The execution flags.
 *
 * @ingroup Ecore_Exe
 */
EOAPI void ecore_obj_exe_command_set(Eo *obj, const char *exe_cmd, Ecore_Exe_Flags flags);

/**
 * @brief Control the command that's executed. FIXME: May need a split/rename.
 *
 * @param[out] exe_cmd The command to execute.
 * @param[out] flags The execution flags.
 *
 * @ingroup Ecore_Exe
 */
EOAPI void ecore_obj_exe_command_get(const Eo *obj, const char **exe_cmd, Ecore_Exe_Flags *flags);

EOAPI extern const Eo_Event_Description _ECORE_EXE_EVENT_DATA_GET;
EOAPI extern const Eo_Event_Description _ECORE_EXE_EVENT_DATA_ERROR;

/** Data received event from the child process
 *
 * @ingroup Ecore_Exe
 */
#define ECORE_EXE_EVENT_DATA_GET (&(_ECORE_EXE_EVENT_DATA_GET))

/** Error received event from the child process
 *
 * @ingroup Ecore_Exe
 */
#define ECORE_EXE_EVENT_DATA_ERROR (&(_ECORE_EXE_EVENT_DATA_ERROR))

#endif
