| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * QEMU System Emulator | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2003-2008 Fabrice Bellard | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-04-01 17:36:23 +02:00
										 |  |  | #define HW_POISON_H /* avoid poison since we patch against rules it "enforces" */
 | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							|  |  |  | #include "qemu/error-report.h"
 | 
					
						
							|  |  |  | #include "qapi/error.h"
 | 
					
						
							|  |  |  | #include "sysemu/replay.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "chardev/char-fe.h"
 | 
					
						
							|  |  |  | #include "chardev/char-io.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-23 22:21:09 +02:00
										 |  |  | #include "chardev-internal.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s) { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return qemu_chr_write(s, buf, len, false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s) { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return qemu_chr_write(s, buf, len, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							| 
									
										
										
										
											2018-06-14 17:51:41 +02:00
										 |  |  |     int offset = 0; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s || !CHARDEV_GET_CLASS(s)->chr_sync_read) { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) { | 
					
						
							|  |  |  |         return replay_char_read_all_load(buf); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (offset < len) { | 
					
						
							|  |  |  |     retry: | 
					
						
							|  |  |  |         res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset, | 
					
						
							|  |  |  |                                                   len - offset); | 
					
						
							|  |  |  |         if (res == -1 && errno == EAGAIN) { | 
					
						
							|  |  |  |             g_usleep(100); | 
					
						
							|  |  |  |             goto retry; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (res == 0) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (res < 0) { | 
					
						
							|  |  |  |             if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) { | 
					
						
							|  |  |  |                 replay_char_read_all_save_error(res); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return res; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         offset += res; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) { | 
					
						
							|  |  |  |         replay_char_read_all_save_buf(buf, offset); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  |     int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s || !CHARDEV_GET_CLASS(s)->chr_ioctl || qemu_chr_replay(s)) { | 
					
						
							|  |  |  |         res = -ENOTSUP; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         res = CHARDEV_GET_CLASS(s)->chr_ioctl(s, cmd, arg); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_get_msgfd(CharBackend *be) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  |     int fd; | 
					
						
							|  |  |  |     int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1; | 
					
						
							|  |  |  |     if (s && qemu_chr_replay(s)) { | 
					
						
							|  |  |  |         error_report("Replay: get msgfd is not supported " | 
					
						
							|  |  |  |                      "for serial devices yet"); | 
					
						
							|  |  |  |         exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s) { | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return CHARDEV_GET_CLASS(s)->get_msgfds ? | 
					
						
							|  |  |  |         CHARDEV_GET_CLASS(s)->get_msgfds(s, fds, len) : -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s) { | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return CHARDEV_GET_CLASS(s)->set_msgfds ? | 
					
						
							|  |  |  |         CHARDEV_GET_CLASS(s)->set_msgfds(s, fds, num) : -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qemu_chr_fe_accept_input(CharBackend *be) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (CHARDEV_GET_CLASS(s)->chr_accept_input) { | 
					
						
							|  |  |  |         CHARDEV_GET_CLASS(s)->chr_accept_input(s); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     qemu_notify_event(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     char buf[CHR_READ_BUF_LEN]; | 
					
						
							|  |  |  |     va_list ap; | 
					
						
							|  |  |  |     va_start(ap, fmt); | 
					
						
							|  |  |  |     vsnprintf(buf, sizeof(buf), fmt, ap); | 
					
						
							|  |  |  |     /* XXX this blocks entire thread. Rewrite to use
 | 
					
						
							|  |  |  |      * qemu_chr_fe_write and background I/O callbacks */ | 
					
						
							|  |  |  |     qemu_chr_fe_write_all(be, (uint8_t *)buf, strlen(buf)); | 
					
						
							|  |  |  |     va_end(ap); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Chardev *qemu_chr_fe_get_driver(CharBackend *be) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:51 +03:00
										 |  |  |     /* this is unsafe for the users that support chardev hotswap */ | 
					
						
							|  |  |  |     assert(be->chr_be_change == NULL); | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     return be->chr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:51 +03:00
										 |  |  | bool qemu_chr_fe_backend_connected(CharBackend *be) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return !!be->chr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:52 +03:00
										 |  |  | bool qemu_chr_fe_backend_open(CharBackend *be) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return be->chr && be->chr->be_open; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int tag = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-23 15:29:48 +00:00
										 |  |  |     if (s) { | 
					
						
							|  |  |  |         if (CHARDEV_IS_MUX(s)) { | 
					
						
							|  |  |  |             MuxChardev *d = MUX_CHARDEV(s); | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-23 15:29:48 +00:00
										 |  |  |             if (d->mux_cnt >= MAX_MUX) { | 
					
						
							| 
									
										
										
										
											2024-03-06 09:15:05 +01:00
										 |  |  |                 error_setg(errp, | 
					
						
							|  |  |  |                            "too many uses of multiplexed chardev '%s'" | 
					
						
							|  |  |  |                            " (maximum is " stringify(MAX_MUX) ")", | 
					
						
							|  |  |  |                            s->label); | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2018-03-23 15:29:48 +00:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             d->backends[d->mux_cnt] = b; | 
					
						
							|  |  |  |             tag = d->mux_cnt++; | 
					
						
							|  |  |  |         } else if (s->be) { | 
					
						
							| 
									
										
										
										
											2024-03-06 09:15:05 +01:00
										 |  |  |             error_setg(errp, "chardev '%s' is already in use", s->label); | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2018-03-23 15:29:48 +00:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             s->be = b; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  |     b->fe_is_open = false; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     b->tag = tag; | 
					
						
							|  |  |  |     b->chr = s; | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-27 00:49:13 +04:00
										 |  |  | void qemu_chr_fe_deinit(CharBackend *b, bool del) | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | { | 
					
						
							|  |  |  |     assert(b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (b->chr) { | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:49 +03:00
										 |  |  |         qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, NULL, true); | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |         if (b->chr->be == b) { | 
					
						
							|  |  |  |             b->chr->be = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (CHARDEV_IS_MUX(b->chr)) { | 
					
						
							|  |  |  |             MuxChardev *d = MUX_CHARDEV(b->chr); | 
					
						
							|  |  |  |             d->backends[b->tag] = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-27 00:49:13 +04:00
										 |  |  |         if (del) { | 
					
						
							| 
									
										
										
										
											2018-07-11 20:00:19 +02:00
										 |  |  |             Object *obj = OBJECT(b->chr); | 
					
						
							|  |  |  |             if (obj->parent) { | 
					
						
							|  |  |  |                 object_unparent(obj); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 object_unref(obj); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-01-27 00:49:13 +04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |         b->chr = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 18:40:51 +06:00
										 |  |  | void qemu_chr_fe_set_handlers_full(CharBackend *b, | 
					
						
							|  |  |  |                                    IOCanReadHandler *fd_can_read, | 
					
						
							|  |  |  |                                    IOReadHandler *fd_read, | 
					
						
							|  |  |  |                                    IOEventHandler *fd_event, | 
					
						
							|  |  |  |                                    BackendChangeHandler *be_change, | 
					
						
							|  |  |  |                                    void *opaque, | 
					
						
							|  |  |  |                                    GMainContext *context, | 
					
						
							|  |  |  |                                    bool set_open, | 
					
						
							|  |  |  |                                    bool sync_state) | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | { | 
					
						
							|  |  |  |     Chardev *s; | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  |     bool fe_open; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     s = b->chr; | 
					
						
							|  |  |  |     if (!s) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!opaque && !fd_can_read && !fd_read && !fd_event) { | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  |         fe_open = false; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |         remove_fd_in_watch(s); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  |         fe_open = true; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     } | 
					
						
							|  |  |  |     b->chr_can_read = fd_can_read; | 
					
						
							|  |  |  |     b->chr_read = fd_read; | 
					
						
							|  |  |  |     b->chr_event = fd_event; | 
					
						
							| 
									
										
										
										
											2017-07-06 15:08:49 +03:00
										 |  |  |     b->chr_be_change = be_change; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     b->opaque = opaque; | 
					
						
							| 
									
										
										
										
											2017-09-21 14:35:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     qemu_chr_be_update_read_handlers(s, context); | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (set_open) { | 
					
						
							|  |  |  |         qemu_chr_fe_set_open(b, fe_open); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (fe_open) { | 
					
						
							|  |  |  |         qemu_chr_fe_take_focus(b); | 
					
						
							|  |  |  |         /* We're connecting to an already opened device, so let's make sure we
 | 
					
						
							|  |  |  |            also get the open event */ | 
					
						
							| 
									
										
										
										
											2018-11-06 18:40:51 +06:00
										 |  |  |         if (sync_state && s->be_open) { | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |             qemu_chr_be_event(s, CHR_EVENT_OPENED); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 18:40:51 +06:00
										 |  |  | void qemu_chr_fe_set_handlers(CharBackend *b, | 
					
						
							|  |  |  |                               IOCanReadHandler *fd_can_read, | 
					
						
							|  |  |  |                               IOReadHandler *fd_read, | 
					
						
							|  |  |  |                               IOEventHandler *fd_event, | 
					
						
							|  |  |  |                               BackendChangeHandler *be_change, | 
					
						
							|  |  |  |                               void *opaque, | 
					
						
							|  |  |  |                               GMainContext *context, | 
					
						
							|  |  |  |                               bool set_open) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     qemu_chr_fe_set_handlers_full(b, fd_can_read, fd_read, fd_event, be_change, | 
					
						
							|  |  |  |                                   opaque, context, set_open, | 
					
						
							|  |  |  |                                   true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | void qemu_chr_fe_take_focus(CharBackend *b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!b->chr) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (CHARDEV_IS_MUX(b->chr)) { | 
					
						
							|  |  |  |         mux_set_focus(b->chr, b->tag); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!be->chr) { | 
					
						
							|  |  |  |         error_setg(errp, "missing associated backend"); | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return qemu_chr_wait_connected(be->chr, errp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qemu_chr_fe_set_echo(CharBackend *be, bool echo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *chr = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (chr && CHARDEV_GET_CLASS(chr)->chr_set_echo) { | 
					
						
							|  |  |  |         CHARDEV_GET_CLASS(chr)->chr_set_echo(chr, echo); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  | void qemu_chr_fe_set_open(CharBackend *be, bool is_open) | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | { | 
					
						
							|  |  |  |     Chardev *chr = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!chr) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  |     if (be->fe_is_open == is_open) { | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  |     be->fe_is_open = is_open; | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     if (CHARDEV_GET_CLASS(chr)->chr_set_fe_open) { | 
					
						
							| 
									
										
										
										
											2023-12-11 14:59:59 +00:00
										 |  |  |         CHARDEV_GET_CLASS(chr)->chr_set_fe_open(chr, is_open); | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, | 
					
						
							| 
									
										
										
										
											2021-08-04 17:01:14 +04:00
										 |  |  |                             FEWatchFunc func, void *user_data) | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  | { | 
					
						
							|  |  |  |     Chardev *s = be->chr; | 
					
						
							|  |  |  |     GSource *src; | 
					
						
							|  |  |  |     guint tag; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s || CHARDEV_GET_CLASS(s)->chr_add_watch == NULL) { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     src = CHARDEV_GET_CLASS(s)->chr_add_watch(s, cond); | 
					
						
							|  |  |  |     if (!src) { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     g_source_set_callback(src, (GSourceFunc)func, user_data, NULL); | 
					
						
							| 
									
										
										
										
											2018-01-04 22:18:33 +08:00
										 |  |  |     tag = g_source_attach(src, s->gcontext); | 
					
						
							| 
									
										
										
										
											2017-01-26 18:26:44 +04:00
										 |  |  |     g_source_unref(src); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return tag; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void qemu_chr_fe_disconnect(CharBackend *be) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Chardev *chr = be->chr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (chr && CHARDEV_GET_CLASS(chr)->chr_disconnect) { | 
					
						
							|  |  |  |         CHARDEV_GET_CLASS(chr)->chr_disconnect(chr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |