]>
Commit | Line | Data |
---|---|---|
d1e70c5e AL |
1 | /* |
2 | * Notifier lists | |
3 | * | |
4 | * Copyright IBM, Corp. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <aliguori@us.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
6b620ca3 PB |
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. | |
d1e70c5e AL |
14 | */ |
15 | ||
aafd7584 | 16 | #include "qemu/osdep.h" |
1de7afc9 | 17 | #include "qemu/notify.h" |
d1e70c5e AL |
18 | |
19 | void notifier_list_init(NotifierList *list) | |
20 | { | |
31552529 | 21 | QLIST_INIT(&list->notifiers); |
d1e70c5e AL |
22 | } |
23 | ||
24 | void notifier_list_add(NotifierList *list, Notifier *notifier) | |
25 | { | |
31552529 | 26 | QLIST_INSERT_HEAD(&list->notifiers, notifier, node); |
d1e70c5e AL |
27 | } |
28 | ||
31552529 | 29 | void notifier_remove(Notifier *notifier) |
d1e70c5e | 30 | { |
31552529 | 31 | QLIST_REMOVE(notifier, node); |
d1e70c5e AL |
32 | } |
33 | ||
9e8dd451 | 34 | void notifier_list_notify(NotifierList *list, void *data) |
d1e70c5e AL |
35 | { |
36 | Notifier *notifier, *next; | |
37 | ||
31552529 | 38 | QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { |
9e8dd451 | 39 | notifier->notify(notifier, data); |
d1e70c5e AL |
40 | } |
41 | } | |
5dae8e5f | 42 | |
374752a2 PD |
43 | bool notifier_list_empty(NotifierList *list) |
44 | { | |
45 | return QLIST_EMPTY(&list->notifiers); | |
46 | } | |
47 | ||
5dae8e5f SH |
48 | void notifier_with_return_list_init(NotifierWithReturnList *list) |
49 | { | |
50 | QLIST_INIT(&list->notifiers); | |
51 | } | |
52 | ||
53 | void notifier_with_return_list_add(NotifierWithReturnList *list, | |
54 | NotifierWithReturn *notifier) | |
55 | { | |
56 | QLIST_INSERT_HEAD(&list->notifiers, notifier, node); | |
57 | } | |
58 | ||
59 | void notifier_with_return_remove(NotifierWithReturn *notifier) | |
60 | { | |
61 | QLIST_REMOVE(notifier, node); | |
62 | } | |
63 | ||
64 | int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data) | |
65 | { | |
66 | NotifierWithReturn *notifier, *next; | |
67 | int ret = 0; | |
68 | ||
69 | QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { | |
70 | ret = notifier->notify(notifier, data); | |
71 | if (ret != 0) { | |
72 | break; | |
73 | } | |
74 | } | |
75 | return ret; | |
76 | } |