From patchwork Fri May 7 09:14:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 51916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3D974B7D5E for ; Sat, 8 May 2010 00:03:25 +1000 (EST) Received: from localhost ([127.0.0.1]:51886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OAO9C-0006Op-Hs for incoming@patchwork.ozlabs.org; Fri, 07 May 2010 10:03:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1OANh6-0000uS-Dt for qemu-devel@nongnu.org; Fri, 07 May 2010 09:34:20 -0400 Received: from [140.186.70.92] (port=58451 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OANh1-00041W-9m for qemu-devel@nongnu.org; Fri, 07 May 2010 09:34:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OAJe7-0008WE-Qb for qemu-devel@nongnu.org; Fri, 07 May 2010 05:15:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58712) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OAJe7-0008Vf-IZ for qemu-devel@nongnu.org; Fri, 07 May 2010 05:14:59 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o479Etr6028567 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 7 May 2010 05:14:56 -0400 Received: from zweiblum.home.kraxel.org (vpn1-6-164.ams2.redhat.com [10.36.6.164]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o479EroQ016378; Fri, 7 May 2010 05:14:54 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 30FC812002; Fri, 7 May 2010 11:14:52 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 7 May 2010 11:14:50 +0200 Message-Id: <1273223691-7657-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/2] switch keyboard led state notification to notifiers. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Gerd Hoffmann --- console.h | 11 +++-------- input.c | 37 ++++++++++++++++--------------------- vnc.c | 13 ++++++++----- vnc.h | 2 +- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/console.h b/console.h index 6def115..431410a 100644 --- a/console.h +++ b/console.h @@ -35,12 +35,6 @@ typedef struct QEMUPutMouseEntry { QTAILQ_ENTRY(QEMUPutMouseEntry) node; } QEMUPutMouseEntry; -typedef struct QEMUPutLEDEntry { - QEMUPutLEDEvent *put_led; - void *opaque; - QTAILQ_ENTRY(QEMUPutLEDEntry) next; -} QEMUPutLEDEntry; - void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque); QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque, int absolute, @@ -48,11 +42,12 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry); void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry); -QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque); -void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); +void qemu_add_led_event_notifier(Notifier *notify); +void qemu_remove_led_event_notifier(Notifier *notify); void kbd_put_keycode(int keycode); void kbd_put_ledstate(int ledstate); +int kbd_get_ledstate(void); void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); /* Does the current mouse generate absolute events */ diff --git a/input.c b/input.c index 8f0941e..8f9ca62 100644 --- a/input.c +++ b/input.c @@ -30,11 +30,13 @@ static QEMUPutKBDEvent *qemu_put_kbd_event; static void *qemu_put_kbd_event_opaque; -static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers); static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers = QTAILQ_HEAD_INITIALIZER(mouse_handlers); static NotifierList mouse_mode_notifiers = NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers); +static NotifierList led_event_notifiers = + NOTIFIER_LIST_INITIALIZER(led_event_notifiers); +static int ledstate; void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) { @@ -100,25 +102,14 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) check_mode_change(); } -QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, - void *opaque) +void qemu_add_led_event_notifier(Notifier *notify) { - QEMUPutLEDEntry *s; - - s = qemu_mallocz(sizeof(QEMUPutLEDEntry)); - - s->put_led = func; - s->opaque = opaque; - QTAILQ_INSERT_TAIL(&led_handlers, s, next); - return s; + notifier_list_add(&led_event_notifiers, notify); } -void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry) +void qemu_remove_led_event_notifier(Notifier *notify) { - if (entry == NULL) - return; - QTAILQ_REMOVE(&led_handlers, entry, next); - qemu_free(entry); + notifier_list_remove(&led_event_notifiers, notify); } void kbd_put_keycode(int keycode) @@ -128,15 +119,19 @@ void kbd_put_keycode(int keycode) } } -void kbd_put_ledstate(int ledstate) +void kbd_put_ledstate(int l) { - QEMUPutLEDEntry *cursor; - - QTAILQ_FOREACH(cursor, &led_handlers, next) { - cursor->put_led(cursor->opaque, ledstate); + if (ledstate != l) { + ledstate = l; + notifier_list_notify(&led_event_notifiers); } } +int kbd_get_ledstate(void) +{ + return ledstate; +} + void kbd_mouse_event(int dx, int dy, int dz, int buttons_state) { QEMUPutMouseEntry *entry; diff --git a/vnc.c b/vnc.c index b1a3fdb..e497c70 100644 --- a/vnc.c +++ b/vnc.c @@ -939,7 +939,7 @@ static void vnc_disconnect_finish(VncState *vs) qemu_remove_mouse_mode_change_notifier(&vs->mouse_mode_notifier); vnc_remove_timer(vs->vd); if (vs->vd->lock_key_sync) - qemu_remove_led_event_handler(vs->led); + qemu_remove_led_event_notifier(&vs->led_notifier); qemu_free(vs); } @@ -1332,9 +1332,10 @@ static void press_key(VncState *vs, int keysym) kbd_put_keycode(keycode | SCANCODE_UP); } -static void kbd_leds(void *opaque, int ledstate) +static void kbd_leds(Notifier *notifier) { - VncState *vs = opaque; + VncState *vs = container_of(notifier, VncState, led_notifier); + int ledstate = kbd_get_ledstate(); int caps, num; caps = ledstate & QEMU_CAPS_LOCK_LED ? 1 : 0; @@ -2234,8 +2235,10 @@ static void vnc_connect(VncDisplay *vd, int csock) vnc_flush(vs); vnc_read_when(vs, protocol_version, 12); reset_keys(vs); - if (vs->vd->lock_key_sync) - vs->led = qemu_add_led_event_handler(kbd_leds, vs); + if (vs->vd->lock_key_sync) { + vs->led_notifier.notify = kbd_leds; + qemu_add_led_event_notifier(&vs->led_notifier); + } vs->mouse_mode_notifier.notify = check_pointer_type_change; qemu_add_mouse_mode_change_notifier(&vs->mouse_mode_notifier); diff --git a/vnc.h b/vnc.h index 1aa71b0..7414d0c 100644 --- a/vnc.h +++ b/vnc.h @@ -159,7 +159,7 @@ struct VncState size_t read_handler_expect; /* input */ uint8_t modifiers_state[256]; - QEMUPutLEDEntry *led; + Notifier led_notifier; /* Encoding specific */