Skip to content

Commit 2184d30

Browse files
committed
<qemu/notify.h>: update to match upstream.
Change-Id: Id51251e5bf106f479a97b45d1a4825ac524ea703
1 parent 58c33ad commit 2184d30

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

include/qemu/notify.h

+35-6
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,53 @@ typedef struct Notifier Notifier;
2020

2121
struct Notifier
2222
{
23-
void (*notify)(Notifier *notifier);
24-
QTAILQ_ENTRY(Notifier) node;
23+
void (*notify)(Notifier *notifier, void *data);
24+
QLIST_ENTRY(Notifier) node;
2525
};
2626

2727
typedef struct NotifierList
2828
{
29-
QTAILQ_HEAD(, Notifier) notifiers;
29+
QLIST_HEAD(, Notifier) notifiers;
3030
} NotifierList;
3131

3232
#define NOTIFIER_LIST_INITIALIZER(head) \
33-
{ QTAILQ_HEAD_INITIALIZER((head).notifiers) }
33+
{ QLIST_HEAD_INITIALIZER((head).notifiers) }
3434

3535
void notifier_list_init(NotifierList *list);
3636

3737
void notifier_list_add(NotifierList *list, Notifier *notifier);
3838

39-
void notifier_list_remove(NotifierList *list, Notifier *notifier);
39+
void notifier_remove(Notifier *notifier);
4040

41-
void notifier_list_notify(NotifierList *list);
41+
void notifier_list_notify(NotifierList *list, void *data);
42+
43+
/* Same as Notifier but allows .notify() to return errors */
44+
typedef struct NotifierWithReturn NotifierWithReturn;
45+
46+
struct NotifierWithReturn {
47+
/**
48+
* Return 0 on success (next notifier will be invoked), otherwise
49+
* notifier_with_return_list_notify() will stop and return the value.
50+
*/
51+
int (*notify)(NotifierWithReturn *notifier, void *data);
52+
QLIST_ENTRY(NotifierWithReturn) node;
53+
};
54+
55+
typedef struct NotifierWithReturnList {
56+
QLIST_HEAD(, NotifierWithReturn) notifiers;
57+
} NotifierWithReturnList;
58+
59+
#define NOTIFIER_WITH_RETURN_LIST_INITIALIZER(head) \
60+
{ QLIST_HEAD_INITIALIZER((head).notifiers) }
61+
62+
void notifier_with_return_list_init(NotifierWithReturnList *list);
63+
64+
void notifier_with_return_list_add(NotifierWithReturnList *list,
65+
NotifierWithReturn *notifier);
66+
67+
void notifier_with_return_remove(NotifierWithReturn *notifier);
68+
69+
int notifier_with_return_list_notify(NotifierWithReturnList *list,
70+
void *data);
4271

4372
#endif

ui/input.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static void check_mode_change(void)
8080

8181
if (is_absolute != current_is_absolute ||
8282
has_absolute != current_has_absolute) {
83-
notifier_list_notify(&mouse_mode_notifiers);
83+
notifier_list_notify(&mouse_mode_notifiers, NULL);
8484
}
8585

8686
current_is_absolute = is_absolute;
@@ -312,5 +312,5 @@ void qemu_add_mouse_mode_change_notifier(Notifier *notify)
312312

313313
void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
314314
{
315-
notifier_list_remove(&mouse_mode_notifiers, notify);
315+
notifier_remove(notify);
316316
}

util/notify.c

+39-7
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,63 @@
99
* This work is licensed under the terms of the GNU GPL, version 2. See
1010
* the COPYING file in the top-level directory.
1111
*
12+
* Contributions after 2012-01-13 are licensed under the terms of the
13+
* GNU GPL, version 2 or (at your option) any later version.
1214
*/
1315

1416
#include "qemu-common.h"
1517
#include "qemu/notify.h"
1618

1719
void notifier_list_init(NotifierList *list)
1820
{
19-
QTAILQ_INIT(&list->notifiers);
21+
QLIST_INIT(&list->notifiers);
2022
}
2123

2224
void notifier_list_add(NotifierList *list, Notifier *notifier)
2325
{
24-
QTAILQ_INSERT_HEAD(&list->notifiers, notifier, node);
26+
QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
2527
}
2628

27-
void notifier_list_remove(NotifierList *list, Notifier *notifier)
29+
void notifier_remove(Notifier *notifier)
2830
{
29-
QTAILQ_REMOVE(&list->notifiers, notifier, node);
31+
QLIST_REMOVE(notifier, node);
3032
}
3133

32-
void notifier_list_notify(NotifierList *list)
34+
void notifier_list_notify(NotifierList *list, void *data)
3335
{
3436
Notifier *notifier, *next;
3537

36-
QTAILQ_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
37-
notifier->notify(notifier);
38+
QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
39+
notifier->notify(notifier, data);
3840
}
3941
}
42+
43+
void notifier_with_return_list_init(NotifierWithReturnList *list)
44+
{
45+
QLIST_INIT(&list->notifiers);
46+
}
47+
48+
void notifier_with_return_list_add(NotifierWithReturnList *list,
49+
NotifierWithReturn *notifier)
50+
{
51+
QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
52+
}
53+
54+
void notifier_with_return_remove(NotifierWithReturn *notifier)
55+
{
56+
QLIST_REMOVE(notifier, node);
57+
}
58+
59+
int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data)
60+
{
61+
NotifierWithReturn *notifier, *next;
62+
int ret = 0;
63+
64+
QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
65+
ret = notifier->notify(notifier, data);
66+
if (ret != 0) {
67+
break;
68+
}
69+
}
70+
return ret;
71+
}

0 commit comments

Comments
 (0)