2015-06-30 18:06:36 +02:00
|
|
|
/* Pinos
|
2015-04-16 16:58:33 +02:00
|
|
|
* 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-05-06 13:01:52 +02:00
|
|
|
#include <string.h>
|
2016-10-07 13:14:32 +02:00
|
|
|
#include <stdio.h>
|
2016-05-06 13:01:52 +02:00
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
#include <gio/gio.h>
|
2016-07-20 17:29:34 +02:00
|
|
|
#include <gio/gunixfdlist.h>
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2016-02-01 15:40:48 +01:00
|
|
|
#include "pinos/client/pinos.h"
|
2016-11-03 19:41:53 +01:00
|
|
|
#include "pinos/client/log.h"
|
2015-05-21 16:49:26 +02:00
|
|
|
|
2016-02-01 15:40:48 +01:00
|
|
|
#include "pinos/server/daemon.h"
|
2016-07-18 17:40:58 +02:00
|
|
|
#include "pinos/server/node.h"
|
2016-07-22 17:17:44 +02:00
|
|
|
#include "pinos/server/client-node.h"
|
2016-07-20 17:29:34 +02:00
|
|
|
#include "pinos/server/client.h"
|
2016-07-22 17:17:44 +02:00
|
|
|
#include "pinos/server/link.h"
|
2016-11-10 15:42:14 +01:00
|
|
|
#include "pinos/server/node-factory.h"
|
2016-10-20 16:26:55 +02:00
|
|
|
#include "pinos/server/data-loop.h"
|
|
|
|
|
#include "pinos/server/main-loop.h"
|
2015-05-04 10:38:26 +02:00
|
|
|
|
2016-02-01 15:40:48 +01:00
|
|
|
#include "pinos/dbus/org-pinos.h"
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
typedef struct {
|
|
|
|
|
PinosDaemon daemon;
|
|
|
|
|
PinosObject object;
|
2016-11-08 18:00:52 +01:00
|
|
|
|
2016-05-18 17:22:34 +02:00
|
|
|
PinosDaemon1 *iface;
|
2015-04-16 16:58:33 +02:00
|
|
|
guint id;
|
|
|
|
|
GDBusConnection *connection;
|
|
|
|
|
GDBusObjectManagerServer *server_manager;
|
|
|
|
|
|
2016-09-27 16:59:45 +02:00
|
|
|
gchar *object_path;
|
|
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
PinosDataLoop *data_loop;
|
2016-06-23 18:52:54 +02:00
|
|
|
|
2016-11-08 18:00:52 +01:00
|
|
|
PinosListener object_added;
|
|
|
|
|
PinosListener object_removed;
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosListener port_unlinked;
|
|
|
|
|
PinosListener notify_state;
|
2016-11-08 18:00:52 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
GHashTable *clients;
|
2016-06-23 18:52:54 +02:00
|
|
|
GHashTable *node_factories;
|
2016-11-10 15:42:14 +01:00
|
|
|
} PinosDaemonImpl;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *daemon);
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
static void
|
2016-07-20 17:29:34 +02:00
|
|
|
handle_client_appeared (PinosClient *client, gpointer user_data)
|
2015-05-04 10:38:26 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = user_data;
|
2015-05-04 10:38:26 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: appeared %p", impl, client);
|
2015-05-04 12:16:30 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_hash_table_insert (impl->clients, (gpointer) client->sender, client);
|
2015-05-04 10:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-07-20 17:29:34 +02:00
|
|
|
handle_client_vanished (PinosClient *client, gpointer user_data)
|
2015-05-04 10:38:26 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = user_data;
|
2015-05-04 10:38:26 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("daemon %p: vanished %p", daemon, client);
|
2016-11-10 15:42:14 +01:00
|
|
|
g_hash_table_remove (impl->clients, (gpointer) client->sender);
|
2016-07-20 17:29:34 +02:00
|
|
|
}
|
2016-04-11 15:26:15 +02:00
|
|
|
|
2016-07-20 17:29:34 +02:00
|
|
|
static PinosClient *
|
|
|
|
|
sender_get_client (PinosDaemon *daemon,
|
2016-09-23 17:08:20 +02:00
|
|
|
const gchar *sender,
|
|
|
|
|
gboolean create)
|
2016-07-20 17:29:34 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = (PinosDaemonImpl *) daemon;
|
2016-07-20 17:29:34 +02:00
|
|
|
PinosClient *client;
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
client = g_hash_table_lookup (impl->clients, sender);
|
2016-09-23 17:08:20 +02:00
|
|
|
if (client == NULL && create) {
|
2016-11-10 15:42:14 +01:00
|
|
|
client = pinos_client_new (daemon->core, sender, NULL);
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("daemon %p: new client %p for %s", daemon, client, sender);
|
2016-07-20 17:29:34 +02:00
|
|
|
g_signal_connect (client,
|
|
|
|
|
"appeared",
|
|
|
|
|
(GCallback) handle_client_appeared,
|
|
|
|
|
daemon);
|
|
|
|
|
g_signal_connect (client,
|
|
|
|
|
"vanished",
|
|
|
|
|
(GCallback) handle_client_vanished,
|
|
|
|
|
daemon);
|
|
|
|
|
}
|
|
|
|
|
return client;
|
2015-05-04 10:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 18:16:52 +02:00
|
|
|
static void
|
2016-07-18 17:40:58 +02:00
|
|
|
handle_remove_node (PinosNode *node,
|
|
|
|
|
gpointer user_data)
|
2015-05-27 18:16:52 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
//PinosClient *client = user_data;
|
2016-04-11 15:26:15 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
//pinos_log_debug ("client %p: node %p remove", daemon, node);
|
|
|
|
|
//pinos_client_remove_object (client, &node->object);
|
2015-05-27 18:16:52 +02:00
|
|
|
}
|
2015-04-20 15:03:14 +02:00
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
static gboolean
|
2016-05-18 17:22:34 +02:00
|
|
|
handle_create_node (PinosDaemon1 *interface,
|
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
|
const gchar *arg_factory_name,
|
|
|
|
|
const gchar *arg_name,
|
|
|
|
|
GVariant *arg_properties,
|
|
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = user_data;
|
2016-06-23 18:52:54 +02:00
|
|
|
PinosNodeFactory *factory;
|
2016-05-18 17:22:34 +02:00
|
|
|
PinosNode *node;
|
2016-07-20 17:29:34 +02:00
|
|
|
PinosClient *client;
|
2016-05-18 17:22:34 +02:00
|
|
|
const gchar *sender, *object_path;
|
2015-07-17 16:57:01 +02:00
|
|
|
PinosProperties *props;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
sender = g_dbus_method_invocation_get_sender (invocation);
|
2016-11-10 15:42:14 +01:00
|
|
|
client = sender_get_client (&impl->daemon, sender, TRUE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: create node: %s", impl, sender);
|
2016-04-11 15:26:15 +02:00
|
|
|
|
2015-07-17 16:57:01 +02:00
|
|
|
props = pinos_properties_from_variant (arg_properties);
|
2016-05-26 12:25:07 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
factory = g_hash_table_lookup (impl->node_factories, arg_factory_name);
|
2016-10-19 17:18:30 +02:00
|
|
|
if (factory == NULL)
|
|
|
|
|
goto no_factory;
|
|
|
|
|
|
|
|
|
|
node = pinos_node_factory_create_node (factory,
|
|
|
|
|
client,
|
|
|
|
|
arg_name,
|
|
|
|
|
props);
|
2015-07-17 16:57:01 +02:00
|
|
|
pinos_properties_free (props);
|
|
|
|
|
|
2016-05-18 17:22:34 +02:00
|
|
|
if (node == NULL)
|
|
|
|
|
goto no_node;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
//pinos_client_add_object (client, &node->object);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
//g_signal_connect (node,
|
|
|
|
|
// "remove",
|
|
|
|
|
// (GCallback) handle_remove_node,
|
|
|
|
|
// client);
|
2016-05-18 17:22:34 +02:00
|
|
|
|
2016-07-18 17:40:58 +02:00
|
|
|
object_path = pinos_node_get_object_path (node);
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: added node %p with path %s", impl, node, object_path);
|
2015-05-05 18:20:32 +02:00
|
|
|
g_dbus_method_invocation_return_value (invocation,
|
|
|
|
|
g_variant_new ("(o)", object_path));
|
2016-08-29 11:44:45 +02:00
|
|
|
g_object_unref (node);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
2016-05-18 17:22:34 +02:00
|
|
|
|
|
|
|
|
/* ERRORS */
|
2016-10-19 17:18:30 +02:00
|
|
|
no_factory:
|
|
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: could find factory named %s", impl, arg_factory_name);
|
2016-10-19 17:18:30 +02:00
|
|
|
g_dbus_method_invocation_return_dbus_error (invocation,
|
|
|
|
|
"org.pinos.Error", "can't find factory");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2016-05-18 17:22:34 +02:00
|
|
|
no_node:
|
|
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: could create node named %s from factory %s", impl, arg_name, arg_factory_name);
|
2016-05-18 17:22:34 +02:00
|
|
|
g_dbus_method_invocation_return_dbus_error (invocation,
|
|
|
|
|
"org.pinos.Error", "can't create node");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
static void
|
2016-11-10 15:42:14 +01:00
|
|
|
on_link_port_unlinked (PinosListener *listener,
|
|
|
|
|
void *object,
|
|
|
|
|
void *data)
|
2016-10-19 17:18:30 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosLink *link = object;
|
|
|
|
|
PinosPort *port = data;
|
|
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, port_unlinked);
|
|
|
|
|
|
|
|
|
|
pinos_log_debug ("daemon %p: link %p: port %p unlinked", impl, link, port);
|
2016-10-19 17:18:30 +02:00
|
|
|
|
2016-10-28 16:56:33 +02:00
|
|
|
if (port->direction == PINOS_DIRECTION_OUTPUT && link->input)
|
2016-11-10 15:42:14 +01:00
|
|
|
try_link_port (link->input->node, link->input, &impl->daemon);
|
2016-10-19 17:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 13:13:41 +02:00
|
|
|
static void
|
2016-11-10 15:42:14 +01:00
|
|
|
on_link_notify_state (PinosListener *listener,
|
|
|
|
|
void *object,
|
|
|
|
|
void *data)
|
2016-09-16 13:13:41 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosLink *link = object;
|
|
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, notify_state);
|
2016-09-16 13:13:41 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
|
PinosLinkState state;
|
|
|
|
|
|
|
|
|
|
state = pinos_link_get_state (link, &error);
|
|
|
|
|
switch (state) {
|
|
|
|
|
case PINOS_LINK_STATE_ERROR:
|
2016-09-27 16:59:45 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: link %p: state error: %s", impl, link, error->message);
|
2016-09-16 13:13:41 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
if (link->input && link->input->node)
|
2016-09-28 10:42:36 +02:00
|
|
|
pinos_node_report_error (link->input->node, g_error_copy (error));
|
2016-10-19 17:18:30 +02:00
|
|
|
if (link->output && link->output->node)
|
2016-09-28 10:42:36 +02:00
|
|
|
pinos_node_report_error (link->output->node, g_error_copy (error));
|
2016-09-16 13:13:41 +02:00
|
|
|
break;
|
2016-09-27 16:59:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 13:13:41 +02:00
|
|
|
case PINOS_LINK_STATE_UNLINKED:
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: link %p: unlinked", impl, link);
|
2016-10-19 17:18:30 +02:00
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
#if 0
|
2016-10-19 17:18:30 +02:00
|
|
|
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));
|
2016-10-20 16:26:55 +02:00
|
|
|
#endif
|
2016-09-16 13:13:41 +02:00
|
|
|
break;
|
2016-10-19 17:18:30 +02:00
|
|
|
|
2016-09-16 13:13:41 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 22:10:57 +02:00
|
|
|
static void
|
2016-10-20 16:26:55 +02:00
|
|
|
try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this)
|
2016-08-08 22:10:57 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = (PinosDaemonImpl *) this;
|
2016-09-23 17:08:20 +02:00
|
|
|
PinosClient *client;
|
2016-08-09 14:49:27 +02:00
|
|
|
PinosProperties *props;
|
|
|
|
|
const gchar *path;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
PinosLink *link;
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
props = node->properties;
|
2016-09-24 18:32:46 +02:00
|
|
|
if (props == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-08-09 14:49:27 +02:00
|
|
|
path = pinos_properties_get (props, "pinos.target.node");
|
|
|
|
|
|
|
|
|
|
if (path) {
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *target;
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
target = pinos_daemon_find_port (this,
|
2016-10-20 16:26:55 +02:00
|
|
|
port,
|
2016-08-09 14:49:27 +02:00
|
|
|
path,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
&error);
|
2016-09-19 09:16:58 +02:00
|
|
|
if (target == NULL)
|
|
|
|
|
goto error;
|
2016-09-02 19:51:23 +02:00
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
if (port->direction == PINOS_DIRECTION_OUTPUT)
|
2016-10-28 16:56:33 +02:00
|
|
|
link = pinos_port_link (port, target, NULL, NULL, &error);
|
2016-09-12 18:29:59 +02:00
|
|
|
else
|
2016-10-28 16:56:33 +02:00
|
|
|
link = pinos_port_link (target, port, NULL, NULL, &error);
|
2016-09-12 18:29:59 +02:00
|
|
|
|
2016-09-19 09:16:58 +02:00
|
|
|
if (link == NULL)
|
|
|
|
|
goto error;
|
2016-09-13 17:43:57 +02:00
|
|
|
|
2016-09-27 16:59:45 +02:00
|
|
|
client = pinos_node_get_client (node);
|
2016-10-19 17:18:30 +02:00
|
|
|
if (client)
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_client_add_object (client, &link->object);
|
|
|
|
|
|
|
|
|
|
impl->port_unlinked.notify = on_link_port_unlinked;
|
|
|
|
|
pinos_signal_add (&link->port_unlinked, &impl->port_unlinked);
|
|
|
|
|
|
|
|
|
|
impl->notify_state.notify = on_link_notify_state;
|
|
|
|
|
pinos_signal_add (&link->notify_state, &impl->notify_state);
|
2016-09-16 13:13:41 +02:00
|
|
|
|
|
|
|
|
pinos_link_activate (link);
|
|
|
|
|
|
2016-08-29 11:44:45 +02:00
|
|
|
g_object_unref (link);
|
2016-08-09 14:49:27 +02:00
|
|
|
}
|
2016-09-19 09:16:58 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
{
|
|
|
|
|
pinos_node_report_error (node, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-08-08 22:10:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-10-20 16:26:55 +02:00
|
|
|
on_port_added (PinosNode *node, PinosPort *port, PinosDaemon *this)
|
|
|
|
|
{
|
|
|
|
|
try_link_port (node, port, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_port_removed (PinosNode *node, PinosPort *port, PinosDaemon *this)
|
2016-09-23 17:08:20 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-10-19 17:18:30 +02:00
|
|
|
on_node_created (PinosNode *node,
|
2016-10-20 16:26:55 +02:00
|
|
|
PinosDaemon *this)
|
2016-09-23 17:08:20 +02:00
|
|
|
{
|
2016-10-19 17:18:30 +02:00
|
|
|
GList *ports, *walk;
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
ports = pinos_node_get_ports (node, PINOS_DIRECTION_INPUT);
|
|
|
|
|
for (walk = ports; walk; walk = g_list_next (walk))
|
2016-10-20 16:26:55 +02:00
|
|
|
on_port_added (node, walk->data, this);
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
ports = pinos_node_get_ports (node, PINOS_DIRECTION_OUTPUT);
|
|
|
|
|
for (walk = ports; walk; walk = g_list_next (walk))
|
2016-10-20 16:26:55 +02:00
|
|
|
on_port_added (node, walk->data, this);
|
2016-10-19 17:18:30 +02:00
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
g_signal_connect (node, "port-added", (GCallback) on_port_added, this);
|
|
|
|
|
g_signal_connect (node, "port-removed", (GCallback) on_port_removed, this);
|
2016-09-23 17:08:20 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
|
2016-09-23 17:08:20 +02:00
|
|
|
static void
|
|
|
|
|
on_node_state_change (PinosNode *node,
|
|
|
|
|
PinosNodeState old,
|
|
|
|
|
PinosNodeState state,
|
2016-10-20 16:26:55 +02:00
|
|
|
PinosDaemon *this)
|
2016-09-23 17:08:20 +02:00
|
|
|
{
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("daemon %p: node %p state change %s -> %s", this, node,
|
2016-09-23 17:08:20 +02:00
|
|
|
pinos_node_state_as_string (old),
|
|
|
|
|
pinos_node_state_as_string (state));
|
|
|
|
|
|
|
|
|
|
if (old == PINOS_NODE_STATE_CREATING && state == PINOS_NODE_STATE_SUSPENDED)
|
2016-10-20 16:26:55 +02:00
|
|
|
on_node_created (node, this);
|
2016-09-23 17:08:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_node_added (PinosDaemon *daemon, PinosNode *node)
|
|
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = (PinosDaemonImpl *) daemon;
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: node %p added", impl, node);
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_object_set (node, "data-loop", impl->data_loop, NULL);
|
2016-09-26 17:27:04 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_signal_connect (node, "state-change", (GCallback) on_node_state_change, impl);
|
2016-09-23 17:08:20 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
if (node->state > PINOS_NODE_STATE_CREATING) {
|
2016-10-19 17:18:30 +02:00
|
|
|
on_node_created (node, daemon);
|
2016-09-23 17:08:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_node_removed (PinosDaemon *daemon, PinosNode *node)
|
2016-08-08 22:10:57 +02:00
|
|
|
{
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("daemon %p: node %p removed", daemon, node);
|
2016-09-23 17:08:20 +02:00
|
|
|
g_signal_handlers_disconnect_by_data (node, daemon);
|
2016-08-08 22:10:57 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 17:17:44 +02:00
|
|
|
static gboolean
|
|
|
|
|
handle_create_client_node (PinosDaemon1 *interface,
|
|
|
|
|
GDBusMethodInvocation *invocation,
|
|
|
|
|
const gchar *arg_name,
|
|
|
|
|
GVariant *arg_properties,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = user_data;
|
|
|
|
|
PinosDaemon *this = &impl->daemon;
|
|
|
|
|
PinosClientNode *node;
|
2016-07-22 17:17:44 +02:00
|
|
|
PinosClient *client;
|
|
|
|
|
const gchar *sender, *object_path;
|
|
|
|
|
PinosProperties *props;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
GUnixFDList *fdlist;
|
2016-11-10 15:42:14 +01:00
|
|
|
int socket, rtsocket;
|
2016-10-14 19:23:05 +02:00
|
|
|
gint fdidx, rtfdidx;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
|
|
|
|
sender = g_dbus_method_invocation_get_sender (invocation);
|
2016-11-10 15:42:14 +01:00
|
|
|
client = sender_get_client (&impl->daemon, sender, TRUE);
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: create client-node: %s", impl, sender);
|
2016-07-22 17:17:44 +02:00
|
|
|
props = pinos_properties_from_variant (arg_properties);
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
node = pinos_client_node_new (this->core,
|
2016-09-27 16:59:45 +02:00
|
|
|
client,
|
2016-08-02 16:34:44 +02:00
|
|
|
arg_name,
|
|
|
|
|
props);
|
2016-09-01 10:04:25 +02:00
|
|
|
pinos_properties_free (props);
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
socket = pinos_client_node_get_socket_pair (node, &error);
|
|
|
|
|
if (socket == -1)
|
2016-07-22 17:17:44 +02:00
|
|
|
goto no_socket;
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
rtsocket = pinos_client_node_get_rtsocket_pair (node, &error);
|
|
|
|
|
if (rtsocket == -1)
|
2016-10-14 19:23:05 +02:00
|
|
|
goto no_socket;
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
//pinos_client_add_object (client, &node->object);
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
object_path = pinos_node_get_object_path (node->node);
|
|
|
|
|
pinos_log_debug ("daemon %p: add client-node %p, %s", impl, node, object_path);
|
2016-07-22 17:17:44 +02:00
|
|
|
|
|
|
|
|
fdlist = g_unix_fd_list_new ();
|
2016-11-10 15:42:14 +01:00
|
|
|
fdidx = g_unix_fd_list_append (fdlist, socket, &error);
|
|
|
|
|
rtfdidx = g_unix_fd_list_append (fdlist, rtsocket, &error);
|
2016-07-22 17:17:44 +02:00
|
|
|
|
|
|
|
|
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
|
2016-10-14 19:23:05 +02:00
|
|
|
g_variant_new ("(ohh)", object_path, fdidx, rtfdidx), fdlist);
|
2016-07-22 17:17:44 +02:00
|
|
|
g_object_unref (fdlist);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
no_socket:
|
|
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: could not create socket %s", impl, error->message);
|
2016-08-29 11:44:45 +02:00
|
|
|
g_object_unref (node);
|
2016-07-22 17:17:44 +02:00
|
|
|
goto exit_error;
|
|
|
|
|
}
|
|
|
|
|
exit_error:
|
|
|
|
|
{
|
|
|
|
|
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
export_server_object (PinosDaemon *daemon,
|
|
|
|
|
GDBusObjectManagerServer *manager)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = (PinosDaemonImpl *) daemon;
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosObjectSkeleton *skel;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_SERVER);
|
2016-05-18 17:22:34 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_object_skeleton_set_daemon1 (skel, impl->iface);
|
2016-05-18 17:22:34 +02:00
|
|
|
|
2015-04-20 17:24:58 +02:00
|
|
|
g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (skel));
|
2016-11-10 15:42:14 +01:00
|
|
|
g_free (impl->object_path);
|
|
|
|
|
impl->object_path = g_strdup (g_dbus_object_get_object_path (G_DBUS_OBJECT (skel)));
|
2015-04-16 16:58:33 +02:00
|
|
|
g_object_unref (skel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bus_acquired_handler (GDBusConnection *connection,
|
2015-07-07 16:46:23 +02:00
|
|
|
const gchar *name,
|
|
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = user_data;
|
|
|
|
|
GDBusObjectManagerServer *manager = impl->server_manager;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
impl->connection = connection;
|
2015-05-21 16:49:26 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
export_server_object (&impl->daemon, manager);
|
2015-05-21 16:49:26 +02:00
|
|
|
|
|
|
|
|
g_dbus_object_manager_server_set_connection (manager, connection);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
name_acquired_handler (GDBusConnection *connection,
|
2015-07-07 16:46:23 +02:00
|
|
|
const gchar *name,
|
|
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
name_lost_handler (GDBusConnection *connection,
|
2015-07-07 16:46:23 +02:00
|
|
|
const gchar *name,
|
|
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = user_data;
|
|
|
|
|
GDBusObjectManagerServer *manager = impl->server_manager;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_dbus_object_manager_server_unexport (manager, PINOS_DBUS_OBJECT_SERVER);
|
2015-04-20 17:24:58 +02:00
|
|
|
g_dbus_object_manager_server_set_connection (manager, connection);
|
2016-11-10 15:42:14 +01:00
|
|
|
g_clear_pointer (&impl->object_path, g_free);
|
|
|
|
|
impl->connection = connection;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-18 17:22:34 +02:00
|
|
|
const gchar *
|
2016-09-27 16:59:45 +02:00
|
|
|
pinos_daemon_get_object_path (PinosDaemon *daemon)
|
2016-05-18 17:22:34 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = (PinosDaemonImpl *) daemon;
|
2016-05-18 17:22:34 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_return_val_if_fail (impl, NULL);
|
2016-05-18 17:22:34 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
return impl->object_path;
|
2016-05-18 17:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
static SpaResult
|
|
|
|
|
daemon_start (PinosDaemon *daemon)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, daemon);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_return_val_if_fail (impl, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
g_return_val_if_fail (impl->id == 0, SPA_RESULT_INVALID_ARGUMENTS);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("daemon %p: start", daemon);
|
2016-04-11 15:26:15 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
impl->id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
2015-07-07 16:46:23 +02:00
|
|
|
PINOS_DBUS_SERVICE,
|
2015-04-16 16:58:33 +02:00
|
|
|
G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
|
|
|
|
bus_acquired_handler,
|
|
|
|
|
name_acquired_handler,
|
|
|
|
|
name_lost_handler,
|
|
|
|
|
daemon,
|
|
|
|
|
NULL);
|
2016-11-10 15:42:14 +01:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
static SpaResult
|
|
|
|
|
daemon_stop (PinosDaemon *daemon)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, daemon);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_return_val_if_fail (impl, SPA_RESULT_INVALID_ARGUMENTS);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("daemon %p: stop", daemon);
|
2016-04-11 15:26:15 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
if (impl->id != 0) {
|
|
|
|
|
g_bus_unown_name (impl->id);
|
|
|
|
|
impl->id = 0;
|
2015-04-21 16:57:09 +02:00
|
|
|
}
|
2016-11-10 15:42:14 +01:00
|
|
|
return SPA_RESULT_OK;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-21 16:57:09 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_daemon_export_uniquely:
|
|
|
|
|
* @daemon: a #PinosDaemon
|
2015-04-21 16:57:09 +02:00
|
|
|
* @skel: a #GDBusObjectSkeleton
|
|
|
|
|
*
|
|
|
|
|
* Export @skel with @daemon with a unique name
|
|
|
|
|
*
|
|
|
|
|
* Returns: the unique named used to export @skel.
|
|
|
|
|
*/
|
2015-04-16 16:58:33 +02:00
|
|
|
gchar *
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_daemon_export_uniquely (PinosDaemon *daemon,
|
|
|
|
|
GDBusObjectSkeleton *skel)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = (PinosDaemonImpl *) daemon;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (impl, NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (skel), NULL);
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_dbus_object_manager_server_export_uniquely (impl->server_manager, skel);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
return g_strdup (g_dbus_object_get_object_path (G_DBUS_OBJECT (skel)));
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 16:57:09 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_daemon_unexport:
|
|
|
|
|
* @daemon: a #PinosDaemon
|
2015-04-21 16:57:09 +02:00
|
|
|
* @object_path: an object path
|
|
|
|
|
*
|
|
|
|
|
* Unexport the object on @object_path
|
|
|
|
|
*/
|
2015-04-16 16:58:33 +02:00
|
|
|
void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_daemon_unexport (PinosDaemon *daemon,
|
|
|
|
|
const gchar *object_path)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = (PinosDaemonImpl *) daemon;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (impl);
|
2015-04-16 16:58:33 +02:00
|
|
|
g_return_if_fail (g_variant_is_object_path (object_path));
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_dbus_object_manager_server_unexport (impl->server_manager, object_path);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 18:00:52 +01:00
|
|
|
static void
|
|
|
|
|
on_registry_object_added (PinosListener *listener,
|
2016-11-10 15:42:14 +01:00
|
|
|
void *object,
|
2016-11-08 18:00:52 +01:00
|
|
|
void *data)
|
2015-05-11 16:08:34 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosObject *obj = data;
|
|
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, object_added);
|
|
|
|
|
PinosDaemon *this = &impl->daemon;
|
2015-05-11 16:08:34 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
if (obj->type == this->core->registry.uri.node) {
|
|
|
|
|
PinosNode *node = obj->implementation;
|
2016-11-08 18:00:52 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
on_node_added (this, node);
|
|
|
|
|
} else if (obj->type == this->core->registry.uri.node_factory) {
|
|
|
|
|
PinosNodeFactory *factory = obj->implementation;
|
2016-11-08 18:00:52 +01:00
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
g_object_get (factory, "name", &name, NULL);
|
2016-11-10 15:42:14 +01:00
|
|
|
g_hash_table_insert (impl->node_factories, name, g_object_ref (factory));
|
2016-11-08 18:00:52 +01:00
|
|
|
}
|
2015-05-11 16:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-08 18:00:52 +01:00
|
|
|
static void
|
|
|
|
|
on_registry_object_removed (PinosListener *listener,
|
2016-11-10 15:42:14 +01:00
|
|
|
void *object,
|
2016-11-08 18:00:52 +01:00
|
|
|
void *data)
|
2015-05-11 16:08:34 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosObject *obj = data;
|
|
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (listener, PinosDaemonImpl, object_added);
|
|
|
|
|
PinosDaemon *this = &impl->daemon;
|
2016-11-08 18:00:52 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
if (obj->type == this->core->registry.uri.node) {
|
|
|
|
|
PinosNode *node = obj->implementation;
|
2016-11-08 18:00:52 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
on_node_removed (this, node);
|
|
|
|
|
} else if (obj->type == this->core->registry.uri.node_factory) {
|
|
|
|
|
PinosNodeFactory *factory = obj->implementation;
|
2016-11-08 18:00:52 +01:00
|
|
|
gchar *name;
|
2015-05-11 16:08:34 +02:00
|
|
|
|
2016-11-08 18:00:52 +01:00
|
|
|
g_object_get (factory, "name", &name, NULL);
|
2016-11-10 15:42:14 +01:00
|
|
|
g_hash_table_remove (impl->node_factories, name);
|
2016-11-08 18:00:52 +01:00
|
|
|
g_free (name);
|
|
|
|
|
}
|
2015-05-11 16:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-17 16:57:01 +02:00
|
|
|
/**
|
2016-10-19 17:18:30 +02:00
|
|
|
* pinos_daemon_find_port:
|
2015-07-17 16:57:01 +02:00
|
|
|
* @daemon: a #PinosDaemon
|
2016-10-20 16:26:55 +02:00
|
|
|
* @other_port: a port to be compatible with
|
2016-05-06 13:01:52 +02:00
|
|
|
* @name: a port name
|
|
|
|
|
* @props: port properties
|
2015-07-17 16:57:01 +02:00
|
|
|
* @format_filter: a format filter
|
|
|
|
|
* @error: location for an error
|
|
|
|
|
*
|
2016-05-06 13:01:52 +02:00
|
|
|
* Find the best port in @daemon that matches the given parameters.
|
2015-07-17 16:57:01 +02:00
|
|
|
*
|
2016-09-15 17:51:34 +02:00
|
|
|
* Returns: a #PinosPort or %NULL when no port could be found.
|
2015-07-17 16:57:01 +02:00
|
|
|
*/
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *
|
|
|
|
|
pinos_daemon_find_port (PinosDaemon *daemon,
|
2016-10-20 16:26:55 +02:00
|
|
|
PinosPort *other_port,
|
2016-05-05 13:31:18 +02:00
|
|
|
const gchar *name,
|
|
|
|
|
PinosProperties *props,
|
2016-10-20 16:26:55 +02:00
|
|
|
GPtrArray *format_filters,
|
2016-05-05 13:31:18 +02:00
|
|
|
GError **error)
|
2015-05-11 16:08:34 +02:00
|
|
|
{
|
2016-10-19 17:18:30 +02:00
|
|
|
PinosPort *best = NULL;
|
2016-09-02 19:51:23 +02:00
|
|
|
gboolean have_name;
|
2016-11-10 15:42:14 +01:00
|
|
|
void *state = NULL;
|
|
|
|
|
PinosObject *o;
|
2015-05-11 16:08:34 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_return_val_if_fail (daemon, NULL);
|
2015-05-11 16:08:34 +02:00
|
|
|
|
2016-05-06 13:01:52 +02:00
|
|
|
have_name = name ? strlen (name) > 0 : FALSE;
|
2015-05-20 12:01:13 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("name \"%s\", %d", name, have_name);
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
while ((o = pinos_registry_iterate_nodes (&daemon->core->registry, &state))) {
|
|
|
|
|
PinosNode *n = o->implementation;
|
|
|
|
|
if (o->flags & PINOS_OBJECT_FLAG_DESTROYING)
|
2016-10-28 16:56:33 +02:00
|
|
|
continue;
|
|
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("node path \"%s\"", pinos_node_get_object_path (n));
|
2016-07-05 12:24:51 +02:00
|
|
|
|
2016-10-19 17:18:30 +02:00
|
|
|
if (have_name) {
|
|
|
|
|
if (g_str_has_suffix (pinos_node_get_object_path (n), name)) {
|
2016-11-03 19:41:53 +01:00
|
|
|
pinos_log_debug ("name \"%s\" matches node %p", name, n);
|
2016-07-25 10:46:29 +02:00
|
|
|
|
2016-10-20 16:26:55 +02:00
|
|
|
best = pinos_node_get_free_port (n, pinos_direction_reverse (other_port->direction));
|
2016-10-19 17:18:30 +02:00
|
|
|
if (best)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
}
|
2016-05-06 13:01:52 +02:00
|
|
|
}
|
2015-05-20 12:01:13 +02:00
|
|
|
if (best == NULL) {
|
2016-07-05 12:24:51 +02:00
|
|
|
g_set_error (error,
|
|
|
|
|
G_IO_ERROR,
|
|
|
|
|
G_IO_ERROR_NOT_FOUND,
|
2016-09-02 19:51:23 +02:00
|
|
|
"No matching Node found");
|
2016-09-15 17:51:34 +02:00
|
|
|
}
|
2016-09-02 19:51:23 +02:00
|
|
|
return best;
|
2015-05-11 16:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-02 18:00:57 +02:00
|
|
|
static void
|
2016-11-10 15:42:14 +01:00
|
|
|
daemon_destroy (PinosObject *object)
|
2015-06-02 18:00:57 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (object, PinosDaemonImpl, object);
|
|
|
|
|
PinosDaemon *this = &impl->daemon;
|
2015-06-02 18:00:57 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_log_debug ("daemon %p: destroy", impl);
|
2016-04-11 15:26:15 +02:00
|
|
|
|
2016-11-08 18:00:52 +01:00
|
|
|
pinos_daemon_stop (this);
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_signal_remove (&impl->object_added);
|
|
|
|
|
pinos_signal_remove (&impl->object_removed);
|
2015-06-02 18:00:57 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
g_clear_object (&impl->server_manager);
|
|
|
|
|
g_clear_object (&impl->iface);
|
|
|
|
|
g_hash_table_unref (impl->clients);
|
|
|
|
|
g_hash_table_unref (impl->node_factories);
|
2016-11-09 12:57:51 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_registry_remove_object (&this->core->registry, &impl->object);
|
|
|
|
|
free (impl);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
void
|
|
|
|
|
pinos_daemon_destroy (PinosDaemon *daemon)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, daemon);
|
2015-07-17 16:57:01 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_object_destroy (&impl->object);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
/**
|
|
|
|
|
* 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)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosDaemonImpl *impl;
|
|
|
|
|
PinosDaemon *this;
|
|
|
|
|
|
|
|
|
|
impl = calloc (1, sizeof (PinosDaemonImpl));
|
|
|
|
|
this = &impl->daemon;
|
|
|
|
|
pinos_log_debug ("daemon %p: new", impl);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
this->core = core;
|
|
|
|
|
this->properties = properties;
|
2016-11-08 18:00:52 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
this->start = daemon_start;
|
|
|
|
|
this->stop = daemon_stop;
|
2016-11-08 18:00:52 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_object_init (&impl->object,
|
|
|
|
|
core->registry.uri.daemon,
|
|
|
|
|
impl,
|
|
|
|
|
daemon_destroy);
|
2016-11-09 12:57:51 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
impl->object_added.notify = on_registry_object_added;
|
|
|
|
|
pinos_signal_add (&core->registry.object_added, &impl->object_added);
|
2016-11-09 12:57:51 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
impl->object_removed.notify = on_registry_object_removed;
|
|
|
|
|
pinos_signal_add (&core->registry.object_removed, &impl->object_removed);
|
2016-11-03 19:41:53 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
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,
|
2016-06-23 18:52:54 +02:00
|
|
|
g_str_equal,
|
|
|
|
|
g_free,
|
|
|
|
|
g_object_unref);
|
2016-10-25 11:15:15 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
impl->iface = pinos_daemon1_skeleton_new ();
|
|
|
|
|
g_signal_connect (impl->iface, "handle-create-node", (GCallback) handle_create_node, daemon);
|
|
|
|
|
g_signal_connect (impl->iface, "handle-create-client-node", (GCallback) handle_create_client_node, daemon);
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
pinos_registry_add_object (&core->registry, &impl->object);
|
|
|
|
|
|
|
|
|
|
return this;
|
2016-06-23 18:52:54 +02:00
|
|
|
}
|