target-microblaze: dec_barrel: Plug TCG temp leak
[qemu/ar7.git] / include / chardev / char-fe.h
blob2cbb262f664008ba940eb35a500500e8d6134682
1 #ifndef QEMU_CHAR_FE_H
2 #define QEMU_CHAR_FE_H
4 #include "chardev/char.h"
6 typedef void IOEventHandler(void *opaque, int event);
8 /* This is the backend as seen by frontend, the actual backend is
9 * Chardev */
10 struct CharBackend {
11 Chardev *chr;
12 IOEventHandler *chr_event;
13 IOCanReadHandler *chr_can_read;
14 IOReadHandler *chr_read;
15 void *opaque;
16 int tag;
17 int fe_open;
20 /**
21 * @qemu_chr_fe_init:
23 * Initializes a front end for the given CharBackend and
24 * Chardev. Call qemu_chr_fe_deinit() to remove the association and
25 * release the driver.
27 * Returns: false on error.
29 bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp);
31 /**
32 * @qemu_chr_fe_deinit:
33 * @b: a CharBackend
34 * @del: if true, delete the chardev backend
36 * Dissociate the CharBackend from the Chardev.
38 * Safe to call without associated Chardev.
40 void qemu_chr_fe_deinit(CharBackend *b, bool del);
42 /**
43 * @qemu_chr_fe_get_driver:
45 * Returns the driver associated with a CharBackend or NULL if no
46 * associated Chardev.
48 Chardev *qemu_chr_fe_get_driver(CharBackend *be);
50 /**
51 * @qemu_chr_fe_set_handlers:
52 * @b: a CharBackend
53 * @fd_can_read: callback to get the amount of data the frontend may
54 * receive
55 * @fd_read: callback to receive data from char
56 * @fd_event: event callback
57 * @opaque: an opaque pointer for the callbacks
58 * @context: a main loop context or NULL for the default
59 * @set_open: whether to call qemu_chr_fe_set_open() implicitely when
60 * any of the handler is non-NULL
62 * Set the front end char handlers. The front end takes the focus if
63 * any of the handler is non-NULL.
65 * Without associated Chardev, nothing is changed.
67 void qemu_chr_fe_set_handlers(CharBackend *b,
68 IOCanReadHandler *fd_can_read,
69 IOReadHandler *fd_read,
70 IOEventHandler *fd_event,
71 void *opaque,
72 GMainContext *context,
73 bool set_open);
75 /**
76 * @qemu_chr_fe_take_focus:
78 * Take the focus (if the front end is muxed).
80 * Without associated Chardev, nothing is changed.
82 void qemu_chr_fe_take_focus(CharBackend *b);
84 /**
85 * @qemu_chr_fe_accept_input:
87 * Notify that the frontend is ready to receive data
89 void qemu_chr_fe_accept_input(CharBackend *be);
91 /**
92 * @qemu_chr_fe_disconnect:
94 * Close a fd accpeted by character backend.
95 * Without associated Chardev, do nothing.
97 void qemu_chr_fe_disconnect(CharBackend *be);
99 /**
100 * @qemu_chr_fe_wait_connected:
102 * Wait for characted backend to be connected, return < 0 on error or
103 * if no assicated Chardev.
105 int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp);
108 * @qemu_chr_fe_set_echo:
110 * Ask the backend to override its normal echo setting. This only really
111 * applies to the stdio backend and is used by the QMP server such that you
112 * can see what you type if you try to type QMP commands.
113 * Without associated Chardev, do nothing.
115 * @echo true to enable echo, false to disable echo
117 void qemu_chr_fe_set_echo(CharBackend *be, bool echo);
120 * @qemu_chr_fe_set_open:
122 * Set character frontend open status. This is an indication that the
123 * front end is ready (or not) to begin doing I/O.
124 * Without associated Chardev, do nothing.
126 void qemu_chr_fe_set_open(CharBackend *be, int fe_open);
129 * @qemu_chr_fe_printf:
131 * Write to a character backend using a printf style interface. This
132 * function is thread-safe. It does nothing without associated
133 * Chardev.
135 * @fmt see #printf
137 void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)
138 GCC_FMT_ATTR(2, 3);
141 * @qemu_chr_fe_add_watch:
143 * If the backend is connected, create and add a #GSource that fires
144 * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP)
145 * is active; return the #GSource's tag. If it is disconnected,
146 * or without associated Chardev, return 0.
148 * @cond the condition to poll for
149 * @func the function to call when the condition happens
150 * @user_data the opaque pointer to pass to @func
152 * Returns: the source tag
154 guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,
155 GIOFunc func, void *user_data);
158 * @qemu_chr_fe_write:
160 * Write data to a character backend from the front end. This function
161 * will send data from the front end to the back end. This function
162 * is thread-safe.
164 * @buf the data
165 * @len the number of bytes to send
167 * Returns: the number of bytes consumed (0 if no assicated Chardev)
169 int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);
172 * @qemu_chr_fe_write_all:
174 * Write data to a character backend from the front end. This function will
175 * send data from the front end to the back end. Unlike @qemu_chr_fe_write,
176 * this function will block if the back end cannot consume all of the data
177 * attempted to be written. This function is thread-safe.
179 * @buf the data
180 * @len the number of bytes to send
182 * Returns: the number of bytes consumed (0 if no assicated Chardev)
184 int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);
187 * @qemu_chr_fe_read_all:
189 * Read data to a buffer from the back end.
191 * @buf the data buffer
192 * @len the number of bytes to read
194 * Returns: the number of bytes read (0 if no assicated Chardev)
196 int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len);
199 * @qemu_chr_fe_ioctl:
201 * Issue a device specific ioctl to a backend. This function is thread-safe.
203 * @cmd see CHR_IOCTL_*
204 * @arg the data associated with @cmd
206 * Returns: if @cmd is not supported by the backend or there is no
207 * associated Chardev, -ENOTSUP, otherwise the return
208 * value depends on the semantics of @cmd
210 int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg);
213 * @qemu_chr_fe_get_msgfd:
215 * For backends capable of fd passing, return the latest file descriptor passed
216 * by a client.
218 * Returns: -1 if fd passing isn't supported or there is no pending file
219 * descriptor. If a file descriptor is returned, subsequent calls to
220 * this function will return -1 until a client sends a new file
221 * descriptor.
223 int qemu_chr_fe_get_msgfd(CharBackend *be);
226 * @qemu_chr_fe_get_msgfds:
228 * For backends capable of fd passing, return the number of file received
229 * descriptors and fills the fds array up to num elements
231 * Returns: -1 if fd passing isn't supported or there are no pending file
232 * descriptors. If file descriptors are returned, subsequent calls to
233 * this function will return -1 until a client sends a new set of file
234 * descriptors.
236 int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int num);
239 * @qemu_chr_fe_set_msgfds:
241 * For backends capable of fd passing, set an array of fds to be passed with
242 * the next send operation.
243 * A subsequent call to this function before calling a write function will
244 * result in overwriting the fd array with the new value without being send.
245 * Upon writing the message the fd array is freed.
247 * Returns: -1 if fd passing isn't supported or no associated Chardev.
249 int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num);
251 #endif /* QEMU_CHAR_FE_H */