BEAST/BSE - Better Audio System and Sound Engine
0.8.2
|
00001 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html 00002 #ifndef __SFI_COM_PORT_H__ 00003 #define __SFI_COM_PORT_H__ 00004 00005 #include <sfi/sfitypes.hh> 00006 #include <sfi/sfiring.hh> 00007 00008 G_BEGIN_DECLS 00009 00010 #define SFI_COM_PORT_MAGIC (0x42534500 /* "BSE\0" */) 00011 00012 struct SfiComPort; 00013 struct SfiComPortLink; 00014 typedef void (*SfiComPortClosedFunc) (SfiComPort *port, void *close_data); 00015 00016 struct SfiComPort { 00017 gchar *ident; 00018 guint ref_count; 00019 GPollFD pfd[2]; /* 0 = remote in, 1 = remote out */ 00020 guint connected : 1; 00021 guint reaped : 1; 00022 guint sigterm_sent : 1; 00023 guint sigkill_sent : 1; 00024 guint exit_signal_sent : 1; 00025 guint dumped_core : 1; 00026 SfiComPortLink *link; 00027 struct { 00028 guint n; 00029 guint8 *data; 00030 guint allocated; 00031 } wbuffer; /* output buffer */ 00032 struct { 00033 guint hlen; 00034 guint8 header[8]; 00035 guint dlen; 00036 guint n; 00037 guint8 *data; 00038 guint allocated; 00039 } rbuffer; /* input buffer */ 00040 SfiRing *rvalues; 00041 GScanner *scanner; 00042 SfiComPortClosedFunc close_func; 00043 gpointer close_data; 00044 gint remote_pid; 00045 gint exit_code; 00046 gint exit_signal; 00047 }; 00048 00049 struct SfiComPortLink 00050 { 00051 Bse::Mutex mutex; 00052 guint ref_count; 00053 SfiComPort *port1; 00054 std::function<void()> wakeup1; 00055 SfiComPort *port2; 00056 std::function<void()> wakeup2; 00057 SfiRing *p1queue; 00058 SfiRing *p2queue; 00059 Bse::Cond wcond; 00060 bool waiting; 00061 }; 00062 00063 /* create ports */ 00064 SfiComPort* sfi_com_port_from_pipe (const gchar *ident, 00065 gint remote_input, 00066 gint remote_output); 00067 SfiComPort* sfi_com_port_from_child (const gchar *ident, 00068 gint remote_input, 00069 gint remote_output, 00070 gint remote_pid); 00071 /* create linked ports */ 00072 void sfi_com_port_create_linked (const gchar *ident1, 00073 std::function<void()> wakeup1, 00074 SfiComPort **port1, 00075 const gchar *ident2, 00076 std::function<void()> wakeup2, 00077 SfiComPort **port2); 00078 SfiComPort* sfi_com_port_ref (SfiComPort *port); 00079 void sfi_com_port_unref (SfiComPort *port); 00080 00081 /* remote I/O */ 00082 void sfi_com_port_send (SfiComPort *port, 00083 const GValue *value); 00084 void sfi_com_port_send_bulk (SfiComPort *port, 00085 SfiRing *value_ring); 00086 GValue* sfi_com_port_recv (SfiComPort *port); 00087 GValue* sfi_com_port_recv_blocking (SfiComPort *port); 00088 00089 /* I/O handling */ 00090 GPollFD* sfi_com_port_get_poll_fds (SfiComPort *port, 00091 guint *n_pfds); 00092 gboolean sfi_com_port_io_pending (SfiComPort *port); 00093 void sfi_com_port_process_io (SfiComPort *port); 00094 00095 00096 /* shutdown */ 00097 void sfi_com_port_set_close_func (SfiComPort *port, 00098 SfiComPortClosedFunc func, 00099 gpointer close_data); 00100 void sfi_com_port_close_remote (SfiComPort *port, 00101 gboolean terminate_child); 00102 void sfi_com_port_reap_child (SfiComPort *port, 00103 gboolean kill_child); 00104 gboolean sfi_com_port_test_reap_child (SfiComPort *port); 00105 00106 G_END_DECLS 00107 00108 #endif /* __SFI_COM_PORT_H__ */