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

@ -60,8 +60,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;
@ -231,13 +230,12 @@ static void impl_on_fd_events(struct spa_source *source)
spa_pod_builder_object(&b, &f[0], 0, type, SPA_POD_TYPE_POD, this->uitem.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);
}
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;
@ -246,10 +244,8 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
this->callbacks = callbacks;
if (callbacks) {
this->callbacks = *callbacks;
this->user_data = user_data;
if ((res = impl_udev_open(this)) < 0)
return res;
@ -268,7 +264,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);
}
@ -325,8 +320,8 @@ impl_monitor_enum_items(struct spa_monitor *monitor, struct spa_monitor_item **i
}
static const struct spa_monitor impl_monitor = {
SPA_VERSION_MONITOR,
NULL,
sizeof(struct spa_monitor),
impl_monitor_set_callbacks,
impl_monitor_enum_items,
};
@ -413,6 +408,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
}
const struct spa_handle_factory spa_v4l2_monitor_factory = {
SPA_VERSION_MONITOR,
NAME,
NULL,
sizeof(struct impl),

View file

@ -157,8 +157,7 @@ struct impl {
uint8_t props_buffer[512];
struct props props;
struct spa_node_callbacks callbacks;
void *user_data;
const struct spa_node_callbacks *callbacks;
struct port out_ports[1];
};
@ -237,7 +236,7 @@ static int do_pause_done(struct spa_loop *loop,
if (SPA_RESULT_IS_OK(res))
res = spa_v4l2_stream_off(this);
this->callbacks.done(&this->node, seq, res, this->user_data);
this->callbacks->done(this->callbacks, &this->node, seq, res);
return SPA_RESULT_OK;
}
@ -276,7 +275,7 @@ static int do_start_done(struct spa_loop *loop,
struct impl *this = user_data;
int res = *(int*)data;
this->callbacks.done(&this->node, seq, res, this->user_data);
this->callbacks->done(this->callbacks, &this->node, seq, res);
return SPA_RESULT_OK;
}
@ -355,9 +354,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 impl *this;
@ -365,8 +362,7 @@ static int impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
this->callbacks = *callbacks;
this->user_data = user_data;
this->callbacks = callbacks;
return SPA_RESULT_OK;
}
@ -821,7 +817,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,
@ -880,7 +876,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,
@ -991,6 +987,7 @@ static int impl_enum_interface_info(const struct spa_handle_factory *factory,
}
const struct spa_handle_factory spa_v4l2_source_factory = {
SPA_VERSION_HANDLE_FACTORY,
NAME,
NULL,
sizeof(struct impl),

View file

@ -934,7 +934,7 @@ static int mmap_read(struct impl *this)
b->outstanding = true;
io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_HAVE_BUFFER;
this->callbacks.have_output(&this->node, this->user_data);
this->callbacks->have_output(this->callbacks, &this->node);
return SPA_RESULT_OK;
}