Add plugin API

Add plugin api, define a factory and methods for introspecting
interfaces.
This commit is contained in:
Wim Taymans 2016-06-09 13:06:35 +02:00
parent 6377b9bd12
commit b8f6e99537
9 changed files with 386 additions and 281 deletions

View file

@ -43,7 +43,8 @@ typedef struct {
} SpiVolumeFormat;
struct _SpiVolume {
SpiNode node;
SpiHandle handle;
SpiNode node;
SpiVolumeParams params;
SpiVolumeParams tmp_params;
@ -187,12 +188,12 @@ reset_volume_params (SpiVolumeParams *params)
}
static SpiResult
spi_volume_node_get_params (SpiNode *node,
spi_volume_node_get_params (SpiHandle *handle,
SpiParams **params)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
if (node == NULL || params == NULL)
if (handle == NULL || params == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
memcpy (&this->tmp_params, &this->params, sizeof (this->tmp_params));
@ -202,16 +203,16 @@ spi_volume_node_get_params (SpiNode *node,
}
static SpiResult
spi_volume_node_set_params (SpiNode *node,
spi_volume_node_set_params (SpiHandle *handle,
const SpiParams *params)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
SpiVolumeParams *p = &this->params;
SpiParamType type;
size_t size;
const void *value;
if (node == NULL)
if (handle == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (params == NULL) {
@ -233,12 +234,12 @@ spi_volume_node_set_params (SpiNode *node,
}
static SpiResult
spi_volume_node_send_command (SpiNode *node,
spi_volume_node_send_command (SpiHandle *handle,
SpiCommand *command)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
if (node == NULL || command == NULL)
if (handle == NULL || command == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (command->type) {
@ -256,7 +257,7 @@ spi_volume_node_send_command (SpiNode *node,
event.data = NULL;
event.size = 0;
this->event_cb (node, &event, this->user_data);
this->event_cb (handle, &event, this->user_data);
}
break;
@ -271,7 +272,7 @@ spi_volume_node_send_command (SpiNode *node,
event.data = NULL;
event.size = 0;
this->event_cb (node, &event, this->user_data);
this->event_cb (handle, &event, this->user_data);
}
break;
@ -286,13 +287,13 @@ spi_volume_node_send_command (SpiNode *node,
}
static SpiResult
spi_volume_node_set_event_callback (SpiNode *node,
spi_volume_node_set_event_callback (SpiHandle *handle,
SpiEventCallback event,
void *user_data)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
if (node == NULL)
if (handle == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
this->event_cb = event;
@ -302,13 +303,13 @@ spi_volume_node_set_event_callback (SpiNode *node,
}
static SpiResult
spi_volume_node_get_n_ports (SpiNode *node,
spi_volume_node_get_n_ports (SpiHandle *handle,
unsigned int *n_input_ports,
unsigned int *max_input_ports,
unsigned int *n_output_ports,
unsigned int *max_output_ports)
{
if (node == NULL)
if (handle == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
@ -324,13 +325,13 @@ spi_volume_node_get_n_ports (SpiNode *node,
}
static SpiResult
spi_volume_node_get_port_ids (SpiNode *node,
spi_volume_node_get_port_ids (SpiHandle *handle,
unsigned int n_input_ports,
uint32_t *input_ids,
unsigned int n_output_ports,
uint32_t *output_ids)
{
if (node == NULL)
if (handle == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (n_input_ports > 0 && input_ids)
@ -343,7 +344,7 @@ spi_volume_node_get_port_ids (SpiNode *node,
static SpiResult
spi_volume_node_add_port (SpiNode *node,
spi_volume_node_add_port (SpiHandle *handle,
SpiDirection direction,
uint32_t *port_id)
{
@ -351,7 +352,7 @@ spi_volume_node_add_port (SpiNode *node,
}
static SpiResult
spi_volume_node_remove_port (SpiNode *node,
spi_volume_node_remove_port (SpiHandle *handle,
uint32_t port_id)
{
return SPI_RESULT_NOT_IMPLEMENTED;
@ -566,14 +567,14 @@ get_format_param (const SpiParams *params,
static SpiResult
spi_volume_node_enum_port_formats (SpiNode *node,
spi_volume_node_enum_port_formats (SpiHandle *handle,
uint32_t port_id,
unsigned int index,
SpiParams **format)
{
static SpiVolumeFormat fmt;
if (node == NULL || format == NULL)
if (handle == NULL || format == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
@ -596,18 +597,18 @@ spi_volume_node_enum_port_formats (SpiNode *node,
}
static SpiResult
spi_volume_node_set_port_format (SpiNode *node,
spi_volume_node_set_port_format (SpiHandle *handle,
uint32_t port_id,
int test_only,
const SpiParams *format)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
SpiParamType type;
size_t size;
const void *value;
SpiVolumeFormat *fmt;
if (node == NULL || format == NULL)
if (handle == NULL || format == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
@ -670,13 +671,13 @@ spi_volume_node_set_port_format (SpiNode *node,
}
static SpiResult
spi_volume_node_get_port_format (SpiNode *node,
spi_volume_node_get_port_format (SpiHandle *handle,
uint32_t port_id,
const SpiParams **format)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
if (node == NULL || format == NULL)
if (handle == NULL || format == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (port_id != 0)
@ -691,11 +692,11 @@ spi_volume_node_get_port_format (SpiNode *node,
}
static SpiResult
spi_volume_node_get_port_info (SpiNode *node,
spi_volume_node_get_port_info (SpiHandle *handle,
uint32_t port_id,
SpiPortInfo *info)
{
if (node == NULL || info == NULL)
if (handle == NULL || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (port_id) {
@ -715,7 +716,7 @@ spi_volume_node_get_port_info (SpiNode *node,
}
static SpiResult
spi_volume_node_get_port_params (SpiNode *node,
spi_volume_node_get_port_params (SpiHandle *handle,
uint32_t port_id,
SpiParams **params)
{
@ -723,7 +724,7 @@ spi_volume_node_get_port_params (SpiNode *node,
}
static SpiResult
spi_volume_node_set_port_params (SpiNode *node,
spi_volume_node_set_port_params (SpiHandle *handle,
uint32_t port_id,
const SpiParams *params)
{
@ -731,14 +732,14 @@ spi_volume_node_set_port_params (SpiNode *node,
}
static SpiResult
spi_volume_node_get_port_status (SpiNode *node,
spi_volume_node_get_port_status (SpiHandle *handle,
uint32_t port_id,
SpiPortStatus *status)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
SpiPortStatusFlags flags = 0;
if (node == NULL || status == NULL)
if (handle == NULL || status == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (!this->have_format)
@ -762,18 +763,18 @@ spi_volume_node_get_port_status (SpiNode *node,
}
static SpiResult
spi_volume_node_push_port_input (SpiNode *node,
spi_volume_node_push_port_input (SpiHandle *handle,
unsigned int n_info,
SpiInputInfo *info)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
SpiBuffer *buffer;
SpiEvent *event;
unsigned int i;
bool have_error = false;
bool have_enough = false;
if (node == NULL || n_info == 0 || info == NULL)
if (handle == NULL || n_info == 0 || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
for (i = 0; i < n_info; i++) {
@ -825,18 +826,18 @@ spi_volume_node_push_port_input (SpiNode *node,
#define MIN(a,b) ((a) < (b) ? (a) : (b))
static SpiResult
spi_volume_node_pull_port_output (SpiNode *node,
spi_volume_node_pull_port_output (SpiHandle *handle,
unsigned int n_info,
SpiOutputInfo *info)
{
SpiVolume *this = (SpiVolume *) node;
SpiVolume *this = (SpiVolume *) handle;
unsigned int si, di, i, n_samples, n_bytes, soff, doff ;
SpiBuffer *sbuf, *dbuf;
SpiData *sd, *dd;
uint16_t *src, *dst;
double volume;
if (node == NULL || n_info == 0 || info == NULL)
if (handle == NULL || n_info == 0 || info == NULL)
return SPI_RESULT_INVALID_ARGUMENTS;
if (info->port_id != 1)
@ -903,30 +904,43 @@ spi_volume_node_pull_port_output (SpiNode *node,
}
static SpiResult
spi_volume_node_enum_interface_info (SpiNode *node,
unsigned int index,
const SpiInterfaceInfo **info)
spi_volume_get_interface (SpiHandle *handle,
uint32_t interface_id,
void **interface)
{
return SPI_RESULT_NOT_IMPLEMENTED;
SpiVolume *this = (SpiVolume *) handle;
if (handle == NULL || interface == 0)
return SPI_RESULT_INVALID_ARGUMENTS;
switch (interface_id) {
case SPI_INTERFACE_ID_NODE:
*interface = &this->node;
break;
default:
return SPI_RESULT_UNKNOWN_INTERFACE;
}
return SPI_RESULT_OK;
}
static SpiResult
spi_volume_node_get_interface (SpiNode *node,
uint32_t interface_id,
void **interface)
{
return SPI_RESULT_NOT_IMPLEMENTED;
}
SpiNode *
SpiHandle *
spi_volume_new (void)
{
SpiHandle *handle;
SpiNode *node;
SpiVolume *this;
node = calloc (1, sizeof (SpiVolume));
handle = calloc (1, sizeof (SpiVolume));
handle->get_interface = spi_volume_get_interface;
this = (SpiVolume *) handle;
this->params.param.enum_param_info = enum_param_info;
this->params.param.set_param = set_param;
this->params.param.get_param = get_param;
reset_volume_params (&this->params);
node = &this->node;
node->get_params = spi_volume_node_get_params;
node->set_params = spi_volume_node_set_params;
node->send_command = spi_volume_node_send_command;
@ -944,14 +958,6 @@ spi_volume_new (void)
node->get_port_status = spi_volume_node_get_port_status;
node->push_port_input = spi_volume_node_push_port_input;
node->pull_port_output = spi_volume_node_pull_port_output;
node->enum_interface_info = spi_volume_node_enum_interface_info;
node->get_interface = spi_volume_node_get_interface;
this = (SpiVolume *) node;
this->params.param.enum_param_info = enum_param_info;
this->params.param.set_param = set_param;
this->params.param.get_param = get_param;
reset_volume_params (&this->params);
return node;
return handle;
}