mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Use mapper to make object id
Reuse object ids by using a mapper Simpify the uri struct a little.
This commit is contained in:
parent
f42268b9a5
commit
e7cae649aa
14 changed files with 61 additions and 64 deletions
|
|
@ -1,3 +1,4 @@
|
|||
load-module libpinos-module-protocol-dbus
|
||||
load-module libpinos-module-suspend-on-idle
|
||||
load-module libpinos-module-spa
|
||||
load-module libpinos-module-autolink
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ on_global_added (PinosListener *listener,
|
|||
{
|
||||
ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_added);
|
||||
|
||||
if (global->type == impl->core->registry.uri.node) {
|
||||
if (global->type == impl->core->uri.node) {
|
||||
PinosNode *node = global->object;
|
||||
on_node_added (impl, node);
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ on_global_removed (PinosListener *listener,
|
|||
{
|
||||
ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_removed);
|
||||
|
||||
if (global->type == impl->core->registry.uri.node) {
|
||||
if (global->type == impl->core->uri.node) {
|
||||
PinosNode *node = global->object;
|
||||
on_node_removed (impl, node);
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ module_new (PinosCore *core,
|
|||
pinos_signal_add (&core->port_unlinked, &impl->port_unlinked, on_link_port_unlinked);
|
||||
pinos_signal_add (&core->link_state_changed, &impl->link_state_changed, on_link_state_changed);
|
||||
|
||||
impl->uri.module = spa_id_map_get_id (core->registry.map, MODULE_URI);
|
||||
impl->uri.module = spa_id_map_get_id (core->uri.map, MODULE_URI);
|
||||
|
||||
impl->global = pinos_core_add_global (core,
|
||||
impl->uri.module,
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ handle_create_node (PinosDaemon1 *interface,
|
|||
goto object_failed;
|
||||
|
||||
pinos_client_add_resource (client,
|
||||
this->core->registry.uri.node,
|
||||
this->core->uri.node,
|
||||
node,
|
||||
(PinosDestroy) pinos_node_destroy);
|
||||
|
||||
|
|
@ -403,7 +403,7 @@ handle_create_client_node (PinosDaemon1 *interface,
|
|||
goto no_socket;
|
||||
|
||||
pinos_client_add_resource (client,
|
||||
this->core->registry.uri.client_node,
|
||||
this->core->uri.client_node,
|
||||
node,
|
||||
(PinosDestroy) pinos_client_node_destroy);
|
||||
|
||||
|
|
@ -493,7 +493,7 @@ on_global_added (PinosListener *listener,
|
|||
PinosProtocolDBus *this = &impl->this;
|
||||
PinosObjectSkeleton *skel;
|
||||
|
||||
if (global->type == this->core->registry.uri.client) {
|
||||
if (global->type == this->core->uri.client) {
|
||||
PinosClient1 *iface;
|
||||
PinosClient *client = global->object;
|
||||
PinosProperties *props = client->properties;
|
||||
|
|
@ -515,7 +515,7 @@ on_global_added (PinosListener *listener,
|
|||
false,
|
||||
(PinosDestroy) client_destroy);
|
||||
|
||||
} else if (global->type == this->core->registry.uri.node) {
|
||||
} else if (global->type == this->core->uri.node) {
|
||||
PinosNode1 *iface;
|
||||
PinosNode *node = global->object;
|
||||
PinosProperties *props = node->properties;
|
||||
|
|
@ -582,7 +582,7 @@ on_global_added (PinosListener *listener,
|
|||
name_lost_handler,
|
||||
proto,
|
||||
NULL);
|
||||
} else if (global->type == this->core->registry.uri.link) {
|
||||
} else if (global->type == this->core->uri.link) {
|
||||
PinosLink1 *iface;
|
||||
PinosLink *link = global->object;
|
||||
PinosProtocolDBusObject *obj;
|
||||
|
|
@ -657,7 +657,7 @@ pinos_protocol_dbus_new (PinosCore *core,
|
|||
|
||||
impl->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX);
|
||||
|
||||
impl->uri.protocol_dbus = spa_id_map_get_id (core->registry.map, PINOS_PROTOCOL_DBUS_URI);
|
||||
impl->uri.protocol_dbus = spa_id_map_get_id (core->uri.map, PINOS_PROTOCOL_DBUS_URI);
|
||||
|
||||
this->global = pinos_core_add_global (core,
|
||||
impl->uri.protocol_dbus,
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ on_global_added (PinosListener *listener,
|
|||
{
|
||||
ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_added);
|
||||
|
||||
if (global->type == impl->core->registry.uri.node) {
|
||||
if (global->type == impl->core->uri.node) {
|
||||
PinosNode *node = global->object;
|
||||
NodeInfo *info;
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ on_global_removed (PinosListener *listener,
|
|||
{
|
||||
ModuleImpl *impl = SPA_CONTAINER_OF (listener, ModuleImpl, global_removed);
|
||||
|
||||
if (global->type == impl->core->registry.uri.node) {
|
||||
if (global->type == impl->core->uri.node) {
|
||||
PinosNode *node = global->object;
|
||||
NodeInfo *info;
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ module_new (PinosCore *core,
|
|||
pinos_signal_add (&core->node_state_request, &impl->node_state_request, on_node_state_request);
|
||||
pinos_signal_add (&core->node_state_changed, &impl->node_state_changed, on_node_state_changed);
|
||||
|
||||
impl->uri.module = spa_id_map_get_id (core->registry.map, MODULE_URI);
|
||||
impl->uri.module = spa_id_map_get_id (core->uri.map, MODULE_URI);
|
||||
|
||||
impl->global = pinos_core_add_global (core,
|
||||
impl->uri.module,
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
|
|||
pinos_log_error ("can't make factory instance: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, impl->core->registry.uri.spa_node, &node_iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle, impl->core->uri.spa_node, &node_iface)) < 0) {
|
||||
pinos_log_error ("can't get NODE interface: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, impl->core->registry.uri.spa_clock, &clock_iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle, impl->core->uri.spa_clock, &clock_iface)) < 0) {
|
||||
pinos_log_info ("no CLOCK interface: %d", res);
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ pinos_spa_monitor_load (PinosCore *core,
|
|||
goto init_failed;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
core->registry.uri.spa_monitor,
|
||||
core->uri.spa_monitor,
|
||||
&iface)) < 0) {
|
||||
free (handle);
|
||||
pinos_log_error ("can't get MONITOR interface: %d", res);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ pinos_spa_node_load (PinosCore *core,
|
|||
goto init_failed;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
core->registry.uri.spa_node,
|
||||
core->uri.spa_node,
|
||||
&iface)) < 0) {
|
||||
pinos_log_error ("can't get interface %d", res);
|
||||
goto interface_failed;
|
||||
|
|
@ -87,7 +87,7 @@ pinos_spa_node_load (PinosCore *core,
|
|||
spa_node = iface;
|
||||
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
core->registry.uri.spa_clock,
|
||||
core->uri.spa_clock,
|
||||
&iface)) < 0) {
|
||||
iface = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ pinos_client_new (PinosCore *core,
|
|||
spa_list_insert (core->client_list.prev, &this->link);
|
||||
|
||||
this->global = pinos_core_add_global (core,
|
||||
core->registry.uri.client,
|
||||
core->uri.client,
|
||||
this);
|
||||
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
typedef struct {
|
||||
PinosCore this;
|
||||
|
||||
uint32_t counter;
|
||||
|
||||
SpaSupport support[4];
|
||||
|
||||
} PinosCoreImpl;
|
||||
|
|
@ -38,13 +36,15 @@ pinos_core_new (PinosMainLoop *main_loop)
|
|||
|
||||
impl = calloc (1, sizeof (PinosCoreImpl));
|
||||
this = &impl->this;
|
||||
pinos_registry_init (&this->registry);
|
||||
pinos_uri_init (&this->uri);
|
||||
|
||||
pinos_map_init (&this->objects, 512);
|
||||
|
||||
this->data_loop = pinos_data_loop_new ();
|
||||
this->main_loop = main_loop;
|
||||
|
||||
impl->support[0].uri = SPA_ID_MAP_URI;
|
||||
impl->support[0].data = this->registry.map;
|
||||
impl->support[0].data = this->uri.map;
|
||||
impl->support[1].uri = SPA_LOG_URI;
|
||||
impl->support[1].data = pinos_log_get ();
|
||||
impl->support[2].uri = SPA_LOOP__DataLoop;
|
||||
|
|
@ -93,17 +93,17 @@ pinos_core_add_global (PinosCore *core,
|
|||
uint32_t type,
|
||||
void *object)
|
||||
{
|
||||
PinosCoreImpl *impl = SPA_CONTAINER_OF (core, PinosCoreImpl, this);
|
||||
PinosGlobal *global;
|
||||
|
||||
global = calloc (1, sizeof (PinosGlobal));
|
||||
global->core = core;
|
||||
global->id = ++impl->counter;
|
||||
global->type = type;
|
||||
global->object = object;
|
||||
|
||||
pinos_signal_init (&global->destroy_signal);
|
||||
|
||||
global->id = pinos_map_insert_new (&core->objects, global);
|
||||
|
||||
spa_list_insert (core->global_list.prev, &global->link);
|
||||
pinos_signal_emit (&core->global_added, core, global);
|
||||
|
||||
|
|
@ -117,6 +117,8 @@ pinos_global_destroy (PinosGlobal *global)
|
|||
|
||||
pinos_signal_emit (&global->destroy_signal, global);
|
||||
|
||||
pinos_map_remove (&core->objects, global->id);
|
||||
|
||||
spa_list_remove (&global->link);
|
||||
pinos_signal_emit (&core->global_removed, core, global);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ typedef struct _PinosGlobal PinosGlobal;
|
|||
|
||||
#include <pinos/server/main-loop.h>
|
||||
#include <pinos/server/data-loop.h>
|
||||
#include <pinos/server/registry.h>
|
||||
#include <pinos/server/uri.h>
|
||||
#include <pinos/server/node.h>
|
||||
#include <pinos/server/link.h>
|
||||
|
||||
|
|
@ -52,7 +52,9 @@ struct _PinosGlobal {
|
|||
* Pinos core object class.
|
||||
*/
|
||||
struct _PinosCore {
|
||||
PinosRegistry registry;
|
||||
PinosURI uri;
|
||||
|
||||
PinosMap objects;
|
||||
|
||||
SpaList global_list;
|
||||
SpaList client_list;
|
||||
|
|
|
|||
|
|
@ -712,7 +712,7 @@ pinos_link_new (PinosCore *core,
|
|||
spa_list_insert (core->link_list.prev, &this->link);
|
||||
|
||||
this->global = pinos_core_add_global (core,
|
||||
core->registry.uri.link,
|
||||
core->uri.link,
|
||||
this);
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pinoscore_headers = [
|
|||
'node.h',
|
||||
'node-factory.h',
|
||||
'port.h',
|
||||
'registry.h',
|
||||
'uri.h',
|
||||
]
|
||||
|
||||
pinoscore_sources = [
|
||||
|
|
@ -25,7 +25,7 @@ pinoscore_sources = [
|
|||
'node.c',
|
||||
'node-factory.c',
|
||||
'port.c',
|
||||
'registry.c',
|
||||
'uri.c',
|
||||
]
|
||||
|
||||
libpinoscore_c_args = [
|
||||
|
|
|
|||
|
|
@ -463,7 +463,7 @@ pinos_node_new (PinosCore *core,
|
|||
spa_list_insert (core->node_list.prev, &this->link);
|
||||
|
||||
this->global = pinos_core_add_global (core,
|
||||
core->registry.uri.node,
|
||||
core->uri.node,
|
||||
this);
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/server/core.h"
|
||||
#include "pinos/server/registry.h"
|
||||
#include "pinos/server/uri.h"
|
||||
#include "pinos/server/node.h"
|
||||
#include "pinos/server/node-factory.h"
|
||||
#include "pinos/server/client.h"
|
||||
|
|
@ -30,20 +30,18 @@
|
|||
#include "spa/include/spa/monitor.h"
|
||||
|
||||
void
|
||||
pinos_registry_init (PinosRegistry *reg)
|
||||
pinos_uri_init (PinosURI *uri)
|
||||
{
|
||||
reg->map = pinos_id_map_get_default();
|
||||
uri->map = pinos_id_map_get_default();
|
||||
|
||||
reg->uri.registry = spa_id_map_get_id (reg->map, PINOS_REGISTRY_URI);
|
||||
reg->uri.node = spa_id_map_get_id (reg->map, PINOS_NODE_URI);
|
||||
reg->uri.node_factory = spa_id_map_get_id (reg->map, PINOS_NODE_FACTORY_URI);
|
||||
reg->uri.link = spa_id_map_get_id (reg->map, PINOS_LINK_URI);
|
||||
reg->uri.client = spa_id_map_get_id (reg->map, PINOS_CLIENT_URI);
|
||||
reg->uri.client_node = spa_id_map_get_id (reg->map, PINOS_CLIENT_NODE_URI);
|
||||
uri->node = spa_id_map_get_id (uri->map, PINOS_NODE_URI);
|
||||
uri->node_factory = spa_id_map_get_id (uri->map, PINOS_NODE_FACTORY_URI);
|
||||
uri->link = spa_id_map_get_id (uri->map, PINOS_LINK_URI);
|
||||
uri->client = spa_id_map_get_id (uri->map, PINOS_CLIENT_URI);
|
||||
uri->client_node = spa_id_map_get_id (uri->map, PINOS_CLIENT_NODE_URI);
|
||||
|
||||
reg->uri.spa_node = spa_id_map_get_id (reg->map, SPA_NODE_URI);
|
||||
reg->uri.spa_clock = spa_id_map_get_id (reg->map, SPA_CLOCK_URI);
|
||||
reg->uri.spa_monitor = spa_id_map_get_id (reg->map, SPA_MONITOR_URI);
|
||||
uri->spa_node = spa_id_map_get_id (uri->map, SPA_NODE_URI);
|
||||
uri->spa_clock = spa_id_map_get_id (uri->map, SPA_CLOCK_URI);
|
||||
uri->spa_monitor = spa_id_map_get_id (uri->map, SPA_MONITOR_URI);
|
||||
|
||||
pinos_map_init (®->objects, 512);
|
||||
}
|
||||
|
|
@ -17,24 +17,29 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PINOS_REGISTRY_H__
|
||||
#define __PINOS_REGISTRY_H__
|
||||
#ifndef __PINOS_URI_H__
|
||||
#define __PINOS_URI_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PINOS_REGISTRY_URI "http://pinos.org/ns/registry"
|
||||
#define PINOS_REGISTRY_PREFIX PINOS_REGISTRY_URI "#"
|
||||
#define PINOS_URI_URI "http://pinos.org/ns/uri"
|
||||
#define PINOS_URI_PREFIX PINOS_URI_URI "#"
|
||||
|
||||
#include <pinos/client/map.h>
|
||||
#include <pinos/client/signal.h>
|
||||
#include <spa/include/spa/id-map.h>
|
||||
|
||||
typedef struct _PinosRegistry PinosRegistry;
|
||||
typedef struct _PinosURI PinosURI;
|
||||
|
||||
/**
|
||||
* PinosURI:
|
||||
*
|
||||
* Pinos URI support struct.
|
||||
*/
|
||||
struct _PinosURI {
|
||||
SpaIDMap *map;
|
||||
|
||||
typedef struct {
|
||||
uint32_t registry;
|
||||
uint32_t node;
|
||||
uint32_t node_factory;
|
||||
uint32_t link;
|
||||
|
|
@ -44,23 +49,12 @@ typedef struct {
|
|||
uint32_t spa_node;
|
||||
uint32_t spa_clock;
|
||||
uint32_t spa_monitor;
|
||||
} PinosURI;
|
||||
|
||||
/**
|
||||
* PinosRegistry:
|
||||
*
|
||||
* Pinos registry struct.
|
||||
*/
|
||||
struct _PinosRegistry {
|
||||
SpaIDMap *map;
|
||||
PinosURI uri;
|
||||
PinosMap objects;
|
||||
};
|
||||
|
||||
void pinos_registry_init (PinosRegistry *reg);
|
||||
void pinos_uri_init (PinosURI *uri);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PINOS_REGISTRY_H__ */
|
||||
#endif /* __PINOS_URI_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue