Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 13 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 14 | #include "qemu/event_notifier.h" |
| 15 | #include "qemu/main-loop.h" |
Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 16 | |
| 17 | int event_notifier_init(EventNotifier *e, int active) |
| 18 | { |
Jan Kiszka | e9bff10 | 2012-11-22 20:56:11 +0100 | [diff] [blame] | 19 | e->event = CreateEvent(NULL, TRUE, FALSE, NULL); |
Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 20 | assert(e->event); |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | void event_notifier_cleanup(EventNotifier *e) |
| 25 | { |
| 26 | CloseHandle(e->event); |
| 27 | } |
| 28 | |
| 29 | HANDLE event_notifier_get_handle(EventNotifier *e) |
| 30 | { |
| 31 | return e->event; |
| 32 | } |
| 33 | |
| 34 | int event_notifier_set_handler(EventNotifier *e, |
| 35 | EventNotifierHandler *handler) |
| 36 | { |
| 37 | if (handler) { |
| 38 | return qemu_add_wait_object(e->event, (IOHandler *)handler, e); |
| 39 | } else { |
| 40 | qemu_del_wait_object(e->event, (IOHandler *)handler, e); |
| 41 | return 0; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | int event_notifier_set(EventNotifier *e) |
| 46 | { |
| 47 | SetEvent(e->event); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int event_notifier_test_and_clear(EventNotifier *e) |
| 52 | { |
| 53 | int ret = WaitForSingleObject(e->event, 0); |
| 54 | if (ret == WAIT_OBJECT_0) { |
| 55 | ResetEvent(e->event); |
| 56 | return true; |
| 57 | } |
| 58 | return false; |
| 59 | } |