mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
conf: factor out pw_conf_match_rules()
Refactor and expose the rules matching code so that it can be used elsewhere.
This commit is contained in:
parent
d83f2520b6
commit
8f90446042
2 changed files with 28 additions and 12 deletions
|
|
@ -1013,12 +1013,6 @@ int pw_context_conf_update_props(struct pw_context *context,
|
||||||
return res == 0 ? data.count : res;
|
return res == 0 ? data.count : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct match {
|
|
||||||
const struct spa_dict *props;
|
|
||||||
int (*matched) (void *data, const char *location, const char *action,
|
|
||||||
const char *val, size_t len);
|
|
||||||
void *data;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* {
|
* {
|
||||||
|
|
@ -1080,7 +1074,7 @@ static bool find_match(struct spa_json *arr, const struct spa_dict *props)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rules = [
|
* [
|
||||||
* {
|
* {
|
||||||
* matches = [
|
* matches = [
|
||||||
* # any of the items in matches needs to match, if one does,
|
* # any of the items in matches needs to match, if one does,
|
||||||
|
|
@ -1099,11 +1093,13 @@ static bool find_match(struct spa_json *arr, const struct spa_dict *props)
|
||||||
* }
|
* }
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
static int match_rules(void *data, const char *location, const char *section,
|
SPA_EXPORT
|
||||||
const char *str, size_t len)
|
int pw_conf_match_rules(const char *str, size_t len, const char *location,
|
||||||
|
const struct spa_dict *props,
|
||||||
|
int (*callback) (void *data, const char *location, const char *action,
|
||||||
|
const char *str, size_t len),
|
||||||
|
void *data)
|
||||||
{
|
{
|
||||||
struct match *match = data;
|
|
||||||
const struct spa_dict *props = match->props;
|
|
||||||
const char *val;
|
const char *val;
|
||||||
struct spa_json it[4], actions;
|
struct spa_json it[4], actions;
|
||||||
|
|
||||||
|
|
@ -1142,13 +1138,28 @@ static int match_rules(void *data, const char *location, const char *section,
|
||||||
if (spa_json_is_container(val, len))
|
if (spa_json_is_container(val, len))
|
||||||
len = spa_json_container_len(&actions, val, len);
|
len = spa_json_container_len(&actions, val, len);
|
||||||
|
|
||||||
if ((res = match->matched(match->data, location, key, val, len)) < 0)
|
if ((res = callback(data, location, key, val, len)) < 0)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct match {
|
||||||
|
const struct spa_dict *props;
|
||||||
|
int (*matched) (void *data, const char *location, const char *action,
|
||||||
|
const char *val, size_t len);
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int match_rules(void *data, const char *location, const char *section,
|
||||||
|
const char *str, size_t len)
|
||||||
|
{
|
||||||
|
struct match *match = data;
|
||||||
|
return pw_conf_match_rules(str, len, location,
|
||||||
|
match->props, match->matched, match->data);
|
||||||
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int pw_context_conf_section_match_rules(struct pw_context *context, const char *section,
|
int pw_context_conf_section_match_rules(struct pw_context *context, const char *section,
|
||||||
const struct spa_dict *props,
|
const struct spa_dict *props,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@ int pw_conf_load_conf(const char *prefix, const char *name, struct pw_properties
|
||||||
int pw_conf_load_state(const char *prefix, const char *name, struct pw_properties *conf);
|
int pw_conf_load_state(const char *prefix, const char *name, struct pw_properties *conf);
|
||||||
int pw_conf_save_state(const char *prefix, const char *name, const struct pw_properties *conf);
|
int pw_conf_save_state(const char *prefix, const char *name, const struct pw_properties *conf);
|
||||||
|
|
||||||
|
int pw_conf_match_rules(const char *str, size_t len, const char *location,
|
||||||
|
const struct spa_dict *props,
|
||||||
|
int (*callback) (void *data, const char *location, const char *action,
|
||||||
|
const char *str, size_t len),
|
||||||
|
void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \}
|
* \}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue