blob: f215dfc2142d230ce155e9c1970ee199efb1c779 [file] [log] [blame]
David Turner025c32f2010-09-10 14:52:42 +02001/*
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 *
David 'Digit' Turner2184d302014-01-13 14:42:19 +010012 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
David Turner025c32f2010-09-10 14:52:42 +020014 */
15
16#include "qemu-common.h"
David 'Digit' Turnere90d6652013-12-14 14:55:12 +010017#include "qemu/notify.h"
David Turner025c32f2010-09-10 14:52:42 +020018
19void notifier_list_init(NotifierList *list)
20{
David 'Digit' Turner2184d302014-01-13 14:42:19 +010021 QLIST_INIT(&list->notifiers);
David Turner025c32f2010-09-10 14:52:42 +020022}
23
24void notifier_list_add(NotifierList *list, Notifier *notifier)
25{
David 'Digit' Turner2184d302014-01-13 14:42:19 +010026 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
David Turner025c32f2010-09-10 14:52:42 +020027}
28
David 'Digit' Turner2184d302014-01-13 14:42:19 +010029void notifier_remove(Notifier *notifier)
David Turner025c32f2010-09-10 14:52:42 +020030{
David 'Digit' Turner2184d302014-01-13 14:42:19 +010031 QLIST_REMOVE(notifier, node);
David Turner025c32f2010-09-10 14:52:42 +020032}
33
David 'Digit' Turner2184d302014-01-13 14:42:19 +010034void notifier_list_notify(NotifierList *list, void *data)
David Turner025c32f2010-09-10 14:52:42 +020035{
36 Notifier *notifier, *next;
37
David 'Digit' Turner2184d302014-01-13 14:42:19 +010038 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
39 notifier->notify(notifier, data);
David Turner025c32f2010-09-10 14:52:42 +020040 }
41}
David 'Digit' Turner2184d302014-01-13 14:42:19 +010042
43void notifier_with_return_list_init(NotifierWithReturnList *list)
44{
45 QLIST_INIT(&list->notifiers);
46}
47
48void notifier_with_return_list_add(NotifierWithReturnList *list,
49 NotifierWithReturn *notifier)
50{
51 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
52}
53
54void notifier_with_return_remove(NotifierWithReturn *notifier)
55{
56 QLIST_REMOVE(notifier, node);
57}
58
59int 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}