Allow mux to specify the default value
Will be written to the output when the selection function returns NULL as the selected input.
This commit is contained in:
parent
920866d8af
commit
c624374cc8
@ -97,13 +97,15 @@ cb_select(struct chan *sel_chan, void *ptr)
|
|||||||
value_str(sel_value), input->chan->name);
|
value_str(sel_value), input->chan->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set to null by default */
|
struct value out_value = mux->def;
|
||||||
struct value out_value = value_null();
|
|
||||||
if (input != NULL && chan_read(input->chan, &out_value) != 0) {
|
if (input != NULL && chan_read(input->chan, &out_value) != 0) {
|
||||||
err("chan_read() failed");
|
err("chan_read() failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbg("setting output chan %s to %s",
|
||||||
|
mux->output->name, value_str(out_value, buf));
|
||||||
|
|
||||||
if (chan_set(mux->output, out_value) != 0) {
|
if (chan_set(mux->output, out_value) != 0) {
|
||||||
err("chan_set() failed");
|
err("chan_set() failed");
|
||||||
return -1;
|
return -1;
|
||||||
@ -180,6 +182,7 @@ mux_init(struct mux *mux,
|
|||||||
mux->output = output;
|
mux->output = output;
|
||||||
mux->ninputs = ninputs;
|
mux->ninputs = ninputs;
|
||||||
mux->inputs = calloc(ninputs, sizeof(struct mux_input));
|
mux->inputs = calloc(ninputs, sizeof(struct mux_input));
|
||||||
|
mux->def = value_null();
|
||||||
|
|
||||||
if (mux->inputs == NULL) {
|
if (mux->inputs == NULL) {
|
||||||
err("calloc failed:");
|
err("calloc failed:");
|
||||||
@ -245,3 +248,9 @@ mux_set_input(struct mux *mux, int64_t index, struct chan *chan)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mux_set_default(struct mux *mux, struct value def)
|
||||||
|
{
|
||||||
|
mux->def = def;
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ struct mux {
|
|||||||
mux_select_func_t select_func;
|
mux_select_func_t select_func;
|
||||||
struct chan *select;
|
struct chan *select;
|
||||||
struct chan *output;
|
struct chan *output;
|
||||||
|
struct value def;
|
||||||
};
|
};
|
||||||
|
|
||||||
void mux_input_init(struct mux_input *mux,
|
void mux_input_init(struct mux_input *mux,
|
||||||
@ -54,4 +55,6 @@ USE_RET struct mux_input *mux_get_input(struct mux *mux,
|
|||||||
USE_RET int mux_register(struct mux *mux,
|
USE_RET int mux_register(struct mux *mux,
|
||||||
struct bay *bay);
|
struct bay *bay);
|
||||||
|
|
||||||
|
void mux_set_default(struct mux *mux, struct value def);
|
||||||
|
|
||||||
#endif /* MUX_H */
|
#endif /* MUX_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user