More type cleanups

SPA_ID_* -> SPA_TYPE_*. We use 'type' for all registered types.
ID refers to either a registered type or an enum.
Improve introspection of object ids. Make 0 an invalid enum and
use it to look up the object id type.
Move some type-info files together.
Swap type and id of the object, we first specify the type and then
the id because the meaning of the id depends on the object type.
This commit is contained in:
Wim Taymans 2018-08-27 15:03:11 +02:00
parent 281b65934e
commit 90c1a95eef
117 changed files with 1198 additions and 1272 deletions

View file

@ -26,17 +26,17 @@ extern "C" {
#include <spa/pod/parser.h>
#include <spa/debug/types.h>
#include <spa/param/format-types.h>
#include <spa/param/type-info.h>
static inline int
spa_debug_format_value(const struct spa_type_info *info,
uint32_t type, void *body, uint32_t size)
{
switch (type) {
case SPA_ID_Bool:
case SPA_TYPE_Bool:
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
break;
case SPA_ID_Enum:
case SPA_TYPE_Enum:
{
const char *str = spa_debug_type_find_name(info, *(int32_t *) body);
char tmp[64];
@ -51,37 +51,37 @@ spa_debug_format_value(const struct spa_type_info *info,
fprintf(stderr, "%s", str);
break;
}
case SPA_ID_Int:
case SPA_TYPE_Int:
fprintf(stderr, "%d", *(int32_t *) body);
break;
case SPA_ID_Long:
case SPA_TYPE_Long:
fprintf(stderr, "%" PRIi64, *(int64_t *) body);
break;
case SPA_ID_Float:
case SPA_TYPE_Float:
fprintf(stderr, "%f", *(float *) body);
break;
case SPA_ID_Double:
case SPA_TYPE_Double:
fprintf(stderr, "%g", *(double *) body);
break;
case SPA_ID_String:
case SPA_TYPE_String:
fprintf(stderr, "%s", (char *) body);
break;
case SPA_ID_Rectangle:
case SPA_TYPE_Rectangle:
{
struct spa_rectangle *r = body;
fprintf(stderr, "%" PRIu32 "x%" PRIu32, r->width, r->height);
break;
}
case SPA_ID_Fraction:
case SPA_TYPE_Fraction:
{
struct spa_fraction *f = body;
fprintf(stderr, "%" PRIu32 "/%" PRIu32, f->num, f->denom);
break;
}
case SPA_ID_Bitmap:
case SPA_TYPE_Bitmap:
fprintf(stderr, "Bitmap");
break;
case SPA_ID_Bytes:
case SPA_TYPE_Bytes:
fprintf(stderr, "Bytes");
break;
default:
@ -100,28 +100,28 @@ static inline int spa_debug_format(int indent,
struct spa_pod *pod;
uint32_t mtype, mstype;
const char *pod_type_names[] = {
[SPA_ID_None] = "none",
[SPA_ID_Bool] = "bool",
[SPA_ID_Enum] = "enum",
[SPA_ID_Int] = "int",
[SPA_ID_Long] = "long",
[SPA_ID_Float] = "float",
[SPA_ID_Double] = "double",
[SPA_ID_String] = "string",
[SPA_ID_Bytes] = "bytes",
[SPA_ID_Rectangle] = "rectangle",
[SPA_ID_Fraction] = "fraction",
[SPA_ID_Bitmap] = "bitmap",
[SPA_ID_Array] = "array",
[SPA_ID_Struct] = "struct",
[SPA_ID_Object] = "object",
[SPA_ID_Pointer] = "pointer",
[SPA_ID_Fd] = "fd",
[SPA_ID_Prop] = "prop",
[SPA_ID_Pod] = "pod"
[SPA_TYPE_None] = "none",
[SPA_TYPE_Bool] = "bool",
[SPA_TYPE_Enum] = "enum",
[SPA_TYPE_Int] = "int",
[SPA_TYPE_Long] = "long",
[SPA_TYPE_Float] = "float",
[SPA_TYPE_Double] = "double",
[SPA_TYPE_String] = "string",
[SPA_TYPE_Bytes] = "bytes",
[SPA_TYPE_Rectangle] = "rectangle",
[SPA_TYPE_Fraction] = "fraction",
[SPA_TYPE_Bitmap] = "bitmap",
[SPA_TYPE_Array] = "array",
[SPA_TYPE_Struct] = "struct",
[SPA_TYPE_Object] = "object",
[SPA_TYPE_Pointer] = "pointer",
[SPA_TYPE_Fd] = "fd",
[SPA_TYPE_Prop] = "prop",
[SPA_TYPE_Pod] = "pod"
};
if (format == NULL || SPA_POD_TYPE(format) != SPA_ID_Object)
if (format == NULL || SPA_POD_TYPE(format) != SPA_TYPE_Object)
return -EINVAL;
@ -144,7 +144,7 @@ static inline int spa_debug_format(int indent,
const char *key;
const struct spa_type_info *ti;
if (pod->type != SPA_ID_Prop)
if (pod->type != SPA_TYPE_Prop)
continue;
prop = (struct spa_pod_prop *)pod;

View file

@ -38,54 +38,54 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
uint32_t type, void *body, uint32_t size)
{
switch (type) {
case SPA_ID_Bool:
case SPA_TYPE_Bool:
spa_debug("%*s" "Bool %d", indent, "", *(int32_t *) body);
break;
case SPA_ID_Enum:
spa_debug("%*s" "Enum %d %s", indent, "", *(int32_t *) body,
case SPA_TYPE_Enum:
spa_debug("%*s" "Enum %d (%s)", indent, "", *(int32_t *) body,
spa_debug_type_find_name(info, *(int32_t *) body));
break;
case SPA_ID_Int:
case SPA_TYPE_Int:
spa_debug("%*s" "Int %d", indent, "", *(int32_t *) body);
break;
case SPA_ID_Long:
case SPA_TYPE_Long:
spa_debug("%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body);
break;
case SPA_ID_Float:
case SPA_TYPE_Float:
spa_debug("%*s" "Float %f", indent, "", *(float *) body);
break;
case SPA_ID_Double:
case SPA_TYPE_Double:
spa_debug("%*s" "Double %f", indent, "", *(double *) body);
break;
case SPA_ID_String:
case SPA_TYPE_String:
spa_debug("%*s" "String \"%s\"", indent, "", (char *) body);
break;
case SPA_ID_Fd:
case SPA_TYPE_Fd:
spa_debug("%*s" "Fd %d", indent, "", *(int *) body);
break;
case SPA_ID_Pointer:
case SPA_TYPE_Pointer:
{
struct spa_pod_pointer_body *b = body;
spa_debug("%*s" "Pointer %s %p", indent, "",
spa_debug_type_find_name(spa_types, b->type), b->value);
break;
}
case SPA_ID_Rectangle:
case SPA_TYPE_Rectangle:
{
struct spa_rectangle *r = body;
spa_debug("%*s" "Rectangle %dx%d", indent, "", r->width, r->height);
break;
}
case SPA_ID_Fraction:
case SPA_TYPE_Fraction:
{
struct spa_fraction *f = body;
spa_debug("%*s" "Fraction %d/%d", indent, "", f->num, f->denom);
break;
}
case SPA_ID_Bitmap:
case SPA_TYPE_Bitmap:
spa_debug("%*s" "Bitmap", indent, "");
break;
case SPA_ID_Array:
case SPA_TYPE_Array:
{
struct spa_pod_array_body *b = body;
void *p;
@ -100,7 +100,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size);
break;
}
case SPA_ID_Struct:
case SPA_TYPE_Struct:
{
struct spa_pod *b = body, *p;
spa_debug("%*s" "Struct: size %d", indent, "", size);
@ -108,14 +108,19 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
spa_debug_pod_value(indent + 2, info, p->type, SPA_POD_BODY(p), p->size);
break;
}
case SPA_ID_Object:
case SPA_TYPE_Object:
{
struct spa_pod_object_body *b = body;
struct spa_pod *p;
const struct spa_type_info *ti = spa_debug_type_find(info, b->type);
const struct spa_type_info *ti;
const struct spa_type_info *ii;
spa_debug("%*s" "Object: size %d, id %s, type %s", indent, "", size,
spa_debug_type_find_name(info, b->id), ti ? ti->name : "unknown");
ti = spa_debug_type_find(info, b->type);
ii = ti ? spa_debug_type_find(ti->values, 0) : NULL;
ii = ii ? spa_debug_type_find(ii->values, b->id) : NULL;
spa_debug("%*s" "Object: size %d, type %s, id %s", indent, "", size,
ti ? ti->name : "unknown", ii ? ii->name : "unknown");
info = ti ? ti->values : info;
@ -124,7 +129,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
p->type, SPA_POD_BODY(p), p->size);
break;
}
case SPA_ID_Prop:
case SPA_TYPE_Prop:
{
struct spa_pod_prop_body *b = body;
void *alt;
@ -188,11 +193,11 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
}
break;
}
case SPA_ID_Bytes:
case SPA_TYPE_Bytes:
spa_debug("%*s" "Bytes", indent, "");
spa_debug_mem(indent + 2, body, size);
break;
case SPA_ID_None:
case SPA_TYPE_None:
spa_debug("%*s" "None", indent, "");
spa_debug_mem(indent + 2, body, size);
break;

View file

@ -28,40 +28,39 @@ extern "C" {
static const struct spa_type_info spa_debug_types[] =
{
{ SPA_ID_INVALID, "", SPA_ID_Enum, spa_types },
{ SPA_ID_INVALID, "", SPA_TYPE_Enum, spa_types },
{ 0, NULL, },
};
static inline const struct spa_type_info *spa_debug_type_find(const struct spa_type_info *info, uint32_t id)
static inline const struct spa_type_info *spa_debug_type_find(const struct spa_type_info *info, uint32_t type)
{
const struct spa_type_info *res;
while (info && info->name) {
if (info->id == SPA_ID_INVALID)
if ((res = spa_debug_type_find(info->values, id)))
if (info->type == SPA_ID_INVALID)
if ((res = spa_debug_type_find(info->values, type)))
return res;
if (info->id == id)
if (info->type == type)
return info;
info++;
}
return NULL;
}
static inline const char *spa_debug_type_find_name(const struct spa_type_info *info, uint32_t id)
static inline const char *spa_debug_type_find_name(const struct spa_type_info *info, uint32_t type)
{
const struct spa_type_info *type;
if ((type = spa_debug_type_find(info, id)) == NULL)
if ((info = spa_debug_type_find(info, type)) == NULL)
return NULL;
return type->name;
return info->name;
}
static inline uint32_t spa_debug_type_find_id(const struct spa_type_info *info, const char *name)
static inline uint32_t spa_debug_type_find_type(const struct spa_type_info *info, const char *name)
{
while (info && info->name) {
uint32_t res;
if (strcmp(info->name, name) == 0)
return info->id;
if ((res = spa_debug_type_find_id(info->values, name)) != SPA_ID_INVALID)
return info->type;
if ((res = spa_debug_type_find_type(info->values, name)) != SPA_ID_INVALID)
return res;
info++;
}