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