User manual

95
const chapi_in * ci = …;
if (ci->set_option_value) {
my_int_opt = 10;
if(ci->set_option_value(ci, “int_opt”, 0, &my_int_opt)) {
// Ok, new option value is set. It is usually used to set defaults
when no values is
// specified in configuration file.
}
my_bool_opt[1] = true;
if(ci->set_option_value(ci, “bool_opt”, 1, &my_bool_opt[1])) {
// Ok, new option value is set for the second value of
// ‘bool_opt’ option. It is usually used to set defaults when
// no values is specified in configuration file.
}
if(ci->set_option_value(ci, “str_opt”, 0, “Some new string value”)) {
// Ok, new option value is set. It is usually used to set
// defaults when no values is specified in configuration file.
}
}
The example above shows that the CHARON core is not obliged to support the indicated
operation. It indicates why the device instance must remember the chapi_in descriptor.
4.19.3 Undoing last change of configuration option value
Undoing option value belongs to the “A request to process loadable component defined
configuration options” class of operations. Such an operation is initiated by the device
instance. The CHARON core is defined as a target of the operation.
To perform the operation, the initiator invokes a routine identified by the undo_option_value
field of the chapi_in descriptor. The initiator provides in the opt_name parameter the name
of configuration option to undo value of and in the opt_val_idx the index of option value to
undo (from 0 to opt_vals_count - 1). The procedure is invoked as follows assuming that
described in the previous chapter options are added during the loadable module
initialization:
// Define option storage somewhere in loadable component implementation
int my_int_opt;
bool my_bool_opt[3];
char my_str_opt[256];
const chapi_in * ci = …;
if (ci->undo_option_value) {
// Undo last changes in bool_opt values for some reason
for(int idx = 0; idx < 3; idx++) {
ci->undo_option_value(ci, “bool_opt”, idx);