BEAST - Free Software Audio Synthesizer and Tracker  0.9.2
sficomwire.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __SFI_COM_WIRE_H__
3 #define __SFI_COM_WIRE_H__
4 
5 #include <sfi/sfitypes.hh>
6 #include <sfi/sfiring.hh>
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif /* __cplusplus */
11 
12 
13 typedef struct _SfiComWire SfiComWire;
14 typedef gboolean (*SfiComDispatch) (gpointer data,
15  guint request,
16  const gchar *request_msg,
17  SfiComWire *wire);
19 {
20  gchar *ident; /* debugging identifier for this connection */
21  gpointer owner; /* ScriptControl object */
22  guint connected : 1;
23  guint remote_input_broke : 1;
24  guint remote_output_broke : 1;
25  guint standard_input_broke : 1;
26  guint standard_output_broke : 1;
27  guint standard_error_broke : 1;
28 
29  SfiComDispatch dispatch_func;
30  gpointer dispatch_data;
31  GDestroyNotify destroy_data;
32 
33  /* message queues */
34  GList *orequests; /* outgoing requests */
35  GList *iresults; /* incoming results */
36  GList *irequests; /* incoming requests */
37  GList *rrequests; /* received requests */
38 
39  /* I/O channels */
40  gint remote_input; /* readable */
41  gint remote_output; /* writable */
42 
43  /* spawned child */
44  gint standard_input; /* writable */
45  gint standard_output; /* readable */
46  gint standard_error; /* readable */
47  gint remote_pid;
48  GString *gstring_stdout;
49  GString *gstring_stderr;
50 
51  /* input buffer */
52  guint8 *ibuffer;
53  guint8 *ibp;
54  guint8 *ibound;
55 
56  /* output buffer */
57  guint8 *obuffer;
58  guint8 *obp;
59  guint8 *obound;
60 };
61 
62 typedef enum /*< skip >*/
63 {
64  SFI_COM_MSG_INVALID = 0,
65  SFI_COM_MSG_RESERVED1 = 1,
66  SFI_COM_MSG_RESERVED2 = 2,
67  SFI_COM_MSG_RESERVED3 = 3,
68  SFI_COM_MSG_RESERVED4 = 4,
69  SFI_COM_MSG_REQUEST = 5,
70  SFI_COM_MSG_RESULT = 6
71 } SfiComMsgType;
72 #define BSE_MAGIC_BSEm (0x4253456d) /* "BSEm" */
73 typedef struct
74 {
75  guint32 magic; /* "BSEm" 0x4253456d */
76  guint32 mlength; /* total length, including magic */
77  guint32 type;
78  guint32 request;
79  gchar *message;
80 } SfiComMsg;
81 
82 
83 /* create wires */
84 SfiComWire* sfi_com_wire_from_pipe (const gchar *ident,
85  gint remote_input,
86  gint remote_output);
87 SfiComWire* sfi_com_wire_from_child (const gchar *ident,
88  gint remote_input,
89  gint remote_output,
90  gint standard_input,
91  gint standard_output,
92  gint standard_error,
93  gint remote_pid);
94 
95 /* handle outgoing */
96 guint sfi_com_wire_send_request (SfiComWire *wire,
97  const gchar *request_msg);
98 gchar* sfi_com_wire_receive_result (SfiComWire *wire,
99  guint request);
100 void sfi_com_wire_forget_request (SfiComWire *wire,
101  guint request);
102 guint sfi_com_wire_peek_first_result (SfiComWire *wire);
103 
104 /* handle incomming */
105 const gchar* sfi_com_wire_receive_request (SfiComWire *wire,
106  guint *request);
107 void sfi_com_wire_send_result (SfiComWire *wire,
108  guint request,
109  const gchar *result_msg);
110 void sfi_com_wire_discard_request (SfiComWire *wire,
111  guint request);
112 
113 /* dispatching */
114 void sfi_com_wire_set_dispatcher (SfiComWire *wire,
115  SfiComDispatch dispatch_func,
116  gpointer dispatch_data,
117  GDestroyNotify destroy_data);
118 void sfi_com_wire_dispatch (SfiComWire *wire,
119  guint request);
120 gboolean sfi_com_wire_need_dispatch (SfiComWire *wire);
121 
122 /* wire I/O */
123 gint* sfi_com_wire_get_read_fds (SfiComWire *wire,
124  guint *n_fds);
125 gint* sfi_com_wire_get_write_fds (SfiComWire *wire,
126  guint *n_fds);
127 GPollFD* sfi_com_wire_get_poll_fds (SfiComWire *wire,
128  guint *n_pfds);
129 void sfi_com_wire_process_io (SfiComWire *wire);
130 gchar* sfi_com_wire_collect_stdout (SfiComWire *wire,
131  guint *n_chars);
132 gchar* sfi_com_wire_collect_stderr (SfiComWire *wire,
133  guint *n_chars);
134 
135 /* shutdown */
136 void sfi_com_wire_close_remote (SfiComWire *wire,
137  gboolean terminate);
138 void sfi_com_wire_destroy (SfiComWire *wire);
139 
140 
141 /* convenience */
142 gboolean sfi_com_wire_receive_dispatch (SfiComWire *wire);
143 void sfi_com_wire_select (SfiComWire *wire,
144  guint timeout);
145 gchar* sfi_com_wire_ping_pong (SfiComWire *wire,
146  const gchar *ping,
147  guint timeout);
148 
149 
150 /* --- fork/exec --- */
151 void sfi_com_set_spawn_dir (const gchar *cwd);
152 const char* sfi_com_spawn_async (const gchar *executable,
153  gint *child_pid,
154  gint *standard_input,
155  gint *standard_output,
156  gint *standard_error,
157  const gchar *command_fd_option,
158  gint *command_input,
159  gint *command_output,
160  SfiRing *args);
161 
162 
163 #ifdef __cplusplus
164 }
165 #endif /* __cplusplus */
166 
167 #endif /* __SFI_COM_WIRE_H__ */
Definition: sficomwire.hh:73
Definition: sfiring.hh:23
Definition: sficomwire.hh:18