|
@@ -22,22 +22,18 @@
|
|
* THE SOFTWARE.
|
|
* THE SOFTWARE.
|
|
*/
|
|
*/
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/osdep.h"
|
|
-#include "qemu-common.h"
|
|
|
|
#include "qemu/cutils.h"
|
|
#include "qemu/cutils.h"
|
|
#include "monitor/monitor.h"
|
|
#include "monitor/monitor.h"
|
|
#include "sysemu/sysemu.h"
|
|
#include "sysemu/sysemu.h"
|
|
#include "qemu/config-file.h"
|
|
#include "qemu/config-file.h"
|
|
#include "qemu/error-report.h"
|
|
#include "qemu/error-report.h"
|
|
-#include "sysemu/char.h"
|
|
|
|
|
|
+#include "chardev/char.h"
|
|
#include "qmp-commands.h"
|
|
#include "qmp-commands.h"
|
|
#include "qapi-visit.h"
|
|
#include "qapi-visit.h"
|
|
#include "sysemu/replay.h"
|
|
#include "sysemu/replay.h"
|
|
#include "qemu/help_option.h"
|
|
#include "qemu/help_option.h"
|
|
|
|
|
|
-#include "char-mux.h"
|
|
|
|
-#include "char-io.h"
|
|
|
|
-#include "char-parallel.h"
|
|
|
|
-#include "char-serial.h"
|
|
|
|
|
|
+#include "chardev/char-mux.h"
|
|
|
|
|
|
/***********************************************************/
|
|
/***********************************************************/
|
|
/* character device */
|
|
/* character device */
|
|
@@ -70,8 +66,7 @@ void qemu_chr_be_event(Chardev *s, int event)
|
|
|
|
|
|
/* Not reporting errors from writing to logfile, as logs are
|
|
/* Not reporting errors from writing to logfile, as logs are
|
|
* defined to be "best effort" only */
|
|
* defined to be "best effort" only */
|
|
-static void qemu_chr_fe_write_log(Chardev *s,
|
|
|
|
- const uint8_t *buf, size_t len)
|
|
|
|
|
|
+static void qemu_chr_write_log(Chardev *s, const uint8_t *buf, size_t len)
|
|
{
|
|
{
|
|
size_t done = 0;
|
|
size_t done = 0;
|
|
ssize_t ret;
|
|
ssize_t ret;
|
|
@@ -95,8 +90,9 @@ static void qemu_chr_fe_write_log(Chardev *s,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static int qemu_chr_fe_write_buffer(Chardev *s,
|
|
|
|
- const uint8_t *buf, int len, int *offset)
|
|
|
|
|
|
+static int qemu_chr_write_buffer(Chardev *s,
|
|
|
|
+ const uint8_t *buf, int len,
|
|
|
|
+ int *offset, bool write_all)
|
|
{
|
|
{
|
|
ChardevClass *cc = CHARDEV_GET_CLASS(s);
|
|
ChardevClass *cc = CHARDEV_GET_CLASS(s);
|
|
int res = 0;
|
|
int res = 0;
|
|
@@ -106,7 +102,7 @@ static int qemu_chr_fe_write_buffer(Chardev *s,
|
|
while (*offset < len) {
|
|
while (*offset < len) {
|
|
retry:
|
|
retry:
|
|
res = cc->chr_write(s, buf + *offset, len - *offset);
|
|
res = cc->chr_write(s, buf + *offset, len - *offset);
|
|
- if (res < 0 && errno == EAGAIN) {
|
|
|
|
|
|
+ if (res < 0 && errno == EAGAIN && write_all) {
|
|
g_usleep(100);
|
|
g_usleep(100);
|
|
goto retry;
|
|
goto retry;
|
|
}
|
|
}
|
|
@@ -116,68 +112,31 @@ static int qemu_chr_fe_write_buffer(Chardev *s,
|
|
}
|
|
}
|
|
|
|
|
|
*offset += res;
|
|
*offset += res;
|
|
|
|
+ if (!write_all) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (*offset > 0) {
|
|
if (*offset > 0) {
|
|
- qemu_chr_fe_write_log(s, buf, *offset);
|
|
|
|
|
|
+ qemu_chr_write_log(s, buf, *offset);
|
|
}
|
|
}
|
|
qemu_mutex_unlock(&s->chr_write_lock);
|
|
qemu_mutex_unlock(&s->chr_write_lock);
|
|
|
|
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
-static bool qemu_chr_replay(Chardev *chr)
|
|
|
|
-{
|
|
|
|
- return qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
|
|
|
|
-{
|
|
|
|
- Chardev *s = be->chr;
|
|
|
|
- ChardevClass *cc;
|
|
|
|
- int ret;
|
|
|
|
-
|
|
|
|
- if (!s) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
|
|
|
|
- int offset;
|
|
|
|
- replay_char_write_event_load(&ret, &offset);
|
|
|
|
- assert(offset <= len);
|
|
|
|
- qemu_chr_fe_write_buffer(s, buf, offset, &offset);
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- cc = CHARDEV_GET_CLASS(s);
|
|
|
|
- qemu_mutex_lock(&s->chr_write_lock);
|
|
|
|
- ret = cc->chr_write(s, buf, len);
|
|
|
|
-
|
|
|
|
- if (ret > 0) {
|
|
|
|
- qemu_chr_fe_write_log(s, buf, ret);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- qemu_mutex_unlock(&s->chr_write_lock);
|
|
|
|
-
|
|
|
|
- if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
|
|
|
|
- replay_char_write_event_save(ret, ret < 0 ? 0 : ret);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int qemu_chr_write_all(Chardev *s, const uint8_t *buf, int len)
|
|
|
|
|
|
+int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all)
|
|
{
|
|
{
|
|
- int offset;
|
|
|
|
|
|
+ int offset = 0;
|
|
int res;
|
|
int res;
|
|
|
|
|
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
|
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
|
|
replay_char_write_event_load(&res, &offset);
|
|
replay_char_write_event_load(&res, &offset);
|
|
assert(offset <= len);
|
|
assert(offset <= len);
|
|
- qemu_chr_fe_write_buffer(s, buf, offset, &offset);
|
|
|
|
|
|
+ qemu_chr_write_buffer(s, buf, offset, &offset, true);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
- res = qemu_chr_fe_write_buffer(s, buf, len, &offset);
|
|
|
|
|
|
+ res = qemu_chr_write_buffer(s, buf, len, &offset, write_all);
|
|
|
|
|
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
|
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
|
|
replay_char_write_event_save(res, offset);
|
|
replay_char_write_event_save(res, offset);
|
|
@@ -189,78 +148,6 @@ int qemu_chr_write_all(Chardev *s, const uint8_t *buf, int len)
|
|
return offset;
|
|
return offset;
|
|
}
|
|
}
|
|
|
|
|
|
-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_all(s, buf, len);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
|
|
|
|
-{
|
|
|
|
- Chardev *s = be->chr;
|
|
|
|
- int offset = 0, counter = 10;
|
|
|
|
- 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 (!counter--) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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_be_can_write(Chardev *s)
|
|
int qemu_chr_be_can_write(Chardev *s)
|
|
{
|
|
{
|
|
CharBackend *be = s->be;
|
|
CharBackend *be = s->be;
|
|
@@ -293,75 +180,12 @@ void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-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;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int qemu_chr_add_client(Chardev *s, int fd)
|
|
int qemu_chr_add_client(Chardev *s, int fd)
|
|
{
|
|
{
|
|
return CHARDEV_GET_CLASS(s)->chr_add_client ?
|
|
return CHARDEV_GET_CLASS(s)->chr_add_client ?
|
|
CHARDEV_GET_CLASS(s)->chr_add_client(s, fd) : -1;
|
|
CHARDEV_GET_CLASS(s)->chr_add_client(s, fd) : -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);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static void qemu_char_open(Chardev *chr, ChardevBackend *backend,
|
|
static void qemu_char_open(Chardev *chr, ChardevBackend *backend,
|
|
bool *be_opened, Error **errp)
|
|
bool *be_opened, Error **errp)
|
|
{
|
|
{
|
|
@@ -473,40 +297,6 @@ static Notifier muxes_realize_notify = {
|
|
.notify = muxes_realize_done,
|
|
.notify = muxes_realize_done,
|
|
};
|
|
};
|
|
|
|
|
|
-Chardev *qemu_chr_fe_get_driver(CharBackend *be)
|
|
|
|
-{
|
|
|
|
- return be->chr;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
|
|
|
|
-{
|
|
|
|
- int tag = 0;
|
|
|
|
-
|
|
|
|
- if (CHARDEV_IS_MUX(s)) {
|
|
|
|
- MuxChardev *d = MUX_CHARDEV(s);
|
|
|
|
-
|
|
|
|
- if (d->mux_cnt >= MAX_MUX) {
|
|
|
|
- goto unavailable;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- d->backends[d->mux_cnt] = b;
|
|
|
|
- tag = d->mux_cnt++;
|
|
|
|
- } else if (s->be) {
|
|
|
|
- goto unavailable;
|
|
|
|
- } else {
|
|
|
|
- s->be = b;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- b->fe_open = false;
|
|
|
|
- b->tag = tag;
|
|
|
|
- b->chr = s;
|
|
|
|
- return true;
|
|
|
|
-
|
|
|
|
-unavailable:
|
|
|
|
- error_setg(errp, QERR_DEVICE_IN_USE, s->label);
|
|
|
|
- return false;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static bool qemu_chr_is_busy(Chardev *s)
|
|
static bool qemu_chr_is_busy(Chardev *s)
|
|
{
|
|
{
|
|
if (CHARDEV_IS_MUX(s)) {
|
|
if (CHARDEV_IS_MUX(s)) {
|
|
@@ -517,84 +307,6 @@ static bool qemu_chr_is_busy(Chardev *s)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void qemu_chr_fe_deinit(CharBackend *b)
|
|
|
|
-{
|
|
|
|
- assert(b);
|
|
|
|
-
|
|
|
|
- if (b->chr) {
|
|
|
|
- qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, true);
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
- b->chr = NULL;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void qemu_chr_fe_set_handlers(CharBackend *b,
|
|
|
|
- IOCanReadHandler *fd_can_read,
|
|
|
|
- IOReadHandler *fd_read,
|
|
|
|
- IOEventHandler *fd_event,
|
|
|
|
- void *opaque,
|
|
|
|
- GMainContext *context,
|
|
|
|
- bool set_open)
|
|
|
|
-{
|
|
|
|
- Chardev *s;
|
|
|
|
- ChardevClass *cc;
|
|
|
|
- int fe_open;
|
|
|
|
-
|
|
|
|
- s = b->chr;
|
|
|
|
- if (!s) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- cc = CHARDEV_GET_CLASS(s);
|
|
|
|
- if (!opaque && !fd_can_read && !fd_read && !fd_event) {
|
|
|
|
- fe_open = 0;
|
|
|
|
- remove_fd_in_watch(s);
|
|
|
|
- } else {
|
|
|
|
- fe_open = 1;
|
|
|
|
- }
|
|
|
|
- b->chr_can_read = fd_can_read;
|
|
|
|
- b->chr_read = fd_read;
|
|
|
|
- b->chr_event = fd_event;
|
|
|
|
- b->opaque = opaque;
|
|
|
|
- if (cc->chr_update_read_handler) {
|
|
|
|
- cc->chr_update_read_handler(s, context);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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 */
|
|
|
|
- if (s->be_open) {
|
|
|
|
- qemu_chr_be_event(s, CHR_EVENT_OPENED);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (CHARDEV_IS_MUX(s)) {
|
|
|
|
- mux_chr_set_handlers(s, context);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-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_wait_connected(Chardev *chr, Error **errp)
|
|
int qemu_chr_wait_connected(Chardev *chr, Error **errp)
|
|
{
|
|
{
|
|
ChardevClass *cc = CHARDEV_GET_CLASS(chr);
|
|
ChardevClass *cc = CHARDEV_GET_CLASS(chr);
|
|
@@ -606,16 +318,6 @@ int qemu_chr_wait_connected(Chardev *chr, Error **errp)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-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);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
|
|
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
|
|
{
|
|
{
|
|
char host[65], port[33], width[8], height[8];
|
|
char host[65], port[33], width[8], height[8];
|
|
@@ -841,7 +543,7 @@ chardev_name_foreach(void (*fn)(const char *name, void *opaque), void *opaque)
|
|
|
|
|
|
object_class_foreach(chardev_class_foreach, TYPE_CHARDEV, false, &fe);
|
|
object_class_foreach(chardev_class_foreach, TYPE_CHARDEV, false, &fe);
|
|
|
|
|
|
- for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
|
|
|
|
|
|
+ for (i = 0; i < (int)ARRAY_SIZE(chardev_alias_table); i++) {
|
|
fn(chardev_alias_table[i].alias, opaque);
|
|
fn(chardev_alias_table[i].alias, opaque);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -887,7 +589,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
- for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
|
|
|
|
|
|
+ for (i = 0; i < (int)ARRAY_SIZE(chardev_alias_table); i++) {
|
|
if (g_strcmp0(chardev_alias_table[i].alias, name) == 0) {
|
|
if (g_strcmp0(chardev_alias_table[i].alias, name) == 0) {
|
|
name = chardev_alias_table[i].typename;
|
|
name = chardev_alias_table[i].typename;
|
|
break;
|
|
break;
|
|
@@ -992,64 +694,6 @@ Chardev *qemu_chr_new(const char *label, const char *filename)
|
|
return chr;
|
|
return chr;
|
|
}
|
|
}
|
|
|
|
|
|
-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);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void qemu_chr_fe_set_open(CharBackend *be, int fe_open)
|
|
|
|
-{
|
|
|
|
- Chardev *chr = be->chr;
|
|
|
|
-
|
|
|
|
- if (!chr) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (be->fe_open == fe_open) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- be->fe_open = fe_open;
|
|
|
|
- if (CHARDEV_GET_CLASS(chr)->chr_set_fe_open) {
|
|
|
|
- CHARDEV_GET_CLASS(chr)->chr_set_fe_open(chr, fe_open);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,
|
|
|
|
- GIOFunc func, void *user_data)
|
|
|
|
-{
|
|
|
|
- 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);
|
|
|
|
- tag = g_source_attach(src, NULL);
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static int qmp_query_chardev_foreach(Object *obj, void *data)
|
|
static int qmp_query_chardev_foreach(Object *obj, void *data)
|
|
{
|
|
{
|
|
Chardev *chr = CHARDEV(obj);
|
|
Chardev *chr = CHARDEV(obj);
|