qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/7] Add support for generic notifier lists
@ 2010-03-10 16:51 Anthony Liguori
  2010-03-10 16:51 ` [Qemu-devel] [PATCH 2/7] Rewrite mouse handlers to use QTAILQ and to have an activation function Anthony Liguori
                   ` (7 more replies)
  0 siblings, 8 replies; 39+ messages in thread
From: Anthony Liguori @ 2010-03-10 16:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Anthony Liguori, Gerd Hoffman, Luiz Capitulino

Notifiers are data-less callbacks and a notifier list is a list of registered
notifiers that all are interested in a particular event.

We'll use this in a few patches to implement mouse change notification.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 Makefile.objs |    1 +
 notify.c      |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 notify.h      |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 notify.c
 create mode 100644 notify.h

diff --git a/Makefile.objs b/Makefile.objs
index e791dd5..dcb5a92 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -104,6 +104,7 @@ common-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 common-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
 common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o
+common-obj-y += notify.o
 
 slirp-obj-y = cksum.o if.o ip_icmp.o ip_input.o ip_output.o
 slirp-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o
diff --git a/notify.c b/notify.c
new file mode 100644
index 0000000..cbb4796
--- /dev/null
+++ b/notify.c
@@ -0,0 +1,53 @@
+/*
+ * Notifier lists
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "notify.h"
+
+void qemu_notifier_list_init(QEMUNotifierList *list)
+{
+    QTAILQ_INIT(&list->notifiers);
+}
+
+void qemu_notifier_list_add(QEMUNotifierList *list, QEMUNotifier *notifier)
+{
+    QEMUNotifierNode *node = qemu_mallocz(sizeof(*node));
+
+    node->notifier = notifier;
+    QTAILQ_INSERT_HEAD(&list->notifiers, node, node);
+}
+
+void qemu_notifier_list_remove(QEMUNotifierList *list, QEMUNotifier *notifier)
+{
+    QEMUNotifierNode *node;
+
+    QTAILQ_FOREACH(node, &list->notifiers, node) {
+        if (node->notifier == notifier) {
+            break;
+        }
+    }
+
+    if (node) {
+        QTAILQ_REMOVE(&list->notifiers, node, node);
+        qemu_free(node);
+    }
+}
+
+void qemu_notifier_list_notify(QEMUNotifierList *list)
+{
+    QEMUNotifierNode *node, *node_next;
+
+    QTAILQ_FOREACH_SAFE(node, &list->notifiers, node, node_next) {
+        node->notifier->notify(node->notifier);
+    }
+}
diff --git a/notify.h b/notify.h
new file mode 100644
index 0000000..075d302
--- /dev/null
+++ b/notify.h
@@ -0,0 +1,49 @@
+/*
+ * Notifier lists
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_NOTIFY_H
+#define QEMU_NOTIFY_H
+
+#include "qemu-queue.h"
+
+typedef struct QEMUNotifier QEMUNotifier;
+typedef struct QEMUNotifierNode QEMUNotifierNode;
+
+struct QEMUNotifier
+{
+    void (*notify)(QEMUNotifier *notifier);
+};
+
+struct QEMUNotifierNode
+{
+    QEMUNotifier *notifier;
+    QTAILQ_ENTRY(QEMUNotifierNode) node;
+};
+
+typedef struct QEMUNotifierList
+{
+    QTAILQ_HEAD(, QEMUNotifierNode) notifiers;
+} QEMUNotifierList;
+
+#define QEMU_NOTIFIER_LIST_INITIALIZER(head) \
+    { QTAILQ_HEAD_INITIALIZER((head).notifiers) }
+
+void qemu_notifier_list_init(QEMUNotifierList *list);
+
+void qemu_notifier_list_add(QEMUNotifierList *list, QEMUNotifier *notifier);
+
+void qemu_notifier_list_remove(QEMUNotifierList *list, QEMUNotifier *notifier);
+
+void qemu_notifier_list_notify(QEMUNotifierList *list);
+
+#endif
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 39+ messages in thread
* [Qemu-devel] [PATCH 1/7] Add support for generic notifier lists (v2)
@ 2010-03-15 20:34 Anthony Liguori
  2010-03-15 20:34 ` [Qemu-devel] [PATCH 3/7] Add kbd_mouse_has_absolute() Anthony Liguori
  0 siblings, 1 reply; 39+ messages in thread
From: Anthony Liguori @ 2010-03-15 20:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Avi Kivity, Anthony Liguori, Gerd Hoffman, Luiz Capitulino

Notifiers are data-less callbacks and a notifier list is a list of registered
notifiers that all are interested in a particular event.

We'll use this in a few patches to implement mouse change notification.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
 - Do not do memory allocations by placing list nodes in notifier
---
 Makefile.objs |    1 +
 notify.c      |   39 +++++++++++++++++++++++++++++++++++++++
 notify.h      |   43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 notify.c
 create mode 100644 notify.h

diff --git a/Makefile.objs b/Makefile.objs
index e791dd5..dcb5a92 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -104,6 +104,7 @@ common-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 common-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
 common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o
+common-obj-y += notify.o
 
 slirp-obj-y = cksum.o if.o ip_icmp.o ip_input.o ip_output.o
 slirp-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o
diff --git a/notify.c b/notify.c
new file mode 100644
index 0000000..bcd3fc5
--- /dev/null
+++ b/notify.c
@@ -0,0 +1,39 @@
+/*
+ * Notifier lists
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "notify.h"
+
+void notifier_list_init(NotifierList *list)
+{
+    QTAILQ_INIT(&list->notifiers);
+}
+
+void notifier_list_add(NotifierList *list, Notifier *notifier)
+{
+    QTAILQ_INSERT_HEAD(&list->notifiers, notifier, node);
+}
+
+void notifier_list_remove(NotifierList *list, Notifier *notifier)
+{
+    QTAILQ_REMOVE(&list->notifiers, notifier, node);
+}
+
+void notifier_list_notify(NotifierList *list)
+{
+    Notifier *notifier, *next;
+
+    QTAILQ_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
+        notifier->notify(notifier);
+    }
+}
diff --git a/notify.h b/notify.h
new file mode 100644
index 0000000..b40522f
--- /dev/null
+++ b/notify.h
@@ -0,0 +1,43 @@
+/*
+ * Notifier lists
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_NOTIFY_H
+#define QEMU_NOTIFY_H
+
+#include "qemu-queue.h"
+
+typedef struct Notifier Notifier;
+
+struct Notifier
+{
+    void (*notify)(Notifier *notifier);
+    QTAILQ_ENTRY(Notifier) node;
+};
+
+typedef struct NotifierList
+{
+    QTAILQ_HEAD(, Notifier) notifiers;
+} NotifierList;
+
+#define NOTIFIER_LIST_INITIALIZER(head) \
+    { QTAILQ_HEAD_INITIALIZER((head).notifiers) }
+
+void notifier_list_init(NotifierList *list);
+
+void notifier_list_add(NotifierList *list, Notifier *notifier);
+
+void notifier_list_remove(NotifierList *list, Notifier *notifier);
+
+void notifier_list_notify(NotifierList *list);
+
+#endif
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2010-03-22 19:39 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-10 16:51 [Qemu-devel] [PATCH 1/7] Add support for generic notifier lists Anthony Liguori
2010-03-10 16:51 ` [Qemu-devel] [PATCH 2/7] Rewrite mouse handlers to use QTAILQ and to have an activation function Anthony Liguori
2010-03-10 16:51 ` [Qemu-devel] [PATCH 3/7] Add kbd_mouse_has_absolute() Anthony Liguori
2010-03-10 16:51 ` [Qemu-devel] [PATCH 4/7] Add notifier for mouse mode changes Anthony Liguori
2010-03-10 16:51 ` [Qemu-devel] [PATCH 5/7] Expose whether a mouse is an absolute device via QMP and the human monitor Anthony Liguori
2010-03-11 14:15   ` [Qemu-devel] " Luiz Capitulino
2010-03-10 16:51 ` [Qemu-devel] [PATCH 6/7] input: make vnc use mouse mode notifiers Anthony Liguori
2010-03-10 22:37   ` [Qemu-devel] " Gerd Hoffmann
2010-03-10 16:51 ` [Qemu-devel] [PATCH 7/7] sdl: use mouse mode notifier Anthony Liguori
2010-03-11 12:57 ` [Qemu-devel] [PATCH 1/7] Add support for generic notifier lists Paul Brook
2010-03-11 13:25   ` [Qemu-devel] " Paolo Bonzini
2010-03-11 13:42     ` Avi Kivity
2010-03-11 14:36       ` Paolo Bonzini
2010-03-11 14:42         ` Avi Kivity
2010-03-11 15:08           ` Anthony Liguori
2010-03-11 13:58     ` Paul Brook
2010-03-11 14:39       ` Paolo Bonzini
2010-03-11 14:11     ` Anthony Liguori
2010-03-11 14:09   ` [Qemu-devel] " Anthony Liguori
2010-03-11 14:19     ` Paul Brook
2010-03-11 14:54       ` Anthony Liguori
2010-03-11 15:19         ` Avi Kivity
2010-03-15 20:31       ` Anthony Liguori
2010-03-15 23:37         ` Anthony Liguori
2010-03-11 13:36 ` Avi Kivity
2010-03-11 14:12   ` Anthony Liguori
2010-03-11 14:48     ` [Qemu-devel] [PATCH] CODING_STYLE: Reserve qemu_ prefix for library wrappers Avi Kivity
2010-03-11 14:55       ` [Qemu-devel] " Anthony Liguori
2010-03-11 23:08         ` Jamie Lokier
2010-03-12 18:47         ` Blue Swirl
2010-03-11 16:19       ` [Qemu-devel] " Markus Armbruster
2010-03-11 23:21       ` [Qemu-devel] " Juan Quintela
2010-03-12  7:58       ` [Qemu-devel] " Aurelien Jarno
2010-03-12 11:28       ` Paul Brook
2010-03-13  2:55       ` Edgar E. Iglesias
2010-03-13  8:17         ` Avi Kivity
2010-03-13 11:11           ` Edgar E. Iglesias
2010-03-22 19:39       ` Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2010-03-15 20:34 [Qemu-devel] [PATCH 1/7] Add support for generic notifier lists (v2) Anthony Liguori
2010-03-15 20:34 ` [Qemu-devel] [PATCH 3/7] Add kbd_mouse_has_absolute() Anthony Liguori

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).