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