clean up proxy and resource api

Remove override for resources, it can't work in general.
Rename method to add_object_listener to add a listener for
events/methods from the remote object.
Rename some methods to _call to call the interface and _notify
to notify the listeners.
Remove unused client event to be notified of resource
implementations.
This commit is contained in:
Wim Taymans 2019-05-29 10:39:24 +02:00
parent b1ea91fa1d
commit e9ecc47696
25 changed files with 196 additions and 249 deletions

View file

@ -30,24 +30,6 @@
#include <extensions/protocol-native.h>
#if 0
static void push_dict(struct spa_pod_builder *b, const struct spa_dict *dict)
{
uint32_t i, n_items;
struct spa_pod_frame f;
n_items = dict ? dict->n_items : 0;
spa_pod_builder_push_struct(b, &f);
spa_pod_builder_int(b, n_items);
for (i = 0; i < n_items; i++) {
spa_pod_builder_string(b, dict->items[i].key);
spa_pod_builder_string(b, dict->items[i].value);
}
spa_pod_builder_pop(b, &f);
}
#endif
static int device_marshal_add_listener(void *object,
struct spa_hook *listener,
const struct spa_device_events *events,
@ -254,7 +236,7 @@ static int device_demarshal_info(void *object,
else {
infop = NULL;
}
pw_resource_do(resource, struct spa_device_events, info, 0, infop);
pw_resource_notify(resource, struct spa_device_events, info, 0, infop);
return 0;
}
@ -332,7 +314,7 @@ static int device_demarshal_result(void *object,
break;
}
pw_resource_do(resource, struct spa_device_events, result, 0, seq, res, type, result);
pw_resource_notify(resource, struct spa_device_events, result, 0, seq, res, type, result);
return 0;
}
@ -364,7 +346,7 @@ static int device_demarshal_event(void *object,
SPA_POD_PodObject(&event)) < 0)
return -EINVAL;
pw_resource_do(resource, struct spa_device_events, event, 0, event);
pw_resource_notify(resource, struct spa_device_events, event, 0, event);
return 0;
}
@ -458,7 +440,7 @@ static int device_demarshal_object_info(void *object,
infop = NULL;
}
pw_resource_do(resource, struct spa_device_events, object_info, 0, id, infop);
pw_resource_notify(resource, struct spa_device_events, object_info, 0, id, infop);
return 0;
}

View file

@ -44,71 +44,6 @@ struct device_data {
struct spa_hook proxy_listener;
};
static void device_event_info(void *_data, const struct spa_device_info *info)
{
struct device_data *data = _data;
struct spa_interface *iface = (struct spa_interface*)data->proxy;
pw_log_debug("%p", data);
spa_interface_call(iface, struct spa_device_events, info, 0, info);
}
static void device_event_result(void *_data, int seq, int res, uint32_t type, const void *result)
{
struct device_data *data = _data;
struct spa_interface *iface = (struct spa_interface*)data->proxy;
pw_log_debug("%p", data);
spa_interface_call(iface, struct spa_device_events, result, 0, seq, res, type, result);
}
static void device_event_event(void *_data, const struct spa_event *event)
{
struct device_data *data = _data;
struct spa_interface *iface = (struct spa_interface*)data->proxy;
pw_log_debug("%p", data);
spa_interface_call(iface, struct spa_device_events, event, 0, event);
}
static void device_event_object_info(void *_data, uint32_t id,
const struct spa_device_object_info *info)
{
struct device_data *data = _data;
struct spa_interface *iface = (struct spa_interface*)data->proxy;
pw_log_debug("%p", data);
spa_interface_call(iface, struct spa_device_events, object_info, 0, id, info);
}
static const struct spa_device_events device_events = {
SPA_VERSION_DEVICE_EVENTS,
.info = device_event_info,
.result = device_event_result,
.event = device_event_event,
.object_info = device_event_object_info,
};
static int device_method_enum_params(void *object, int seq,
uint32_t id, uint32_t index, uint32_t max,
const struct spa_pod *filter)
{
struct device_data *data = object;
pw_log_debug("%p", data);
return spa_device_enum_params(data->device, seq, id, index, max, filter);
}
static int device_method_set_param(void *object,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct device_data *data = object;
pw_log_debug("%p", data);
return spa_device_set_param(data->device, id, flags, param);
}
static const struct spa_device_methods device_methods = {
SPA_VERSION_DEVICE_METHODS,
.enum_params = device_method_enum_params,
.set_param = device_method_set_param,
};
static void device_proxy_destroy(void *_data)
{
struct device_data *data = _data;
@ -124,6 +59,7 @@ struct pw_proxy *pw_remote_spa_device_export(struct pw_remote *remote,
uint32_t type, struct pw_properties *props, void *object)
{
struct spa_device *device = object;
struct spa_interface *iface;
struct pw_proxy *proxy;
struct device_data *data;
@ -142,9 +78,14 @@ struct pw_proxy *pw_remote_spa_device_export(struct pw_remote *remote,
data->core = pw_remote_get_core(remote);
data->proxy = proxy;
iface = (struct spa_interface*)proxy;
pw_proxy_add_listener(proxy, &data->proxy_listener, &proxy_events, data);
pw_proxy_add_proxy_listener(proxy, &data->device_methods, &device_methods, data);
spa_device_add_listener(device, &data->device_listener, &device_events, data);
pw_proxy_add_object_listener(proxy, &data->device_methods,
device->iface.cb.funcs, device->iface.cb.data);
spa_device_add_listener(device, &data->device_listener,
iface->cb.funcs, iface->cb.data);
return proxy;
}

View file

@ -49,13 +49,14 @@ struct impl {
struct pw_resource *resource;
struct spa_hook resource_listener;
struct spa_hook implementation_listener;
struct pw_global *parent;
unsigned int registered:1;
};
#define pw_device_resource(r,m,v,...) \
pw_resource_notify_res(r,struct spa_device_methods,m,v,__VA_ARGS__)
pw_resource_call_res(r,struct spa_device_methods,m,v,__VA_ARGS__)
#define pw_device_resource_enum_params(r,...) \
pw_device_resource(r,enum_params,0,__VA_ARGS__)
@ -161,6 +162,7 @@ static void device_resource_destroy(void *data)
impl->resource = NULL;
spa_hook_remove(&impl->device_listener);
spa_hook_remove(&impl->resource_listener);
spa_hook_remove(&impl->implementation_listener);
pw_device_destroy(impl->device);
}
@ -185,6 +187,7 @@ static void device_destroy(void *data)
impl->device = NULL;
spa_hook_remove(&impl->device_listener);
spa_hook_remove(&impl->resource_listener);
spa_hook_remove(&impl->implementation_listener);
pw_resource_destroy(impl->resource);
}
@ -227,12 +230,13 @@ struct pw_device *pw_client_device_new(struct pw_resource *resource,
&impl->device_listener,
&device_events, impl);
pw_resource_add_listener(impl->resource,
&impl->resource_listener,
&resource_events,
impl);
pw_resource_set_implementation(impl->resource,
&resource_implementation,
impl);
&impl->resource_listener,
&resource_events,
impl);
pw_resource_add_object_listener(impl->resource,
&impl->implementation_listener,
&resource_implementation,
impl);
return device;
}

View file

@ -163,6 +163,7 @@ struct impl {
struct spa_hook node_listener;
struct spa_hook resource_listener;
struct spa_hook object_listener;
struct pw_array mems;
@ -174,7 +175,7 @@ struct impl {
};
#define pw_client_node_resource(r,m,v,...) \
pw_resource_notify_res(r,struct pw_client_node_proxy_events,m,v,__VA_ARGS__)
pw_resource_call_res(r,struct pw_client_node_proxy_events,m,v,__VA_ARGS__)
#define pw_client_node_resource_add_mem(r,...) \
pw_client_node_resource(r,add_mem,0,__VA_ARGS__)
@ -476,11 +477,10 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
update_io(this, this->ios, id, memid);
pw_client_node_resource_set_io(this->resource,
return pw_client_node_resource_set_io(this->resource,
id,
memid,
mem_offset, mem_size);
return 0;
}
static int impl_node_send_command(void *object, const struct spa_command *command)
@ -1224,6 +1224,7 @@ static void client_node_resource_destroy(void *data)
impl->node.resource = this->resource = NULL;
spa_hook_remove(&impl->resource_listener);
spa_hook_remove(&impl->object_listener);
if (node->data_source.fd != -1) {
spa_loop_invoke(node->data_loop,
@ -1695,12 +1696,13 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
this->node->rt.target.data = impl;
pw_resource_add_listener(this->resource,
&impl->resource_listener,
&resource_events,
impl);
pw_resource_set_implementation(this->resource,
&client_node_methods,
impl);
&impl->resource_listener,
&resource_events,
impl);
pw_resource_add_object_listener(this->resource,
&impl->object_listener,
&client_node_methods,
impl);
this->node->port_user_data_size = sizeof(struct port);

View file

@ -53,7 +53,7 @@ static int client_node_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -820,7 +820,7 @@ static int client_node_demarshal_get_node(void *object, const struct pw_protocol
SPA_POD_Int(&new_id)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_client_node_proxy_methods, get_node, 0,
return pw_resource_notify(resource, struct pw_client_node_proxy_methods, get_node, 0,
version, new_id);
}
@ -898,7 +898,7 @@ static int client_node_demarshal_update(void *object, const struct pw_protocol_n
}
}
pw_resource_do(resource, struct pw_client_node_proxy_methods, update, 0, change_mask,
pw_resource_notify(resource, struct pw_client_node_proxy_methods, update, 0, change_mask,
n_params,
params, infop);
return 0;
@ -980,7 +980,7 @@ static int client_node_demarshal_port_update(void *object, const struct pw_proto
}
}
pw_resource_do(resource, struct pw_client_node_proxy_methods, port_update, 0, direction,
pw_resource_notify(resource, struct pw_client_node_proxy_methods, port_update, 0, direction,
port_id,
change_mask,
n_params,
@ -999,7 +999,7 @@ static int client_node_demarshal_set_active(void *object, const struct pw_protoc
SPA_POD_Bool(&active)) < 0)
return -EINVAL;
pw_resource_do(resource, struct pw_client_node_proxy_methods, set_active, 0, active);
pw_resource_notify(resource, struct pw_client_node_proxy_methods, set_active, 0, active);
return 0;
}
@ -1014,7 +1014,7 @@ static int client_node_demarshal_event_method(void *object, const struct pw_prot
SPA_POD_PodObject(&event)) < 0)
return -EINVAL;
pw_resource_do(resource, struct pw_client_node_proxy_methods, event, 0, event);
pw_resource_notify(resource, struct pw_client_node_proxy_methods, event, 0, event);
return 0;
}

View file

@ -38,7 +38,7 @@ static int core_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -401,7 +401,7 @@ static int core_method_demarshal_hello(void *object, const struct pw_protocol_na
SPA_POD_Int(&version)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_core_proxy_methods, hello, 0, version);
return pw_resource_notify(resource, struct pw_core_proxy_methods, hello, 0, version);
}
static int core_method_demarshal_sync(void *object, const struct pw_protocol_native_message *msg)
@ -416,7 +416,7 @@ static int core_method_demarshal_sync(void *object, const struct pw_protocol_nat
SPA_POD_Int(&seq)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_core_proxy_methods, sync, 0, id, seq);
return pw_resource_notify(resource, struct pw_core_proxy_methods, sync, 0, id, seq);
}
static int core_method_demarshal_pong(void *object, const struct pw_protocol_native_message *msg)
@ -431,7 +431,7 @@ static int core_method_demarshal_pong(void *object, const struct pw_protocol_nat
SPA_POD_Int(&seq)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_core_proxy_methods, pong, 0, id, seq);
return pw_resource_notify(resource, struct pw_core_proxy_methods, pong, 0, id, seq);
}
static int core_method_demarshal_error(void *object, const struct pw_protocol_native_message *msg)
@ -450,7 +450,7 @@ static int core_method_demarshal_error(void *object, const struct pw_protocol_na
SPA_POD_String(&error)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_core_proxy_methods, error, 0, id, seq, res, error);
return pw_resource_notify(resource, struct pw_core_proxy_methods, error, 0, id, seq, res, error);
}
static int core_method_demarshal_get_registry(void *object, const struct pw_protocol_native_message *msg)
@ -465,7 +465,7 @@ static int core_method_demarshal_get_registry(void *object, const struct pw_prot
SPA_POD_Int(&new_id)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_core_proxy_methods, get_registry, 0, version, new_id);
return pw_resource_notify(resource, struct pw_core_proxy_methods, get_registry, 0, version, new_id);
}
static int core_method_demarshal_create_object(void *object, const struct pw_protocol_native_message *msg)
@ -504,7 +504,7 @@ static int core_method_demarshal_create_object(void *object, const struct pw_pro
SPA_POD_Int(&new_id), NULL) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_core_proxy_methods, create_object, 0, factory_name,
return pw_resource_notify(resource, struct pw_core_proxy_methods, create_object, 0, factory_name,
type, version,
&props, new_id);
}
@ -527,7 +527,7 @@ static int core_method_demarshal_destroy(void *object, const struct pw_protocol_
if ((r = pw_client_find_resource(client, id)) == NULL)
goto no_resource;
return pw_resource_do(resource, struct pw_core_proxy_methods, destroy, 0, r);
return pw_resource_notify(resource, struct pw_core_proxy_methods, destroy, 0, r);
no_resource:
pw_log_error("client %p: can't find resouce %d", client, id);
@ -541,7 +541,7 @@ static int registry_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -594,7 +594,7 @@ static int registry_demarshal_bind(void *object, const struct pw_protocol_native
SPA_POD_Int(&new_id)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_registry_proxy_methods, bind, 0, id, type, version, new_id);
return pw_resource_notify(resource, struct pw_registry_proxy_methods, bind, 0, id, type, version, new_id);
}
static int registry_demarshal_destroy(void *object, const struct pw_protocol_native_message *msg)
@ -608,7 +608,7 @@ static int registry_demarshal_destroy(void *object, const struct pw_protocol_nat
SPA_POD_Int(&id)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_registry_proxy_methods, destroy, 0, id);
return pw_resource_notify(resource, struct pw_registry_proxy_methods, destroy, 0, id);
}
static int module_method_marshal_add_listener(void *object,
@ -617,7 +617,7 @@ static int module_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -684,7 +684,7 @@ static int device_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -833,7 +833,7 @@ static int device_demarshal_enum_params(void *object, const struct pw_protocol_n
SPA_POD_Pod(&filter)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_device_proxy_methods, enum_params, 0,
return pw_resource_notify(resource, struct pw_device_proxy_methods, enum_params, 0,
seq, id, index, num, filter);
}
@ -866,7 +866,7 @@ static int device_demarshal_set_param(void *object, const struct pw_protocol_nat
SPA_POD_Pod(&param)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_device_proxy_methods, set_param, 0, id, flags, param);
return pw_resource_notify(resource, struct pw_device_proxy_methods, set_param, 0, id, flags, param);
}
static int factory_method_marshal_add_listener(void *object,
@ -875,7 +875,7 @@ static int factory_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -942,7 +942,7 @@ static int node_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -1095,7 +1095,7 @@ static int node_demarshal_subscribe_params(void *object, const struct pw_protoco
if (ctype != SPA_TYPE_Id)
return -EINVAL;
return pw_resource_do(resource, struct pw_node_proxy_methods, subscribe_params, 0,
return pw_resource_notify(resource, struct pw_node_proxy_methods, subscribe_params, 0,
ids, n_ids);
}
@ -1135,7 +1135,7 @@ static int node_demarshal_enum_params(void *object, const struct pw_protocol_nat
SPA_POD_Pod(&filter)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_node_proxy_methods, enum_params, 0,
return pw_resource_notify(resource, struct pw_node_proxy_methods, enum_params, 0,
seq, id, index, num, filter);
}
@ -1168,7 +1168,7 @@ static int node_demarshal_set_param(void *object, const struct pw_protocol_nativ
SPA_POD_Pod(&param)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_node_proxy_methods, set_param, 0, id, flags, param);
return pw_resource_notify(resource, struct pw_node_proxy_methods, set_param, 0, id, flags, param);
}
static int node_marshal_send_command(void *object, const struct spa_command *command)
@ -1193,7 +1193,7 @@ static int node_demarshal_send_command(void *object, const struct pw_protocol_na
SPA_POD_Pod(&command)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_node_proxy_methods, send_command, 0, command);
return pw_resource_notify(resource, struct pw_node_proxy_methods, send_command, 0, command);
}
static int port_method_marshal_add_listener(void *object,
@ -1202,7 +1202,7 @@ static int port_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -1342,7 +1342,7 @@ static int port_demarshal_subscribe_params(void *object, const struct pw_protoco
if (ctype != SPA_TYPE_Id)
return -EINVAL;
return pw_resource_do(resource, struct pw_port_proxy_methods, subscribe_params, 0,
return pw_resource_notify(resource, struct pw_port_proxy_methods, subscribe_params, 0,
ids, n_ids);
}
@ -1382,7 +1382,7 @@ static int port_demarshal_enum_params(void *object, const struct pw_protocol_nat
SPA_POD_Pod(&filter)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_port_proxy_methods, enum_params, 0,
return pw_resource_notify(resource, struct pw_port_proxy_methods, enum_params, 0,
seq, id, index, num, filter);
}
@ -1392,7 +1392,7 @@ static int client_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}
@ -1535,7 +1535,7 @@ static int client_demarshal_error(void *object, const struct pw_protocol_native_
SPA_POD_String(&error)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_client_proxy_methods, error, 0, id, res, error);
return pw_resource_notify(resource, struct pw_client_proxy_methods, error, 0, id, res, error);
}
static int client_marshal_get_permissions(void *object, uint32_t index, uint32_t num)
@ -1589,7 +1589,7 @@ static int client_demarshal_update_properties(void *object, const struct pw_prot
SPA_POD_String(&props.items[i].value), NULL) < 0)
return -EINVAL;
}
return pw_resource_do(resource, struct pw_client_proxy_methods, update_properties, 0,
return pw_resource_notify(resource, struct pw_client_proxy_methods, update_properties, 0,
&props);
}
@ -1605,7 +1605,7 @@ static int client_demarshal_get_permissions(void *object, const struct pw_protoc
SPA_POD_Int(&num)) < 0)
return -EINVAL;
return pw_resource_do(resource, struct pw_client_proxy_methods, get_permissions, 0, index, num);
return pw_resource_notify(resource, struct pw_client_proxy_methods, get_permissions, 0, index, num);
}
static int client_marshal_update_permissions(void *object, uint32_t n_permissions,
@ -1650,7 +1650,7 @@ static int client_demarshal_update_permissions(void *object, const struct pw_pro
SPA_POD_Int(&permissions[i].permissions), NULL) < 0)
return -EINVAL;
}
return pw_resource_do(resource, struct pw_client_proxy_methods, update_permissions, 0,
return pw_resource_notify(resource, struct pw_client_proxy_methods, update_permissions, 0,
n_permissions, permissions);
}
@ -1660,7 +1660,7 @@ static int link_method_marshal_add_listener(void *object,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
pw_proxy_add_object_listener(proxy, listener, events, data);
return 0;
}