libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Data Fields
dr_cfg_t Struct Reference

#include <dr.h>

Data Fields

bool writable
 Defines whether this dataref will be writable or read-only.
 
size_t count
 
size_t stride
 
void(* read_cb )(dr_t *dr, void *value_out)
 
void(* write_cb )(dr_t *dr, void *value_in)
 
bool_t(* read_scalar_cb )(dr_t *dr, void *value_out)
 
bool_t(* write_scalar_cb )(dr_t *dr, void *value_in)
 
int(* read_array_cb )(dr_t *dr, void *values_out, int off, int cnt)
 
void(* write_array_cb )(dr_t *dr, void *values_in, int off, int cnt)
 
void * cb_userinfo
 

Detailed Description

Specifies additional configuration parameters for a dataref.

This data structure is used by the dr_create_*_cfg() functions to specify additional configurable features of owned datarefs. See the description of the individual fields for their purpose. The structure is designed in such a way that you can simply ignore the fields you don't need and thus leave them at 0 or NULL (which is valid). Example of using this configuration structure in code:

int my_data = 0;
dr_t my_dataref = {};
bool_t my_read_callback(dr_t *dr, void *value_out);
dr_create_i_cfg(&my_dataref, &my_data,
.writable = true,
.read_scalar_cb = my_read_callback,
.cb_userinfo = get_some_userinfo(),
}, "my_plugin/my_data");
void dr_create_i_cfg(dr_t *dr, int *value, dr_cfg_t cfg, const char *fmt,...)
Definition dr.c:703
Definition dr.h:177
See also
dr_create_i_cfg()
dr_create_f_cfg()
dr_create_f64_cfg()
dr_create_vi_cfg()
dr_create_vf_cfg()
dr_create_vf64_cfg()
dr_create_vi_autoscalar_cfg()
dr_create_vf_autoscalar_cfg()
dr_create_vf64_autoscalar_cfg()
dr_create_b_cfg()
dr_get_cb_userinfo()

Definition at line 177 of file dr.h.

Field Documentation

◆ cb_userinfo

void* cb_userinfo

Optional user info field that you can set to whatever you want. Use it to stash any extra information you need in your callbacks and read it using dr_get_cb_userinfo().

Definition at line 291 of file dr.h.

◆ count

size_t count

The number of elements in the value array for array datarefs. Ignored for scalar datarefs.

Definition at line 182 of file dr.h.

◆ read_array_cb

int(* read_array_cb) (dr_t *dr, void *values_out, int off, int cnt)

Same as read_scalar_cb, but for array datarefs. To take over the dataref read, return a value >= 0 from this callback. If you return a value <0, the normal array read functions get executed.

Definition at line 278 of file dr.h.

◆ read_cb

void(* read_cb) (dr_t *dr, void *value_out)

For scalar datarefs we expose, setting this field to a callback will make that callback be called after a read attempt to the dataref is made. The dr machinery first reads the dataref from the memory location in value and then calls read_cb here (if not NULL), with a copy of the dataref value in value_out, allowing your callback to modify it before being returned to the initiator of the dataref read operation. The type of data in value_out will be the same as that which you used to create the dataref (e.g. if you created the dataref using dr_create_i, the value pointed to by the second argument will be an int). Please note that modifying the value* in the callback's second argument won't alter anything at the dataref's value location.

IMPORTANT: you cannot use this function to substitute the preceding dataref value pointer read. You cannot pass NULL in dr_create_* for the memory location and expect to simply synthesize the value in this callback - this will result in a NULL pointer dereference and assertion failure. To synthesize dataref values on the fly, use the read_scalar_cb, and read_array_cb callbacks.

Definition at line 238 of file dr.h.

◆ read_scalar_cb

bool_t(* read_scalar_cb) (dr_t *dr, void *value_out)

If not NULL, this callback gets called before a scalar read is attempted from the dataref's memory location. The value_out argument will point to a new memory location to which you can write a new value to be returned to the originator of the dataref read. The size of the value must match the size of the type originally used to create the dataref (e.g. int if you created the dataref using dr_create_i).

If you wish to synthesize a new value, return B_TRUE from this callback. This bypasses any attempt to read the dataref's memory location directly and instead just returns the value you've written to value_out. Otherwise, if you return B_FALSE, the dr machinery will read the memory pointed to by the value field in the dataref.

Definition at line 261 of file dr.h.

◆ stride

size_t stride

Used by array datarefs to define the distance between successive elements of the array in memory. If left at zero, the default is to use the size of the native data type (e.g. sizeof(int) for integer datarefs). You can set this to a non-zero value in case your data is contained in an array of data structures, which themselves contain multiple fields. In that case, the stride is used to skip to the correct offset in the array. For example:

struct my_data {
int foo;
float bar;
};
static struct my_data my_array[32] = {};
// this exposes just the `foo' fields in `my_array` above
static dr_t foo_dataref = {};
// this exposes just the `bar' fields in `my_array` above
static dr_t bar_dataref = {};
dr_create_vi_cfg(&foo_dataref, &my_array[0].foo,
.count = ARRAY_NUM_ELEM(my_array),
.stride = sizeof (struct my_data),
}, "my_plugin/foo_data");
dr_create_vf_cfg(&bar_dataref, &my_array[0].bar,
.count = ARRAY_NUM_ELEM(my_array),
.stride = sizeof (struct my_data),
}, "my_plugin/bar_data");
#define ARRAY_NUM_ELEM(_array)
Definition core.h:171
void dr_create_vi_cfg(dr_t *dr, int *value, dr_cfg_t cfg, const char *fmt,...)
Definition dr.c:781
void dr_create_vf_cfg(dr_t *dr, float *value, dr_cfg_t cfg, const char *fmt,...)
Definition dr.c:806

Definition at line 215 of file dr.h.

◆ writable

bool writable

Defines whether this dataref will be writable or read-only.

Definition at line 179 of file dr.h.

◆ write_array_cb

void(* write_array_cb) (dr_t *dr, void *values_in, int off, int cnt)

Same as write_scalar_cb, but for array datarefs. If this callback is present, the write is aborted after it is called. There is no facility provided to "continue" the regular array dataref write path as normal.

Definition at line 285 of file dr.h.

◆ write_cb

void(* write_cb) (dr_t *dr, void *value_in)

Same as the read_cb callback, but called before a new value is written into the memory location referenced from the dataref. You can use this callback to modify the value to be written.

Definition at line 244 of file dr.h.

◆ write_scalar_cb

bool_t(* write_scalar_cb) (dr_t *dr, void *value_in)

Same as read_scalar_cb, but instead is called before any attempt is made to write to the dataref's value memory location. The value_in argument points to the value being attempted to be written. If you return B_TRUE from this callback, the write is stopped and no actual dereference of the value pointer in this dataref is performed. Otherwise, the value being written is written as normal. You can still use this callback to alter the value being written though.

Definition at line 272 of file dr.h.


The documentation for this struct was generated from the following file: