From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PULL 2/6] Defer BrlAPI tty acquisition to when guest starts using device
Date: Fri, 28 Oct 2016 14:11:34 +0200 [thread overview]
Message-ID: <1477656698-13569-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1477656698-13569-1-git-send-email-kraxel@redhat.com>
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
We do not want to catch the BrlAPI input/ouput immediately, but only
when the guest has started discussing withour virtual device.
This notably fixes input before the guest driver has started.
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
backends/baum.c | 81 ++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 49 insertions(+), 32 deletions(-)
diff --git a/backends/baum.c b/backends/baum.c
index dedc520..b92369d 100644
--- a/backends/baum.c
+++ b/backends/baum.c
@@ -92,6 +92,7 @@ typedef struct {
brlapi_handle_t *brlapi;
int brlapi_fd;
unsigned int x, y;
+ bool deferred_init;
uint8_t in_buf[BUF_SIZE];
uint8_t in_buf_used;
@@ -223,6 +224,49 @@ static const uint8_t nabcc_translation[2][256] = {
DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 1, 0, 0), '_'),
};
+/* The guest OS has started discussing with us, finish initializing BrlAPI */
+static int baum_deferred_init(BaumDriverState *baum)
+{
+#if defined(CONFIG_SDL)
+#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
+ SDL_SysWMinfo info;
+#endif
+#endif
+ int tty;
+
+ if (baum->deferred_init) {
+ return 1;
+ }
+
+ if (brlapi__getDisplaySize(baum->brlapi, &baum->x, &baum->y) == -1) {
+ brlapi_perror("baum: brlapi__getDisplaySize");
+ return 0;
+ }
+
+#if defined(CONFIG_SDL)
+#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
+ memset(&info, 0, sizeof(info));
+ SDL_VERSION(&info.version);
+ if (SDL_GetWMInfo(&info)) {
+ tty = info.info.x11.wmwindow;
+ } else {
+#endif
+#endif
+ tty = BRLAPI_TTY_DEFAULT;
+#if defined(CONFIG_SDL)
+#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
+ }
+#endif
+#endif
+
+ if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) {
+ brlapi_perror("baum: brlapi__enterTtyMode");
+ return 0;
+ }
+ baum->deferred_init = 1;
+ return 1;
+}
+
/* The serial port can receive more of our data */
static void baum_accept_input(struct CharDriverState *chr)
{
@@ -449,6 +493,8 @@ static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
return 0;
if (!baum->brlapi)
return len;
+ if (!baum_deferred_init(baum))
+ return len;
while (len) {
/* Complete our buffer as much as possible */
@@ -500,6 +546,8 @@ static void baum_chr_read(void *opaque)
int ret;
if (!baum->brlapi)
return;
+ if (!baum_deferred_init(baum))
+ return;
while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) {
DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code);
/* Emulate */
@@ -599,12 +647,6 @@ static CharDriverState *chr_baum_init(const char *id,
BaumDriverState *baum;
CharDriverState *chr;
brlapi_handle_t *handle;
-#if defined(CONFIG_SDL)
-#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
- SDL_SysWMinfo info;
-#endif
-#endif
- int tty;
chr = qemu_chr_alloc(common, errp);
if (!chr) {
@@ -627,39 +669,14 @@ static CharDriverState *chr_baum_init(const char *id,
brlapi_strerror(brlapi_error_location()));
goto fail_handle;
}
+ baum->deferred_init = 0;
baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum);
- if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) {
- error_setg(errp, "brlapi__getDisplaySize: %s",
- brlapi_strerror(brlapi_error_location()));
- goto fail;
- }
-
-#if defined(CONFIG_SDL)
-#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
- memset(&info, 0, sizeof(info));
- SDL_VERSION(&info.version);
- if (SDL_GetWMInfo(&info))
- tty = info.info.x11.wmwindow;
- else
-#endif
-#endif
- tty = BRLAPI_TTY_DEFAULT;
-
- if (brlapi__enterTtyMode(handle, tty, NULL) == -1) {
- error_setg(errp, "brlapi__enterTtyMode: %s",
- brlapi_strerror(brlapi_error_location()));
- goto fail;
- }
-
qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
return chr;
-fail:
- timer_free(baum->cellCount_timer);
- brlapi__closeConnection(handle);
fail_handle:
g_free(handle);
g_free(chr);
--
1.8.3.1
next prev parent reply other threads:[~2016-10-28 12:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-28 12:11 [Qemu-devel] [PULL 0/6] ui patch queue Gerd Hoffmann
2016-10-28 12:11 ` [Qemu-devel] [PULL 1/6] Add dots keypresses support to the baum braille device Gerd Hoffmann
2016-10-28 12:11 ` Gerd Hoffmann [this message]
2016-10-28 12:11 ` [Qemu-devel] [PULL 3/6] gtk: fix compilation warning with gtk 3.22.2 Gerd Hoffmann
2016-10-28 12:11 ` [Qemu-devel] [PULL 4/6] ui/gtk: Fix non-working DELETE key Gerd Hoffmann
2016-10-28 12:11 ` [Qemu-devel] [PULL 5/6] curses: fix left/right arrow translation Gerd Hoffmann
2016-10-28 12:11 ` [Qemu-devel] [PULL 6/6] curses: Use cursesw instead of curses Gerd Hoffmann
2016-10-31 11:45 ` Cornelia Huck
2016-10-31 12:01 ` Samuel Thibault
2016-10-31 12:05 ` Samuel Thibault
2016-10-31 12:08 ` Cornelia Huck
2016-10-31 12:16 ` Samuel Thibault
2016-10-31 12:39 ` Samuel Thibault
2016-10-31 12:48 ` Cornelia Huck
2016-10-31 14:03 ` Samuel Thibault
2016-10-31 13:08 ` Cornelia Huck
2016-10-31 15:39 ` Samuel Thibault
2016-11-02 9:09 ` Cornelia Huck
2016-10-28 17:55 ` [Qemu-devel] [PULL 0/6] ui patch queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1477656698-13569-3-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=samuel.thibault@ens-lyon.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).