DESCRIPTION
The HAL query API is an interface to retrieve information about:
-
pins
-
params
-
signals
-
components
-
functions
-
threads
Additionally, the query API can set the value of pins, params and signals. The query API uses a standard structure to capture both input and output. Most query API functions use a callback function with the following signature:
typedef int (*hal_query_cb)(hal_query_t *query, void *arg);
It is important to remember that the HAL mutex is held while the callback function is executing. You may call other query API functions from within the callback (the HAL mutex is recursive).
|
Warning
|
You should never exit your program from within a callback. Doing so would keep HAL locked and all other programs are forever blocked from performing actions. Beware of OS signals during callbacks (see signal(2) and signal(7)). You should also beware of performing blocking I/O. Taking a long time in callbacks may be problematic for performance. It may be better to collect data in the callback and handle the slow operations outside of it. |
A query’s details is defined by the query structure;
typedef struct {
const char *name;
hal_qtype_t qtype;
union {
void *vpval;
const void *cpval;
rtapi_intptr_t ipval;
rtapi_uintptr_t upval;
rtapi_sint sival;
rtapi_uint uival;
} callerdata;
union {
hal_query_pp_t pp;
hal_query_sig_t sig;
hal_query_comp_t comp;
hal_query_funct_t funct;
hal_query_thread_t thread;
};
} hal_query_t;
typedef enum {
HAL_QTYPE_ANY = 0,
HAL_QTYPE_PIN,
HAL_QTYPE_PARAM,
HAL_QTYPE_SIGNAL,
HAL_QTYPE_COMP,
HAL_QTYPE_FUNCT,
HAL_QTYPE_THREAD,
HAL_QTYPE_THREAD_FUNCT,
} hal_qtype_t;
The fields name and qtype are used as a selector. The user may use the callerdata fields to propagate additional data to the callback. The callerdata fields are never altered by any query function.
Data is returned in the individual sub-field.
| pp |
Pin and param data.
The qtype field is set to |
| sig |
Signal data.
The qtype field is set to |
| comp |
Component data.
The qtype field is set to |
| funct |
Function data.
The qtype field is set to |
| thread |
Thread data.
The qtype field is set to |
QUERY FUNCTIONS
- hal_get_p, hal_getref_p, hal_set_p
-
Retrieve or set the value of a pin or param.
The value and opaque reference is retrieved with hal_get_p. Only the opaque reference is retrieved with hal_getref_p (useful for existence test). Setting a pin or param can be done with hal_set_p. - hal_get_s, hal_getref_s, hal_set_s
-
Retrieve or set the value of a signal.
The value and opaque reference is retrieved with hal_get_s. Only the opaque reference is retrieved with hal_getref_s (useful for existence test). Setting a signal can be done with hal_set_s. - hal_list_p
-
Iterate all pins or params registered with HAL. You can limit the search to pins, params or both. The pin and param values, including reference, can be accessed in the callback.
- hal_list_s
-
Iterate all signals registered with HAL. The signal values, including reference, can be accessed in the callback.
- hal_list_p_s
-
Iterate all pins connected to a specific signal. The pin values, including reference, can be accessed in the callback.
- hal_list_comp
-
Iterate all components registered with HAL
- hal_list_funct
-
Iterate all functions registered with HAL
- hal_list_thread
-
Iterate all threads registered with HAL.
You can select to iterate the functions attached to a threads while iterating threads.
PINS AND PARAMS
Query data for pins and param is handled by the hal_query_pp_t structure:
typedef struct {
hal_type_t type;
hal_refs_u ref;
hal_query_value_u value;
hal_pdir_t dir;
const char *alias;
const char *signal;
const char *comp;
int comp_id;
} hal_query_pp_t;
The hal_query_t fields name and qtype will be set before the callback is invoked.
The name fields will point to the actual live pin or parameter name.
The qtype field will indicate whether the data contains a pin (HAL_QTYPE_PIN) or a param (HAL_QTYPE_PARAM).
SIGNALS
Query data for signals is handled by the hal_query_sig_t structure:
typedef struct {
hal_type_t type;
hal_refs_u ref;
hal_query_value_u value;
int writers;
int readers;
int bidirs;
} hal_query_sig_t;
The hal_query_t field name will be set before the callback is invoked. The name fields will point to the actual live signal name.
| type |
The signal type as described in hal_type_t(3). |
| ref |
The opaque reference as described in hal_refs_u(3). |
| value |
The value is a union hal_query_value_u of supported values.
The type field indicates which value you should select from the union.
You should make sure to use the proper field.
See above under pins and parameters for details. |
| writers |
The number of |
| readers |
The number of |
| bidirs |
The number of |
COMPONENTS
Query data for components is handled by the hal_query_comp_t structure:
typedef struct {
int comp_id;
hal_comp_type_t type;
int pid;
bool ready;
const char *insmod;
} hal_query_comp_t;
The hal_query_t field name will be set before the callback is invoked. The name fields will point to the actual live component name.
| comp_id |
The component ID assigned to the component (returned by hal_init(3)). |
| type |
The component type (
|
| pid |
The process ID of the user-space program that created the component. |
| ready |
True if the component is in the ready state. |
| insmod |
The |
FUNCTIONS
Query data for functions is handled by the hal_query_funct_t structure:
typedef struct {
int comp_id;
const char *comp;
int users;
rtapi_intptr_t arg;
rtapi_intptr_t funct;
bool reentrant;
} hal_query_funct_t;
The hal_query_t field name will be set before the callback is invoked. The name fields will point to the actual live function name.
| comp_id |
The owning component’s ID. This is set by the calls to hal_export_functf(3). |
| comp |
The owning component’s name. |
| users |
The number of times the function is in use by one or more threads. |
| arg |
Internal reference to the argument passed to the function when executed. You cannot dereference this value as it’s address belongs to a different process. |
| funct |
Internal reference to the functions location in memory. You cannot dereference this value as it’s address belongs to a different process. |
| reentrant |
Set to true if the function has no static references and can be called twice or more at the same time. |
THREADS
Query data for threads is handled by the hal_query_thread_t structure:
typedef struct {
int comp_id;
const char *comp;
int priority;
long int period;
int functidx;
const char *funct;
bool is_init;
} hal_query_thread_t;
The hal_query_t field name will be set before the callback is invoked. The name fields will point to the actual live thread name.
| comp_id |
The owning component’s ID. |
| comp |
The owning component’s name. |
| priority |
Internal priority of the thread. |
| period |
The cycle time of the thread in nanoseconds. |
| functidx |
Only set if iterating a thread’s functions (HAL_QTYPE_THREAD_FUNCT). |
| funct |
Only set if iterating a thread’s functions (HAL_QTYPE_THREAD_FUNCT). |
| is_init |
Only set if iterating a thread’s functions (HAL_QTYPE_THREAD_FUNCT). |
REALTIME CONSIDERATIONS
The query API functions are not available from realtime. The HAL library query functions are not exported to realtime modules. Only non-realtime user-space programs linking to HAL library can use the query functions.
RETURN VALUE
All functions returns zero (0) on success. A negative errno code is returned when an error is encountered. The callback’s return value is returned verbatim.
SEE ALSO
hal_set_p(3), hal_set_s(3), hal_get_p(3), hal_get_s(3), hal_getref_p(3), hal_getref_s(3), hal_list_p(3), hal_list_s(3), hal_list_p_s(3), hal_list_comp(3), hal_list_funct(3), hal_list_thread(3), hal_comp_by_name(3), hal_comp_by_id(3), hal_statistics(3), hal_type_t(3), hal_refs_u(3).