mirror of https://github.com/mpv-player/mpv
m_property: add read_sub_validate to check if should be processed
In many cases it makes sense to early exit instead of preparing all the data only to return type or not implemented.
This commit is contained in:
parent
273906490d
commit
4bbe961885
|
@ -432,6 +432,23 @@ int m_property_strdup_ro(int action, void* arg, const char *var)
|
|||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int m_property_read_sub_validate(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
{
|
||||
m_property_unkey(&action, &arg);
|
||||
switch (action) {
|
||||
case M_PROPERTY_GET_TYPE:
|
||||
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
|
||||
return M_PROPERTY_OK;
|
||||
case M_PROPERTY_GET:
|
||||
case M_PROPERTY_PRINT:
|
||||
case M_PROPERTY_KEY_ACTION:
|
||||
return M_PROPERTY_VALID;
|
||||
default:
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
};
|
||||
}
|
||||
|
||||
// This allows you to make a list of values (like from a struct) available
|
||||
// as a number of sub-properties. The property list is set up with the current
|
||||
// property values on the stack before calling this function.
|
||||
|
|
|
@ -107,6 +107,9 @@ struct m_property_action_arg {
|
|||
};
|
||||
|
||||
enum mp_property_return {
|
||||
// Returned from validator if action should be executed.
|
||||
M_PROPERTY_VALID = 2,
|
||||
|
||||
// Returned on success.
|
||||
M_PROPERTY_OK = 1,
|
||||
|
||||
|
@ -212,6 +215,8 @@ struct m_sub_property {
|
|||
#define SUB_PROP_PTS(f) \
|
||||
.type = {.type = &m_option_type_time}, .value = {.double_ = (f)}
|
||||
|
||||
int m_property_read_sub_validate(void *ctx, struct m_property *prop,
|
||||
int action, void *arg);
|
||||
int m_property_read_sub(const struct m_sub_property *props, int action, void *arg);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue