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