]>
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 | * | |
12 | */ | |
13 | ||
14 | #ifndef QEMU_NOTIFY_H | |
15 | #define QEMU_NOTIFY_H | |
16 | ||
1de7afc9 | 17 | #include "qemu/queue.h" |
d1e70c5e AL |
18 | |
19 | typedef struct Notifier Notifier; | |
20 | ||
21 | struct Notifier | |
22 | { | |
9e8dd451 | 23 | void (*notify)(Notifier *notifier, void *data); |
31552529 | 24 | QLIST_ENTRY(Notifier) node; |
d1e70c5e AL |
25 | }; |
26 | ||
27 | typedef struct NotifierList | |
28 | { | |
31552529 | 29 | QLIST_HEAD(, Notifier) notifiers; |
d1e70c5e AL |
30 | } NotifierList; |
31 | ||
32 | #define NOTIFIER_LIST_INITIALIZER(head) \ | |
31552529 | 33 | { QLIST_HEAD_INITIALIZER((head).notifiers) } |
d1e70c5e AL |
34 | |
35 | void notifier_list_init(NotifierList *list); | |
36 | ||
37 | void notifier_list_add(NotifierList *list, Notifier *notifier); | |
38 | ||
31552529 | 39 | void notifier_remove(Notifier *notifier); |
d1e70c5e | 40 | |
9e8dd451 | 41 | void notifier_list_notify(NotifierList *list, void *data); |
d1e70c5e | 42 | |
5dae8e5f SH |
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); | |
71 | ||
d1e70c5e | 72 | #endif |