dmi_attribute_resolve
Synopsis
#include <opendmi/attribute.h>
const dmi_attribute_t *dmi_attribute_resolve(const dmi_attribute_t *attr, const void *info);
Description
The dmi_attribute_resolve function returns the attribute which describes the
value of the member attr declares in the decoded structure info.
An attribute of any type but a variant one describes its value itself, and is
returned as it is. The member of a variant attribute holds the selector rather
than the value, see DMI_ATTRIBUTE_VARIANT: the selector is read from
info as a signed integer of the width of the member, and the variant whose
selector it equals is returned, or the default variant if no other one
matches. The value is then read, checked and formatted with the attribute
returned, e.g. by dmi_attribute_format, while the variant attribute keeps
naming the member, since the code, the name and the level of a variant are
not used.
dmi_attributes_walk resolves the attributes on its own, and gives the
callbacks both of them.
The attribute returned belongs to the specification, and must not be freed.
Return value
Returns attr if it is not a variant attribute, and the variant matching the
selector or the default variant otherwise. Returns nullptr if no variant
matches and there is no default one, which means the structure holds no
value for the attribute, or if attr or info is nullptr, or if attr
is a variant attribute without .variants.
Errors
DMI_ERROR_ARGUMENT_NULL-
Raised if
attrorinfoisnullptr. The function takes no context, so the error reaches no error queue. DMI_ERROR_ARGUMENT_INVALID-
Raised if
attris a variant attribute whose.variantsisnullptr, and reaches no error queue either.
Example
const dmi_data_t *info = entity->info;
const dmi_attribute_t *value_attr = dmi_attribute_resolve(attr, info);
if (value_attr != nullptr) {
char *text = dmi_attribute_format(context, value_attr,
info + value_attr->value.offset, true);
if (text != nullptr) {
printf("%s: %s\n", dmi_attribute_name(attr, entity->spec->code), text);
dmi_free(text);
}
}