hooks: use hook to implement the callbacks

This way we get the version check implemented and save some
code.
This commit is contained in:
Wim Taymans 2019-05-15 11:19:23 +02:00
parent a78617c6a8
commit 6ee192dff5
26 changed files with 121 additions and 111 deletions

View file

@ -51,8 +51,7 @@ struct impl {
struct spa_log *log;
struct spa_loop *main_loop;
const struct spa_monitor_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
struct udev *udev;
struct udev_monitor *umonitor;
@ -266,7 +265,7 @@ static int emit_device(struct impl *this, uint32_t id, struct udev_device *dev)
event = spa_pod_builder_add_object(&b, SPA_TYPE_EVENT_Monitor, id);
fill_item(this, dev, &item, &b);
this->callbacks->event(this->callbacks_data, event);
spa_monitor_call_event(&this->callbacks, event);
return 0;
}
@ -378,8 +377,7 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
if (callbacks) {
if ((res = impl_udev_open(this)) < 0)

View file

@ -293,8 +293,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -292,8 +292,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -750,7 +750,9 @@ again:
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
state->io->buffer_id = b->id;
spa_log_trace_fp(state->log, "alsa-util %p: reuse buffer %u", state, b->id);
state->callbacks->reuse_buffer(state->callbacks_data, 0, b->id);
spa_node_call_reuse_buffer(&state->callbacks, 0, b->id);
state->ready_offset = 0;
}
written += n_frames;
@ -953,7 +955,7 @@ static int handle_play(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
state->range->min_size = state->threshold * state->frame_size;
state->range->max_size = state->threshold * state->frame_size;
}
res = state->callbacks->ready(state->callbacks_data, SPA_STATUS_NEED_BUFFER);
res = spa_node_call_ready(&state->callbacks, SPA_STATUS_NEED_BUFFER);
}
else {
res = spa_alsa_write(state, 0);
@ -987,7 +989,7 @@ static int handle_capture(struct state *state, uint64_t nsec, snd_pcm_sframes_t
io->buffer_id = b->id;
io->status = SPA_STATUS_HAVE_BUFFER;
}
state->callbacks->ready(state->callbacks_data, SPA_STATUS_HAVE_BUFFER);
spa_node_call_ready(&state->callbacks, SPA_STATUS_HAVE_BUFFER);
}
return 0;
}

View file

@ -82,8 +82,7 @@ struct state {
snd_output_t *output;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
uint64_t info_all;
struct spa_node_info info;

View file

@ -119,8 +119,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
bool async;
struct spa_source timer_source;
@ -394,7 +393,7 @@ static void on_output(struct spa_source *source)
res = make_buffer(this);
if (res == SPA_STATUS_HAVE_BUFFER)
this->callbacks->ready(this->callbacks_data, res);
spa_node_call_ready(&this->callbacks, res);
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
@ -511,8 +510,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -92,8 +92,7 @@ struct impl {
struct spa_loop *data_loop;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
uint64_t info_all;
struct spa_node_info info;
@ -571,7 +570,8 @@ static int flush_data(struct impl *this, uint64_t now_time)
spa_list_remove(&b->link);
b->outstanding = true;
spa_log_trace(this->log, "a2dp-sink %p: reuse buffer %u", this, b->id);
this->callbacks->reuse_buffer(this->callbacks_data, 0, b->id);
spa_node_call_reuse_buffer(&this->callbacks, 0, b->id);
port->ready_offset = 0;
}
total_frames += n_frames;
@ -699,7 +699,7 @@ static void a2dp_on_timeout(struct spa_source *source)
port->range->min_size = this->threshold * port->frame_size;
port->range->max_size = this->write_samples * port->frame_size;
}
this->callbacks->ready(this->callbacks_data, SPA_STATUS_NEED_BUFFER);
spa_node_call_ready(&this->callbacks, SPA_STATUS_NEED_BUFFER);
}
flush_data(this, now_time);
}
@ -974,8 +974,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -92,8 +92,7 @@ struct impl {
struct spa_loop *data_loop;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
uint64_t info_all;
struct spa_node_info info;
@ -379,7 +378,7 @@ static void decode_sbc_data(struct impl *this, uint8_t *src, size_t src_size)
spa_log_debug(this->log, "data decoded successfully for buffer_id=%d", buffer->id);
spa_list_append(&port->ready, &buffer->link);
this->callbacks->ready(this->callbacks_data, SPA_STATUS_HAVE_BUFFER);
spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_BUFFER);
}
static void a2dp_on_ready_read(struct spa_source *source)
@ -608,8 +607,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -60,8 +60,7 @@ struct spa_bt_monitor {
struct spa_dbus_connection *dbus_connection;
DBusConnection *conn;
const struct spa_monitor_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
uint32_t count;
@ -532,7 +531,7 @@ static int device_add(struct spa_bt_monitor *monitor, struct spa_bt_device *devi
fill_item(monitor, device, &item, &b);
device->added = true;
monitor->callbacks->event(monitor->callbacks_data, event);
spa_monitor_call_event(&monitor->callbacks, event);
return 0;
}
@ -552,7 +551,7 @@ static int device_remove(struct spa_bt_monitor *monitor, struct spa_bt_device *d
fill_item(monitor, device, &item, &b);
device->added = false;
monitor->callbacks->event(monitor->callbacks_data, event);
spa_monitor_call_event(&monitor->callbacks, event);
return 0;
}
@ -2051,8 +2050,7 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct spa_bt_monitor, monitor);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
if (callbacks) {
get_managed_objects(this);

View file

@ -85,8 +85,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
struct spa_source timer_source;
struct itimerspec timerspec;
@ -194,7 +193,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
static void set_timer(struct impl *this, bool enabled)
{
if ((this->callbacks && this->callbacks->ready) || this->props.live) {
if (this->callbacks.funcs || this->props.live) {
if (enabled) {
if (this->props.live) {
uint64_t next_time = this->start_time + this->elapsed_time;
@ -216,7 +215,7 @@ static inline void read_timer(struct impl *this)
{
uint64_t expirations;
if ((this->callbacks && this->callbacks->ready) || this->props.live) {
if (this->callbacks.funcs || this->props.live) {
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
perror("read timerfd");
}
@ -237,8 +236,7 @@ static int consume_buffer(struct impl *this)
if (spa_list_is_empty(&port->ready)) {
io->status = SPA_STATUS_NEED_BUFFER;
if (this->callbacks->ready)
this->callbacks->ready(this->callbacks_data, SPA_STATUS_NEED_BUFFER);
spa_node_call_ready(&this->callbacks, SPA_STATUS_NEED_BUFFER);
}
if (spa_list_is_empty(&port->ready)) {
spa_log_error(this->log, NAME " %p: no buffers", this);
@ -391,12 +389,11 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
if (this->data_loop == NULL && callbacks != NULL && callbacks->ready != NULL) {
if (this->data_loop == NULL && callbacks != NULL) {
spa_log_error(this->log, "a data_loop is needed for async operation");
return -EINVAL;
}
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
@ -700,7 +697,7 @@ static int impl_node_process(struct spa_node *node)
io->buffer_id = SPA_ID_INVALID;
io->status = SPA_STATUS_OK;
}
if (this->callbacks == NULL || this->callbacks->ready == NULL)
if (this->callbacks.funcs == NULL)
return consume_buffer(this);
else
return SPA_STATUS_OK;

View file

@ -86,8 +86,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
struct spa_source timer_source;
struct itimerspec timerspec;
@ -212,7 +211,7 @@ static int fill_buffer(struct impl *this, struct buffer *b)
static void set_timer(struct impl *this, bool enabled)
{
if ((this->callbacks && this->callbacks->ready) || this->props.live) {
if (this->callbacks.funcs || this->props.live) {
if (enabled) {
if (this->props.live) {
uint64_t next_time = this->start_time + this->elapsed_time;
@ -234,7 +233,7 @@ static inline void read_timer(struct impl *this)
{
uint64_t expirations;
if ((this->callbacks && this->callbacks->ready) || this->props.live) {
if (this->callbacks.funcs || this->props.live) {
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) != sizeof(uint64_t))
perror("read timerfd");
}
@ -292,8 +291,8 @@ static void on_output(struct spa_source *source)
res = make_buffer(this);
if (res == SPA_STATUS_HAVE_BUFFER && this->callbacks && this->callbacks->ready)
this->callbacks->ready(this->callbacks_data, res);
if (res == SPA_STATUS_HAVE_BUFFER && this->callbacks.funcs)
spa_node_call_ready(&this->callbacks, res);
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
@ -404,12 +403,11 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
if (this->data_loop == NULL && (callbacks != NULL && callbacks->ready != NULL)) {
if (this->data_loop == NULL && callbacks != NULL) {
spa_log_error(this->log, "a data_loop is needed for async operation");
return -EINVAL;
}
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}
@ -737,7 +735,7 @@ static int impl_node_process(struct spa_node *node)
io->buffer_id = SPA_ID_INVALID;
}
if ((this->callbacks == NULL || this->callbacks->ready == NULL) &&
if (this->callbacks.funcs == NULL &&
(io->status == SPA_STATUS_NEED_BUFFER))
return make_buffer(this);
else

View file

@ -48,8 +48,7 @@ struct impl {
struct spa_log *log;
struct spa_loop *main_loop;
const struct spa_monitor_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
struct udev *udev;
struct udev_monitor *umonitor;
@ -175,7 +174,7 @@ static int emit_device(struct impl *this, uint32_t id, struct udev_device *dev)
event = spa_pod_builder_add_object(&b, SPA_TYPE_EVENT_Monitor, id);
fill_item(this, dev, &item, &b);
this->callbacks->event(this->callbacks_data, event);
spa_monitor_call_event(&this->callbacks, event);
return 0;
}
@ -284,8 +283,8 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
if (callbacks) {
if ((res = impl_udev_open(this)) < 0)
return res;

View file

@ -134,8 +134,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
struct port out_ports[1];
@ -384,8 +383,7 @@ static int impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -1206,7 +1206,7 @@ static int mmap_read(struct impl *this)
}
spa_log_trace(this->log, "v4l2 %p: now queued %d", this, b->id);
this->callbacks->ready(this->callbacks_data, SPA_STATUS_HAVE_BUFFER);
spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_BUFFER);
return 0;
}

View file

@ -104,8 +104,7 @@ struct impl {
struct props props;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
bool async;
struct spa_source timer_source;
@ -340,7 +339,7 @@ static void on_output(struct spa_source *source)
res = make_buffer(this);
if (res == SPA_STATUS_HAVE_BUFFER)
this->callbacks->ready(this->callbacks_data, res);
spa_node_call_ready(&this->callbacks, res);
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
@ -456,8 +455,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}