spa: make common function to find type from short name

This commit is contained in:
Wim Taymans 2022-01-20 18:02:41 +01:00
parent ba7e5d619d
commit aa128ed489
4 changed files with 25 additions and 47 deletions

View file

@ -96,6 +96,26 @@ static inline uint32_t spa_debug_type_find_type(const struct spa_type_info *info
return SPA_ID_INVALID;
}
static inline const struct spa_type_info *spa_debug_type_find_short(const struct spa_type_info *info, const char *name)
{
while (info && info->name) {
if (strcmp(spa_debug_type_short_name(info->name), name) == 0)
return info;
if (strcmp(info->name, name) == 0)
return info;
if (info->type != 0 && info->type == (uint32_t)atoi(name))
return info;
info++;
}
return NULL;
}
static inline uint32_t spa_debug_type_find_type_short(const struct spa_type_info *info, const char *name)
{
if ((info = spa_debug_type_find_short(info, name)) == NULL)
return SPA_ID_INVALID;
return info->type;
}
/**
* \}
*/

View file

@ -44,20 +44,6 @@ extern "C" {
* \{
*/
static inline const struct spa_type_info *spa_debug_type_info_short(const struct spa_type_info *info, const char *name)
{
while (info && info->name) {
if (spa_streq(info->name, name))
return info;
if (spa_streq(spa_debug_type_short_name(info->name), name))
return info;
if (info->type != 0 && info->type == (uint32_t)atoi(name))
return info;
info++;
}
return NULL;
}
static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags, uint32_t id,
const struct spa_type_info *info, struct spa_json *iter, const char *value, int len)
{
@ -80,7 +66,7 @@ static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags
const struct spa_type_info *pi;
if ((l = spa_json_next(&it[0], &v)) <= 0)
break;
if ((pi = spa_debug_type_info_short(ti->values, key)) != NULL)
if ((pi = spa_debug_type_find_short(ti->values, key)) != NULL)
type = pi->type;
else if (!spa_atou32(key, &type, 0))
continue;
@ -149,7 +135,7 @@ static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags
spa_json_parse_stringn(value, len, val, len+1);
switch (info ? info->parent : (uint32_t)SPA_TYPE_Struct) {
case SPA_TYPE_Id:
if ((ti = spa_debug_type_info_short(info->values, val)) != NULL)
if ((ti = spa_debug_type_find_short(info->values, val)) != NULL)
type = ti->type;
else if (!spa_atou32(val, &type, 0))
return -EINVAL;

View file

@ -173,20 +173,6 @@ static const struct pw_impl_node_events node_events = {
.port_init = node_port_init,
};
static const struct spa_type_info *find_type_info(const struct spa_type_info *info, const char *name)
{
while (info && info->name) {
if (spa_streq(info->name, name))
return info;
if (spa_streq(spa_debug_type_short_name(info->name), name))
return info;
if (info->type != 0 && info->type == (uint32_t)atoi(name))
return info;
info++;
}
return NULL;
}
static int handle_node_param(struct pw_impl_node *node, const char *key, const char *value)
{
const struct spa_type_info *ti;
@ -195,7 +181,7 @@ static int handle_node_param(struct pw_impl_node *node, const char *key, const c
struct spa_pod *pod;
int res;
ti = find_type_info(spa_type_param, key);
ti = spa_debug_type_find_short(spa_type_param, key);
if (ti == NULL)
return -ENOENT;

View file

@ -1477,20 +1477,6 @@ static bool do_export_node(struct data *data, const char *cmd, char *args, char
return false;
}
static const struct spa_type_info *find_type_info(const struct spa_type_info *info, const char *name)
{
while (info && info->name) {
if (spa_streq(info->name, name))
return info;
if (spa_streq(spa_debug_type_short_name(info->name), name))
return info;
if (info->type != 0 && info->type == (uint32_t)atoi(name))
return info;
info++;
}
return NULL;
}
static bool do_enum_params(struct data *data, const char *cmd, char *args, char **error)
{
struct remote_data *rd = data->current;
@ -1507,7 +1493,7 @@ static bool do_enum_params(struct data *data, const char *cmd, char *args, char
}
id = atoi(a[0]);
ti = find_type_info(spa_type_param, a[1]);
ti = spa_debug_type_find_short(spa_type_param, a[1]);
if (ti == NULL) {
*error = spa_aprintf("%s: unknown param type: %s", cmd, a[1]);
return false;
@ -1574,7 +1560,7 @@ static bool do_set_param(struct data *data, const char *cmd, char *args, char **
return false;
}
ti = find_type_info(spa_type_param, a[1]);
ti = spa_debug_type_find_short(spa_type_param, a[1]);
if (ti == NULL) {
*error = spa_aprintf("%s: unknown param type: %s", cmd, a[1]);
return false;