blob: 06de63a839a15b98b8a2d17c33a17e8f4677ee54 [file] [log] [blame]
Anthony Liguorid1e70c52010-03-09 13:16:14 -06001/*
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 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +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.
Anthony Liguorid1e70c52010-03-09 13:16:14 -060014 */
15
Peter Maydellaafd7582016-01-29 17:49:55 +000016#include "qemu/osdep.h"
Anthony Liguorid1e70c52010-03-09 13:16:14 -060017#include "qemu-common.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010018#include "qemu/notify.h"
Anthony Liguorid1e70c52010-03-09 13:16:14 -060019
20void notifier_list_init(NotifierList *list)
21{
Paolo Bonzini31552522012-01-13 17:34:01 +010022 QLIST_INIT(&list->notifiers);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060023}
24
25void notifier_list_add(NotifierList *list, Notifier *notifier)
26{
Paolo Bonzini31552522012-01-13 17:34:01 +010027 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060028}
29
Paolo Bonzini31552522012-01-13 17:34:01 +010030void notifier_remove(Notifier *notifier)
Anthony Liguorid1e70c52010-03-09 13:16:14 -060031{
Paolo Bonzini31552522012-01-13 17:34:01 +010032 QLIST_REMOVE(notifier, node);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060033}
34
Jan Kiszka9e8dd452011-06-20 14:06:26 +020035void notifier_list_notify(NotifierList *list, void *data)
Anthony Liguorid1e70c52010-03-09 13:16:14 -060036{
37 Notifier *notifier, *next;
38
Paolo Bonzini31552522012-01-13 17:34:01 +010039 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
Jan Kiszka9e8dd452011-06-20 14:06:26 +020040 notifier->notify(notifier, data);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060041 }
42}
Stefan Hajnoczi5dae8e52013-06-24 17:13:09 +020043
44void notifier_with_return_list_init(NotifierWithReturnList *list)
45{
46 QLIST_INIT(&list->notifiers);
47}
48
49void notifier_with_return_list_add(NotifierWithReturnList *list,
50 NotifierWithReturn *notifier)
51{
52 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
53}
54
55void notifier_with_return_remove(NotifierWithReturn *notifier)
56{
57 QLIST_REMOVE(notifier, node);
58}
59
60int 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}