types: work on types

Move static pod types to type system
work on type info for types
Move the event and command ids to an enum to make it easier to extend
later.
This commit is contained in:
Wim Taymans 2018-08-24 10:53:09 +02:00
parent fca3e1d85d
commit 805e3bb6c1
82 changed files with 812 additions and 924 deletions

View file

@ -34,11 +34,11 @@ spa_debug_format_value(const struct spa_type_info *info,
uint32_t type, void *body, uint32_t size)
{
switch (type) {
case SPA_POD_TYPE_BOOL:
case SPA_ID_Bool:
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
break;
case SPA_POD_TYPE_ID:
case SPA_POD_TYPE_INT:
case SPA_ID_Enum:
case SPA_ID_Int:
{
const char *str = spa_debug_type_find_name(info, *(int32_t *) body);
char tmp[64];
@ -53,37 +53,38 @@ spa_debug_format_value(const struct spa_type_info *info,
fprintf(stderr, "%s", str);
break;
}
case SPA_POD_TYPE_LONG:
case SPA_ID_Long:
fprintf(stderr, "%" PRIi64, *(int64_t *) body);
break;
case SPA_POD_TYPE_FLOAT:
case SPA_ID_Float:
fprintf(stderr, "%f", *(float *) body);
break;
case SPA_POD_TYPE_DOUBLE:
case SPA_ID_Double:
fprintf(stderr, "%g", *(double *) body);
break;
case SPA_POD_TYPE_STRING:
case SPA_ID_String:
fprintf(stderr, "%s", (char *) body);
break;
case SPA_POD_TYPE_RECTANGLE:
case SPA_ID_Rectangle:
{
struct spa_rectangle *r = body;
fprintf(stderr, "%" PRIu32 "x%" PRIu32, r->width, r->height);
break;
}
case SPA_POD_TYPE_FRACTION:
case SPA_ID_Fraction:
{
struct spa_fraction *f = body;
fprintf(stderr, "%" PRIu32 "/%" PRIu32, f->num, f->denom);
break;
}
case SPA_POD_TYPE_BITMAP:
case SPA_ID_Bitmap:
fprintf(stderr, "Bitmap");
break;
case SPA_POD_TYPE_BYTES:
case SPA_ID_Bytes:
fprintf(stderr, "Bytes");
break;
default:
fprintf(stderr, "INVALID type %d", type);
break;
}
return 0;
@ -98,29 +99,28 @@ static inline int spa_debug_format(int indent,
struct spa_pod *pod;
uint32_t mtype, mstype;
const char *pod_type_names[] = {
[SPA_POD_TYPE_INVALID] = "invalid",
[SPA_POD_TYPE_NONE] = "none",
[SPA_POD_TYPE_BOOL] = "bool",
[SPA_POD_TYPE_ID] = "id",
[SPA_POD_TYPE_INT] = "int",
[SPA_POD_TYPE_LONG] = "long",
[SPA_POD_TYPE_FLOAT] = "float",
[SPA_POD_TYPE_DOUBLE] = "double",
[SPA_POD_TYPE_STRING] = "string",
[SPA_POD_TYPE_BYTES] = "bytes",
[SPA_POD_TYPE_RECTANGLE] = "rectangle",
[SPA_POD_TYPE_FRACTION] = "fraction",
[SPA_POD_TYPE_BITMAP] = "bitmap",
[SPA_POD_TYPE_ARRAY] = "array",
[SPA_POD_TYPE_STRUCT] = "struct",
[SPA_POD_TYPE_OBJECT] = "object",
[SPA_POD_TYPE_POINTER] = "pointer",
[SPA_POD_TYPE_FD] = "fd",
[SPA_POD_TYPE_PROP] = "prop",
[SPA_POD_TYPE_POD] = "pod"
[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"
};
if (format == NULL || SPA_POD_TYPE(format) != SPA_POD_TYPE_OBJECT)
if (format == NULL || SPA_POD_TYPE(format) != SPA_ID_Object)
return -EINVAL;
@ -143,7 +143,7 @@ static inline int spa_debug_format(int indent,
const char *key;
const struct spa_type_info *ti;
if (pod->type != SPA_POD_TYPE_PROP)
if (pod->type != SPA_ID_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_POD_TYPE_BOOL:
case SPA_ID_Bool:
spa_debug("%*s" "Bool %d", indent, "", *(int32_t *) body);
break;
case SPA_POD_TYPE_ID:
spa_debug("%*s" "Id %d %s", indent, "", *(int32_t *) body,
case SPA_ID_Enum:
spa_debug("%*s" "Enum %d %s", indent, "", *(int32_t *) body,
spa_debug_type_find_name(info, *(int32_t *) body));
break;
case SPA_POD_TYPE_INT:
case SPA_ID_Int:
spa_debug("%*s" "Int %d", indent, "", *(int32_t *) body);
break;
case SPA_POD_TYPE_LONG:
case SPA_ID_Long:
spa_debug("%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body);
break;
case SPA_POD_TYPE_FLOAT:
case SPA_ID_Float:
spa_debug("%*s" "Float %f", indent, "", *(float *) body);
break;
case SPA_POD_TYPE_DOUBLE:
case SPA_ID_Double:
spa_debug("%*s" "Double %f", indent, "", *(double *) body);
break;
case SPA_POD_TYPE_STRING:
case SPA_ID_String:
spa_debug("%*s" "String \"%s\"", indent, "", (char *) body);
break;
case SPA_POD_TYPE_FD:
case SPA_ID_Fd:
spa_debug("%*s" "Fd %d", indent, "", *(int *) body);
break;
case SPA_POD_TYPE_POINTER:
case SPA_ID_Pointer:
{
struct spa_pod_pointer_body *b = body;
spa_debug("%*s" "Pointer %s %p", indent, "",
spa_debug_type_find_name(info, b->type), b->value);
break;
}
case SPA_POD_TYPE_RECTANGLE:
case SPA_ID_Rectangle:
{
struct spa_rectangle *r = body;
spa_debug("%*s" "Rectangle %dx%d", indent, "", r->width, r->height);
break;
}
case SPA_POD_TYPE_FRACTION:
case SPA_ID_Fraction:
{
struct spa_fraction *f = body;
spa_debug("%*s" "Fraction %d/%d", indent, "", f->num, f->denom);
break;
}
case SPA_POD_TYPE_BITMAP:
case SPA_ID_Bitmap:
spa_debug("%*s" "Bitmap", indent, "");
break;
case SPA_POD_TYPE_ARRAY:
case SPA_ID_Array:
{
struct spa_pod_array_body *b = body;
void *p;
@ -96,7 +96,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_POD_TYPE_STRUCT:
case SPA_ID_Struct:
{
struct spa_pod *b = body, *p;
spa_debug("%*s" "Struct: size %d", indent, "", size);
@ -104,7 +104,7 @@ 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_POD_TYPE_OBJECT:
case SPA_ID_Object:
{
struct spa_pod_object_body *b = body;
struct spa_pod *p;
@ -117,7 +117,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
p->type, SPA_POD_BODY(p), p->size);
break;
}
case SPA_POD_TYPE_PROP:
case SPA_ID_Prop:
{
struct spa_pod_prop_body *b = body;
void *alt;
@ -176,11 +176,11 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info,
}
break;
}
case SPA_POD_TYPE_BYTES:
case SPA_ID_Bytes:
spa_debug("%*s" "Bytes", indent, "");
spa_debug_mem(indent + 2, body, size);
break;
case SPA_POD_TYPE_NONE:
case SPA_ID_None:
spa_debug("%*s" "None", indent, "");
spa_debug_mem(indent + 2, body, size);
break;

View file

@ -24,16 +24,11 @@
extern "C" {
#endif
#include <spa/monitor/monitor-types.h>
#include <spa/node/node-types.h>
#include <spa/param/buffers.h>
#include <spa/param/buffers-types.h>
#include <spa/utils/type-info.h>
static const struct spa_type_info spa_debug_types[] =
{
{ SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_monitor },
{ SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_node },
{ SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_param_buffers },
{ SPA_ID_INVALID, "", SPA_ID_Enum, spa_types },
{ 0, NULL, },
};