mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-11 13:30:07 -05:00
Beginnings of dbus based control
This commit is contained in:
parent
becae3e7fa
commit
ee202e13e9
19 changed files with 2086 additions and 28 deletions
|
|
@ -33,9 +33,6 @@
|
|||
|
||||
#include "pinos/server/daemon.h"
|
||||
#include "pinos/server/client-node.h"
|
||||
#include "pinos/server/link.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
#include "spa/include/spa/control.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include "pinos/server/daemon.h"
|
||||
#include "pinos/server/node.h"
|
||||
#include "pinos/server/client-node.h"
|
||||
#include "pinos/server/dbus-client-node.h"
|
||||
#include "pinos/server/client.h"
|
||||
#include "pinos/server/link.h"
|
||||
#include "pinos/server/rt-loop.h"
|
||||
|
|
@ -426,6 +427,66 @@ exit_error:
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_register_client_node (PinosDaemon1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
GVariant *arg_properties,
|
||||
const gchar *arg_path,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosDaemon *daemon = user_data;
|
||||
PinosNode *node;
|
||||
PinosClient *client;
|
||||
const gchar *sender;
|
||||
PinosProperties *props;
|
||||
GError *error = NULL;
|
||||
GUnixFDList *fdlist;
|
||||
gint fdidx;
|
||||
GSocket *socket;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
client = sender_get_client (daemon, sender, TRUE);
|
||||
|
||||
g_debug ("daemon %p: register client-node: %s", daemon, sender);
|
||||
props = pinos_properties_from_variant (arg_properties);
|
||||
|
||||
node = pinos_dbus_client_node_new (daemon,
|
||||
client,
|
||||
arg_path,
|
||||
props);
|
||||
pinos_properties_free (props);
|
||||
|
||||
socket = pinos_dbus_client_node_get_socket_pair (PINOS_DBUS_CLIENT_NODE (node), &error);
|
||||
if (socket == NULL)
|
||||
goto no_socket;
|
||||
|
||||
pinos_client_add_object (client, G_OBJECT (node));
|
||||
g_object_unref (node);
|
||||
|
||||
fdlist = g_unix_fd_list_new ();
|
||||
fdidx = g_unix_fd_list_append (fdlist, g_socket_get_fd (socket), &error);
|
||||
g_object_unref (socket);
|
||||
|
||||
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
|
||||
g_variant_new ("(h)", fdidx), fdlist);
|
||||
g_object_unref (fdlist);
|
||||
|
||||
return TRUE;
|
||||
|
||||
no_socket:
|
||||
{
|
||||
g_debug ("daemon %p: could not create socket %s", daemon, error->message);
|
||||
g_object_unref (node);
|
||||
goto exit_error;
|
||||
}
|
||||
exit_error:
|
||||
{
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
g_clear_error (&error);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
export_server_object (PinosDaemon *daemon,
|
||||
GDBusObjectManagerServer *manager)
|
||||
|
|
@ -941,6 +1002,7 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
priv->iface = pinos_daemon1_skeleton_new ();
|
||||
g_signal_connect (priv->iface, "handle-create-node", (GCallback) handle_create_node, daemon);
|
||||
g_signal_connect (priv->iface, "handle-create-client-node", (GCallback) handle_create_client_node, daemon);
|
||||
g_signal_connect (priv->iface, "handle-register-client-node", (GCallback) handle_register_client_node, daemon);
|
||||
|
||||
priv->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX);
|
||||
priv->clients = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
|
@ -950,7 +1012,6 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
g_object_unref);
|
||||
priv->loop = pinos_rtloop_new();
|
||||
|
||||
priv->main_loop.handle = NULL;
|
||||
priv->main_loop.size = sizeof (SpaPoll);
|
||||
priv->main_loop.info = NULL;
|
||||
priv->main_loop.info = NULL;
|
||||
|
|
@ -958,7 +1019,6 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
priv->main_loop.update_item = do_update_item;
|
||||
priv->main_loop.remove_item = do_remove_item;
|
||||
|
||||
priv->log.handle = NULL;
|
||||
priv->log.size = sizeof (SpaLog);
|
||||
priv->log.info = NULL;
|
||||
priv->log.level = SPA_LOG_LEVEL_INFO;
|
||||
|
|
|
|||
334
pinos/server/dbus-client-node.c
Normal file
334
pinos/server/dbus-client-node.c
Normal file
|
|
@ -0,0 +1,334 @@
|
|||
/* 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 <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
#include <poll.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/enumtypes.h"
|
||||
#include "pinos/client/private.h"
|
||||
|
||||
#include "pinos/server/daemon.h"
|
||||
#include "pinos/server/dbus-client-node.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
#include "spa/include/spa/control.h"
|
||||
|
||||
|
||||
struct _PinosDBusClientNodePrivate
|
||||
{
|
||||
int fd;
|
||||
GSocket *sockets[2];
|
||||
SpaHandle *handle;
|
||||
};
|
||||
|
||||
#define PINOS_DBUS_CLIENT_NODE_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_DBUS_CLIENT_NODE, PinosDBusClientNodePrivate))
|
||||
|
||||
G_DEFINE_TYPE (PinosDBusClientNode, pinos_dbus_client_node, PINOS_TYPE_NODE);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_NONE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
//static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void
|
||||
pinos_dbus_client_node_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosDBusClientNode *node = PINOS_DBUS_CLIENT_NODE (_object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (node, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_dbus_client_node_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosDBusClientNode *node = PINOS_DBUS_CLIENT_NODE (_object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (node, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_dbus_client_node_get_socket_pair:
|
||||
* @node: a #PinosDBusClientNode
|
||||
* @error: a #GError
|
||||
*
|
||||
* Create or return a previously create socket pair for @node. The
|
||||
* Socket for the other end is returned.
|
||||
*
|
||||
* Returns: a #GSocket that can be used to send/receive buffers to node.
|
||||
*/
|
||||
GSocket *
|
||||
pinos_dbus_client_node_get_socket_pair (PinosDBusClientNode *this,
|
||||
GError **error)
|
||||
{
|
||||
PinosNode *node;
|
||||
PinosDBusClientNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_DBUS_CLIENT_NODE (this), FALSE);
|
||||
node = PINOS_NODE (this);
|
||||
priv = this->priv;
|
||||
|
||||
if (priv->sockets[1] == NULL) {
|
||||
SpaProps *props;
|
||||
SpaPropValue value;
|
||||
int fd[2];
|
||||
|
||||
if (socketpair (AF_UNIX, SOCK_STREAM, 0, fd) != 0)
|
||||
goto no_sockets;
|
||||
|
||||
priv->sockets[0] = g_socket_new_from_fd (fd[0], error);
|
||||
if (priv->sockets[0] == NULL)
|
||||
goto create_failed;
|
||||
|
||||
priv->sockets[1] = g_socket_new_from_fd (fd[1], error);
|
||||
if (priv->sockets[1] == NULL)
|
||||
goto create_failed;
|
||||
|
||||
priv->fd = g_socket_get_fd (priv->sockets[0]);
|
||||
|
||||
spa_node_get_props (node->node, &props);
|
||||
value.value = &priv->fd;
|
||||
value.size = sizeof (int);
|
||||
spa_props_set_value (props, spa_props_index_for_name (props, "socket"), &value);
|
||||
spa_node_set_props (node->node, props);
|
||||
}
|
||||
return g_object_ref (priv->sockets[1]);
|
||||
|
||||
/* ERRORS */
|
||||
no_sockets:
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
"could not create socketpair: %s", strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
create_failed:
|
||||
{
|
||||
g_clear_object (&priv->sockets[0]);
|
||||
g_clear_object (&priv->sockets[1]);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_dbus_client_node_dispose (GObject * object)
|
||||
{
|
||||
PinosDBusClientNode *this = PINOS_DBUS_CLIENT_NODE (object);
|
||||
PinosNode *node = PINOS_NODE (this);
|
||||
SpaProps *props;
|
||||
SpaPropValue value;
|
||||
int fd = -1;
|
||||
|
||||
g_debug ("client-node %p: dispose", this);
|
||||
|
||||
spa_node_get_props (node->node, &props);
|
||||
value.value = &fd;
|
||||
value.size = sizeof (int);
|
||||
spa_props_set_value (props, spa_props_index_for_name (props, "socket"), &value);
|
||||
|
||||
value.value = NULL;
|
||||
value.size = sizeof (void *);
|
||||
spa_props_set_value (props, spa_props_index_for_name (props, "connection"), &value);
|
||||
spa_node_set_props (node->node, props);
|
||||
|
||||
G_OBJECT_CLASS (pinos_dbus_client_node_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_dbus_client_node_finalize (GObject * object)
|
||||
{
|
||||
PinosDBusClientNode *this = PINOS_DBUS_CLIENT_NODE (object);
|
||||
PinosDBusClientNodePrivate *priv = this->priv;
|
||||
|
||||
g_debug ("client-node %p: finalize", this);
|
||||
|
||||
g_clear_object (&priv->sockets[0]);
|
||||
g_clear_object (&priv->sockets[1]);
|
||||
spa_handle_clear (priv->handle);
|
||||
g_free (priv->handle);
|
||||
|
||||
G_OBJECT_CLASS (pinos_dbus_client_node_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_dbus_client_node_constructed (GObject * object)
|
||||
{
|
||||
PinosDBusClientNode *this = PINOS_DBUS_CLIENT_NODE (object);
|
||||
|
||||
g_debug ("client-node %p: constructed", this);
|
||||
|
||||
G_OBJECT_CLASS (pinos_dbus_client_node_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_dbus_client_node_class_init (PinosDBusClientNodeClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosDBusClientNodePrivate));
|
||||
|
||||
gobject_class->constructed = pinos_dbus_client_node_constructed;
|
||||
gobject_class->dispose = pinos_dbus_client_node_dispose;
|
||||
gobject_class->finalize = pinos_dbus_client_node_finalize;
|
||||
gobject_class->set_property = pinos_dbus_client_node_set_property;
|
||||
gobject_class->get_property = pinos_dbus_client_node_get_property;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_dbus_client_node_init (PinosDBusClientNode * node)
|
||||
{
|
||||
node->priv = PINOS_DBUS_CLIENT_NODE_GET_PRIVATE (node);
|
||||
|
||||
g_debug ("client-node %p: new", node);
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
make_node (PinosDaemon *daemon, SpaHandle **handle, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
||||
if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) {
|
||||
g_error ("can't load %s: %s", lib, dlerror());
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) {
|
||||
g_error ("can't find enum function");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const SpaHandleFactory *factory;
|
||||
void *iface;
|
||||
|
||||
if ((res = enum_func (&factory, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
g_error ("can't enumerate factories: %d", res);
|
||||
break;
|
||||
}
|
||||
if (strcmp (factory->name, name))
|
||||
continue;
|
||||
|
||||
*handle = calloc (1, factory->size);
|
||||
if ((res = factory->init (factory,
|
||||
*handle,
|
||||
NULL,
|
||||
daemon->support,
|
||||
daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (*handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
}
|
||||
*node = iface;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_dbus_client_node_new:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @client: the client owner
|
||||
* @path: a dbus path
|
||||
* @properties: extra properties
|
||||
*
|
||||
* Create a new #PinosNode.
|
||||
*
|
||||
* Returns: a new #PinosNode
|
||||
*/
|
||||
PinosNode *
|
||||
pinos_dbus_client_node_new (PinosDaemon *daemon,
|
||||
PinosClient *client,
|
||||
const gchar *path,
|
||||
PinosProperties *properties)
|
||||
{
|
||||
SpaNode *n;
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
PinosNode *node;
|
||||
SpaProps *props;
|
||||
SpaPropValue value;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||
|
||||
if ((res = make_node (daemon,
|
||||
&handle,
|
||||
&n,
|
||||
"build/spa/plugins/remote/libspa-remote.so",
|
||||
"dbus-proxy")) < 0) {
|
||||
g_error ("can't create proxy: %d", res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
spa_node_get_props (n, &props);
|
||||
g_object_get (daemon, "connection", &value.value, NULL);
|
||||
value.size = sizeof (void *);
|
||||
spa_props_set_value (props, spa_props_index_for_name (props, "connection"), &value);
|
||||
spa_node_set_props (n, props);
|
||||
|
||||
node = g_object_new (PINOS_TYPE_DBUS_CLIENT_NODE,
|
||||
"daemon", daemon,
|
||||
"client", client,
|
||||
"name", path,
|
||||
"properties", properties,
|
||||
"node", n,
|
||||
NULL);
|
||||
|
||||
PINOS_DBUS_CLIENT_NODE (node)->priv->handle = handle;
|
||||
|
||||
return node;
|
||||
}
|
||||
75
pinos/server/dbus-client-node.h
Normal file
75
pinos/server/dbus-client-node.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* 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_DBUS_CLIENT_NODE_H__
|
||||
#define __PINOS_DBUS_CLIENT_NODE_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <pinos/server/node.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define PINOS_TYPE_DBUS_CLIENT_NODE (pinos_dbus_client_node_get_type ())
|
||||
#define PINOS_IS_DBUS_CLIENT_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_DBUS_CLIENT_NODE))
|
||||
#define PINOS_IS_DBUS_CLIENT_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_DBUS_CLIENT_NODE))
|
||||
#define PINOS_DBUS_CLIENT_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_DBUS_CLIENT_NODE, PinosDBusClientNodeClass))
|
||||
#define PINOS_DBUS_CLIENT_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_DBUS_CLIENT_NODE, PinosDBusClientNode))
|
||||
#define PINOS_DBUS_CLIENT_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_DBUS_CLIENT_NODE, PinosDBusClientNodeClass))
|
||||
#define PINOS_DBUS_CLIENT_NODE_CAST(obj) ((PinosDBusClientNode*)(obj))
|
||||
#define PINOS_DBUS_CLIENT_NODE_CLASS_CAST(klass) ((PinosDBusClientNodeClass*)(klass))
|
||||
|
||||
typedef struct _PinosDBusClientNode PinosDBusClientNode;
|
||||
typedef struct _PinosDBusClientNodeClass PinosDBusClientNodeClass;
|
||||
typedef struct _PinosDBusClientNodePrivate PinosDBusClientNodePrivate;
|
||||
|
||||
/**
|
||||
* PinosDBusClientNode:
|
||||
*
|
||||
* Pinos client node object class.
|
||||
*/
|
||||
struct _PinosDBusClientNode {
|
||||
PinosNode object;
|
||||
|
||||
PinosDBusClientNodePrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosDBusClientNodeClass:
|
||||
*
|
||||
* Pinos client node object class.
|
||||
*/
|
||||
struct _PinosDBusClientNodeClass {
|
||||
PinosNodeClass parent_class;
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_dbus_client_node_get_type (void);
|
||||
|
||||
PinosNode * pinos_dbus_client_node_new (PinosDaemon *daemon,
|
||||
PinosClient *client,
|
||||
const gchar *path,
|
||||
PinosProperties *properties);
|
||||
|
||||
GSocket * pinos_dbus_client_node_get_socket_pair (PinosDBusClientNode *node,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_DBUS_CLIENT_NODE_H__ */
|
||||
|
|
@ -3,6 +3,7 @@ pinoscore_headers = [
|
|||
'client-node.h',
|
||||
'command.h',
|
||||
'daemon.h',
|
||||
'dbus-client-node.h',
|
||||
'link.h',
|
||||
'module.h',
|
||||
'node.h',
|
||||
|
|
@ -16,6 +17,7 @@ pinoscore_sources = [
|
|||
'client-node.c',
|
||||
'command.c',
|
||||
'daemon.c',
|
||||
'dbus-client-node.c',
|
||||
'link.c',
|
||||
'module.c',
|
||||
'node.c',
|
||||
|
|
|
|||
|
|
@ -328,7 +328,6 @@ pinos_rtloop_init (PinosRTLoop * this)
|
|||
|
||||
g_debug ("rt-loop %p: new", this);
|
||||
|
||||
this->poll.handle = NULL;
|
||||
this->poll.size = sizeof (SpaPoll);
|
||||
this->poll.info = NULL;
|
||||
this->poll.add_item = do_add_item;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue