mirror of https://gitee.com/openkylin/libvirt.git
examples: Use G_N_ELEMENTS instead of ARRAY_CARDINALITY
We try to keep the example programs independent of libraries other than libvirt. Rename the locally defined ARRAY_CARDINALITY macro to G_N_ELEMENTS which GLib provides, even though we don't actually include GLib. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
88131931b8
commit
d99f17a502
|
@ -9,7 +9,7 @@
|
||||||
#include <libvirt/libvirt.h>
|
#include <libvirt/libvirt.h>
|
||||||
#include <libvirt/virterror.h>
|
#include <libvirt/virterror.h>
|
||||||
|
|
||||||
#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
|
#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))
|
||||||
#define STREQ(a, b) (strcmp(a, b) == 0)
|
#define STREQ(a, b) (strcmp(a, b) == 0)
|
||||||
#define NULLSTR(s) ((s) ? (s) : "<null>")
|
#define NULLSTR(s) ((s) ? (s) : "<null>")
|
||||||
|
|
||||||
|
@ -1135,10 +1135,10 @@ struct secretEventData secretEvents[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* make sure that the events are kept in sync */
|
/* make sure that the events are kept in sync */
|
||||||
verify(ARRAY_CARDINALITY(domainEvents) == VIR_DOMAIN_EVENT_ID_LAST);
|
verify(G_N_ELEMENTS(domainEvents) == VIR_DOMAIN_EVENT_ID_LAST);
|
||||||
verify(ARRAY_CARDINALITY(storagePoolEvents) == VIR_STORAGE_POOL_EVENT_ID_LAST);
|
verify(G_N_ELEMENTS(storagePoolEvents) == VIR_STORAGE_POOL_EVENT_ID_LAST);
|
||||||
verify(ARRAY_CARDINALITY(nodeDeviceEvents) == VIR_NODE_DEVICE_EVENT_ID_LAST);
|
verify(G_N_ELEMENTS(nodeDeviceEvents) == VIR_NODE_DEVICE_EVENT_ID_LAST);
|
||||||
verify(ARRAY_CARDINALITY(secretEvents) == VIR_SECRET_EVENT_ID_LAST);
|
verify(G_N_ELEMENTS(secretEvents) == VIR_SECRET_EVENT_ID_LAST);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
|
@ -1190,7 +1190,7 @@ main(int argc, char **argv)
|
||||||
strdup("callback 1"), myFreeFunc);
|
strdup("callback 1"), myFreeFunc);
|
||||||
|
|
||||||
/* register common domain callbacks */
|
/* register common domain callbacks */
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(domainEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(domainEvents); i++) {
|
||||||
struct domainEventData *event = domainEvents + i;
|
struct domainEventData *event = domainEvents + i;
|
||||||
|
|
||||||
event->id = virConnectDomainEventRegisterAny(dconn, NULL,
|
event->id = virConnectDomainEventRegisterAny(dconn, NULL,
|
||||||
|
@ -1212,7 +1212,7 @@ main(int argc, char **argv)
|
||||||
strdup("net callback"), myFreeFunc);
|
strdup("net callback"), myFreeFunc);
|
||||||
|
|
||||||
/* register common storage pool callbacks */
|
/* register common storage pool callbacks */
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(storagePoolEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(storagePoolEvents); i++) {
|
||||||
struct storagePoolEventData *event = storagePoolEvents + i;
|
struct storagePoolEventData *event = storagePoolEvents + i;
|
||||||
|
|
||||||
event->id = virConnectStoragePoolEventRegisterAny(dconn, NULL,
|
event->id = virConnectStoragePoolEventRegisterAny(dconn, NULL,
|
||||||
|
@ -1228,7 +1228,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* register common node device callbacks */
|
/* register common node device callbacks */
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(nodeDeviceEvents); i++) {
|
||||||
struct nodeDeviceEventData *event = nodeDeviceEvents + i;
|
struct nodeDeviceEventData *event = nodeDeviceEvents + i;
|
||||||
|
|
||||||
event->id = virConnectNodeDeviceEventRegisterAny(dconn, NULL,
|
event->id = virConnectNodeDeviceEventRegisterAny(dconn, NULL,
|
||||||
|
@ -1244,7 +1244,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* register common secret callbacks */
|
/* register common secret callbacks */
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(secretEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(secretEvents); i++) {
|
||||||
struct secretEventData *event = secretEvents + i;
|
struct secretEventData *event = secretEvents + i;
|
||||||
|
|
||||||
event->id = virConnectSecretEventRegisterAny(dconn, NULL,
|
event->id = virConnectSecretEventRegisterAny(dconn, NULL,
|
||||||
|
@ -1282,27 +1282,27 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
printf("Deregistering domain event callbacks\n");
|
printf("Deregistering domain event callbacks\n");
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(domainEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(domainEvents); i++) {
|
||||||
if (domainEvents[i].id > 0)
|
if (domainEvents[i].id > 0)
|
||||||
virConnectDomainEventDeregisterAny(dconn, domainEvents[i].id);
|
virConnectDomainEventDeregisterAny(dconn, domainEvents[i].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("Deregistering storage pool event callbacks\n");
|
printf("Deregistering storage pool event callbacks\n");
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(storagePoolEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(storagePoolEvents); i++) {
|
||||||
if (storagePoolEvents[i].id > 0)
|
if (storagePoolEvents[i].id > 0)
|
||||||
virConnectStoragePoolEventDeregisterAny(dconn, storagePoolEvents[i].id);
|
virConnectStoragePoolEventDeregisterAny(dconn, storagePoolEvents[i].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("Deregistering node device event callbacks\n");
|
printf("Deregistering node device event callbacks\n");
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(nodeDeviceEvents); i++) {
|
||||||
if (nodeDeviceEvents[i].id > 0)
|
if (nodeDeviceEvents[i].id > 0)
|
||||||
virConnectNodeDeviceEventDeregisterAny(dconn, nodeDeviceEvents[i].id);
|
virConnectNodeDeviceEventDeregisterAny(dconn, nodeDeviceEvents[i].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Deregistering secret event callbacks\n");
|
printf("Deregistering secret event callbacks\n");
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(secretEvents); i++) {
|
for (i = 0; i < G_N_ELEMENTS(secretEvents); i++) {
|
||||||
if (secretEvents[i].id > 0)
|
if (secretEvents[i].id > 0)
|
||||||
virConnectSecretEventDeregisterAny(dconn, secretEvents[i].id);
|
virConnectSecretEventDeregisterAny(dconn, secretEvents[i].id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue