2007-06-26 22:51:01 +00:00
|
|
|
/*
|
2012-12-12 16:52:12 +00:00
|
|
|
* virevent.c: event loop for monitoring file handles
|
2007-06-26 22:51:01 +00:00
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Copyright (C) 2007, 2011-2014 Red Hat, Inc.
|
2007-06-26 22:51:01 +00:00
|
|
|
* Copyright (C) 2007 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2007-06-26 22:51:01 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-06-26 22:51:01 +00:00
|
|
|
|
2012-12-12 16:52:12 +00:00
|
|
|
#include "virevent.h"
|
2012-12-12 16:54:55 +00:00
|
|
|
#include "vireventpoll.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2007-06-26 22:51:01 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("util.event");
|
|
|
|
|
2014-10-28 18:38:04 +00:00
|
|
|
static virEventAddHandleFunc addHandleImpl;
|
|
|
|
static virEventUpdateHandleFunc updateHandleImpl;
|
|
|
|
static virEventRemoveHandleFunc removeHandleImpl;
|
|
|
|
static virEventAddTimeoutFunc addTimeoutImpl;
|
|
|
|
static virEventUpdateTimeoutFunc updateTimeoutImpl;
|
|
|
|
static virEventRemoveTimeoutFunc removeTimeoutImpl;
|
2007-06-26 22:51:01 +00:00
|
|
|
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
*
|
|
|
|
* Below this point are *PUBLIC* APIs for event
|
|
|
|
* loop integration with applications using libvirt.
|
|
|
|
* These API contracts cannot be changed.
|
|
|
|
*
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
|
2011-06-15 21:54:30 +00:00
|
|
|
/**
|
2013-02-01 22:50:34 +00:00
|
|
|
* virEventAddHandle:
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
|
|
|
* @fd: file handle to monitor for events
|
|
|
|
* @events: bitset of events to watch from virEventHandleType constants
|
|
|
|
* @cb: callback to invoke when an event occurs
|
|
|
|
* @opaque: user data to pass to callback
|
2013-02-01 22:50:34 +00:00
|
|
|
* @ff: callback to free opaque when handle is removed
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Register a callback for monitoring file handle events. This function
|
|
|
|
* requires that an event loop has previously been registered with
|
|
|
|
* virEventRegisterImpl() or virEventRegisterDefaultImpl().
|
2013-02-01 22:50:34 +00:00
|
|
|
*
|
2013-09-18 18:56:01 +00:00
|
|
|
* Returns -1 if the file handle cannot be registered, otherwise a handle
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* watch number to be used for updating and unregistering for events.
|
2011-06-15 21:54:30 +00:00
|
|
|
*/
|
2013-02-01 22:50:34 +00:00
|
|
|
int
|
|
|
|
virEventAddHandle(int fd,
|
|
|
|
int events,
|
|
|
|
virEventHandleCallback cb,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback ff)
|
|
|
|
{
|
2007-06-26 22:51:01 +00:00
|
|
|
if (!addHandleImpl)
|
|
|
|
return -1;
|
|
|
|
|
2008-11-19 16:24:01 +00:00
|
|
|
return addHandleImpl(fd, events, cb, opaque, ff);
|
2007-06-26 22:51:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 21:54:30 +00:00
|
|
|
/**
|
2013-02-01 22:50:34 +00:00
|
|
|
* virEventUpdateHandle:
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
|
|
|
* @watch: watch whose file handle to update
|
|
|
|
* @events: bitset of events to watch from virEventHandleType constants
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Change event set for a monitored file handle. This function
|
|
|
|
* requires that an event loop has previously been registered with
|
|
|
|
* virEventRegisterImpl() or virEventRegisterDefaultImpl().
|
2013-02-01 22:50:34 +00:00
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Will not fail if fd exists.
|
2011-06-15 21:54:30 +00:00
|
|
|
*/
|
2013-02-01 22:50:34 +00:00
|
|
|
void
|
|
|
|
virEventUpdateHandle(int watch, int events)
|
|
|
|
{
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
if (updateHandleImpl)
|
|
|
|
updateHandleImpl(watch, events);
|
2007-09-19 01:27:32 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 21:54:30 +00:00
|
|
|
/**
|
2013-02-01 22:50:34 +00:00
|
|
|
* virEventRemoveHandle:
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
|
|
|
* @watch: watch whose file handle to remove
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Unregister a callback from a file handle. This function
|
|
|
|
* requires that an event loop has previously been registered with
|
|
|
|
* virEventRegisterImpl() or virEventRegisterDefaultImpl().
|
2013-02-01 22:50:34 +00:00
|
|
|
*
|
|
|
|
* Returns -1 if the file handle was not registered, 0 upon success.
|
2011-06-15 21:54:30 +00:00
|
|
|
*/
|
2013-02-01 22:50:34 +00:00
|
|
|
int
|
|
|
|
virEventRemoveHandle(int watch)
|
|
|
|
{
|
2007-06-26 22:51:01 +00:00
|
|
|
if (!removeHandleImpl)
|
|
|
|
return -1;
|
|
|
|
|
2008-11-19 16:19:36 +00:00
|
|
|
return removeHandleImpl(watch);
|
2007-06-26 22:51:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 21:54:30 +00:00
|
|
|
/**
|
2013-02-01 22:50:34 +00:00
|
|
|
* virEventAddTimeout:
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
2011-06-15 23:35:19 +00:00
|
|
|
* @timeout: time between events in milliseconds
|
2011-06-15 21:54:30 +00:00
|
|
|
* @cb: callback to invoke when an event occurs
|
|
|
|
* @opaque: user data to pass to callback
|
2013-02-01 22:50:34 +00:00
|
|
|
* @ff: callback to free opaque when timeout is removed
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Register a callback for a timer event. This function
|
|
|
|
* requires that an event loop has previously been registered with
|
|
|
|
* virEventRegisterImpl() or virEventRegisterDefaultImpl().
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Setting @timeout to -1 will disable the timer. Setting @timeout
|
2011-06-15 21:54:30 +00:00
|
|
|
* to zero will cause it to fire on every event loop iteration.
|
|
|
|
*
|
2013-02-01 22:50:34 +00:00
|
|
|
* Returns -1 if the timer cannot be registered, a positive
|
|
|
|
* integer timer id upon success.
|
2011-06-15 21:54:30 +00:00
|
|
|
*/
|
2013-02-01 22:50:34 +00:00
|
|
|
int
|
|
|
|
virEventAddTimeout(int timeout,
|
|
|
|
virEventTimeoutCallback cb,
|
|
|
|
void *opaque,
|
|
|
|
virFreeCallback ff)
|
|
|
|
{
|
2007-06-26 22:51:01 +00:00
|
|
|
if (!addTimeoutImpl)
|
|
|
|
return -1;
|
|
|
|
|
2008-11-19 16:24:01 +00:00
|
|
|
return addTimeoutImpl(timeout, cb, opaque, ff);
|
2007-06-26 22:51:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 21:54:30 +00:00
|
|
|
/**
|
2013-02-01 22:50:34 +00:00
|
|
|
* virEventUpdateTimeout:
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
|
|
|
* @timer: timer id to change
|
2013-02-01 22:50:34 +00:00
|
|
|
* @timeout: time between events in milliseconds
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Change frequency for a timer. This function
|
|
|
|
* requires that an event loop has previously been registered with
|
|
|
|
* virEventRegisterImpl() or virEventRegisterDefaultImpl().
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
|
|
|
* Setting frequency to -1 will disable the timer. Setting the frequency
|
|
|
|
* to zero will cause it to fire on every event loop iteration.
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Will not fail if timer exists.
|
2011-06-15 21:54:30 +00:00
|
|
|
*/
|
2013-02-01 22:50:34 +00:00
|
|
|
void
|
|
|
|
virEventUpdateTimeout(int timer, int timeout)
|
|
|
|
{
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
if (updateTimeoutImpl)
|
|
|
|
updateTimeoutImpl(timer, timeout);
|
2007-09-19 01:27:32 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 21:54:30 +00:00
|
|
|
/**
|
2013-02-01 22:50:34 +00:00
|
|
|
* virEventRemoveTimeout:
|
2011-06-15 21:54:30 +00:00
|
|
|
*
|
|
|
|
* @timer: the timer id to remove
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Unregister a callback for a timer. This function
|
|
|
|
* requires that an event loop has previously been registered with
|
|
|
|
* virEventRegisterImpl() or virEventRegisterDefaultImpl().
|
2013-02-01 22:50:34 +00:00
|
|
|
*
|
|
|
|
* Returns -1 if the timer was not registered, 0 upon success.
|
2011-06-15 21:54:30 +00:00
|
|
|
*/
|
2013-02-01 22:50:34 +00:00
|
|
|
int
|
|
|
|
virEventRemoveTimeout(int timer)
|
|
|
|
{
|
2007-06-26 22:51:01 +00:00
|
|
|
if (!removeTimeoutImpl)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return removeTimeoutImpl(timer);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:59:54 +00:00
|
|
|
|
2008-10-23 13:18:18 +00:00
|
|
|
/**
|
|
|
|
* virEventRegisterImpl:
|
|
|
|
* @addHandle: the callback to add fd handles
|
|
|
|
* @updateHandle: the callback to update fd handles
|
|
|
|
* @removeHandle: the callback to remove fd handles
|
|
|
|
* @addTimeout: the callback to add a timeout
|
|
|
|
* @updateTimeout: the callback to update a timeout
|
|
|
|
* @removeTimeout: the callback to remove a timeout
|
2010-10-13 10:19:02 +00:00
|
|
|
*
|
2011-03-02 16:59:54 +00:00
|
|
|
* Registers an event implementation, to allow integration
|
|
|
|
* with an external event loop. Applications would use this
|
|
|
|
* to integrate with the libglib2 event loop, or libevent
|
|
|
|
* or the QT event loop.
|
|
|
|
*
|
2015-09-25 08:54:21 +00:00
|
|
|
* For proper event handling, it is important that the event implementation
|
|
|
|
* is registered before a connection to the Hypervisor is opened.
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Use of the virEventAddHandle() and similar APIs require that the
|
|
|
|
* corresponding handler is registered. Use of the
|
|
|
|
* virConnectDomainEventRegisterAny() and similar APIs requires that
|
|
|
|
* the three timeout handlers are registered. Likewise, the three
|
|
|
|
* timeout handlers must be registered if the remote server has been
|
|
|
|
* configured to send keepalive messages, or if the client intends
|
|
|
|
* to call virConnectSetKeepAlive(), to avoid either side from
|
|
|
|
* unexpectedly closing the connection due to inactivity.
|
|
|
|
*
|
2011-03-02 16:59:54 +00:00
|
|
|
* If an application does not need to integrate with an
|
|
|
|
* existing event loop implementation, then the
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* virEventRegisterDefaultImpl() method can be used to setup
|
2011-03-02 16:59:54 +00:00
|
|
|
* the generic libvirt implementation.
|
2008-10-23 13:18:18 +00:00
|
|
|
*/
|
|
|
|
void virEventRegisterImpl(virEventAddHandleFunc addHandle,
|
|
|
|
virEventUpdateHandleFunc updateHandle,
|
|
|
|
virEventRemoveHandleFunc removeHandle,
|
|
|
|
virEventAddTimeoutFunc addTimeout,
|
|
|
|
virEventUpdateTimeoutFunc updateTimeout,
|
2011-03-02 16:59:54 +00:00
|
|
|
virEventRemoveTimeoutFunc removeTimeout)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("addHandle=%p updateHandle=%p removeHandle=%p "
|
|
|
|
"addTimeout=%p updateTimeout=%p removeTimeout=%p",
|
|
|
|
addHandle, updateHandle, removeHandle,
|
|
|
|
addTimeout, updateTimeout, removeTimeout);
|
|
|
|
|
2007-06-26 22:51:01 +00:00
|
|
|
addHandleImpl = addHandle;
|
2007-09-19 01:27:32 +00:00
|
|
|
updateHandleImpl = updateHandle;
|
2007-06-26 22:51:01 +00:00
|
|
|
removeHandleImpl = removeHandle;
|
|
|
|
addTimeoutImpl = addTimeout;
|
2007-09-19 01:27:32 +00:00
|
|
|
updateTimeoutImpl = updateTimeout;
|
2007-06-26 22:51:01 +00:00
|
|
|
removeTimeoutImpl = removeTimeout;
|
|
|
|
}
|
2011-03-02 16:59:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virEventRegisterDefaultImpl:
|
|
|
|
*
|
|
|
|
* Registers a default event implementation based on the
|
|
|
|
* poll() system call. This is a generic implementation
|
|
|
|
* that can be used by any client application which does
|
|
|
|
* not have a need to integrate with an external event
|
|
|
|
* loop impl.
|
|
|
|
*
|
2015-09-25 08:54:21 +00:00
|
|
|
* For proper event handling, it is important that the event implementation
|
|
|
|
* is registered before a connection to the Hypervisor is opened.
|
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* Once registered, the application has to invoke virEventRunDefaultImpl() in
|
2011-09-22 11:47:07 +00:00
|
|
|
* a loop to process events. Failure to do so may result in connections being
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* closed unexpectedly as a result of keepalive timeout. The default
|
|
|
|
* event loop fully supports handle and timeout events, but only
|
|
|
|
* wakes up on events registered by libvirt API calls such as
|
|
|
|
* virEventAddHandle() or virConnectDomainEventRegisterAny().
|
2011-03-09 03:42:19 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
2011-03-02 16:59:54 +00:00
|
|
|
*/
|
|
|
|
int virEventRegisterDefaultImpl(void)
|
|
|
|
{
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("registering default event implementation");
|
2011-03-02 16:59:54 +00:00
|
|
|
|
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (virEventPollInit() < 0) {
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virEventRegisterImpl(
|
|
|
|
virEventPollAddHandle,
|
|
|
|
virEventPollUpdateHandle,
|
|
|
|
virEventPollRemoveHandle,
|
|
|
|
virEventPollAddTimeout,
|
|
|
|
virEventPollUpdateTimeout,
|
|
|
|
virEventPollRemoveTimeout
|
|
|
|
);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virEventRunDefaultImpl:
|
|
|
|
*
|
|
|
|
* Run one iteration of the event loop. Applications
|
|
|
|
* will generally want to have a thread which invokes
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* this method in an infinite loop. Furthermore, it is wise
|
|
|
|
* to set up a pipe-to-self handler (via virEventAddHandle())
|
|
|
|
* or a timeout (via virEventAddTimeout()) before calling this
|
|
|
|
* function, as it will block forever if there are no
|
|
|
|
* registered events.
|
2011-03-02 16:59:54 +00:00
|
|
|
*
|
2014-10-28 18:38:04 +00:00
|
|
|
* static bool quit;
|
2011-03-02 16:59:54 +00:00
|
|
|
*
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* while (!quit) {
|
|
|
|
* if (virEventRunDefaultImpl() < 0)
|
2011-03-02 16:59:54 +00:00
|
|
|
* ...print error...
|
event: improve public API docs
Since libvirt 0.9.3, the entire virevent.c file has been a public
API, so improve the documentation in this file. Also, fix a
potential core dump - it could only be triggered by bogus use of
the API and would only affect the caller (not libvirtd), but we
might as well be nice.
* src/libvirt.c (virConnectSetKeepAlive)
(virConnectDomainEventRegister, virConnectDomainEventRegisterAny)
(virConnectNetworkEventRegisterAny): Document event loop requirement.
* src/util/virevent.c (virEventAddHandle, virEventRemoveHandle)
(virEventAddTimeout, virEventRemoveTimeout): Likewise.
(virEventUpdateHandle, virEventUpdateTimeout): Likewise, and avoid
core dump if caller didn't register handler.
(virEventRunDefaultImpl): Expand example, and set up code block in
html docs.
(virEventRegisterImpl, virEventRegisterDefaultImpl): Document more
on the use of the event loop.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-31 14:57:17 +00:00
|
|
|
* }
|
2011-03-09 03:42:19 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on failure.
|
2011-03-02 16:59:54 +00:00
|
|
|
*/
|
|
|
|
int virEventRunDefaultImpl(void)
|
|
|
|
{
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("running default event implementation");
|
2011-03-02 16:59:54 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
if (virEventPollRunOnce() < 0) {
|
|
|
|
virDispatchError(NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|