1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "qemu/osdep.h"
17#include "qemu-common.h"
18#include "qemu/notify.h"
19
20void notifier_list_init(NotifierList *list)
21{
22 QLIST_INIT(&list->notifiers);
23}
24
25void notifier_list_add(NotifierList *list, Notifier *notifier)
26{
27 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
28}
29
30void notifier_remove(Notifier *notifier)
31{
32 QLIST_REMOVE(notifier, node);
33}
34
35void notifier_list_notify(NotifierList *list, void *data)
36{
37 Notifier *notifier, *next;
38
39 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
40 notifier->notify(notifier, data);
41 }
42}
43
44void notifier_with_return_list_init(NotifierWithReturnList *list)
45{
46 QLIST_INIT(&list->notifiers);
47}
48
49void notifier_with_return_list_add(NotifierWithReturnList *list,
50 NotifierWithReturn *notifier)
51{
52 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
53}
54
55void notifier_with_return_remove(NotifierWithReturn *notifier)
56{
57 QLIST_REMOVE(notifier, node);
58}
59
60int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data)
61{
62 NotifierWithReturn *notifier, *next;
63 int ret = 0;
64
65 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
66 ret = notifier->notify(notifier, data);
67 if (ret != 0) {
68 break;
69 }
70 }
71 return ret;
72}
73