BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
sficomwire.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __SFI_COM_WIRE_H__
00003 #define __SFI_COM_WIRE_H__
00004 
00005 #include <sfi/sfitypes.hh>
00006 #include <sfi/sfiring.hh>
00007 
00008 #ifdef __cplusplus
00009 extern "C" {
00010 #endif /* __cplusplus */
00011 
00012 
00013 typedef struct _SfiComWire SfiComWire;
00014 typedef gboolean (*SfiComDispatch)      (gpointer        data,
00015                                          guint           request,
00016                                          const gchar    *request_msg,
00017                                          SfiComWire     *wire);
00018 struct _SfiComWire
00019 {
00020   gchar         *ident;         /* debugging identifier for this connection */
00021   gpointer       owner;         /* ScriptControl object */
00022   guint          connected : 1;
00023   guint          remote_input_broke : 1;
00024   guint          remote_output_broke : 1;
00025   guint          standard_input_broke : 1;
00026   guint          standard_output_broke : 1;
00027   guint          standard_error_broke : 1;
00028 
00029   SfiComDispatch dispatch_func;
00030   gpointer       dispatch_data;
00031   GDestroyNotify destroy_data;
00032 
00033   /* message queues */
00034   GList         *orequests;     /* outgoing requests */
00035   GList         *iresults;      /* incoming results */
00036   GList         *irequests;     /* incoming requests */
00037   GList         *rrequests;     /* received requests */
00038 
00039   /* I/O channels */
00040   gint           remote_input;          /* readable */
00041   gint           remote_output;         /* writable */
00042 
00043   /* spawned child */
00044   gint           standard_input;        /* writable */
00045   gint           standard_output;       /* readable */
00046   gint           standard_error;        /* readable */
00047   gint           remote_pid;
00048   GString       *gstring_stdout;
00049   GString       *gstring_stderr;
00050 
00051   /* input buffer */
00052   guint8        *ibuffer;
00053   guint8        *ibp;
00054   guint8        *ibound;
00055 
00056   /* output buffer */
00057   guint8        *obuffer;
00058   guint8        *obp;
00059   guint8        *obound;
00060 };
00061 
00062 typedef enum /*< skip >*/
00063 {
00064   SFI_COM_MSG_INVALID           = 0,
00065   SFI_COM_MSG_RESERVED1         = 1,
00066   SFI_COM_MSG_RESERVED2         = 2,
00067   SFI_COM_MSG_RESERVED3         = 3,
00068   SFI_COM_MSG_RESERVED4         = 4,
00069   SFI_COM_MSG_REQUEST           = 5,
00070   SFI_COM_MSG_RESULT            = 6
00071 } SfiComMsgType;
00072 #define BSE_MAGIC_BSEm          (0x4253456d)    /* "BSEm" */
00073 typedef struct
00074 {
00075   guint32       magic;          /* "BSEm" 0x4253456d */
00076   guint32       mlength;        /* total length, including magic */
00077   guint32       type;
00078   guint32       request;
00079   gchar        *message;
00080 } SfiComMsg;
00081 
00082 
00083 /* create wires */
00084 SfiComWire*     sfi_com_wire_from_pipe          (const gchar    *ident,
00085                                                  gint            remote_input,
00086                                                  gint            remote_output);
00087 SfiComWire*     sfi_com_wire_from_child         (const gchar    *ident,
00088                                                  gint            remote_input,
00089                                                  gint            remote_output,
00090                                                  gint            standard_input,
00091                                                  gint            standard_output,
00092                                                  gint            standard_error,
00093                                                  gint            remote_pid);
00094 
00095 /* handle outgoing */
00096 guint           sfi_com_wire_send_request       (SfiComWire     *wire,
00097                                                  const gchar    *request_msg);
00098 gchar*          sfi_com_wire_receive_result     (SfiComWire     *wire,
00099                                                  guint           request);
00100 void            sfi_com_wire_forget_request     (SfiComWire     *wire,
00101                                                  guint           request);
00102 guint           sfi_com_wire_peek_first_result  (SfiComWire     *wire);
00103 
00104 /* handle incomming */
00105 const gchar*    sfi_com_wire_receive_request    (SfiComWire     *wire,
00106                                                  guint          *request);
00107 void            sfi_com_wire_send_result        (SfiComWire     *wire,
00108                                                  guint           request,
00109                                                  const gchar    *result_msg);
00110 void            sfi_com_wire_discard_request    (SfiComWire     *wire,
00111                                                  guint           request);
00112 
00113 /* dispatching */
00114 void            sfi_com_wire_set_dispatcher     (SfiComWire     *wire,
00115                                                  SfiComDispatch  dispatch_func,
00116                                                  gpointer        dispatch_data,
00117                                                  GDestroyNotify  destroy_data);
00118 void            sfi_com_wire_dispatch           (SfiComWire     *wire,
00119                                                  guint           request);
00120 gboolean        sfi_com_wire_need_dispatch      (SfiComWire     *wire);
00121 
00122 /* wire I/O */
00123 gint*           sfi_com_wire_get_read_fds       (SfiComWire     *wire,
00124                                                  guint          *n_fds);
00125 gint*           sfi_com_wire_get_write_fds      (SfiComWire     *wire,
00126                                                  guint          *n_fds);
00127 GPollFD*        sfi_com_wire_get_poll_fds       (SfiComWire     *wire,
00128                                                  guint          *n_pfds);
00129 void            sfi_com_wire_process_io         (SfiComWire     *wire);
00130 gchar*          sfi_com_wire_collect_stdout     (SfiComWire     *wire,
00131                                                  guint          *n_chars);
00132 gchar*          sfi_com_wire_collect_stderr     (SfiComWire     *wire,
00133                                                  guint          *n_chars);
00134 
00135 /* shutdown */
00136 void            sfi_com_wire_close_remote       (SfiComWire     *wire,
00137                                                  gboolean        terminate);
00138 void            sfi_com_wire_destroy            (SfiComWire     *wire);
00139 
00140 
00141 /* convenience */
00142 gboolean        sfi_com_wire_receive_dispatch   (SfiComWire     *wire);
00143 void            sfi_com_wire_select             (SfiComWire     *wire,
00144                                                  guint           timeout);
00145 gchar*          sfi_com_wire_ping_pong          (SfiComWire     *wire,
00146                                                  const gchar    *ping,
00147                                                  guint           timeout);
00148 
00149 
00150 /* --- fork/exec --- */
00151 void            sfi_com_set_spawn_dir           (const gchar    *cwd);
00152 const char*     sfi_com_spawn_async             (const gchar    *executable,
00153                                                  gint           *child_pid,
00154                                                  gint           *standard_input,
00155                                                  gint           *standard_output,
00156                                                  gint           *standard_error,
00157                                                  const gchar    *command_fd_option,
00158                                                  gint           *command_input,
00159                                                  gint           *command_output,
00160                                                  SfiRing        *args);
00161 
00162 
00163 #ifdef __cplusplus
00164 }
00165 #endif /* __cplusplus */
00166 
00167 #endif /* __SFI_COM_WIRE_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines