mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Fix the example code for event handling in C
* examples/domain-events/events-c/event-test.c: fixed the example code for event handling, patch by Pritesh Kothari daniel
This commit is contained in:
parent
107a7bd06b
commit
a76e46044d
@ -1,3 +1,8 @@
|
|||||||
|
Mon May 25 11:42:15 CEST 2009 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* examples/domain-events/events-c/event-test.c: fixed the example
|
||||||
|
code for event handling, patch by Pritesh Kothari
|
||||||
|
|
||||||
Thu May 21 15:22:22 BST 2009 Daniel P. Berrange <berrange@redhat.com>
|
Thu May 21 15:22:22 BST 2009 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
Test case for QEMU driver ARGV -> XML conversion
|
Test case for QEMU driver ARGV -> XML conversion
|
||||||
|
@ -116,7 +116,7 @@ static const char *eventDetailToString(int event, int detail) {
|
|||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_EVENT_SUSPENDED:
|
case VIR_DOMAIN_EVENT_SUSPENDED:
|
||||||
if (detail == VIR_DOMAIN_EVENT_SUSPENDED_PAUSED)
|
if (detail == VIR_DOMAIN_EVENT_SUSPENDED_PAUSED)
|
||||||
ret = "Unpaused";
|
ret = "Paused";
|
||||||
else if (detail == VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED)
|
else if (detail == VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED)
|
||||||
ret = "Migrated";
|
ret = "Migrated";
|
||||||
break;
|
break;
|
||||||
@ -291,6 +291,8 @@ static void stop(int sig)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int sts;
|
int sts;
|
||||||
|
int callback1ret = -1;
|
||||||
|
int callback2ret = -1;
|
||||||
struct sigaction action_stop = {
|
struct sigaction action_stop = {
|
||||||
.sa_handler = stop
|
.sa_handler = stop
|
||||||
};
|
};
|
||||||
@ -320,48 +322,51 @@ int main(int argc, char **argv)
|
|||||||
DEBUG0("Registering domain event cbs");
|
DEBUG0("Registering domain event cbs");
|
||||||
|
|
||||||
/* Add 2 callbacks to prove this works with more than just one */
|
/* Add 2 callbacks to prove this works with more than just one */
|
||||||
virConnectDomainEventRegister(dconn, myDomainEventCallback1,
|
callback1ret = virConnectDomainEventRegister(dconn, myDomainEventCallback1,
|
||||||
strdup("callback 1"), myFreeFunc);
|
strdup("callback 1"), myFreeFunc);
|
||||||
virConnectDomainEventRegister(dconn, myDomainEventCallback2,
|
callback2ret = virConnectDomainEventRegister(dconn, myDomainEventCallback2,
|
||||||
strdup("callback 2"), myFreeFunc);
|
strdup("callback 2"), myFreeFunc);
|
||||||
|
|
||||||
while(run) {
|
if ((callback1ret == 0) && (callback2ret == 0) ) {
|
||||||
struct pollfd pfd = { .fd = h_fd,
|
while(run) {
|
||||||
.events = h_event,
|
struct pollfd pfd = { .fd = h_fd,
|
||||||
.revents = 0};
|
.events = h_event,
|
||||||
|
.revents = 0};
|
||||||
|
|
||||||
sts = poll(&pfd, 1, TIMEOUT_MS);
|
sts = poll(&pfd, 1, TIMEOUT_MS);
|
||||||
|
|
||||||
/* We are assuming timeout of 0 here - so execute every time */
|
/* We are assuming timeout of 0 here - so execute every time */
|
||||||
if(t_cb && t_active)
|
if(t_cb && t_active)
|
||||||
t_cb(t_timeout,t_opaque);
|
t_cb(t_timeout,t_opaque);
|
||||||
|
|
||||||
|
if (sts == 0) {
|
||||||
|
/* DEBUG0("Poll timeout"); */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (sts < 0 ) {
|
||||||
|
DEBUG0("Poll failed");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( pfd.revents & POLLHUP ) {
|
||||||
|
DEBUG0("Reset by peer");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(h_cb) {
|
||||||
|
h_cb(0,
|
||||||
|
h_fd,
|
||||||
|
myPollEventToEventHandleType(pfd.revents & h_event),
|
||||||
|
h_opaque);
|
||||||
|
}
|
||||||
|
|
||||||
if (sts == 0) {
|
|
||||||
/* DEBUG0("Poll timeout"); */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (sts < 0 ) {
|
|
||||||
DEBUG0("Poll failed");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( pfd.revents & POLLHUP ) {
|
|
||||||
DEBUG0("Reset by peer");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(h_cb) {
|
DEBUG0("Deregistering event handlers");
|
||||||
h_cb(0,
|
virConnectDomainEventDeregister(dconn, myDomainEventCallback1);
|
||||||
h_fd,
|
virConnectDomainEventDeregister(dconn, myDomainEventCallback2);
|
||||||
myPollEventToEventHandleType(pfd.revents & h_event),
|
|
||||||
h_opaque);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG0("Deregistering event handlers");
|
|
||||||
virConnectDomainEventDeregister(dconn, myDomainEventCallback1);
|
|
||||||
virConnectDomainEventDeregister(dconn, myDomainEventCallback2);
|
|
||||||
|
|
||||||
DEBUG0("Closing connection");
|
DEBUG0("Closing connection");
|
||||||
if( dconn && virConnectClose(dconn)<0 ) {
|
if( dconn && virConnectClose(dconn)<0 ) {
|
||||||
printf("error closing\n");
|
printf("error closing\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user