Add versions to structures

Use versions instead of size
Remove user_data from callbacks, we can simply pass the callback struct.
This commit is contained in:
Wim Taymans 2017-06-14 18:32:39 +02:00
parent 4a219e81dd
commit c3b73ba47d
45 changed files with 344 additions and 303 deletions

View file

@ -58,8 +58,7 @@ struct impl {
struct spa_log *log;
struct spa_loop *main_loop;
struct spa_monitor_callbacks callbacks;
void *user_data;
const struct spa_monitor_callbacks *callbacks;
struct udev *udev;
struct udev_monitor *umonitor;
@ -350,15 +349,14 @@ static void impl_on_fd_events(struct spa_source *source)
spa_pod_builder_object(&b, &f[0], 0, type, SPA_POD_TYPE_POD, this->item);
event = SPA_POD_BUILDER_DEREF(&b, f[0].ref, struct spa_event);
this->callbacks.event(&this->monitor, event, this->user_data);
this->callbacks->event(this->callbacks, &this->monitor, event);
}
close_card(this);
}
static int
impl_monitor_set_callbacks(struct spa_monitor *monitor,
const struct spa_monitor_callbacks *callbacks,
size_t callbacks_size, void *user_data)
const struct spa_monitor_callbacks *callbacks)
{
int res;
struct impl *this;
@ -367,10 +365,9 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
if (callbacks) {
this->callbacks = *callbacks;
this->user_data = user_data;
this->callbacks = callbacks;
if (callbacks) {
if ((res = impl_udev_open(this)) < 0)
return res;
@ -389,7 +386,6 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
spa_loop_add_source(this->main_loop, &this->source);
} else {
spa_zero(this->callbacks);
spa_loop_remove_source(this->main_loop, &this->source);
}
@ -454,8 +450,8 @@ static int impl_monitor_enum_items(struct spa_monitor *monitor,
}
static const struct spa_monitor impl_monitor = {
SPA_VERSION_MONITOR,
NULL,
sizeof(struct spa_monitor),
impl_monitor_set_callbacks,
impl_monitor_enum_items,
};
@ -542,6 +538,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
}
const struct spa_handle_factory spa_alsa_monitor_factory = {
SPA_VERSION_HANDLE_FACTORY,
NAME,
NULL,
sizeof(struct impl),

View file

@ -92,7 +92,7 @@ static int do_send_done(struct spa_loop *loop, bool async, uint32_t seq, size_t
{
struct state *this = user_data;
this->callbacks.done(&this->node, seq, *(int*)data, this->user_data);
this->callbacks->done(this->callbacks, &this->node, seq, *(int*)data);
return SPA_RESULT_OK;
}
@ -150,8 +150,7 @@ static int impl_node_send_command(struct spa_node *node, struct spa_command *com
static int
impl_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size, void *user_data)
const struct spa_node_callbacks *callbacks)
{
struct state *this;
@ -159,8 +158,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
this->callbacks = *callbacks;
this->user_data = user_data;
this->callbacks = callbacks;
return SPA_RESULT_OK;
}
@ -569,7 +567,7 @@ static int impl_node_process_output(struct spa_node *node)
static const struct spa_node impl_node = {
sizeof(struct spa_node),
SPA_VERSION_NODE,
NULL,
impl_node_get_props,
impl_node_set_props,
@ -692,6 +690,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
}
const struct spa_handle_factory spa_alsa_sink_factory = {
SPA_VERSION_HANDLE_FACTORY,
NAME,
NULL,
sizeof(struct state),

View file

@ -94,7 +94,7 @@ static int do_send_done(struct spa_loop *loop, bool async, uint32_t seq, size_t
{
struct state *this = user_data;
this->callbacks.done(&this->node, seq, *(int*)data, this->user_data);
this->callbacks->done(this->callbacks, &this->node, seq, *(int*)data);
return SPA_RESULT_OK;
}
@ -168,7 +168,7 @@ static int impl_node_send_command(struct spa_node *node, struct spa_command *com
static int
impl_node_set_callbacks(struct spa_node *node,
const struct spa_node_callbacks *callbacks, size_t callbacks_size, void *user_data)
const struct spa_node_callbacks *callbacks)
{
struct state *this;
@ -176,8 +176,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
this->callbacks = *callbacks;
this->user_data = user_data;
this->callbacks = callbacks;
return SPA_RESULT_OK;
}
@ -578,7 +577,7 @@ static int impl_node_process_output(struct spa_node *node)
}
static const struct spa_node impl_node = {
sizeof(struct spa_node),
SPA_VERSION_NODE,
NULL,
impl_node_get_props,
impl_node_set_props,
@ -635,7 +634,7 @@ static int impl_clock_get_time(struct spa_clock *clock,
}
static const struct spa_clock impl_clock = {
sizeof(struct spa_clock),
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_get_props,
@ -746,7 +745,9 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
return SPA_RESULT_OK;
}
const struct spa_handle_factory spa_alsa_source_factory = { NAME,
const struct spa_handle_factory spa_alsa_source_factory = {
SPA_VERSION_HANDLE_FACTORY,
NAME,
NULL,
sizeof(struct state),
impl_init,

View file

@ -324,7 +324,7 @@ pull_frames(struct state *state,
io->range.offset = state->sample_count * state->frame_size;
io->range.min_size = state->threshold * state->frame_size;
io->range.max_size = frames * state->frame_size;
state->callbacks.need_input(&state->node, state->user_data);
state->callbacks->need_input(state->callbacks, &state->node);
}
while (!spa_list_is_empty(&state->ready) && to_write > 0) {
uint8_t *src, *dst;
@ -371,7 +371,10 @@ pull_frames(struct state *state,
b->outstanding = true;
state->io->buffer_id = b->outbuf->id;
spa_log_trace(state->log, "alsa-util %p: reuse buffer %u", state, b->outbuf->id);
state->callbacks.reuse_buffer(&state->node, 0, b->outbuf->id, state->user_data);
state->callbacks->reuse_buffer(state->callbacks,
&state->node,
0,
b->outbuf->id);
state->ready_offset = 0;
}
total_frames += n_frames;
@ -427,7 +430,7 @@ push_frames(struct state *state,
b->outstanding = true;
io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_HAVE_BUFFER;
state->callbacks.have_output(&state->node, state->user_data);
state->callbacks->have_output(state->callbacks, &state->node);
}
}
return total_frames;

View file

@ -118,8 +118,7 @@ struct state {
snd_pcm_stream_t stream;
snd_output_t *output;
struct spa_node_callbacks callbacks;
void *user_data;
const struct spa_node_callbacks *callbacks;
uint8_t props_buffer[1024];
struct props props;