Patchwork [RESENT,1/2] switch keyboard led state notification to notifiers.

login
register
mail settings
Submitter Gerd Hoffmann
Date June 14, 2010, 3:18 p.m.
Message ID <1276528722-14745-1-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/55550/
State New
Headers show

Comments

Gerd Hoffmann - June 14, 2010, 3:18 p.m.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 console.h |   11 +++--------
 input.c   |   37 ++++++++++++++++---------------------
 vnc.c     |   13 ++++++++-----
 vnc.h     |    2 +-
 4 files changed, 28 insertions(+), 35 deletions(-)

Patch

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 */