vireventpoll.h 3.8 KB
Newer Older
D
Daniel P. Berrange 已提交
1
/*
2
 * vireventpoll.h: Poll based event loop for monitoring file handles
D
Daniel P. Berrange 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Copyright (C) 2007 Daniel P. Berrange
 * Copyright (C) 2007 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
D
Daniel P. Berrange 已提交
20 21
 */

22 23
#ifndef LIBVIRT_VIREVENTPOLL_H
# define LIBVIRT_VIREVENTPOLL_H
D
Daniel P. Berrange 已提交
24

25
# include "internal.h"
D
Daniel P. Berrange 已提交
26 27

/**
28
 * virEventPollAddHandle: register a callback for monitoring file handle events
D
Daniel P. Berrange 已提交
29 30
 *
 * @fd: file handle to monitor for events
31 32
 * @events: bitset of events to watch from POLLnnn constants
 * @cb: callback to invoke when an event occurs
D
Daniel P. Berrange 已提交
33 34 35 36
 * @opaque: user data to pass to callback
 *
 * returns -1 if the file handle cannot be registered, 0 upon success
 */
37
int virEventPollAddHandle(int fd, int events,
O
Osier Yang 已提交
38 39 40
                          virEventHandleCallback cb,
                          void *opaque,
                          virFreeCallback ff);
D
Daniel P. Berrange 已提交
41

42
/**
43
 * virEventPollUpdateHandle: change event set for a monitored file handle
44
 *
45
 * @watch: watch whose handle to update
46
 * @events: bitset of events to watch from POLLnnn constants
47 48 49
 *
 * Will not fail if fd exists
 */
50
void virEventPollUpdateHandle(int watch, int events);
51

D
Daniel P. Berrange 已提交
52
/**
53
 * virEventPollRemoveHandle: unregister a callback from a file handle
D
Daniel P. Berrange 已提交
54
 *
55
 * @watch: watch whose handle to remove
D
Daniel P. Berrange 已提交
56 57 58
 *
 * returns -1 if the file handle was not registered, 0 upon success
 */
59
int virEventPollRemoveHandle(int watch);
D
Daniel P. Berrange 已提交
60 61

/**
62
 * virEventPollAddTimeout: register a callback for a timer event
D
Daniel P. Berrange 已提交
63
 *
64
 * @frequency: time between events in milliseconds
65
 * @cb: callback to invoke when an event occurs
D
Daniel P. Berrange 已提交
66 67
 * @opaque: user data to pass to callback
 *
68 69 70
 * Setting frequency to -1 will disable the timer. Setting the frequency
 * to zero will cause it to fire on every event loop iteration.
 *
D
Daniel P. Berrange 已提交
71 72 73
 * returns -1 if the file handle cannot be registered, a positive
 * integer timer id upon success
 */
74
int virEventPollAddTimeout(int frequency,
O
Osier Yang 已提交
75 76 77
                           virEventTimeoutCallback cb,
                           void *opaque,
                           virFreeCallback ff);
78 79

/**
80
 * virEventPollUpdateTimeout: change frequency for a timer
81 82 83 84 85 86 87 88 89
 *
 * @timer: timer id to change
 * @frequency: time between events in milliseconds
 *
 * Setting frequency to -1 will disable the timer. Setting the frequency
 * to zero will cause it to fire on every event loop iteration.
 *
 * Will not fail if timer exists
 */
90
void virEventPollUpdateTimeout(int timer, int frequency);
D
Daniel P. Berrange 已提交
91 92

/**
93
 * virEventPollRemoveTimeout: unregister a callback for a timer
D
Daniel P. Berrange 已提交
94 95 96 97 98
 *
 * @timer: the timer id to remove
 *
 * returns -1 if the timer was not registered, 0 upon success
 */
99
int virEventPollRemoveTimeout(int timer);
D
Daniel P. Berrange 已提交
100

101
/**
102
 * virEventPollInit: Initialize the event loop
103 104 105
 *
 * returns -1 if initialization failed
 */
106
int virEventPollInit(void);
107

D
Daniel P. Berrange 已提交
108
/**
109
 * virEventPollRunOnce: run a single iteration of the event loop.
D
Daniel P. Berrange 已提交
110 111 112 113 114 115
 *
 * Blocks the caller until at least one file handle has an
 * event or the first timer expires.
 *
 * returns -1 if the event monitoring failed
 */
116
int virEventPollRunOnce(void);
D
Daniel P. Berrange 已提交
117

118 119
int virEventPollFromNativeEvents(int events);
int virEventPollToNativeEvents(int events);
120 121


122
/**
123
 * virEventPollInterrupt: wakeup any thread waiting in poll()
124
 *
C
Chen Hanxiao 已提交
125
 * return -1 if wakeup failed
126
 */
127
int virEventPollInterrupt(void);
128

129

130
#endif /* LIBVIRT_VIREVENTPOLL_H */