Convert daemon/virsh over to use primary event APIs, rather than impl

The daemon code calls virEventAddHandleImpl directly instead
of calling the wrapper virEventAddHandle.

* tools/console.c, daemon/libvirtd.c, daemon/mdns.c: Convert to
  use primary event APIs
This commit is contained in:
Daniel P. Berrange 2011-03-02 15:08:31 +00:00
parent bcb40b852c
commit 5d2c045cd8
3 changed files with 54 additions and 51 deletions

View File

@ -63,6 +63,7 @@
#include "remote_driver.h"
#include "conf.h"
#include "event.h"
#include "src/util/event.h"
#include "memory.h"
#include "stream.h"
#include "hooks.h"
@ -1104,12 +1105,12 @@ static int qemudNetworkEnable(struct qemud_server *server) {
sock = server->sockets;
while (sock) {
if ((sock->watch = virEventAddHandleImpl(sock->fd,
VIR_EVENT_HANDLE_READABLE |
VIR_EVENT_HANDLE_ERROR |
VIR_EVENT_HANDLE_HANGUP,
qemudDispatchServerEvent,
server, NULL)) < 0) {
if ((sock->watch = virEventAddHandle(sock->fd,
VIR_EVENT_HANDLE_READABLE |
VIR_EVENT_HANDLE_ERROR |
VIR_EVENT_HANDLE_HANGUP,
qemudDispatchServerEvent,
server, NULL)) < 0) {
VIR_ERROR0(_("Failed to add server event callback"));
return -1;
}
@ -1541,7 +1542,7 @@ error:
*/
void qemudDispatchClientFailure(struct qemud_client *client) {
if (client->watch != -1) {
virEventRemoveHandleImpl(client->watch);
virEventRemoveHandle(client->watch);
client->watch = -1;
}
@ -2235,10 +2236,10 @@ int qemudRegisterClientEvent(struct qemud_server *server,
mode = qemudCalculateHandleMode(client);
if ((client->watch = virEventAddHandleImpl(client->fd,
mode,
qemudDispatchClientEvent,
server, NULL)) < 0)
if ((client->watch = virEventAddHandle(client->fd,
mode,
qemudDispatchClientEvent,
server, NULL)) < 0)
return -1;
return 0;
@ -2252,7 +2253,7 @@ void qemudUpdateClientEvent(struct qemud_client *client) {
mode = qemudCalculateHandleMode(client);
virEventUpdateHandleImpl(client->watch, mode);
virEventUpdateHandle(client->watch, mode);
}
@ -2304,7 +2305,7 @@ static void qemudInactiveTimer(int timerid, void *data) {
if (virStateActive() ||
server->clients) {
VIR_DEBUG0("Timer expired but still active, not shutting down");
virEventUpdateTimeoutImpl(timerid, -1);
virEventUpdateTimeout(timerid, -1);
} else {
VIR_DEBUG0("Timer expired and inactive, shutting down");
server->quitEventThread = 1;
@ -2347,9 +2348,9 @@ static void *qemudRunLoop(void *opaque) {
virMutexLock(&server->lock);
if (timeout > 0 &&
(timerid = virEventAddTimeoutImpl(-1,
qemudInactiveTimer,
server, NULL)) < 0) {
(timerid = virEventAddTimeout(-1,
qemudInactiveTimer,
server, NULL)) < 0) {
VIR_ERROR0(_("Failed to register shutdown timeout"));
return NULL;
}
@ -2378,14 +2379,14 @@ static void *qemudRunLoop(void *opaque) {
if (timerActive) {
if (server->clients) {
VIR_DEBUG("Deactivating shutdown timer %d", timerid);
virEventUpdateTimeoutImpl(timerid, -1);
virEventUpdateTimeout(timerid, -1);
timerActive = 0;
}
} else {
if (!virStateActive() &&
!server->clients) {
VIR_DEBUG("Activating shutdown timer %d", timerid);
virEventUpdateTimeoutImpl(timerid, timeout * 1000);
virEventUpdateTimeout(timerid, timeout * 1000);
timerActive = 1;
}
}
@ -2501,7 +2502,7 @@ static void qemudCleanup(struct qemud_server *server) {
while (sock) {
struct qemud_socket *next = sock->next;
if (sock->watch)
virEventRemoveHandleImpl(sock->watch);
virEventRemoveHandle(sock->watch);
VIR_FORCE_CLOSE(sock->fd);
/* Unlink unix domain sockets which are not in
@ -3081,10 +3082,10 @@ daemonSetupSignals(struct qemud_server *server)
sig_action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sig_action, NULL);
if (virEventAddHandleImpl(sigpipe[0],
VIR_EVENT_HANDLE_READABLE,
qemudDispatchSignalEvent,
server, NULL) < 0) {
if (virEventAddHandle(sigpipe[0],
VIR_EVENT_HANDLE_READABLE,
qemudDispatchSignalEvent,
server, NULL) < 0) {
VIR_ERROR0(_("Failed to register callback for signal pipe"));
goto error;
}

View File

@ -40,6 +40,7 @@
#include "libvirtd.h"
#include "mdns.h"
#include "event.h"
#include "src/util/event.h"
#include "memory.h"
#define AVAHI_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
@ -257,10 +258,10 @@ static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED
AVAHI_DEBUG("New handle %p FD %d Event %d", w, w->fd, event);
hEvents = virPollEventToEventHandleType(event);
if ((w->watch = virEventAddHandleImpl(fd, hEvents,
libvirtd_mdns_watch_dispatch,
w,
libvirtd_mdns_watch_dofree)) < 0) {
if ((w->watch = virEventAddHandle(fd, hEvents,
libvirtd_mdns_watch_dispatch,
w,
libvirtd_mdns_watch_dofree)) < 0) {
VIR_FREE(w);
return NULL;
}
@ -271,7 +272,7 @@ static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED
static void libvirtd_mdns_watch_update(AvahiWatch *w, AvahiWatchEvent event)
{
AVAHI_DEBUG("Update handle %p FD %d Event %d", w, w->fd, event);
virEventUpdateHandleImpl(w->watch, event);
virEventUpdateHandle(w->watch, event);
}
static AvahiWatchEvent libvirtd_mdns_watch_get_events(AvahiWatch *w)
@ -283,14 +284,14 @@ static AvahiWatchEvent libvirtd_mdns_watch_get_events(AvahiWatch *w)
static void libvirtd_mdns_watch_free(AvahiWatch *w)
{
AVAHI_DEBUG("Free handle %p %d", w, w->fd);
virEventRemoveHandleImpl(w->watch);
virEventRemoveHandle(w->watch);
}
static void libvirtd_mdns_timeout_dispatch(int timer ATTRIBUTE_UNUSED, void *opaque)
{
AvahiTimeout *t = (AvahiTimeout*)opaque;
AVAHI_DEBUG("Dispatch timeout %p %d", t, timer);
virEventUpdateTimeoutImpl(t->timer, -1);
virEventUpdateTimeout(t->timer, -1);
t->callback(t, t->userdata);
}
@ -329,10 +330,10 @@ static AvahiTimeout *libvirtd_mdns_timeout_new(const AvahiPoll *api ATTRIBUTE_UN
timeout = -1;
}
t->timer = virEventAddTimeoutImpl(timeout,
libvirtd_mdns_timeout_dispatch,
t,
libvirtd_mdns_timeout_dofree);
t->timer = virEventAddTimeout(timeout,
libvirtd_mdns_timeout_dispatch,
t,
libvirtd_mdns_timeout_dofree);
t->callback = cb;
t->userdata = userdata;
@ -364,13 +365,13 @@ static void libvirtd_mdns_timeout_update(AvahiTimeout *t, const struct timeval *
timeout = -1;
}
virEventUpdateTimeoutImpl(t->timer, timeout);
virEventUpdateTimeout(t->timer, timeout);
}
static void libvirtd_mdns_timeout_free(AvahiTimeout *t)
{
AVAHI_DEBUG("Free timeout %p", t);
virEventRemoveTimeoutImpl(t->timer);
virEventRemoveTimeout(t->timer);
}

View File

@ -44,6 +44,7 @@
# include "virterror_internal.h"
# include "daemon/event.h"
# include "src/util/event.h"
/* ie Ctrl-] as per telnet */
# define CTRL_CLOSE_BRACKET '\35'
@ -93,9 +94,9 @@ virConsoleShutdown(virConsolePtr con)
con->quit = true;
virStreamEventRemoveCallback(con->st);
if (con->stdinWatch != -1)
virEventRemoveHandleImpl(con->stdinWatch);
virEventRemoveHandle(con->stdinWatch);
if (con->stdinWatch != -1)
virEventRemoveHandleImpl(con->stdoutWatch);
virEventRemoveHandle(con->stdoutWatch);
con->stdinWatch = -1;
con->stdoutWatch = -1;
}
@ -134,8 +135,8 @@ virConsoleEventOnStream(virStreamPtr st,
}
con->streamToTerminal.offset += got;
if (con->streamToTerminal.offset)
virEventUpdateHandleImpl(con->stdoutWatch,
VIR_EVENT_HANDLE_WRITABLE);
virEventUpdateHandle(con->stdoutWatch,
VIR_EVENT_HANDLE_WRITABLE);
}
if (events & VIR_STREAM_EVENT_WRITABLE &&
@ -266,7 +267,7 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED,
}
if (!con->streamToTerminal.offset)
virEventUpdateHandleImpl(con->stdoutWatch, 0);
virEventUpdateHandle(con->stdoutWatch, 0);
if (events & VIR_EVENT_HANDLE_ERROR ||
events & VIR_EVENT_HANDLE_HANGUP) {
@ -331,16 +332,16 @@ int vshRunConsole(virDomainPtr dom, const char *devname)
if (virDomainOpenConsole(dom, devname, con->st, 0) < 0)
goto cleanup;
con->stdinWatch = virEventAddHandleImpl(STDIN_FILENO,
VIR_EVENT_HANDLE_READABLE,
virConsoleEventOnStdin,
con,
NULL);
con->stdoutWatch = virEventAddHandleImpl(STDOUT_FILENO,
0,
virConsoleEventOnStdout,
con,
NULL);
con->stdinWatch = virEventAddHandle(STDIN_FILENO,
VIR_EVENT_HANDLE_READABLE,
virConsoleEventOnStdin,
con,
NULL);
con->stdoutWatch = virEventAddHandle(STDOUT_FILENO,
0,
virConsoleEventOnStdout,
con,
NULL);
virStreamEventAddCallback(con->st,
VIR_STREAM_EVENT_READABLE,