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;
}