blob: 14b4f7d2c04c0a9f2d5011ae86f93b502ac8204b [file] [log] [blame]
Paolo Bonzinifc97a652010-05-24 17:26:13 +02001/*
2 * event notifier support
3 *
4 * Copyright Red Hat, Inc. 2010
5 *
6 * Authors:
7 * Michael S. Tsirkin <mst@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12
Peter Maydellaafd7582016-01-29 17:49:55 +000013#include "qemu/osdep.h"
Paolo Bonzinifc97a652010-05-24 17:26:13 +020014#include "qemu-common.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010015#include "qemu/event_notifier.h"
16#include "qemu/main-loop.h"
Paolo Bonzinifc97a652010-05-24 17:26:13 +020017
18int event_notifier_init(EventNotifier *e, int active)
19{
Jan Kiszkae9bff102012-11-22 20:56:11 +010020 e->event = CreateEvent(NULL, TRUE, FALSE, NULL);
Paolo Bonzinifc97a652010-05-24 17:26:13 +020021 assert(e->event);
22 return 0;
23}
24
25void event_notifier_cleanup(EventNotifier *e)
26{
27 CloseHandle(e->event);
28}
29
30HANDLE event_notifier_get_handle(EventNotifier *e)
31{
32 return e->event;
33}
34
35int event_notifier_set_handler(EventNotifier *e,
36 EventNotifierHandler *handler)
37{
38 if (handler) {
39 return qemu_add_wait_object(e->event, (IOHandler *)handler, e);
40 } else {
41 qemu_del_wait_object(e->event, (IOHandler *)handler, e);
42 return 0;
43 }
44}
45
46int event_notifier_set(EventNotifier *e)
47{
48 SetEvent(e->event);
49 return 0;
50}
51
52int event_notifier_test_and_clear(EventNotifier *e)
53{
54 int ret = WaitForSingleObject(e->event, 0);
55 if (ret == WAIT_OBJECT_0) {
56 ResetEvent(e->event);
57 return true;
58 }
59 return false;
60}