vireventpoll.h 3.7 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
#pragma once
D
Daniel P. Berrange 已提交
23

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

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

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

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

/**
61
 * virEventPollAddTimeout: register a callback for a timer event
D
Daniel P. Berrange 已提交
62
 *
63
 * @frequency: time between events in milliseconds
64
 * @cb: callback to invoke when an event occurs
D
Daniel P. Berrange 已提交
65 66
 * @opaque: user data to pass to callback
 *
67 68 69
 * 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 已提交
70 71 72
 * returns -1 if the file handle cannot be registered, a positive
 * integer timer id upon success
 */
73
int virEventPollAddTimeout(int frequency,
O
Osier Yang 已提交
74 75 76
                           virEventTimeoutCallback cb,
                           void *opaque,
                           virFreeCallback ff);
77 78

/**
79
 * virEventPollUpdateTimeout: change frequency for a timer
80 81 82 83 84 85 86 87 88
 *
 * @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
 */
89
void virEventPollUpdateTimeout(int timer, int frequency);
D
Daniel P. Berrange 已提交
90 91

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

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

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

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


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