From 3a14c3e36af4f3dcf271e8261cf68cc71a0483f8 Mon Sep 17 00:00:00 2001
Message-Id: <3a14c3e36af4f3dcf271e8261cf68cc71a0483f8@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Fri, 26 Sep 2014 12:43:57 +0200
Subject: [PATCH] add an example how to use tunable event
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 9e734ab73eb171bd09bb71c8fd6d21e266c06875)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1115898
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
examples/object-events/event-test.c | 52 ++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
index d6cfe46..9e09736 100644
--- a/examples/object-events/event-test.c
+++ b/examples/object-events/event-test.c
@@ -464,6 +464,48 @@ static int myNetworkEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
return 0;
}
+static int
+myDomainEventTunableCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ virTypedParameterPtr params,
+ int nparams,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ size_t i;
+
+ printf("%s EVENT: Domain %s(%d) tunable updated:\n",
+ __func__, virDomainGetName(dom), virDomainGetID(dom));
+
+ for (i = 0; i < nparams; i++) {
+ switch (params[i].type) {
+ case VIR_TYPED_PARAM_INT:
+ printf("\t%s: %d\n", params[i].field, params[i].value.i);
+ break;
+ case VIR_TYPED_PARAM_UINT:
+ printf("\t%s: %u\n", params[i].field, params[i].value.ui);
+ break;
+ case VIR_TYPED_PARAM_LLONG:
+ printf("\t%s: %lld\n", params[i].field, params[i].value.l);
+ break;
+ case VIR_TYPED_PARAM_ULLONG:
+ printf("\t%s: %llu\n", params[i].field, params[i].value.ul);
+ break;
+ case VIR_TYPED_PARAM_DOUBLE:
+ printf("\t%s: %g\n", params[i].field, params[i].value.d);
+ break;
+ case VIR_TYPED_PARAM_BOOLEAN:
+ printf("\t%s: %d\n", params[i].field, params[i].value.b);
+ break;
+ case VIR_TYPED_PARAM_STRING:
+ printf("\t%s: %s\n", params[i].field, params[i].value.s);
+ break;
+ default:
+ printf("\t%s: unknown type\n", params[i].field);
+ }
+ }
+
+ return 0;
+}
static void myFreeFunc(void *opaque)
{
@@ -506,6 +548,7 @@ int main(int argc, char **argv)
int callback14ret = -1;
int callback15ret = -1;
int callback16ret = -1;
+ int callback17ret = -1;
struct sigaction action_stop;
memset(&action_stop, 0, sizeof(action_stop));
@@ -624,6 +667,11 @@ int main(int argc, char **argv)
VIR_NETWORK_EVENT_ID_LIFECYCLE,
VIR_NETWORK_EVENT_CALLBACK(myNetworkEventCallback),
strdup("net callback"), myFreeFunc);
+ callback17ret = virConnectDomainEventRegisterAny(dconn,
+ NULL,
+ VIR_DOMAIN_EVENT_ID_TUNABLE,
+ VIR_DOMAIN_EVENT_CALLBACK(myDomainEventTunableCallback),
+ strdup("tunable"), myFreeFunc);
if ((callback1ret != -1) &&
(callback2ret != -1) &&
@@ -639,7 +687,8 @@ int main(int argc, char **argv)
(callback13ret != -1) &&
(callback14ret != -1) &&
(callback15ret != -1) &&
- (callback16ret != -1)) {
+ (callback16ret != -1) &&
+ (callback17ret != -1)) {
if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to start keepalive protocol: %s\n",
@@ -671,6 +720,7 @@ int main(int argc, char **argv)
virConnectDomainEventDeregisterAny(dconn, callback14ret);
virConnectDomainEventDeregisterAny(dconn, callback15ret);
virConnectNetworkEventDeregisterAny(dconn, callback16ret);
+ virConnectDomainEventDeregisterAny(dconn, callback17ret);
if (callback8ret != -1)
virConnectDomainEventDeregisterAny(dconn, callback8ret);
}
--
2.1.1