From patchwork Mon Jun 14 15:18:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 55550 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 53162B7D69 for ; Tue, 15 Jun 2010 01:20:26 +1000 (EST) Received: from localhost ([127.0.0.1]:36356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOBSZ-000143-30 for incoming@patchwork.ozlabs.org; Mon, 14 Jun 2010 11:20:23 -0400 Received: from [140.186.70.92] (port=60167 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOBR6-00013K-Sz for qemu-devel@nongnu.org; Mon, 14 Jun 2010 11:18:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOBR4-0005yp-Fo for qemu-devel@nongnu.org; Mon, 14 Jun 2010 11:18:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64169) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOBR4-0005yV-99 for qemu-devel@nongnu.org; Mon, 14 Jun 2010 11:18:50 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5EFIm2L014355 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 14 Jun 2010 11:18:48 -0400 Received: from rincewind.home.kraxel.org (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5EFIjTr013520; Mon, 14 Jun 2010 11:18:47 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 29EA641629; Mon, 14 Jun 2010 17:18:43 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 14 Jun 2010 17:18:41 +0200 Message-Id: <1276528722-14745-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [RESENT 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 cac959f..171b32c 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 651442d..af178d9 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 ed0e096..b25b6a1 100644 --- a/vnc.c +++ b/vnc.c @@ -988,7 +988,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); } @@ -1381,9 +1381,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; @@ -2296,8 +2297,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 7b64cf7..9336952 100644 --- a/vnc.h +++ b/vnc.h @@ -165,7 +165,7 @@ struct VncState size_t read_handler_expect; /* input */ uint8_t modifiers_state[256]; - QEMUPutLEDEntry *led; + Notifier led_notifier; /* Encoding specific */