2016-11-10 15:42:14 +01:00
|
|
|
/* Pinos
|
|
|
|
|
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-16 16:57:47 +01:00
|
|
|
#include <pinos/client/pinos.h>
|
2016-11-10 15:42:14 +01:00
|
|
|
#include <pinos/server/core.h>
|
|
|
|
|
#include <pinos/server/data-loop.h>
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2016-11-14 12:42:00 +01:00
|
|
|
PinosCore this;
|
2016-11-10 15:42:14 +01:00
|
|
|
|
|
|
|
|
SpaSupport support[4];
|
|
|
|
|
|
|
|
|
|
} PinosCoreImpl;
|
|
|
|
|
|
|
|
|
|
PinosCore *
|
|
|
|
|
pinos_core_new (PinosMainLoop *main_loop)
|
|
|
|
|
{
|
|
|
|
|
PinosCoreImpl *impl;
|
2016-11-14 12:42:00 +01:00
|
|
|
PinosCore *this;
|
2016-11-10 15:42:14 +01:00
|
|
|
|
|
|
|
|
impl = calloc (1, sizeof (PinosCoreImpl));
|
2016-11-14 12:42:00 +01:00
|
|
|
this = &impl->this;
|
2016-11-21 16:29:15 +01:00
|
|
|
pinos_uri_init (&this->uri);
|
|
|
|
|
|
|
|
|
|
pinos_map_init (&this->objects, 512);
|
2016-11-10 15:42:14 +01:00
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
this->data_loop = pinos_data_loop_new ();
|
|
|
|
|
this->main_loop = main_loop;
|
2016-11-10 15:42:14 +01:00
|
|
|
|
|
|
|
|
impl->support[0].uri = SPA_ID_MAP_URI;
|
2016-11-21 16:29:15 +01:00
|
|
|
impl->support[0].data = this->uri.map;
|
2016-11-10 15:42:14 +01:00
|
|
|
impl->support[1].uri = SPA_LOG_URI;
|
|
|
|
|
impl->support[1].data = pinos_log_get ();
|
2016-11-18 17:46:01 +01:00
|
|
|
impl->support[2].uri = SPA_LOOP__DataLoop;
|
|
|
|
|
impl->support[2].data = this->data_loop->loop->loop;
|
|
|
|
|
impl->support[3].uri = SPA_LOOP__MainLoop;
|
2016-11-22 13:06:22 +01:00
|
|
|
impl->support[3].data = this->main_loop->loop->loop;
|
2016-11-14 12:42:00 +01:00
|
|
|
this->support = impl->support;
|
|
|
|
|
this->n_support = 4;
|
|
|
|
|
|
2016-11-18 17:46:01 +01:00
|
|
|
pinos_data_loop_start (this->data_loop);
|
|
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
spa_list_init (&this->global_list);
|
|
|
|
|
spa_list_init (&this->client_list);
|
|
|
|
|
spa_list_init (&this->node_list);
|
2016-11-15 20:12:31 +01:00
|
|
|
spa_list_init (&this->node_factory_list);
|
2016-11-14 12:42:00 +01:00
|
|
|
spa_list_init (&this->link_list);
|
|
|
|
|
pinos_signal_init (&this->destroy_signal);
|
|
|
|
|
pinos_signal_init (&this->global_added);
|
|
|
|
|
pinos_signal_init (&this->global_removed);
|
2016-11-21 12:54:40 +01:00
|
|
|
pinos_signal_init (&this->node_state_request);
|
2016-11-14 12:42:00 +01:00
|
|
|
pinos_signal_init (&this->node_state_changed);
|
|
|
|
|
pinos_signal_init (&this->port_added);
|
|
|
|
|
pinos_signal_init (&this->port_removed);
|
|
|
|
|
pinos_signal_init (&this->port_unlinked);
|
|
|
|
|
pinos_signal_init (&this->link_state_changed);
|
2016-11-15 13:29:58 +01:00
|
|
|
pinos_signal_init (&this->node_unlink);
|
|
|
|
|
pinos_signal_init (&this->node_unlink_done);
|
2016-11-14 12:42:00 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
this->global = pinos_core_add_global (this,
|
|
|
|
|
this->uri.core,
|
|
|
|
|
this);
|
|
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pinos_core_destroy (PinosCore *core)
|
|
|
|
|
{
|
|
|
|
|
PinosCoreImpl *impl = SPA_CONTAINER_OF (core, PinosCoreImpl, this);
|
|
|
|
|
|
|
|
|
|
pinos_signal_emit (&core->destroy_signal, core);
|
|
|
|
|
|
|
|
|
|
pinos_data_loop_destroy (core->data_loop);
|
|
|
|
|
|
|
|
|
|
free (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PinosGlobal *
|
|
|
|
|
pinos_core_add_global (PinosCore *core,
|
|
|
|
|
uint32_t type,
|
2016-11-16 16:57:47 +01:00
|
|
|
void *object)
|
2016-11-14 12:42:00 +01:00
|
|
|
{
|
|
|
|
|
PinosGlobal *global;
|
|
|
|
|
|
|
|
|
|
global = calloc (1, sizeof (PinosGlobal));
|
|
|
|
|
global->core = core;
|
|
|
|
|
global->type = type;
|
|
|
|
|
global->object = object;
|
|
|
|
|
|
2016-11-15 17:06:09 +01:00
|
|
|
pinos_signal_init (&global->destroy_signal);
|
|
|
|
|
|
2016-11-21 16:29:15 +01:00
|
|
|
global->id = pinos_map_insert_new (&core->objects, global);
|
|
|
|
|
|
2016-11-15 17:06:09 +01:00
|
|
|
spa_list_insert (core->global_list.prev, &global->link);
|
2016-11-14 12:42:00 +01:00
|
|
|
pinos_signal_emit (&core->global_added, core, global);
|
|
|
|
|
|
|
|
|
|
return global;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
static void
|
|
|
|
|
sync_destroy (void *object,
|
|
|
|
|
void *data,
|
|
|
|
|
SpaResult res,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
PinosGlobal *global = object;
|
|
|
|
|
|
|
|
|
|
pinos_log_debug ("global %p: sync destroy", global);
|
|
|
|
|
free (global);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-11-16 16:57:47 +01:00
|
|
|
pinos_global_destroy (PinosGlobal *global)
|
2016-11-14 12:42:00 +01:00
|
|
|
{
|
2016-11-16 16:57:47 +01:00
|
|
|
PinosCore *core = global->core;
|
|
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
pinos_log_debug ("global %p: destroy", global);
|
2016-11-15 17:06:09 +01:00
|
|
|
pinos_signal_emit (&global->destroy_signal, global);
|
|
|
|
|
|
2016-11-21 16:29:15 +01:00
|
|
|
pinos_map_remove (&core->objects, global->id);
|
|
|
|
|
|
2016-11-15 17:06:09 +01:00
|
|
|
spa_list_remove (&global->link);
|
2016-11-14 12:42:00 +01:00
|
|
|
pinos_signal_emit (&core->global_removed, core, global);
|
2016-11-10 15:42:14 +01:00
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
pinos_main_loop_defer (core->main_loop,
|
|
|
|
|
global,
|
|
|
|
|
SPA_RESULT_WAIT_SYNC,
|
|
|
|
|
sync_destroy,
|
|
|
|
|
global);
|
2016-11-16 16:57:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PinosPort *
|
|
|
|
|
pinos_core_find_port (PinosCore *core,
|
|
|
|
|
PinosPort *other_port,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
PinosProperties *props,
|
|
|
|
|
SpaFormat **format_filters,
|
|
|
|
|
char **error)
|
|
|
|
|
{
|
|
|
|
|
PinosPort *best = NULL;
|
|
|
|
|
bool have_id;
|
|
|
|
|
PinosNode *n;
|
|
|
|
|
|
|
|
|
|
have_id = id != SPA_ID_INVALID;
|
|
|
|
|
|
|
|
|
|
pinos_log_debug ("id \"%u\", %d", id, have_id);
|
|
|
|
|
|
|
|
|
|
spa_list_for_each (n, &core->node_list, link) {
|
|
|
|
|
pinos_log_debug ("node id \"%d\"", n->global->id);
|
|
|
|
|
|
|
|
|
|
if (have_id) {
|
|
|
|
|
if (n->global->id == id) {
|
|
|
|
|
pinos_log_debug ("id \"%u\" matches node %p", id, n);
|
|
|
|
|
|
|
|
|
|
best = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction));
|
|
|
|
|
if (best)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (best == NULL) {
|
|
|
|
|
asprintf (error, "No matching Node found");
|
|
|
|
|
}
|
|
|
|
|
return best;
|
2016-11-10 15:42:14 +01:00
|
|
|
}
|
2016-11-22 13:06:22 +01:00
|
|
|
|
|
|
|
|
PinosNodeFactory *
|
|
|
|
|
pinos_core_find_node_factory (PinosCore *core,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
PinosNodeFactory *factory;
|
|
|
|
|
|
|
|
|
|
spa_list_for_each (factory, &core->node_factory_list, link) {
|
|
|
|
|
if (strcmp (factory->name, name) == 0)
|
|
|
|
|
return factory;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|