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 | * |
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. |
14 | */ |
15 | |
16 | #include "qemu/osdep.h" |
17 | #include "qemu/notify.h" |
18 | |
19 | void notifier_list_init(NotifierList *list) |
20 | { |
21 | QLIST_INIT(&list->notifiers); |
22 | } |
23 | |
24 | void notifier_list_add(NotifierList *list, Notifier *notifier) |
25 | { |
26 | QLIST_INSERT_HEAD(&list->notifiers, notifier, node); |
27 | } |
28 | |
29 | void notifier_remove(Notifier *notifier) |
30 | { |
31 | QLIST_REMOVE(notifier, node); |
32 | } |
33 | |
34 | void notifier_list_notify(NotifierList *list, void *data) |
35 | { |
36 | Notifier *notifier, *next; |
37 | |
38 | QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { |
39 | notifier->notify(notifier, data); |
40 | } |
41 | } |
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 | } |
72 | |