mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
Introduce VIR_TYPED_PARAMS_DEBUG macro for dumping typed params
All APIs that take typed parameters are only using params address in their entry point debug messages. With the new VIR_TYPED_PARAMS_DEBUG macro, all functions can easily log all individual typed parameters passed to them.
This commit is contained in:
parent
8a7f1166e1
commit
fefb0d5464
@ -67,6 +67,7 @@ ignored_functions = {
|
||||
"virTypedParamsValidate": "internal function in virtypedparam.c",
|
||||
"virTypedParameterAssign": "internal function in virtypedparam.c",
|
||||
"virTypedParameterAssignFromStr": "internal function in virtypedparam.c",
|
||||
"virTypedParameterToString": "internal function in virtypedparam.c",
|
||||
"virTypedParamsCheck": "internal function in virtypedparam.c",
|
||||
}
|
||||
|
||||
|
@ -1943,6 +1943,9 @@ virTPMCreateCancelPath;
|
||||
# util/virtypedparam.h
|
||||
virTypedParameterAssign;
|
||||
virTypedParameterAssignFromStr;
|
||||
virTypedParameterToString;
|
||||
virTypedParameterTypeFromString;
|
||||
virTypedParameterTypeToString;
|
||||
virTypedParamsCheck;
|
||||
virTypedParamsReplaceString;
|
||||
virTypedParamsValidate;
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
VIR_ENUM_DECL(virTypedParameter)
|
||||
VIR_ENUM_IMPL(virTypedParameter, VIR_TYPED_PARAM_LAST,
|
||||
"unknown",
|
||||
"int",
|
||||
@ -135,6 +134,52 @@ virTypedParamsCheck(virTypedParameterPtr params,
|
||||
return true;
|
||||
}
|
||||
|
||||
char *
|
||||
virTypedParameterToString(virTypedParameterPtr param)
|
||||
{
|
||||
char *value;
|
||||
int ret = -1;
|
||||
|
||||
switch (param->type) {
|
||||
case VIR_TYPED_PARAM_INT:
|
||||
if ((ret = virAsprintf(&value, "%d", param->value.i)) < 0)
|
||||
virReportOOMError();
|
||||
break;
|
||||
case VIR_TYPED_PARAM_UINT:
|
||||
if ((ret = virAsprintf(&value, "%u", param->value.ui)) < 0)
|
||||
virReportOOMError();
|
||||
break;
|
||||
case VIR_TYPED_PARAM_LLONG:
|
||||
if ((ret = virAsprintf(&value, "%lld", param->value.l)) < 0)
|
||||
virReportOOMError();
|
||||
break;
|
||||
case VIR_TYPED_PARAM_ULLONG:
|
||||
if ((ret = virAsprintf(&value, "%llu", param->value.ul)) < 0)
|
||||
virReportOOMError();
|
||||
break;
|
||||
case VIR_TYPED_PARAM_DOUBLE:
|
||||
if ((ret = virAsprintf(&value, "%g", param->value.d)) < 0)
|
||||
virReportOOMError();
|
||||
break;
|
||||
case VIR_TYPED_PARAM_BOOLEAN:
|
||||
if ((ret = virAsprintf(&value, "%d", param->value.b)) < 0)
|
||||
virReportOOMError();
|
||||
break;
|
||||
case VIR_TYPED_PARAM_STRING:
|
||||
ret = VIR_STRDUP(value, param->value.s);
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unexpected type %d for field %s"),
|
||||
param->type, param->field);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Assign name, type, and the appropriately typed arg to param; in the
|
||||
* case of a string, the caller is assumed to have malloc'd a string,
|
||||
* or can pass NULL to have this function malloc an empty string.
|
||||
|
@ -24,6 +24,7 @@
|
||||
# define __VIR_TYPED_PARAM_H_
|
||||
|
||||
# include "internal.h"
|
||||
# include "virutil.h"
|
||||
|
||||
int virTypedParamsValidate(virTypedParameterPtr params, int nparams,
|
||||
/* const char *name, int type ... */ ...)
|
||||
@ -49,4 +50,23 @@ int virTypedParamsReplaceString(virTypedParameterPtr *params,
|
||||
const char *name,
|
||||
const char *value);
|
||||
|
||||
char *virTypedParameterToString(virTypedParameterPtr param);
|
||||
|
||||
VIR_ENUM_DECL(virTypedParameter)
|
||||
|
||||
# define VIR_TYPED_PARAMS_DEBUG(params, nparams) \
|
||||
do { \
|
||||
int _i; \
|
||||
if (!params) \
|
||||
break; \
|
||||
for (_i = 0; _i < (nparams); _i++) { \
|
||||
char *_value = virTypedParameterToString((params) + _i); \
|
||||
VIR_DEBUG("params[\"%s\"]=(%s)%s", \
|
||||
(params)[_i].field, \
|
||||
virTypedParameterTypeToString((params)[_i].type), \
|
||||
NULLSTR(_value)); \
|
||||
VIR_FREE(_value); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* __VIR_TYPED_PARAM_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user