dmi_registry_iter_initialize

Synopsis

#include <opendmi/registry.h>

typedef struct dmi_registry_iter {
    dmi_registry_t       *registry;
    dmi_filter_t         *filter;
    dmi_registry_entry_t *position;
    bool                  is_done;
} dmi_registry_iter_t;

bool dmi_registry_iter_initialize(
        dmi_registry_iter_t *iter,
        dmi_registry_t      *registry,
        dmi_filter_t        *filter);

bool dmi_registry_iter_has_next(dmi_registry_iter_t *iter);

dmi_entity_t *dmi_registry_iter_next(dmi_registry_iter_t *iter);

Description

An iterator walks the structures of a registry in the order of the table, and yields the ones a filter matches, see dmi_filter_match, or all of them if there is no filter.

The dmi_registry_iter_initialize function sets up an iterator to walk registry, from its first structure. An iterator which has been used already is set up again the same way.

The dmi_registry_iter_next function moves the iterator to the next structure the filter matches, and returns its entity. Once the iterator has run past the last structure, it stays there, and the function returns nullptr for every call that follows.

The dmi_registry_iter_has_next function tells whether the next call to dmi_registry_iter_next would return a structure, without moving the iterator.

An iterator is a plain variable, which is not allocated and needs no destroying, and several iterators may walk a registry at once. The members of the iterator are private to the library. The registry and the filter are not copied, and must stay valid while the iterator is used. The entities belong to the registry, see dmi_registry_lookup.

Parameters

iter

Iterator to set up, to move or to query.

registry

Registry to walk, see dmi_get_registry.

filter

Filter which tells the structures to yield, or nullptr to yield all of them.

Return value

dmi_registry_iter_initialize returns true on success, and false if iter or registry is nullptr.

dmi_registry_iter_has_next returns true if a structure is left to yield, and false otherwise, or if iter is nullptr.

dmi_registry_iter_next returns the entity of the next structure, or nullptr if no structure is left to yield, or if iter is nullptr.

Errors

DMI_ERROR_ARGUMENT_NULL

Raised by dmi_registry_iter_initialize if iter or registry is nullptr, in which case it is not reported, since there is no context to hold it.

dmi_registry_iter_has_next and dmi_registry_iter_next raise no errors, and take nullptr for an iterator with nothing left to yield.

Example

Print the locators of the memory devices:

dmi_registry_t     *registry = dmi_get_registry(context);
dmi_registry_iter_t iter;
dmi_entity_t       *entity;

if (dmi_registry_iter_initialize(&iter, registry, nullptr)) {
    while ((entity = dmi_registry_iter_next(&iter)) != nullptr) {
        if (dmi_entity_type(entity) != DMI_TYPE(memory_device))
            continue;

        const dmi_memory_device_t *device =
                dmi_entity_info(entity, DMI_TYPE(memory_device));

        if ((device != nullptr) && (device->device_locator != nullptr))
            printf("%s\n", device->device_locator);
    }
}

The structure type is checked before the information is asked for, since dmi_entity_info raises an error for a structure of another type. See dmi_filter_create for an iterator which yields the structures found at the given type numbers only.