Make interface types a string

This is more in line with wayland and it allows us to create new
interfaces in modules without having to add anything to the type
enum. It also removes some lookups to map type_id to readable
name in debug.
This commit is contained in:
Wim Taymans 2019-12-19 13:15:10 +01:00
parent 9657486a81
commit f391353c7f
123 changed files with 791 additions and 1251 deletions

View file

@ -193,7 +193,7 @@ static void push_params(struct spa_pod_builder *b, uint32_t n_params,
static void *
core_method_marshal_create_object(void *object,
const char *factory_name,
uint32_t type, uint32_t version,
const char *type, uint32_t version,
const struct spa_dict *props, size_t user_data_size)
{
struct pw_proxy *proxy = object;
@ -213,7 +213,7 @@ core_method_marshal_create_object(void *object,
spa_pod_builder_push_struct(b, &f);
spa_pod_builder_add(b,
SPA_POD_String(factory_name),
SPA_POD_Id(type),
SPA_POD_String(type),
SPA_POD_Int(version),
NULL);
push_dict(b, props);
@ -595,15 +595,15 @@ static int core_method_demarshal_create_object(void *object, const struct pw_pro
struct pw_resource *resource = object;
struct spa_pod_parser prs;
struct spa_pod_frame f[2];
uint32_t version, type, new_id;
const char *factory_name;
uint32_t version, new_id;
const char *factory_name, *type;
struct spa_dict props = SPA_DICT_INIT(NULL, 0);
spa_pod_parser_init(&prs, msg->data, msg->size);
if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
spa_pod_parser_get(&prs,
SPA_POD_String(&factory_name),
SPA_POD_Id(&type),
SPA_POD_String(&type),
SPA_POD_Int(&version),
NULL) < 0)
return -EINVAL;
@ -664,7 +664,7 @@ static int registry_method_marshal_add_listener(void *object,
}
static void registry_marshal_global(void *object, uint32_t id, uint32_t permissions,
uint32_t type, uint32_t version, const struct spa_dict *props)
const char *type, uint32_t version, const struct spa_dict *props)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
@ -676,7 +676,7 @@ static void registry_marshal_global(void *object, uint32_t id, uint32_t permissi
spa_pod_builder_add(b,
SPA_POD_Int(id),
SPA_POD_Int(permissions),
SPA_POD_Id(type),
SPA_POD_String(type),
SPA_POD_Int(version),
NULL);
push_dict(b, props);
@ -701,12 +701,13 @@ static int registry_demarshal_bind(void *object, const struct pw_protocol_native
{
struct pw_resource *resource = object;
struct spa_pod_parser prs;
uint32_t id, version, type, new_id;
uint32_t id, version, new_id;
char *type;
spa_pod_parser_init(&prs, msg->data, msg->size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&id),
SPA_POD_Id(&type),
SPA_POD_String(&type),
SPA_POD_Int(&version),
SPA_POD_Int(&new_id)) < 0)
return -EINVAL;
@ -998,7 +999,7 @@ static void factory_marshal_info(void *object, const struct pw_factory_info *inf
spa_pod_builder_add(b,
SPA_POD_Int(info->id),
SPA_POD_String(info->name),
SPA_POD_Id(info->type),
SPA_POD_String(info->type),
SPA_POD_Int(info->version),
SPA_POD_Long(info->change_mask),
NULL);
@ -1021,7 +1022,7 @@ static int factory_demarshal_info(void *object, const struct pw_protocol_native_
spa_pod_parser_get(&prs,
SPA_POD_Int(&info.id),
SPA_POD_String(&info.name),
SPA_POD_Id(&info.type),
SPA_POD_String(&info.type),
SPA_POD_Int(&info.version),
SPA_POD_Long(&info.change_mask), NULL) < 0)
return -EINVAL;
@ -1815,7 +1816,8 @@ static int registry_demarshal_global(void *object, const struct pw_protocol_nati
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
struct spa_pod_frame f[2];
uint32_t id, permissions, type, version;
uint32_t id, permissions, version;
char *type;
struct spa_dict props = SPA_DICT_INIT(NULL, 0);
spa_pod_parser_init(&prs, msg->data, msg->size);
@ -1823,7 +1825,7 @@ static int registry_demarshal_global(void *object, const struct pw_protocol_nati
spa_pod_parser_get(&prs,
SPA_POD_Int(&id),
SPA_POD_Int(&permissions),
SPA_POD_Id(&type),
SPA_POD_String(&type),
SPA_POD_Int(&version), NULL) < 0)
return -EINVAL;
@ -1856,7 +1858,7 @@ static int registry_demarshal_global_remove(void *object, const struct pw_protoc
}
static void * registry_marshal_bind(void *object, uint32_t id,
uint32_t type, uint32_t version, size_t user_data_size)
const char *type, uint32_t version, size_t user_data_size)
{
struct pw_proxy *proxy = object;
struct spa_pod_builder *b;
@ -1873,7 +1875,7 @@ static void * registry_marshal_bind(void *object, uint32_t id,
spa_pod_builder_add_struct(b,
SPA_POD_Int(id),
SPA_POD_Id(type),
SPA_POD_String(type),
SPA_POD_Int(version),
SPA_POD_Int(new_id));

View file

@ -28,6 +28,9 @@
#include "pipewire/protocol.h"
#include "pipewire/resource.h"
#include "extensions/protocol-native.h"
#include "extensions/metadata.h"
#include "extensions/session-manager.h"
#include "extensions/client-node.h"
#include "interfaces.h"
#include "typemap.h"
@ -275,6 +278,23 @@ uint32_t pw_protocol_native0_type_from_v2(struct pw_impl_client *client, uint32_
return type_map[index].id;
}
SPA_EXPORT
const char * pw_protocol_native0_name_from_v2(struct pw_impl_client *client, uint32_t type)
{
void *t;
uint32_t index;
struct protocol_compat_v2 *compat_v2 = client->compat_v2;
if ((t = pw_map_lookup(&compat_v2->types, type)) == NULL)
return NULL;
index = PW_MAP_PTR_TO_ID(t);
if (index >= SPA_N_ELEMENTS(type_map))
return NULL;
return type_map[index].name;
}
SPA_EXPORT
uint32_t pw_protocol_native0_type_to_v2(struct pw_impl_client *client,
const struct spa_type_info *info, uint32_t type)
@ -614,7 +634,7 @@ static int core_demarshal_create_object(void *object, const struct pw_protocol_n
struct spa_pod_parser prs;
struct spa_pod_frame f;
uint32_t version, type, new_id, i;
const char *factory_name;
const char *factory_name, *type_name;
struct spa_dict props;
spa_pod_parser_init(&prs, msg->data, msg->size);
@ -636,10 +656,12 @@ static int core_demarshal_create_object(void *object, const struct pw_protocol_n
if (spa_pod_parser_get(&prs, "i", &new_id, NULL) < 0)
return -EINVAL;
type = pw_protocol_native0_type_from_v2(client, type);
type_name = pw_protocol_native0_name_from_v2(client, type);
if (type_name == NULL)
return -EINVAL;
return pw_resource_notify(resource, struct pw_core_methods, create_object, 0, factory_name,
type, version,
type_name, version,
&props, new_id);
}
@ -702,19 +724,20 @@ static int core_demarshal_update_types_server(void *object, const struct pw_prot
}
static void registry_marshal_global(void *object, uint32_t id, uint32_t permissions,
uint32_t type, uint32_t version, const struct spa_dict *props)
const char *type, uint32_t version, const struct spa_dict *props)
{
struct pw_resource *resource = object;
struct pw_impl_client *client = resource->client;
struct spa_pod_builder *b;
struct spa_pod_frame f;
uint32_t i, n_items, parent_id;
uint32_t type_id;
b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_V0_EVENT_GLOBAL, NULL);
n_items = props ? props->n_items : 0;
type = pw_protocol_native0_type_to_v2(client, pw_type_info(), type);
type_id = pw_protocol_native0_find_type(client, type);
parent_id = 0;
version = 0;
@ -723,7 +746,7 @@ static void registry_marshal_global(void *object, uint32_t id, uint32_t permissi
"i", id,
"i", parent_id,
"i", permissions,
"I", type,
"I", type_id,
"i", version,
"i", n_items, NULL);
@ -754,6 +777,7 @@ static int registry_demarshal_bind(void *object, const struct pw_protocol_native
struct pw_resource *resource = object;
struct spa_pod_parser prs;
uint32_t id, version, type, new_id;
const char *type_name;
spa_pod_parser_init(&prs, msg->data, msg->size);
if (spa_pod_parser_get_struct(&prs,
@ -763,9 +787,11 @@ static int registry_demarshal_bind(void *object, const struct pw_protocol_native
"i", &new_id) < 0)
return -EINVAL;
type = pw_protocol_native0_type_from_v2(resource->client, type);
type_name = pw_protocol_native0_name_from_v2(resource->client, type);
if (type_name == NULL)
return -EINVAL;
return pw_resource_notify(resource, struct pw_registry_methods, bind, 0, id, type, version, new_id);
return pw_resource_notify(resource, struct pw_registry_methods, bind, 0, id, type_name, version, new_id);
}
static void module_marshal_info(void *object, const struct pw_module_info *info)
@ -810,7 +836,7 @@ static void factory_marshal_info(void *object, const struct pw_factory_info *inf
n_items = info->props ? info->props->n_items : 0;
type = pw_protocol_native0_type_to_v2(client, pw_type_info(), info->type);
type = pw_protocol_native0_find_type(client, info->type);
version = 0;
spa_pod_builder_push_struct(b, &f);

View file

@ -5,34 +5,34 @@ const struct type_info {
uint32_t id;
} type_map[] = {
{ "Spa:Interface:TypeMap", SPA_TYPE_INFO_INTERFACE_BASE, 0, },
{ "Spa:Interface:Log", SPA_TYPE_INFO_INTERFACE_BASE "Log", SPA_TYPE_INTERFACE_Log, },
{ "Spa:Interface:Loop", SPA_TYPE_INFO_INTERFACE_BASE "Loop", SPA_TYPE_INTERFACE_Loop, },
{ "Spa:Interface:LoopControl", SPA_TYPE_INFO_INTERFACE_BASE "LoopControl", SPA_TYPE_INTERFACE_LoopControl, },
{ "Spa:Interface:LoopUtils", SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils", SPA_TYPE_INTERFACE_LoopUtils, },
{ "PipeWire:Interface:Core", PW_TYPE_INFO_INTERFACE_BASE "Core", PW_TYPE_INTERFACE_Core, },
{ "PipeWire:Interface:Registry", PW_TYPE_INFO_INTERFACE_BASE "Registry", PW_TYPE_INTERFACE_Registry, },
{ "PipeWire:Interface:Node", PW_TYPE_INFO_INTERFACE_BASE "Node", PW_TYPE_INTERFACE_Node, },
{ "PipeWire:Interface:Port", PW_TYPE_INFO_INTERFACE_BASE "Port", PW_TYPE_INTERFACE_Port,},
{ "PipeWire:Interface:Factory", PW_TYPE_INFO_INTERFACE_BASE "Factory", PW_TYPE_INTERFACE_Factory, },
{ "PipeWire:Interface:Link", PW_TYPE_INFO_INTERFACE_BASE "Link", PW_TYPE_INTERFACE_Link, },
{ "PipeWire:Interface:Client", PW_TYPE_INFO_INTERFACE_BASE "Client", PW_TYPE_INTERFACE_Client, },
{ "PipeWire:Interface:Module", PW_TYPE_INFO_INTERFACE_BASE "Module", PW_TYPE_INTERFACE_Module, },
{ "PipeWire:Interface:Device", PW_TYPE_INFO_INTERFACE_BASE "Device", PW_TYPE_INTERFACE_Device, },
{ "Spa:Interface:Log", SPA_TYPE_INTERFACE_Log, 0, },
{ "Spa:Interface:Loop", SPA_TYPE_INTERFACE_Loop, 0, },
{ "Spa:Interface:LoopControl", SPA_TYPE_INTERFACE_LoopControl, 0, },
{ "Spa:Interface:LoopUtils", SPA_TYPE_INTERFACE_LoopUtils, 0, },
{ "PipeWire:Interface:Core", PW_TYPE_INTERFACE_Core, 0, },
{ "PipeWire:Interface:Registry", PW_TYPE_INTERFACE_Registry, 0, },
{ "PipeWire:Interface:Node", PW_TYPE_INTERFACE_Node, 0, },
{ "PipeWire:Interface:Port", PW_TYPE_INTERFACE_Port,0, },
{ "PipeWire:Interface:Factory", PW_TYPE_INTERFACE_Factory, 0, },
{ "PipeWire:Interface:Link", PW_TYPE_INTERFACE_Link, 0, },
{ "PipeWire:Interface:Client", PW_TYPE_INTERFACE_Client, 0, },
{ "PipeWire:Interface:Module", PW_TYPE_INTERFACE_Module, 0, },
{ "PipeWire:Interface:Device", PW_TYPE_INTERFACE_Device, 0, },
{ "PipeWire:Interface:Metadata", PW_TYPE_INFO_INTERFACE_BASE "Metadata", PW_TYPE_INTERFACE_Metadata, },
{ "PipeWire:Interface:Session", PW_TYPE_INFO_INTERFACE_BASE "Session", PW_TYPE_INTERFACE_Session, },
{ "PipeWire:Interface:Endpoint", PW_TYPE_INFO_INTERFACE_BASE "Endpoint", PW_TYPE_INTERFACE_Endpoint, },
{ "PipeWire:Interface:EndpointStream", PW_TYPE_INFO_INTERFACE_BASE "EndpointStream", PW_TYPE_INTERFACE_EndpointStream, },
{ "PipeWire:Interface:EndpointLink", PW_TYPE_INFO_INTERFACE_BASE "EndpointLink", PW_TYPE_INTERFACE_EndpointLink, },
{ "PipeWire:Interface:Metadata", PW_TYPE_INTERFACE_Metadata, 0, },
{ "PipeWire:Interface:Session", PW_TYPE_INTERFACE_Session, 0, },
{ "PipeWire:Interface:Endpoint", PW_TYPE_INTERFACE_Endpoint, 0, },
{ "PipeWire:Interface:EndpointStream", PW_TYPE_INTERFACE_EndpointStream, 0, },
{ "PipeWire:Interface:EndpointLink", PW_TYPE_INTERFACE_EndpointLink, 0, },
{ "PipeWire:Interface:ClientNode", PW_TYPE_INFO_INTERFACE_BASE "ClientNode", PW_TYPE_INTERFACE_ClientNode, },
{ "PipeWire:Interface:ClientSession", PW_TYPE_INFO_INTERFACE_BASE "ClientSession", PW_TYPE_INTERFACE_ClientSession, },
{ "PipeWire:Interface:ClientEndpoint", PW_TYPE_INFO_INTERFACE_BASE "ClientEndpoint", PW_TYPE_INTERFACE_ClientEndpoint, },
{ "PipeWire:Interface:ClientNode", PW_TYPE_INTERFACE_ClientNode, 0, },
{ "PipeWire:Interface:ClientSession", PW_TYPE_INTERFACE_ClientSession, 0, },
{ "PipeWire:Interface:ClientEndpoint", PW_TYPE_INTERFACE_ClientEndpoint, 0, },
{ "Spa:Interface:Node", SPA_TYPE_INFO_INTERFACE_BASE "Node", SPA_TYPE_INTERFACE_Node, },
{ "Spa:Interface:Node", SPA_TYPE_INTERFACE_Node, 0, },
{ "Spa:Interface:Clock", },
{ "Spa:Interface:Monitor", },
{ "Spa:Interface:Device", SPA_TYPE_INFO_INTERFACE_BASE "Device", SPA_TYPE_INTERFACE_Device, },
{ "Spa:Interface:Device", SPA_TYPE_INTERFACE_Device, 0, },
{ "Spa:POD:Object:Param:Format", SPA_TYPE_INFO_Format, SPA_TYPE_OBJECT_Format, },
{ "Spa:POD:Object:Param:Props", SPA_TYPE_INFO_Props, SPA_TYPE_OBJECT_Props, },
{ "Spa:Pointer:IO:Buffers", },
@ -102,7 +102,7 @@ const struct type_info {
{ "Spa:Enum:ParamId:IO:Props:In", },
{ "Spa:Enum:ParamId:IO:Props:Out", },
{ "Spa:POD:Object:Param:IO:Prop", },
{ "Spa:Interface:DBus", SPA_TYPE_INFO_INTERFACE_BASE "DBus", SPA_TYPE_INTERFACE_DBus, },
{ "Spa:Interface:DBus", SPA_TYPE_INFO_INTERFACE_BASE "DBus", 0, },
{ "Spa:Enum:MediaType:audio", SPA_TYPE_INFO_MEDIA_TYPE_BASE "audio", SPA_MEDIA_TYPE_audio, },
{ "Spa:Enum:MediaType:video", SPA_TYPE_INFO_MEDIA_TYPE_BASE "video", SPA_MEDIA_TYPE_video, },
{ "Spa:Enum:MediaType:image", SPA_TYPE_INFO_MEDIA_TYPE_BASE "image", SPA_MEDIA_TYPE_image, },