Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
sficomport.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_PORT_H__
3 #define __SFI_COM_PORT_H__
4 
5 #include <sfi/sfitypes.hh>
6 #include <sfi/sfiring.hh>
7 
8 #define SFI_COM_PORT_MAGIC (0x42534500 /* "BSE\0" */)
9 
10 struct SfiComPort;
11 struct SfiComPortLink;
12 typedef void (*SfiComPortClosedFunc) (SfiComPort *port, void *close_data);
13 
14 struct SfiComPort {
15  gchar *ident;
16  guint ref_count;
17  GPollFD pfd[2]; /* 0 = remote in, 1 = remote out */
18  guint connected : 1;
19  guint reaped : 1;
20  guint sigterm_sent : 1;
21  guint sigkill_sent : 1;
22  guint exit_signal_sent : 1;
23  guint dumped_core : 1;
24  SfiComPortLink *link;
25  struct {
26  guint n;
27  guint8 *data;
28  guint allocated;
29  } wbuffer; /* output buffer */
30  struct {
31  guint hlen;
32  guint8 header[8];
33  guint dlen;
34  guint n;
35  guint8 *data;
36  guint allocated;
37  } rbuffer; /* input buffer */
38  SfiRing *rvalues;
39  GScanner *scanner;
40  SfiComPortClosedFunc close_func;
41  gpointer close_data;
42  gint remote_pid;
43  gint exit_code;
44  gint exit_signal;
45 };
46 
48 {
49  Bse::Mutex mutex;
50  guint ref_count;
51  SfiComPort *port1;
52  std::function<void()> wakeup1;
53  SfiComPort *port2;
54  std::function<void()> wakeup2;
55  SfiRing *p1queue;
56  SfiRing *p2queue;
57  Bse::Cond wcond;
58  bool waiting;
59 };
60 
61 /* create ports */
62 SfiComPort* sfi_com_port_from_pipe (const gchar *ident,
63  gint remote_input,
64  gint remote_output);
65 SfiComPort* sfi_com_port_from_child (const gchar *ident,
66  gint remote_input,
67  gint remote_output,
68  gint remote_pid);
69 /* create linked ports */
70 void sfi_com_port_create_linked (const gchar *ident1,
71  std::function<void()> wakeup1,
72  SfiComPort **port1,
73  const gchar *ident2,
74  std::function<void()> wakeup2,
75  SfiComPort **port2);
76 SfiComPort* sfi_com_port_ref (SfiComPort *port);
77 void sfi_com_port_unref (SfiComPort *port);
78 
79 /* remote I/O */
80 void sfi_com_port_send (SfiComPort *port,
81  const GValue *value);
82 void sfi_com_port_send_bulk (SfiComPort *port,
83  SfiRing *value_ring);
84 GValue* sfi_com_port_recv (SfiComPort *port);
85 GValue* sfi_com_port_recv_blocking (SfiComPort *port);
86 
87 /* I/O handling */
88 GPollFD* sfi_com_port_get_poll_fds (SfiComPort *port,
89  guint *n_pfds);
90 gboolean sfi_com_port_io_pending (SfiComPort *port);
91 void sfi_com_port_process_io (SfiComPort *port);
92 
93 
94 /* shutdown */
95 void sfi_com_port_set_close_func (SfiComPort *port,
96  SfiComPortClosedFunc func,
97  gpointer close_data);
98 void sfi_com_port_close_remote (SfiComPort *port,
99  gboolean terminate_child);
100 void sfi_com_port_reap_child (SfiComPort *port,
101  gboolean kill_child);
102 gboolean sfi_com_port_test_reap_child (SfiComPort *port);
103 
104 #endif /* __SFI_COM_PORT_H__ */
Definition: sficomport.hh:14
Definition: sfiring.hh:21