SYNOPSIS
#include <hal.h>
typedef int (*hal_query_cb)(hal_query_t *query, void *arg);
int hal_list_comp(hal_query_t *query, hal_query_cb callback, void *arg);
ARGUMENTS
- query
-
The query structure that returns all data found.
- callback
-
The callback function to invoke for each signal found.
- arg
-
A user defined pointer to a user defined data structure. The arg pointer is passed verbatim to the callback function.
DESCRIPTION
The hal_list_comp() function will iterate all registered components and call the callback for each. The query structure should be set to zero before the call.
The callback is called with all fields set appropriately.
The query.qtype is set to HAL_QTYPE_COMP.
The iteration continues until no more components are available or the callback returns non-zero. You can return a positive value from the callback to signal termination of iteration without triggering an error. The return value from the callback is returned from the hal_list_comp() function as is.
RETURN VALUE
Returns zero (0) on success. The return value of the callback is returned if it was non-zero. A negative errno code is returned if any problem is detected:
| -EFAULT |
The shared memory was not mapped. |
| -EINVAL |
An invalid argument was passed. |
EXAMPLES
static int print_comps_cb(hal_query_t *query, void *arg)
{
const char *pattern = (const char *)arg;
if(!fnmatch(pattern, query->name, FNM_NOESCAPE|FNM_CASEFOLD)) {
printf("%s(%d) %s %d %s (%s)\n",
query->name,
query->comp.comp_id,
query->comp.type == HAL_COMP_TYPE_REALTIME ? "RT" : "User",
query->comp.pid,
query->comp.ready ? "ready" : "notready",
query->comp.insmod ? query->comp.insmod : "");
}
return 0; // Keep on going
}
// Print components that match a pattern
int print_comps(const char *pattern)
{
hal_query_t query = {};
int rv = hal_list_comp(&query, print_comps_cb, (void *)pattern);
if(0 != rv)
printf("Iteration failure: %s", hal_strerror(rv));
return rv;
}
SEE ALSO
hal_query_t(3)