]> Git Repo - qemu.git/blame - include/chardev/char-fe.h
char: move CharBackend handling in char-fe unit
[qemu.git] / include / chardev / char-fe.h
CommitLineData
4d43a603
MAL
1#ifndef QEMU_CHAR_FE_H
2#define QEMU_CHAR_FE_H
3
4#include "chardev/char.h"
5
6typedef void IOEventHandler(void *opaque, int event);
7
8/* This is the backend as seen by frontend, the actual backend is
9 * Chardev */
10struct 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;
18};
19
20/**
21 * @qemu_chr_fe_init:
22 *
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.
26 *
27 * Returns: false on error.
28 */
29bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp);
30
31/**
32 * @qemu_chr_fe_deinit:
33 *
34 * Dissociate the CharBackend from the Chardev.
35 *
36 * Safe to call without associated Chardev.
37 */
38void qemu_chr_fe_deinit(CharBackend *b);
39
40/**
41 * @qemu_chr_fe_get_driver:
42 *
43 * Returns the driver associated with a CharBackend or NULL if no
44 * associated Chardev.
45 */
46Chardev *qemu_chr_fe_get_driver(CharBackend *be);
47
48/**
49 * @qemu_chr_fe_set_handlers:
50 * @b: a CharBackend
51 * @fd_can_read: callback to get the amount of data the frontend may
52 * receive
53 * @fd_read: callback to receive data from char
54 * @fd_event: event callback
55 * @opaque: an opaque pointer for the callbacks
56 * @context: a main loop context or NULL for the default
57 * @set_open: whether to call qemu_chr_fe_set_open() implicitely when
58 * any of the handler is non-NULL
59 *
60 * Set the front end char handlers. The front end takes the focus if
61 * any of the handler is non-NULL.
62 *
63 * Without associated Chardev, nothing is changed.
64 */
65void qemu_chr_fe_set_handlers(CharBackend *b,
66 IOCanReadHandler *fd_can_read,
67 IOReadHandler *fd_read,
68 IOEventHandler *fd_event,
69 void *opaque,
70 GMainContext *context,
71 bool set_open);
72
73/**
74 * @qemu_chr_fe_take_focus:
75 *
76 * Take the focus (if the front end is muxed).
77 *
78 * Without associated Chardev, nothing is changed.
79 */
80void qemu_chr_fe_take_focus(CharBackend *b);
81
82/**
83 * @qemu_chr_fe_accept_input:
84 *
85 * Notify that the frontend is ready to receive data
86 */
87void qemu_chr_fe_accept_input(CharBackend *be);
88
89/**
90 * @qemu_chr_fe_disconnect:
91 *
92 * Close a fd accpeted by character backend.
93 * Without associated Chardev, do nothing.
94 */
95void qemu_chr_fe_disconnect(CharBackend *be);
96
97/**
98 * @qemu_chr_fe_wait_connected:
99 *
100 * Wait for characted backend to be connected, return < 0 on error or
101 * if no assicated Chardev.
102 */
103int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp);
104
105/**
106 * @qemu_chr_fe_set_echo:
107 *
108 * Ask the backend to override its normal echo setting. This only really
109 * applies to the stdio backend and is used by the QMP server such that you
110 * can see what you type if you try to type QMP commands.
111 * Without associated Chardev, do nothing.
112 *
113 * @echo true to enable echo, false to disable echo
114 */
115void qemu_chr_fe_set_echo(CharBackend *be, bool echo);
116
117/**
118 * @qemu_chr_fe_set_open:
119 *
120 * Set character frontend open status. This is an indication that the
121 * front end is ready (or not) to begin doing I/O.
122 * Without associated Chardev, do nothing.
123 */
124void qemu_chr_fe_set_open(CharBackend *be, int fe_open);
125
126/**
127 * @qemu_chr_fe_printf:
128 *
129 * Write to a character backend using a printf style interface. This
130 * function is thread-safe. It does nothing without associated
131 * Chardev.
132 *
133 * @fmt see #printf
134 */
135void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)
136 GCC_FMT_ATTR(2, 3);
137
138/**
139 * @qemu_chr_fe_add_watch:
140 *
141 * If the backend is connected, create and add a #GSource that fires
142 * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP)
143 * is active; return the #GSource's tag. If it is disconnected,
144 * or without associated Chardev, return 0.
145 *
146 * @cond the condition to poll for
147 * @func the function to call when the condition happens
148 * @user_data the opaque pointer to pass to @func
149 *
150 * Returns: the source tag
151 */
152guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,
153 GIOFunc func, void *user_data);
154
155/**
156 * @qemu_chr_fe_write:
157 *
158 * Write data to a character backend from the front end. This function
159 * will send data from the front end to the back end. This function
160 * is thread-safe.
161 *
162 * @buf the data
163 * @len the number of bytes to send
164 *
165 * Returns: the number of bytes consumed (0 if no assicated Chardev)
166 */
167int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len);
168
169/**
170 * @qemu_chr_fe_write_all:
171 *
172 * Write data to a character backend from the front end. This function will
173 * send data from the front end to the back end. Unlike @qemu_chr_fe_write,
174 * this function will block if the back end cannot consume all of the data
175 * attempted to be written. This function is thread-safe.
176 *
177 * @buf the data
178 * @len the number of bytes to send
179 *
180 * Returns: the number of bytes consumed (0 if no assicated Chardev)
181 */
182int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len);
183
184/**
185 * @qemu_chr_fe_read_all:
186 *
187 * Read data to a buffer from the back end.
188 *
189 * @buf the data buffer
190 * @len the number of bytes to read
191 *
192 * Returns: the number of bytes read (0 if no assicated Chardev)
193 */
194int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len);
195
196/**
197 * @qemu_chr_fe_ioctl:
198 *
199 * Issue a device specific ioctl to a backend. This function is thread-safe.
200 *
201 * @cmd see CHR_IOCTL_*
202 * @arg the data associated with @cmd
203 *
204 * Returns: if @cmd is not supported by the backend or there is no
205 * associated Chardev, -ENOTSUP, otherwise the return
206 * value depends on the semantics of @cmd
207 */
208int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg);
209
210/**
211 * @qemu_chr_fe_get_msgfd:
212 *
213 * For backends capable of fd passing, return the latest file descriptor passed
214 * by a client.
215 *
216 * Returns: -1 if fd passing isn't supported or there is no pending file
217 * descriptor. If a file descriptor is returned, subsequent calls to
218 * this function will return -1 until a client sends a new file
219 * descriptor.
220 */
221int qemu_chr_fe_get_msgfd(CharBackend *be);
222
223/**
224 * @qemu_chr_fe_get_msgfds:
225 *
226 * For backends capable of fd passing, return the number of file received
227 * descriptors and fills the fds array up to num elements
228 *
229 * Returns: -1 if fd passing isn't supported or there are no pending file
230 * descriptors. If file descriptors are returned, subsequent calls to
231 * this function will return -1 until a client sends a new set of file
232 * descriptors.
233 */
234int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int num);
235
236/**
237 * @qemu_chr_fe_set_msgfds:
238 *
239 * For backends capable of fd passing, set an array of fds to be passed with
240 * the next send operation.
241 * A subsequent call to this function before calling a write function will
242 * result in overwriting the fd array with the new value without being send.
243 * Upon writing the message the fd array is freed.
244 *
245 * Returns: -1 if fd passing isn't supported or no associated Chardev.
246 */
247int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num);
248
249#endif /* QEMU_CHAR_FE_H */
This page took 0.044176 seconds and 4 git commands to generate.