Rework dbus handling

Remove the Daemon object and remove all dbus code from the main
objects. We can use the signals in a separate module to create and
destroy the DBus interfaces.
Move the dbus protocol in a module
Move the autolink policy to a module
This commit is contained in:
Wim Taymans 2016-11-16 16:57:47 +01:00
parent b9e2b1c0e3
commit dfbfb4c9ee
28 changed files with 1122 additions and 1007 deletions

View file

@ -35,7 +35,7 @@
#include "pinos/client/serialize.h"
#include "pinos/client/transport.h"
#include "pinos/server/daemon.h"
#include "pinos/server/core.h"
#include "pinos/server/client-node.h"
#include "spa/include/spa/node.h"

View file

@ -27,64 +27,8 @@
typedef struct
{
PinosClient this;
guint id;
PinosClient1 *iface;
} PinosClientImpl;
static void
client_name_appeared_handler (GDBusConnection *connection,
const gchar *name,
const gchar *name_owner,
gpointer user_data)
{
PinosClientImpl *impl = user_data;
PinosClient *this = &impl->this;
PinosObjectSkeleton *skel;
pinos_log_debug ("client %p: appeared %s %s", this, name, name_owner);
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_CLIENT);
pinos_object_skeleton_set_client1 (skel, impl->iface);
this->global = pinos_core_add_global (this->core,
this->core->registry.uri.client,
this,
skel);
}
static void
client_name_vanished_handler (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
PinosClientImpl *impl = user_data;
PinosClient *this = &impl->this;
pinos_log_debug ("client %p: vanished %s", this, name);
pinos_core_remove_global (this->core,
this->global);
this->global = NULL;
g_bus_unwatch_name (impl->id);
}
static void
client_watch_name (PinosClient *this)
{
PinosClientImpl *impl = SPA_CONTAINER_OF (this, PinosClientImpl, this);
impl->id = g_bus_watch_name_on_connection (this->core->connection,
this->sender,
G_BUS_NAME_WATCHER_FLAGS_NONE,
client_name_appeared_handler,
client_name_vanished_handler,
impl,
(GDestroyNotify) pinos_client_destroy);
}
PinosResource *
pinos_client_add_resource (PinosClient *client,
uint32_t type,
@ -95,6 +39,7 @@ pinos_client_add_resource (PinosClient *client,
resource = calloc (1, sizeof (PinosResource));
resource->core = client->core;
resource->client = client;
resource->id = 0;
resource->type = type;
resource->object = object;
@ -109,11 +54,10 @@ pinos_client_add_resource (PinosClient *client,
return resource;
}
void
pinos_client_remove_resource (PinosClient *client,
PinosResource *resource)
SpaResult
pinos_resource_destroy (PinosResource *resource)
{
pinos_log_debug ("client %p: resource %p destroy", client, resource);
pinos_log_debug ("resource %p: destroy", resource);
pinos_signal_emit (&resource->destroy_signal, resource);
spa_list_remove (&resource->link);
@ -122,29 +66,21 @@ pinos_client_remove_resource (PinosClient *client,
resource->destroy (resource->object);
free (resource);
}
bool
pinos_client_has_resource (PinosClient *client,
PinosResource *resource)
{
return false;
return SPA_RESULT_OK;
}
/**
* pinos_client_new:
* @daemon: a #PinosDaemon
* @sender: the sender id
* @prefix: a prefix
* @properties: extra client properties
*
* Make a new #PinosClient object and register it to @daemon under the @prefix.
* Make a new #PinosClient object and register it to @core
*
* Returns: a new #PinosClient
*/
PinosClient *
pinos_client_new (PinosCore *core,
const gchar *sender,
PinosProperties *properties)
{
PinosClient *this;
@ -155,18 +91,17 @@ pinos_client_new (PinosCore *core,
this = &impl->this;
this->core = core;
this->sender = strdup (sender);
this->properties = properties;
spa_list_init (&this->resource_list);
pinos_signal_init (&this->destroy_signal);
impl->iface = pinos_client1_skeleton_new ();
client_watch_name (this);
spa_list_insert (core->client_list.prev, &this->link);
this->global = pinos_core_add_global (core,
core->registry.uri.client,
this);
return this;
}
@ -185,16 +120,16 @@ pinos_client_destroy (PinosClient * client)
pinos_log_debug ("client %p: destroy", client);
pinos_signal_emit (&client->destroy_signal, client);
pinos_global_destroy (client->global);
spa_list_for_each_safe (resource, tmp, &client->resource_list, link)
pinos_client_remove_resource (client, resource);
pinos_resource_destroy (resource);
spa_list_remove (&client->link);
free (client->sender);
if (client->properties)
pinos_properties_free (client->properties);
g_clear_object (&impl->iface);
free (impl);
return SPA_RESULT_OK;

View file

@ -32,12 +32,14 @@ typedef struct _PinosResource PinosResource;
typedef void (*PinosDestroy) (void *object);
#include <pinos/client/object.h>
#include <pinos/server/daemon.h>
#include <pinos/server/core.h>
struct _PinosResource {
PinosCore *core;
SpaList link;
PinosClient *client;
uint32_t id;
uint32_t type;
void *object;
@ -57,7 +59,6 @@ struct _PinosClient {
SpaList link;
PinosGlobal *global;
char *sender;
PinosProperties *properties;
SpaList resource_list;
@ -67,7 +68,6 @@ struct _PinosClient {
};
PinosClient * pinos_client_new (PinosCore *core,
const gchar *sender,
PinosProperties *properties);
SpaResult pinos_client_destroy (PinosClient *client);
@ -77,10 +77,7 @@ PinosResource * pinos_client_add_resource (PinosClient *client,
void *object,
PinosDestroy destroy);
void pinos_client_remove_resource (PinosClient *client,
PinosResource *resource);
bool pinos_client_has_resource (PinosClient *client,
PinosResource *resource);
SpaResult pinos_resource_destroy (PinosResource *resource);
#ifdef __cplusplus
}

View file

@ -25,7 +25,7 @@
extern "C" {
#endif
#include <pinos/server/daemon.h>
#include <pinos/server/core.h>
typedef struct _PinosCommand PinosCommand;

View file

@ -17,13 +17,14 @@
* Boston, MA 02110-1301, USA.
*/
#include <pinos/client/pinos.h>
#include <pinos/server/core.h>
#include <pinos/server/data-loop.h>
typedef struct {
PinosCore this;
GDBusObjectManagerServer *server_manager;
uint32_t counter;
SpaSupport support[4];
@ -87,17 +88,16 @@ pinos_core_destroy (PinosCore *core)
PinosGlobal *
pinos_core_add_global (PinosCore *core,
uint32_t type,
void *object,
PinosObjectSkeleton *skel)
void *object)
{
PinosCoreImpl *impl = SPA_CONTAINER_OF (core, PinosCoreImpl, this);
PinosGlobal *global;
global = calloc (1, sizeof (PinosGlobal));
global->core = core;
global->id = 0;
global->id = ++impl->counter;
global->type = type;
global->object = object;
global->skel = skel;
pinos_signal_init (&global->destroy_signal);
@ -107,16 +107,53 @@ pinos_core_add_global (PinosCore *core,
return global;
}
void
pinos_core_remove_global (PinosCore *core,
PinosGlobal *global)
SpaResult
pinos_global_destroy (PinosGlobal *global)
{
PinosCore *core = global->core;
pinos_signal_emit (&global->destroy_signal, global);
spa_list_remove (&global->link);
pinos_signal_emit (&core->global_removed, core, global);
g_clear_object (&global->skel);
free (global);
return SPA_RESULT_OK;
}
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;
}

View file

@ -27,8 +27,6 @@ extern "C" {
typedef struct _PinosCore PinosCore;
typedef struct _PinosGlobal PinosGlobal;
#include <gio/gio.h>
#include <spa/include/spa/log.h>
#include <pinos/server/main-loop.h>
#include <pinos/server/data-loop.h>
@ -36,8 +34,6 @@ typedef struct _PinosGlobal PinosGlobal;
#include <pinos/server/node.h>
#include <pinos/server/link.h>
#include "pinos/dbus/org-pinos.h"
struct _PinosGlobal {
PinosCore *core;
SpaList link;
@ -47,9 +43,6 @@ struct _PinosGlobal {
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
PinosGlobal *global));
PinosObjectSkeleton *skel;
const char *object_path;
};
/**
@ -60,8 +53,6 @@ struct _PinosGlobal {
struct _PinosCore {
PinosRegistry registry;
GDBusConnection *connection;
SpaList global_list;
SpaList client_list;
SpaList node_list;
@ -111,10 +102,16 @@ void pinos_core_destroy (PinosCore *core);
PinosGlobal * pinos_core_add_global (PinosCore *core,
uint32_t type,
void *object,
PinosObjectSkeleton *skel);
void pinos_core_remove_global (PinosCore *core,
PinosGlobal *global);
void *object);
SpaResult pinos_global_destroy (PinosGlobal *global);
PinosPort * pinos_core_find_port (PinosCore *core,
PinosPort *other_port,
uint32_t id,
PinosProperties *props,
SpaFormat **format_filter,
char **error);
#ifdef __cplusplus
}

View file

@ -1,660 +0,0 @@
/* 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.
*/
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
#include "config.h"
#include "pinos/client/pinos.h"
#include "pinos/client/log.h"
#include "pinos/server/daemon.h"
#include "pinos/server/node.h"
#include "pinos/server/client-node.h"
#include "pinos/server/client.h"
#include "pinos/server/link.h"
#include "pinos/server/node-factory.h"
#include "pinos/server/data-loop.h"
#include "pinos/server/main-loop.h"
#include "pinos/dbus/org-pinos.h"
typedef struct {
PinosDaemon this;
GDBusObjectManagerServer *server_manager;
PinosDaemon1 *iface;
guint id;
PinosListener global_added;
PinosListener global_removed;
PinosListener port_added;
PinosListener port_removed;
PinosListener port_unlinked;
PinosListener node_state_changed;
PinosListener link_state_changed;
} PinosDaemonImpl;
static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *daemon);
static PinosClient *
sender_get_client (PinosDaemon *daemon,
const char *sender,
bool create)
{
PinosClient *client;
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,
const char *arg_factory_name,
const char *arg_name,
GVariant *arg_properties,
gpointer user_data)
{
PinosDaemonImpl *impl = user_data;
PinosDaemon *this = &impl->this;
PinosNodeFactory *factory;
PinosNode *node;
PinosClient *client;
const char *sender, *object_path;
PinosProperties *props;
sender = g_dbus_method_invocation_get_sender (invocation);
client = sender_get_client (this, sender, TRUE);
pinos_log_debug ("daemon %p: create node: %s", impl, sender);
props = pinos_properties_from_variant (arg_properties);
factory = find_factory_by_name (this, arg_factory_name);
if (factory == NULL)
goto no_factory;
node = pinos_node_factory_create_node (factory,
client,
arg_name,
props);
pinos_properties_free (props);
if (node == NULL)
goto no_node;
//pinos_client_add_object (client, &node->object);
object_path = node->global->object_path;
pinos_log_debug ("daemon %p: added node %p with path %s", impl, node, object_path);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)", object_path));
return TRUE;
/* ERRORS */
no_factory:
{
pinos_log_debug ("daemon %p: could find factory named %s", impl, arg_factory_name);
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pinos.Error", "can't find factory");
return TRUE;
}
no_node:
{
pinos_log_debug ("daemon %p: could create node named %s from factory %s", impl, arg_name, arg_factory_name);
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pinos.Error", "can't create node");
return TRUE;
}
}
static void
on_link_port_unlinked (PinosListener *listener,
PinosLink *link,
PinosPort *port)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, port_unlinked);
pinos_log_debug ("daemon %p: link %p: port %p unlinked", impl, link, port);
if (port->direction == PINOS_DIRECTION_OUTPUT && link->input)
try_link_port (link->input->node, link->input, &impl->this);
}
static void
on_link_state_changed (PinosListener *listener,
PinosLink *link)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, link_state_changed);
PinosLinkState state;
state = link->state;
switch (state) {
case PINOS_LINK_STATE_ERROR:
{
pinos_log_debug ("daemon %p: link %p: state error: %s", impl, link, link->error);
if (link->input && link->input->node)
pinos_node_report_error (link->input->node, strdup (link->error));
if (link->output && link->output->node)
pinos_node_report_error (link->output->node, strdup (link->error));
break;
}
case PINOS_LINK_STATE_UNLINKED:
pinos_log_debug ("daemon %p: link %p: unlinked", impl, link);
#if 0
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_NODE_LINK,
"error node unlinked");
if (link->input && link->input->node)
pinos_node_report_error (link->input->node, g_error_copy (error));
if (link->output && link->output->node)
pinos_node_report_error (link->output->node, g_error_copy (error));
#endif
break;
case PINOS_LINK_STATE_INIT:
case PINOS_LINK_STATE_NEGOTIATING:
case PINOS_LINK_STATE_ALLOCATING:
case PINOS_LINK_STATE_PAUSED:
case PINOS_LINK_STATE_RUNNING:
break;
}
}
static void
try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this)
{
//PinosDaemonImpl *impl = SPA_CONTAINER_OF (this, PinosDaemonImpl, this);
//PinosClient *client;
PinosProperties *props;
const char *path;
char *error = NULL;
PinosLink *link;
props = node->properties;
if (props == NULL)
return;
path = pinos_properties_get (props, "pinos.target.node");
if (path) {
PinosPort *target;
target = pinos_daemon_find_port (this,
port,
path,
NULL,
NULL,
&error);
if (target == NULL)
goto error;
if (port->direction == PINOS_DIRECTION_OUTPUT)
link = pinos_port_link (port, target, NULL, NULL, &error);
else
link = pinos_port_link (target, port, NULL, NULL, &error);
if (link == NULL)
goto error;
#if 0
client = pinos_node_get_client (node);
if (client)
pinos_client_add_object (client, &link->object);
#endif
pinos_link_activate (link);
}
return;
error:
{
pinos_node_report_error (node, error);
return;
}
}
static void
on_port_added (PinosListener *listener,
PinosNode *node,
PinosPort *port)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, port_added);
try_link_port (node, port, &impl->this);
}
static void
on_port_removed (PinosListener *listener,
PinosNode *node,
PinosPort *port)
{
}
static void
on_node_created (PinosNode *node,
PinosDaemonImpl *impl)
{
PinosPort *port;
spa_list_for_each (port, &node->input_ports, link)
on_port_added (&impl->port_added, node, port);
spa_list_for_each (port, &node->output_ports, link)
on_port_added (&impl->port_added, node, port);
}
static void
on_node_state_changed (PinosListener *listener,
PinosNode *node,
PinosNodeState old,
PinosNodeState state)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, node_state_changed);
pinos_log_debug ("daemon %p: node %p state change %s -> %s", impl, node,
pinos_node_state_as_string (old),
pinos_node_state_as_string (state));
if (old == PINOS_NODE_STATE_CREATING && state == PINOS_NODE_STATE_SUSPENDED)
on_node_created (node, impl);
}
static void
on_node_added (PinosDaemon *daemon, PinosNode *node)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
pinos_log_debug ("daemon %p: node %p added", impl, node);
pinos_node_set_data_loop (node, daemon->core->data_loop);
if (node->state > PINOS_NODE_STATE_CREATING) {
on_node_created (node, impl);
}
}
static void
on_node_removed (PinosDaemon *daemon, PinosNode *node)
{
pinos_log_debug ("daemon %p: node %p removed", daemon, node);
}
static bool
handle_create_client_node (PinosDaemon1 *interface,
GDBusMethodInvocation *invocation,
const char *arg_name,
GVariant *arg_properties,
gpointer user_data)
{
PinosDaemonImpl *impl = user_data;
PinosDaemon *this = &impl->this;
PinosClientNode *node;
PinosClient *client;
SpaResult res;
const char *sender, *object_path;
PinosProperties *props;
GError *error = NULL;
GUnixFDList *fdlist;
int ctrl_fd, data_fd;
int ctrl_idx, data_idx;
sender = g_dbus_method_invocation_get_sender (invocation);
client = sender_get_client (this, sender, TRUE);
pinos_log_debug ("daemon %p: create client-node: %s", impl, sender);
props = pinos_properties_from_variant (arg_properties);
node = pinos_client_node_new (this->core,
arg_name,
props);
if ((res = pinos_client_node_get_ctrl_socket (node, &ctrl_fd)) < 0)
goto no_socket;
if ((res = pinos_client_node_get_data_socket (node, &data_fd)) < 0)
goto no_socket;
pinos_client_add_resource (client,
this->core->registry.uri.client_node,
node,
(PinosDestroy) pinos_client_node_destroy);
object_path = node->node->global->object_path;
pinos_log_debug ("daemon %p: add client-node %p, %s", impl, node, object_path);
fdlist = g_unix_fd_list_new ();
ctrl_idx = g_unix_fd_list_append (fdlist, ctrl_fd, &error);
data_idx = g_unix_fd_list_append (fdlist, data_fd, &error);
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
g_variant_new ("(ohh)", object_path, ctrl_idx, data_idx), fdlist);
g_object_unref (fdlist);
return TRUE;
no_socket:
{
pinos_log_debug ("daemon %p: could not create socket: %s", impl, strerror (errno));
pinos_client_node_destroy (node);
goto exit_error;
}
exit_error:
{
g_dbus_method_invocation_return_gerror (invocation, error);
g_clear_error (&error);
return TRUE;
}
}
#if 0
static void
export_server_object (PinosDaemon *daemon,
GDBusObjectManagerServer *manager)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_SERVER);
pinos_object_skeleton_set_daemon1 (skel, impl->iface);
g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (skel));
g_free (impl->object_path);
impl->object_path = g_strdup (g_dbus_object_get_object_path (G_DBUS_OBJECT (skel)));
g_object_unref (skel);
}
#endif
static void
bus_acquired_handler (GDBusConnection *connection,
const char *name,
gpointer user_data)
{
PinosDaemonImpl *impl = user_data;
PinosDaemon *this = &impl->this;
GDBusObjectManagerServer *manager = impl->server_manager;
this->core->connection = connection;
g_dbus_object_manager_server_set_connection (manager, connection);
}
static void
name_acquired_handler (GDBusConnection *connection,
const char *name,
gpointer user_data)
{
}
static void
name_lost_handler (GDBusConnection *connection,
const char *name,
gpointer user_data)
{
PinosDaemonImpl *impl = user_data;
PinosDaemon *this = &impl->this;
GDBusObjectManagerServer *manager = impl->server_manager;
g_dbus_object_manager_server_set_connection (manager, connection);
this->core->connection = connection;
}
static SpaResult
daemon_start (PinosDaemon *daemon)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
g_return_val_if_fail (impl, SPA_RESULT_INVALID_ARGUMENTS);
g_return_val_if_fail (impl->id == 0, SPA_RESULT_INVALID_ARGUMENTS);
pinos_log_debug ("daemon %p: start", daemon);
impl->id = g_bus_own_name (G_BUS_TYPE_SESSION,
PINOS_DBUS_SERVICE,
G_BUS_NAME_OWNER_FLAGS_REPLACE,
bus_acquired_handler,
name_acquired_handler,
name_lost_handler,
daemon,
NULL);
return SPA_RESULT_OK;
}
static SpaResult
daemon_stop (PinosDaemon *daemon)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
g_return_val_if_fail (impl, SPA_RESULT_INVALID_ARGUMENTS);
pinos_log_debug ("daemon %p: stop", daemon);
if (impl->id != 0) {
g_bus_unown_name (impl->id);
impl->id = 0;
}
return SPA_RESULT_OK;
}
static void
on_global_added (PinosListener *listener,
PinosCore *core,
PinosGlobal *global)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, global_added);
PinosDaemon *this = &impl->this;
if (global->skel) {
g_dbus_object_manager_server_export_uniquely (impl->server_manager,
G_DBUS_OBJECT_SKELETON (global->skel));
global->object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (global->skel));
}
if (global->type == this->core->registry.uri.node) {
PinosNode *node = global->object;
on_node_added (this, node);
}
}
static void
on_global_removed (PinosListener *listener,
PinosCore *core,
PinosGlobal *global)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, global_removed);
PinosDaemon *this = &impl->this;
if (global->object_path) {
g_dbus_object_manager_server_unexport (impl->server_manager, global->object_path);
}
if (global->type == this->core->registry.uri.node) {
PinosNode *node = global->object;
on_node_removed (this, node);
}
}
/**
* pinos_daemon_find_port:
* @daemon: a #PinosDaemon
* @other_port: a port to be compatible with
* @name: a port name
* @props: port properties
* @format_filter: a format filter
* @error: location for an error
*
* Find the best port in @daemon that matches the given parameters.
*
* Returns: a #PinosPort or %NULL when no port could be found.
*/
PinosPort *
pinos_daemon_find_port (PinosDaemon *daemon,
PinosPort *other_port,
const char *name,
PinosProperties *props,
SpaFormat **format_filters,
char **error)
{
PinosPort *best = NULL;
bool have_name;
PinosNode *n;
g_return_val_if_fail (daemon, NULL);
have_name = name ? strlen (name) > 0 : FALSE;
pinos_log_debug ("name \"%s\", %d", name, have_name);
spa_list_for_each (n, &daemon->core->node_list, link) {
pinos_log_debug ("node path \"%s\"", n->global->object_path);
if (have_name) {
if (g_str_has_suffix (n->global->object_path, name)) {
pinos_log_debug ("name \"%s\" matches node %p", name, 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;
}
/**
* pinos_daemon_new:
* @core: #PinosCore
* @properties: #PinosProperties
*
* Make a new #PinosDaemon object with given @properties
*
* Returns: a new #PinosDaemon
*/
PinosDaemon *
pinos_daemon_new (PinosCore *core,
PinosProperties *properties)
{
PinosDaemonImpl *impl;
PinosDaemon *this;
PinosObjectSkeleton *skel;
impl = calloc (1, sizeof (PinosDaemonImpl));
this = &impl->this;
pinos_log_debug ("daemon %p: new", impl);
this->core = core;
this->properties = properties;
this->start = daemon_start;
this->stop = daemon_stop;
pinos_signal_init (&this->destroy_signal);
pinos_signal_add (&core->global_added, &impl->global_added, on_global_added);
pinos_signal_add (&core->global_removed, &impl->global_removed, on_global_removed);
pinos_signal_add (&core->node_state_changed, &impl->node_state_changed, on_node_state_changed);
pinos_signal_add (&core->port_added, &impl->port_added, on_port_added);
pinos_signal_add (&core->port_removed, &impl->port_removed, on_port_removed);
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->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX);
impl->iface = pinos_daemon1_skeleton_new ();
g_signal_connect (impl->iface, "handle-create-node", (GCallback) handle_create_node, impl);
g_signal_connect (impl->iface, "handle-create-client-node", (GCallback) handle_create_client_node, impl);
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_SERVER);
pinos_object_skeleton_set_daemon1 (skel, impl->iface);
pinos_daemon1_set_user_name (impl->iface, g_get_user_name ());
pinos_daemon1_set_host_name (impl->iface, g_get_host_name ());
pinos_daemon1_set_version (impl->iface, PACKAGE_VERSION);
pinos_daemon1_set_name (impl->iface, PACKAGE_NAME);
pinos_daemon1_set_cookie (impl->iface, g_random_int());
pinos_daemon1_set_properties (impl->iface, pinos_properties_to_variant (this->properties));
this->global = pinos_core_add_global (core,
core->registry.uri.daemon,
this,
skel);
return this;
}
void
pinos_daemon_destroy (PinosDaemon *daemon)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
pinos_log_debug ("daemon %p: destroy", impl);
pinos_signal_emit (&daemon->destroy_signal, daemon);
pinos_daemon_stop (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);
free (impl);
}

View file

@ -1,75 +0,0 @@
/* 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.
*/
#ifndef __PINOS_DAEMON_H__
#define __PINOS_DAEMON_H__
#ifdef __cplusplus
extern "C" {
#endif
#define PINOS_DAEMON_URI "http://pinos.org/ns/daemon"
#define PINOS_DAEMON_PREFIX PINOS_DAEMON_URI "#"
typedef struct _PinosDaemon PinosDaemon;
#include <pinos/client/properties.h>
#include <pinos/server/core.h>
#include <pinos/server/node.h>
#include <pinos/server/port.h>
/**
* PinosDaemon:
*
* Pinos daemon object class.
*/
struct _PinosDaemon {
PinosCore *core;
SpaList link;
PinosGlobal *global;
PinosProperties *properties;
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
PinosDaemon *daemon));
SpaResult (*start) (PinosDaemon *daemon);
SpaResult (*stop) (PinosDaemon *daemon);
};
PinosDaemon * pinos_daemon_new (PinosCore *core,
PinosProperties *properties);
void pinos_daemon_destroy (PinosDaemon *daemon);
#define pinos_daemon_start(d) (d)->start(d)
#define pinos_daemon_stop(d) (d)->stop(d)
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
PinosPort *other_port,
const char *name,
PinosProperties *props,
SpaFormat **format_filter,
char **error);
#ifdef __cplusplus
}
#endif
#endif /* __PINOS_DAEMON_H__ */

View file

@ -19,8 +19,6 @@
#include <string.h>
#include <gio/gio.h>
#include <spa/include/spa/video/format.h>
#include <spa/lib/debug.h>
@ -29,19 +27,12 @@
#include "pinos/server/link.h"
#include "pinos/dbus/org-pinos.h"
#define PINOS_LINK_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_LINK, PinosLinkPrivate))
#define MAX_BUFFERS 16
typedef struct
{
PinosLink this;
PinosLink1 *iface;
uint32_t seq;
SpaFormat **format_filter;
@ -589,36 +580,6 @@ on_output_async_complete_notify (PinosListener *listener,
pinos_main_loop_defer_complete (this->core->main_loop, impl, seq, res);
}
#if 0
static void
on_property_notify (GObject *obj,
GParamSpec *pspec,
gpointer user_data)
{
PinosLink *this = user_data;
PinosLinkImpl *impl = (PinosLinkImpl *) this;
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "output-port") == 0) {
if (this->output) {
pinos_link1_set_output_node (impl->iface, pinos_node_get_object_path (this->output->node));
pinos_link1_set_output_port (impl->iface, this->output->port);
} else {
pinos_link1_set_output_node (impl->iface, "/");
pinos_link1_set_output_port (impl->iface, -1);
}
}
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "input-port") == 0) {
if (this->input) {
pinos_link1_set_input_node (impl->iface, pinos_node_get_object_path (this->input->node));
pinos_link1_set_input_port (impl->iface, this->input->port);
} else {
pinos_link1_set_input_node (impl->iface, "/");
pinos_link1_set_input_port (impl->iface, -1);
}
}
}
#endif
static void
on_port_unlinked (PinosPort *port, PinosLink *this, SpaResult res, gulong id)
{
@ -712,7 +673,6 @@ pinos_link_new (PinosCore *core,
{
PinosLinkImpl *impl;
PinosLink *this;
PinosObjectSkeleton *skel;
impl = calloc (1, sizeof (PinosLinkImpl));
this = &impl->this;
@ -751,14 +711,9 @@ pinos_link_new (PinosCore *core,
spa_list_insert (core->link_list.prev, &this->link);
impl->iface = pinos_link1_skeleton_new ();
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_LINK);
pinos_object_skeleton_set_link1 (skel, impl->iface);
this->global = pinos_core_add_global (core,
core->registry.uri.link,
this,
skel);
this);
return this;
}
@ -812,8 +767,6 @@ do_link_remove_done (SpaPoll *poll,
pinos_main_loop_defer_cancel (this->core->main_loop, this, 0);
g_clear_object (&impl->iface);
if (impl->allocated)
pinos_memblock_free (&impl->buffer_mem);
@ -866,7 +819,7 @@ pinos_link_destroy (PinosLink * this)
pinos_log_debug ("link %p: destroy", impl);
pinos_signal_emit (&this->destroy_signal, this);
pinos_core_remove_global (this->core, this->global);
pinos_global_destroy (this->global);
spa_list_remove (&this->link);
if (this->input) {

View file

@ -32,9 +32,9 @@ typedef struct _PinosLink PinosLink;
#include <spa/include/spa/ringbuffer.h>
#include <pinos/client/mem.h>
#include <pinos/client/object.h>
#include <pinos/server/daemon.h>
#include <pinos/server/core.h>
#include <pinos/server/port.h>
#include <pinos/server/main-loop.h>
/**

View file

@ -373,14 +373,13 @@ main_loop_run (PinosMainLoop *loop)
/**
* pinos_main_loop_new:
* @context: a #GMainContext or %NULL to use the default context
*
* Create a new #PinosMainLoop.
*
* Returns: a new #PinosMainLoop
*/
PinosMainLoop *
pinos_main_loop_new (GMainContext *context)
pinos_main_loop_new (void)
{
PinosMainLoopImpl *impl;
PinosMainLoop *this;
@ -388,7 +387,7 @@ pinos_main_loop_new (GMainContext *context)
impl = calloc (1, sizeof (PinosMainLoopImpl));
pinos_log_debug ("main-loop %p: new", impl);
impl->context = context;
impl->context = g_main_context_default ();
this = &impl->this;
this->run = main_loop_run;
this->quit = main_loop_quit;

View file

@ -25,7 +25,6 @@ extern "C" {
#endif
#include <spa/include/spa/poll.h>
#include <spa/include/spa/node-event.h>
typedef struct _PinosMainLoop PinosMainLoop;
@ -63,7 +62,7 @@ struct _PinosMainLoop {
void *data);
};
PinosMainLoop * pinos_main_loop_new (GMainContext *context);
PinosMainLoop * pinos_main_loop_new (void);
void pinos_main_loop_destroy (PinosMainLoop *loop);
#define pinos_main_loop_run(m) (m)->run(m)

View file

@ -3,7 +3,6 @@ pinoscore_headers = [
'client-node.h',
'command.h',
'core.h',
'daemon.h',
'data-loop.h',
'link.h',
'main-loop.h',
@ -19,7 +18,6 @@ pinoscore_sources = [
'client-node.c',
'command.c',
'core.c',
'daemon.c',
'data-loop.c',
'link.c',
'main-loop.c',

View file

@ -27,16 +27,12 @@
#include "pinos/server/node.h"
#include "pinos/server/data-loop.h"
#include "pinos/server/main-loop.h"
#include "pinos/server/daemon.h"
#include "pinos/dbus/org-pinos.h"
typedef struct
{
PinosNode this;
PinosClient *client;
PinosNode1 *iface;
uint32_t seq;
@ -391,37 +387,15 @@ on_node_event (SpaNode *node, SpaNodeEvent *event, void *user_data)
}
}
static bool
handle_remove (PinosNode1 *interface,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
PinosNode *this = user_data;
pinos_log_debug ("node %p: remove", this);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("()"));
return true;
}
static void
init_complete (PinosNode *this)
{
PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this);
PinosProperties *props = this->properties;
update_port_ids (this, false);
pinos_log_debug ("node %p: init completed", this);
impl->async_init = false;
if (impl->client)
pinos_node1_set_owner (impl->iface, this->global->object_path);
else
pinos_node1_set_owner (impl->iface, "/");
pinos_node1_set_name (impl->iface, this->name);
pinos_node1_set_properties (impl->iface, props ? pinos_properties_to_variant (props) : NULL);
pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED);
}
@ -442,7 +416,6 @@ pinos_node_new (PinosCore *core,
{
PinosNodeImpl *impl;
PinosNode *this;
PinosObjectSkeleton *skel;
impl = calloc (1, sizeof (PinosNodeImpl));
this = &impl->this;
@ -454,6 +427,7 @@ pinos_node_new (PinosCore *core,
this->node = node;
this->clock = clock;
this->data_loop = core->data_loop;
if (spa_node_set_event_callback (this->node, on_node_event, this) < 0)
pinos_log_warn ("node %p: error setting callback", this);
@ -463,13 +437,7 @@ pinos_node_new (PinosCore *core,
pinos_signal_init (&this->transport_changed);
pinos_signal_init (&this->loop_changed);
impl->iface = pinos_node1_skeleton_new ();
g_signal_connect (impl->iface, "handle-remove",
(GCallback) handle_remove,
this);
this->state = PINOS_NODE_STATE_CREATING;
pinos_node1_set_state (impl->iface, this->state);
spa_list_init (&this->input_ports);
spa_list_init (&this->output_ports);
@ -498,13 +466,9 @@ pinos_node_new (PinosCore *core,
}
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);
this->global = pinos_core_add_global (core,
core->registry.uri.node,
this,
skel);
this);
return this;
}
@ -528,7 +492,6 @@ do_node_remove_done (SpaPoll *poll,
spa_list_for_each_safe (port, tmp, &this->output_ports, link)
pinos_port_destroy (port);
g_clear_object (&impl->iface);
free (this->name);
free (this->error);
if (this->properties)
@ -594,7 +557,7 @@ pinos_node_destroy (PinosNode * this)
pinos_signal_emit (&this->destroy_signal, this);
spa_list_remove (&this->link);
pinos_core_remove_global (this->core, this->global);
pinos_global_destroy (this->global);
res = spa_poll_invoke (&this->data_loop->poll,
do_node_remove,
@ -764,11 +727,8 @@ void
pinos_node_update_state (PinosNode *node,
PinosNodeState state)
{
PinosNodeImpl *impl = SPA_CONTAINER_OF (node, PinosNodeImpl, this);
PinosNodeState old;
g_return_if_fail (node);
old = node->state;
if (old != state) {
pinos_log_debug ("node %p: update state from %s -> %s", node,
@ -776,7 +736,6 @@ pinos_node_update_state (PinosNode *node,
pinos_node_state_as_string (state));
node->state = state;
pinos_node1_set_state (impl->iface, state);
pinos_signal_emit (&node->core->node_state_changed, node, old, state);
}
}
@ -792,18 +751,14 @@ void
pinos_node_report_error (PinosNode *node,
char *error)
{
PinosNodeImpl *impl = SPA_CONTAINER_OF (node, PinosNodeImpl, this);
PinosNodeState old;
g_return_if_fail (node);
free (node->error);
remove_idle_timeout (node);
node->error = error;
old = node->state;
node->state = PINOS_NODE_STATE_ERROR;
pinos_log_debug ("node %p: got error state %s", node, error);
pinos_node1_set_state (impl->iface, PINOS_NODE_STATE_ERROR);
pinos_signal_emit (&node->core->node_state_changed, node, old, node->state);
}

View file

@ -101,8 +101,6 @@ SpaResult pinos_node_destroy (PinosNode *node);
void pinos_node_set_data_loop (PinosNode *node,
PinosDataLoop *loop);
PinosClient * pinos_node_get_client (PinosNode *node);
PinosPort * pinos_node_get_free_port (PinosNode *node,
PinosDirection direction);

View file

@ -21,7 +21,6 @@
#include "pinos/client/pinos.h"
#include "pinos/server/core.h"
#include "pinos/server/daemon.h"
#include "pinos/server/registry.h"
#include "pinos/server/node.h"
#include "pinos/server/node-factory.h"
@ -35,7 +34,6 @@ pinos_registry_init (PinosRegistry *reg)
{
reg->map = pinos_id_map_get_default();
reg->uri.daemon = spa_id_map_get_id (reg->map, PINOS_DAEMON_URI);
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);
@ -49,21 +47,3 @@ pinos_registry_init (PinosRegistry *reg)
pinos_map_init (&reg->objects, 512);
}
PinosObject *
pinos_registry_iterate_objects (PinosRegistry *reg,
uint32_t type,
void **state)
{
unsigned int idx;
PinosObject *o;
while (true) {
idx = SPA_PTR_TO_INT (*state);
*state = SPA_INT_TO_PTR (idx+1);
o = pinos_map_lookup (&reg->objects, idx);
if (o != NULL)
break;
}
return o;
}

View file

@ -29,13 +29,11 @@ extern "C" {
#include <pinos/client/map.h>
#include <pinos/client/signal.h>
#include <pinos/client/object.h>
#include <spa/include/spa/id-map.h>
typedef struct _PinosRegistry PinosRegistry;
typedef struct {
uint32_t daemon;
uint32_t registry;
uint32_t node;
uint32_t node_factory;
@ -61,15 +59,6 @@ struct _PinosRegistry {
void pinos_registry_init (PinosRegistry *reg);
PinosObject * pinos_registry_iterate_objects (PinosRegistry *reg,
uint32_t type,
void **state);
#define pinos_registry_iterate_nodes(reg,state) \
pinos_registry_iterate_objects(reg, (reg)->uri.node,state)
#define pinos_registry_iterate_node_factoriess(reg,state) \
pinos_registry_iterate_objects(reg, (reg)->uri.node_factory,state)
#ifdef __cplusplus
}
#endif