Remove hastables, use lists
Remove obsolete ringbuffer
some small cleanups
This commit is contained in:
Wim Taymans 2016-11-15 20:12:31 +01:00
parent b6ad45bb74
commit 1a48bccca0
16 changed files with 93 additions and 554 deletions

View file

@ -165,7 +165,7 @@ pinos_client_new (PinosCore *core,
client_watch_name (this);
spa_list_insert (core->client_list.prev, &this->list);
spa_list_insert (core->client_list.prev, &this->link);
return this;
}
@ -188,7 +188,7 @@ pinos_client_destroy (PinosClient * client)
spa_list_for_each_safe (resource, tmp, &client->resource_list, link)
pinos_client_remove_resource (client, resource);
spa_list_remove (&client->list);
spa_list_remove (&client->link);
free (client->sender);
if (client->properties)

View file

@ -54,7 +54,7 @@ struct _PinosResource {
*/
struct _PinosClient {
PinosCore *core;
SpaList list;
SpaList link;
PinosGlobal *global;
char *sender;

View file

@ -56,6 +56,7 @@ pinos_core_new (PinosMainLoop *main_loop)
spa_list_init (&this->global_list);
spa_list_init (&this->client_list);
spa_list_init (&this->node_list);
spa_list_init (&this->node_factory_list);
spa_list_init (&this->link_list);
pinos_signal_init (&this->destroy_signal);
pinos_signal_init (&this->global_added);
@ -115,5 +116,7 @@ pinos_core_remove_global (PinosCore *core,
spa_list_remove (&global->link);
pinos_signal_emit (&core->global_removed, core, global);
g_clear_object (&global->skel);
free (global);
}

View file

@ -65,9 +65,9 @@ struct _PinosCore {
SpaList global_list;
SpaList client_list;
SpaList node_list;
SpaList node_factory_list;
SpaList link_list;
PinosMainLoop *main_loop;
PinosDataLoop *data_loop;

View file

@ -55,9 +55,6 @@ typedef struct {
PinosListener port_unlinked;
PinosListener node_state_changed;
PinosListener link_state_changed;
GHashTable *clients;
GHashTable *node_factories;
} PinosDaemonImpl;
static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *daemon);
@ -67,16 +64,29 @@ sender_get_client (PinosDaemon *daemon,
const char *sender,
bool create)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
PinosClient *client;
client = g_hash_table_lookup (impl->clients, sender);
if (client == NULL && create) {
client = pinos_client_new (daemon->core, sender, NULL);
spa_list_for_each (client, &daemon->core->client_list, link) {
if (strcmp (client->sender, sender) == 0)
return client;
}
client = pinos_client_new (daemon->core, sender, NULL);
return client;
}
static PinosNodeFactory *
find_factory_by_name (PinosDaemon *daemon,
const char *name)
{
PinosNodeFactory *factory;
spa_list_for_each (factory, &daemon->core->node_factory_list, link) {
if (strcmp (factory->name, name) == 0)
return factory;
}
return NULL;
}
static bool
handle_create_node (PinosDaemon1 *interface,
GDBusMethodInvocation *invocation,
@ -100,7 +110,7 @@ handle_create_node (PinosDaemon1 *interface,
props = pinos_properties_from_variant (arg_properties);
factory = g_hash_table_lookup (impl->node_factories, arg_factory_name);
factory = find_factory_by_name (this, arg_factory_name);
if (factory == NULL)
goto no_factory;
@ -490,14 +500,6 @@ on_global_added (PinosListener *listener,
PinosNode *node = global->object;
on_node_added (this, node);
} else if (global->type == this->core->registry.uri.node_factory) {
PinosNodeFactory *factory = global->object;
g_hash_table_insert (impl->node_factories, (void *)factory->name, factory);
} else if (global->type == this->core->registry.uri.client) {
PinosClient *client = global->object;
g_hash_table_insert (impl->clients, (gpointer) client->sender, client);
}
}
@ -517,14 +519,6 @@ on_global_removed (PinosListener *listener,
PinosNode *node = global->object;
on_node_removed (this, node);
} else if (global->type == this->core->registry.uri.node_factory) {
PinosNodeFactory *factory = global->object;
g_hash_table_remove (impl->node_factories, factory->name);
} else if (global->type == this->core->registry.uri.client) {
PinosClient *client = global->object;
g_hash_table_remove (impl->clients, (gpointer) client->sender);
}
}
@ -559,7 +553,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
pinos_log_debug ("name \"%s\", %d", name, have_name);
spa_list_for_each (n, &daemon->core->node_list, list) {
spa_list_for_each (n, &daemon->core->node_list, link) {
pinos_log_debug ("node path \"%s\"", n->global->object_path);
if (have_name) {
@ -617,11 +611,6 @@ pinos_daemon_new (PinosCore *core,
pinos_signal_add (&core->link_state_changed, &impl->link_state_changed, on_link_state_changed);
impl->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX);
impl->clients = g_hash_table_new (g_str_hash, g_str_equal);
impl->node_factories = g_hash_table_new_full (g_str_hash,
g_str_equal,
NULL,
NULL);
impl->iface = pinos_daemon1_skeleton_new ();
g_signal_connect (impl->iface, "handle-create-node", (GCallback) handle_create_node, impl);
@ -658,11 +647,14 @@ pinos_daemon_destroy (PinosDaemon *daemon)
pinos_signal_remove (&impl->global_added);
pinos_signal_remove (&impl->global_removed);
pinos_signal_remove (&impl->node_state_changed);
pinos_signal_remove (&impl->port_added);
pinos_signal_remove (&impl->port_removed);
pinos_signal_remove (&impl->port_unlinked);
pinos_signal_remove (&impl->link_state_changed);
g_clear_object (&impl->server_manager);
g_clear_object (&impl->iface);
g_hash_table_unref (impl->clients);
g_hash_table_unref (impl->node_factories);
free (impl);
}

View file

@ -41,7 +41,7 @@ typedef struct _PinosDaemon PinosDaemon;
*/
struct _PinosDaemon {
PinosCore *core;
SpaList list;
SpaList link;
PinosGlobal *global;
PinosProperties *properties;

View file

@ -749,7 +749,7 @@ pinos_link_new (PinosCore *core,
this->output->node, this->output->port_id,
this->input->node, this->input->port_id);
spa_list_insert (core->link_list.prev, &this->list);
spa_list_insert (core->link_list.prev, &this->link);
impl->iface = pinos_link1_skeleton_new ();
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_LINK);
@ -867,7 +867,7 @@ pinos_link_destroy (PinosLink * this)
pinos_signal_emit (&this->destroy_signal, this);
pinos_core_remove_global (this->core, this->global);
spa_list_remove (&this->list);
spa_list_remove (&this->link);
if (this->input) {
pinos_signal_remove (&impl->input_port_destroy);

View file

@ -44,7 +44,7 @@ typedef struct _PinosLink PinosLink;
*/
struct _PinosLink {
PinosCore *core;
SpaList list;
SpaList link;
PinosGlobal *global;
PinosProperties *properties;

View file

@ -38,6 +38,10 @@ typedef struct _PinosNodeFactory PinosNodeFactory;
* Pinos node factory interface.
*/
struct _PinosNodeFactory {
PinosCore *core;
SpaList link;
PinosGlobal *global;
const char *name;
PinosNode * (*create_node) (PinosNodeFactory *factory,

View file

@ -496,7 +496,7 @@ pinos_node_new (PinosCore *core,
(PinosDeferFunc) init_complete,
NULL);
}
spa_list_insert (core->node_list.prev, &this->list);
spa_list_insert (core->node_list.prev, &this->link);
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_NODE);
pinos_object_skeleton_set_node1 (skel, impl->iface);
@ -593,7 +593,7 @@ pinos_node_destroy (PinosNode * this)
pinos_log_debug ("node %p: destroy", impl);
pinos_signal_emit (&this->destroy_signal, this);
spa_list_remove (&this->list);
spa_list_remove (&this->link);
pinos_core_remove_global (this->core, this->global);
res = spa_poll_invoke (&this->data_loop->poll,

View file

@ -48,7 +48,7 @@ typedef struct _PinosNode PinosNode;
*/
struct _PinosNode {
PinosCore *core;
SpaList list;
SpaList link;
PinosGlobal *global;
bool unlinking;