]>
Commit | Line | Data |
---|---|---|
d1e70c5e AL |
1 | /* |
2 | * Notifier lists | |
3 | * | |
4 | * Copyright IBM, Corp. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
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" |
d1e70c5e | 17 | #include "qemu-common.h" |
1de7afc9 | 18 | #include "qemu/notify.h" |
d1e70c5e AL |
19 | |
20 | void notifier_list_init(NotifierList *list) | |
21 | { | |
31552529 | 22 | QLIST_INIT(&list->notifiers); |
d1e70c5e AL |
23 | } |
24 | ||
25 | void notifier_list_add(NotifierList *list, Notifier *notifier) | |
26 | { | |
31552529 | 27 | QLIST_INSERT_HEAD(&list->notifiers, notifier, node); |
d1e70c5e AL |
28 | } |
29 | ||
31552529 | 30 | void notifier_remove(Notifier *notifier) |
d1e70c5e | 31 | { |
31552529 | 32 | QLIST_REMOVE(notifier, node); |
d1e70c5e AL |
33 | } |
34 | ||
9e8dd451 | 35 | void notifier_list_notify(NotifierList *list, void *data) |
d1e70c5e AL |
36 | { |
37 | Notifier *notifier, *next; | |
38 | ||
31552529 | 39 | QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { |
9e8dd451 | 40 | notifier->notify(notifier, data); |
d1e70c5e AL |
41 | } |
42 | } | |
5dae8e5f SH |
43 | |
44 | void notifier_with_return_list_init(NotifierWithReturnList *list) | |
45 | { | |
46 | QLIST_INIT(&list->notifiers); | |
47 | } | |
48 | ||
49 | void notifier_with_return_list_add(NotifierWithReturnList *list, | |
50 | NotifierWithReturn *notifier) | |
51 | { | |
52 | QLIST_INSERT_HEAD(&list->notifiers, notifier, node); | |
53 | } | |
54 | ||
55 | void notifier_with_return_remove(NotifierWithReturn *notifier) | |
56 | { | |
57 | QLIST_REMOVE(notifier, node); | |
58 | } | |
59 | ||
60 | int 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 | } |