mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-17 07:00:03 -05:00
some more rework
This commit is contained in:
parent
ca4f3d84cd
commit
eefe6aacb9
24 changed files with 849 additions and 2829 deletions
|
|
@ -26,7 +26,7 @@
|
|||
#include "pinos/client/pinos.h"
|
||||
|
||||
#include "pinos/server/daemon.h"
|
||||
#include "pinos/server/server-node.h"
|
||||
#include "pinos/server/node.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
|
|
@ -122,15 +122,15 @@ sender_data_new (PinosDaemon *daemon,
|
|||
}
|
||||
|
||||
static void
|
||||
handle_remove_node (PinosServerNode *node,
|
||||
gpointer user_data)
|
||||
handle_remove_node (PinosNode *node,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosDaemon *daemon = user_data;
|
||||
PinosDaemonPrivate *priv = daemon->priv;
|
||||
const gchar *sender;
|
||||
SenderData *data;
|
||||
|
||||
sender = pinos_server_node_get_sender (node);
|
||||
sender = pinos_node_get_sender (node);
|
||||
|
||||
g_debug ("daemon %p: sender %s removed node %p", daemon, sender, node);
|
||||
|
||||
|
|
@ -173,10 +173,10 @@ handle_create_node (PinosDaemon1 *interface,
|
|||
arg_name,
|
||||
props);
|
||||
} else {
|
||||
node = pinos_server_node_new (daemon,
|
||||
sender,
|
||||
arg_name,
|
||||
props);
|
||||
node = pinos_node_new (daemon,
|
||||
sender,
|
||||
arg_name,
|
||||
props);
|
||||
}
|
||||
|
||||
pinos_properties_free (props);
|
||||
|
|
@ -195,7 +195,7 @@ handle_create_node (PinosDaemon1 *interface,
|
|||
(GCallback) handle_remove_node,
|
||||
daemon);
|
||||
|
||||
object_path = pinos_server_node_get_object_path (PINOS_SERVER_NODE (node));
|
||||
object_path = pinos_node_get_object_path (node);
|
||||
g_debug ("daemon %p: added node %p with path %s", daemon, node, object_path);
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("(o)", object_path));
|
||||
|
|
@ -385,18 +385,18 @@ pinos_daemon_unexport (PinosDaemon *daemon,
|
|||
/**
|
||||
* pinos_daemon_add_node:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @node: a #PinosServerNode
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Add @node to @daemon.
|
||||
*/
|
||||
void
|
||||
pinos_daemon_add_node (PinosDaemon *daemon,
|
||||
PinosServerNode *node)
|
||||
pinos_daemon_add_node (PinosDaemon *daemon,
|
||||
PinosNode *node)
|
||||
{
|
||||
PinosDaemonPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_DAEMON (daemon));
|
||||
g_return_if_fail (PINOS_IS_SERVER_NODE (node));
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
priv = daemon->priv;
|
||||
|
||||
priv->nodes = g_list_prepend (priv->nodes, node);
|
||||
|
|
@ -405,18 +405,18 @@ pinos_daemon_add_node (PinosDaemon *daemon,
|
|||
/**
|
||||
* pinos_daemon_remove_node:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @node: a #PinosServerNode
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Remove @node from @daemon.
|
||||
*/
|
||||
void
|
||||
pinos_daemon_remove_node (PinosDaemon *daemon,
|
||||
PinosServerNode *node)
|
||||
pinos_daemon_remove_node (PinosDaemon *daemon,
|
||||
PinosNode *node)
|
||||
{
|
||||
PinosDaemonPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_DAEMON (daemon));
|
||||
g_return_if_fail (PINOS_IS_SERVER_NODE (node));
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
priv = daemon->priv;
|
||||
|
||||
priv->nodes = g_list_remove (priv->nodes, node);
|
||||
|
|
@ -444,7 +444,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
GError **error)
|
||||
{
|
||||
PinosDaemonPrivate *priv;
|
||||
PinosServerPort *best = NULL;
|
||||
PinosPort *best = NULL;
|
||||
GList *nodes, *ports;
|
||||
gboolean have_name, created_port = FALSE;
|
||||
|
||||
|
|
@ -454,19 +454,19 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
have_name = name ? strlen (name) > 0 : FALSE;
|
||||
|
||||
for (nodes = priv->nodes; nodes; nodes = g_list_next (nodes)) {
|
||||
PinosServerNode *n = nodes->data;
|
||||
PinosNode *n = nodes->data;
|
||||
gboolean node_found = FALSE;
|
||||
|
||||
g_debug ("name %s, node path %s", name, pinos_server_node_get_object_path (n));
|
||||
g_debug ("name %s, node path %s", name, pinos_node_get_object_path (n));
|
||||
|
||||
/* we found the node */
|
||||
if (have_name && g_str_has_suffix (pinos_server_node_get_object_path (n), name)) {
|
||||
if (have_name && g_str_has_suffix (pinos_node_get_object_path (n), name)) {
|
||||
g_debug ("name \"%s\" matches node %p", name, n);
|
||||
node_found = TRUE;
|
||||
}
|
||||
|
||||
for (ports = pinos_node_get_ports (PINOS_NODE (n)); ports; ports = g_list_next (ports)) {
|
||||
PinosServerPort *p = ports->data;
|
||||
for (ports = pinos_node_get_ports (n); ports; ports = g_list_next (ports)) {
|
||||
PinosPort *p = ports->data;
|
||||
PinosDirection dir;
|
||||
GBytes *format;
|
||||
|
||||
|
|
@ -474,16 +474,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
if (dir != direction)
|
||||
continue;
|
||||
|
||||
if (have_name && !node_found) {
|
||||
if (!g_str_has_suffix (pinos_server_port_get_object_path (p), name))
|
||||
continue;
|
||||
g_debug ("name \"%s\" matches port %p", name, p);
|
||||
best = p;
|
||||
node_found = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
format = pinos_port_filter_formats (PINOS_PORT (p), format_filter, NULL);
|
||||
format = pinos_port_filter_formats (p, format_filter, NULL);
|
||||
if (format != NULL) {
|
||||
g_debug ("port %p matches filter", p);
|
||||
g_bytes_unref (format);
|
||||
|
|
@ -494,7 +485,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
|
|||
}
|
||||
if (best == NULL && node_found) {
|
||||
g_debug ("node %p: making port", n);
|
||||
best = pinos_server_node_create_port_sync (n, direction, name, format_filter, props);
|
||||
best = pinos_node_add_port (n, direction, NULL);
|
||||
if (best != NULL) {
|
||||
created_port = TRUE;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ typedef struct _PinosDaemon PinosDaemon;
|
|||
typedef struct _PinosDaemonClass PinosDaemonClass;
|
||||
typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
|
||||
|
||||
#include <pinos/server/server-node.h>
|
||||
#include <pinos/server/server-port.h>
|
||||
#include <pinos/server/node.h>
|
||||
#include <pinos/server/port.h>
|
||||
#include <pinos/server/node-factory.h>
|
||||
#include <pinos/client/properties.h>
|
||||
|
||||
|
|
@ -74,8 +74,8 @@ void pinos_daemon_stop (PinosDaemon *daemon);
|
|||
gchar * pinos_daemon_export_uniquely (PinosDaemon *daemon, GDBusObjectSkeleton *skel);
|
||||
void pinos_daemon_unexport (PinosDaemon *daemon, const gchar *name);
|
||||
|
||||
void pinos_daemon_add_node (PinosDaemon *daemon, PinosServerNode *node);
|
||||
void pinos_daemon_remove_node (PinosDaemon *daemon, PinosServerNode *node);
|
||||
void pinos_daemon_add_node (PinosDaemon *daemon, PinosNode *node);
|
||||
void pinos_daemon_remove_node (PinosDaemon *daemon, PinosNode *node);
|
||||
|
||||
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
|
||||
PinosDirection direction,
|
||||
|
|
|
|||
838
pinos/server/node.c
Normal file
838
pinos/server/node.c
Normal file
|
|
@ -0,0 +1,838 @@
|
|||
/* 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 <stdlib.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/enumtypes.h"
|
||||
|
||||
#include "pinos/server/node.h"
|
||||
#include "pinos/server/daemon.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
#define PINOS_NODE_GET_PRIVATE(node) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((node), PINOS_TYPE_NODE, PinosNodePrivate))
|
||||
|
||||
struct _PinosNodePrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
PinosNode1 *iface;
|
||||
|
||||
gchar *sender;
|
||||
gchar *object_path;
|
||||
gchar *name;
|
||||
|
||||
PinosNodeState state;
|
||||
GError *error;
|
||||
guint idle_timeout;
|
||||
|
||||
PinosProperties *properties;
|
||||
|
||||
GList *ports;
|
||||
};
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (PinosNode, pinos_node, G_TYPE_OBJECT);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DAEMON,
|
||||
PROP_SENDER,
|
||||
PROP_OBJECT_PATH,
|
||||
PROP_NAME,
|
||||
PROP_STATE,
|
||||
PROP_PROPERTIES,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_REMOVE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static gboolean
|
||||
node_set_state (PinosNode *node,
|
||||
PinosNodeState state)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static PinosPort *
|
||||
node_add_port (PinosNode *node,
|
||||
PinosDirection direction,
|
||||
GError **error)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
PinosPort *port;
|
||||
|
||||
port = g_object_new (PINOS_TYPE_PORT,
|
||||
"daemon", priv->daemon,
|
||||
"node", node,
|
||||
"direction", direction,
|
||||
NULL);
|
||||
return port;
|
||||
}
|
||||
|
||||
static void
|
||||
node_remove_port (PinosNode *node,
|
||||
PinosPort *port)
|
||||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_add_port (PinosNode1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
PinosDirection arg_direction,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
const gchar *sender;
|
||||
PinosPort *port;
|
||||
GError *error = NULL;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
if (g_strcmp0 (priv->sender, sender) != 0)
|
||||
goto not_allowed;
|
||||
|
||||
port = pinos_node_add_port (node, arg_direction, &error);
|
||||
if (port == NULL)
|
||||
goto no_port;
|
||||
|
||||
g_debug ("node %p: add port %p", node, port);
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("(u)", 1));
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
not_allowed:
|
||||
{
|
||||
g_debug ("sender %s is not owner of node with sender %s", sender, priv->sender);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "not node owner");
|
||||
return TRUE;
|
||||
}
|
||||
no_port:
|
||||
{
|
||||
g_debug ("node %p: could create port", node);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "can't create port");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_remove (PinosNode1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
|
||||
g_debug ("node %p: remove", node);
|
||||
pinos_node_remove (node);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("()"));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_node_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (_object);
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
g_value_set_object (value, priv->daemon);
|
||||
break;
|
||||
|
||||
case PROP_SENDER:
|
||||
g_value_set_string (value, priv->sender);
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_PATH:
|
||||
g_value_set_string (value, priv->object_path);
|
||||
break;
|
||||
|
||||
case PROP_NAME:
|
||||
g_value_set_string (value, priv->name);
|
||||
break;
|
||||
|
||||
case PROP_STATE:
|
||||
g_value_set_enum (value, priv->state);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
g_value_set_boxed (value, priv->properties);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (node, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_node_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (_object);
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
priv->daemon = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_SENDER:
|
||||
priv->sender = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_NAME:
|
||||
priv->name = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
if (priv->properties)
|
||||
pinos_properties_free (priv->properties);
|
||||
priv->properties = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (node, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
node_register_object (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
PinosDaemon *daemon = priv->daemon;
|
||||
PinosObjectSkeleton *skel;
|
||||
|
||||
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_NODE);
|
||||
|
||||
pinos_object_skeleton_set_node1 (skel, priv->iface);
|
||||
|
||||
g_free (priv->object_path);
|
||||
priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
|
||||
g_debug ("node %p: register object %s", node, priv->object_path);
|
||||
pinos_daemon_add_node (daemon, node);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
node_unregister_object (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
g_debug ("node %p: unregister object %s", node, priv->object_path);
|
||||
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||
pinos_daemon_remove_node (priv->daemon, node);
|
||||
}
|
||||
|
||||
static void
|
||||
on_property_notify (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "sender") == 0) {
|
||||
pinos_node1_set_owner (priv->iface, priv->sender);
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "name") == 0) {
|
||||
pinos_node1_set_name (priv->iface, pinos_node_get_name (node));
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "properties") == 0) {
|
||||
PinosProperties *props = pinos_node_get_properties (node);
|
||||
pinos_node1_set_properties (priv->iface, props ? pinos_properties_to_variant (props) : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_node_constructed (GObject * obj)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (obj);
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
g_debug ("node %p: constructed", node);
|
||||
|
||||
g_signal_connect (node, "notify", (GCallback) on_property_notify, node);
|
||||
G_OBJECT_CLASS (pinos_node_parent_class)->constructed (obj);
|
||||
|
||||
if (priv->sender == NULL) {
|
||||
priv->sender = g_strdup (pinos_daemon_get_sender (priv->daemon));
|
||||
pinos_node1_set_owner (priv->iface, priv->sender);
|
||||
}
|
||||
|
||||
node_register_object (node);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_node_dispose (GObject * obj)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (obj);
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
||||
|
||||
g_debug ("node %p: dispose", node);
|
||||
node_unregister_object (node);
|
||||
|
||||
g_list_free_full (priv->ports, (GDestroyNotify) g_object_unref);
|
||||
priv->ports = NULL;
|
||||
|
||||
G_OBJECT_CLASS (pinos_node_parent_class)->dispose (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_node_finalize (GObject * obj)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (obj);
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
g_debug ("node %p: finalize", node);
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_free (priv->sender);
|
||||
g_free (priv->name);
|
||||
g_clear_error (&priv->error);
|
||||
if (priv->properties)
|
||||
pinos_properties_free (priv->properties);
|
||||
|
||||
G_OBJECT_CLASS (pinos_node_parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_node_class_init (PinosNodeClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
PinosNodeClass *node_class = PINOS_NODE_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosNodePrivate));
|
||||
|
||||
gobject_class->constructed = pinos_node_constructed;
|
||||
gobject_class->dispose = pinos_node_dispose;
|
||||
gobject_class->finalize = pinos_node_finalize;
|
||||
gobject_class->set_property = pinos_node_set_property;
|
||||
gobject_class->get_property = pinos_node_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DAEMON,
|
||||
g_param_spec_object ("daemon",
|
||||
"Daemon",
|
||||
"The Daemon",
|
||||
PINOS_TYPE_DAEMON,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SENDER,
|
||||
g_param_spec_string ("sender",
|
||||
"Sender",
|
||||
"The Sender",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
g_param_spec_string ("object-path",
|
||||
"Object Path",
|
||||
"The object path",
|
||||
NULL,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_NAME,
|
||||
g_param_spec_string ("name",
|
||||
"Name",
|
||||
"The node name",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_STATE,
|
||||
g_param_spec_enum ("state",
|
||||
"State",
|
||||
"The state of the node",
|
||||
PINOS_TYPE_NODE_STATE,
|
||||
PINOS_NODE_STATE_SUSPENDED,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_PROPERTIES,
|
||||
g_param_spec_boxed ("properties",
|
||||
"Properties",
|
||||
"The properties of the node",
|
||||
PINOS_TYPE_PROPERTIES,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
|
||||
node_class->set_state = node_set_state;
|
||||
node_class->add_port = node_add_port;
|
||||
node_class->remove_port = node_remove_port;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_node_init (PinosNode * node)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv = PINOS_NODE_GET_PRIVATE (node);
|
||||
|
||||
g_debug ("node %p: new", node);
|
||||
priv->iface = pinos_node1_skeleton_new ();
|
||||
g_signal_connect (priv->iface, "handle-add-port",
|
||||
(GCallback) handle_add_port,
|
||||
node);
|
||||
g_signal_connect (priv->iface, "handle-remove",
|
||||
(GCallback) handle_remove,
|
||||
node);
|
||||
priv->state = PINOS_NODE_STATE_SUSPENDED;
|
||||
pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_SUSPENDED);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_new:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @sender: the path of the owner
|
||||
* @name: a name
|
||||
* @properties: extra properties
|
||||
*
|
||||
* Create a new #PinosNode.
|
||||
*
|
||||
* Returns: a new #PinosNode
|
||||
*/
|
||||
PinosNode *
|
||||
pinos_node_new (PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *properties)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||
|
||||
return g_object_new (PINOS_TYPE_NODE,
|
||||
"daemon", daemon,
|
||||
"sender", sender,
|
||||
"name", name,
|
||||
"properties", properties,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_name:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the name of @node
|
||||
*
|
||||
* Returns: the name of @node
|
||||
*/
|
||||
const gchar *
|
||||
pinos_node_get_name (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_state:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the state of @node
|
||||
*
|
||||
* Returns: the state of @node
|
||||
*/
|
||||
PinosNodeState
|
||||
pinos_node_get_state (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), PINOS_NODE_STATE_ERROR);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_properties:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the properties of @node
|
||||
*
|
||||
* Returns: the properties of @node
|
||||
*/
|
||||
PinosProperties *
|
||||
pinos_node_get_properties (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_daemon:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the daemon of @node.
|
||||
*
|
||||
* Returns: the daemon of @node.
|
||||
*/
|
||||
PinosDaemon *
|
||||
pinos_node_get_daemon (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->daemon;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_sender:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the owner path of @node.
|
||||
*
|
||||
* Returns: the owner path of @node.
|
||||
*/
|
||||
const gchar *
|
||||
pinos_node_get_sender (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->sender;
|
||||
}
|
||||
/**
|
||||
* pinos_node_get_object_path:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the object path of @node.
|
||||
*
|
||||
* Returns: the object path of @node.
|
||||
*/
|
||||
const gchar *
|
||||
pinos_node_get_object_path (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->object_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_remove:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Remove @node. This will stop the transfer on the node and
|
||||
* free the resources allocated by @node.
|
||||
*/
|
||||
void
|
||||
pinos_node_remove (PinosNode *node)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
|
||||
g_debug ("node %p: remove", node);
|
||||
g_signal_emit (node, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_remove_port (PinosPort *port, PinosNode *node)
|
||||
{
|
||||
pinos_node_remove_port (node, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_add_port:
|
||||
* @node: a #PinosNode
|
||||
* @direction: the direction of the port
|
||||
* @error: location of #GError
|
||||
*
|
||||
* Add the #PinosPort to @node
|
||||
*
|
||||
* Returns: a new #PinosPort or %NULL
|
||||
*/
|
||||
PinosPort *
|
||||
pinos_node_add_port (PinosNode *node,
|
||||
PinosDirection direction,
|
||||
GError **error)
|
||||
{
|
||||
PinosNodeClass *klass;
|
||||
PinosNodePrivate *priv;
|
||||
PinosPort *port;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
klass = PINOS_NODE_GET_CLASS (node);
|
||||
if (!klass->add_port) {
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "add-port not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_debug ("node %p: add port", node);
|
||||
port = klass->add_port (node, direction, error);
|
||||
|
||||
if (port) {
|
||||
priv->ports = g_list_append (priv->ports, port);
|
||||
g_signal_connect (port, "remove", (GCallback) handle_remove_port, node);
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_remove_port:
|
||||
* @node: a #PinosNode
|
||||
* @port: (transfer full): a #PinosPort
|
||||
*
|
||||
* Remove the #PinosPort from @node
|
||||
*/
|
||||
void
|
||||
pinos_node_remove_port (PinosNode *node, PinosPort *port)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
PinosNodeClass *klass;
|
||||
GList *find;
|
||||
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
priv = node->priv;
|
||||
|
||||
find = g_list_find (priv->ports, port);
|
||||
if (find) {
|
||||
klass = PINOS_NODE_GET_CLASS (node);
|
||||
|
||||
if (klass->remove_port)
|
||||
klass->remove_port (node, port);
|
||||
|
||||
g_debug ("node %p: removed port %p", node, port);
|
||||
priv->ports = g_list_delete_link (priv->ports, find);
|
||||
g_object_unref (port);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_get_ports:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Get the list of ports in @node.
|
||||
*
|
||||
* Returns: a #GList of ports owned by @node.
|
||||
*/
|
||||
GList *
|
||||
pinos_node_get_ports (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->ports;
|
||||
}
|
||||
|
||||
static void
|
||||
remove_idle_timeout (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
if (priv->idle_timeout) {
|
||||
g_source_remove (priv->idle_timeout);
|
||||
priv->idle_timeout = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_set_state:
|
||||
* @node: a #PinosNode
|
||||
* @state: a #PinosNodeState
|
||||
*
|
||||
* Set the state of @node to @state.
|
||||
*
|
||||
* Returns: %TRUE on success.
|
||||
*/
|
||||
gboolean
|
||||
pinos_node_set_state (PinosNode *node,
|
||||
PinosNodeState state)
|
||||
{
|
||||
PinosNodeClass *klass;
|
||||
gboolean res;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_NODE (node), FALSE);
|
||||
|
||||
klass = PINOS_NODE_GET_CLASS (node);
|
||||
|
||||
remove_idle_timeout (node);
|
||||
|
||||
g_debug ("node %p: set state to %s", node, pinos_node_state_as_string (state));
|
||||
if (klass->set_state)
|
||||
res = klass->set_state (node, state);
|
||||
else
|
||||
res = FALSE;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_update_state:
|
||||
* @node: a #PinosNode
|
||||
* @state: a #PinosNodeState
|
||||
*
|
||||
* Update the state of a node. This method is used from
|
||||
* inside @node itself.
|
||||
*/
|
||||
void
|
||||
pinos_node_update_state (PinosNode *node,
|
||||
PinosNodeState state)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
priv = node->priv;
|
||||
|
||||
if (priv->state != state) {
|
||||
g_debug ("node %p: update state to %s", node, pinos_node_state_as_string (state));
|
||||
priv->state = state;
|
||||
g_object_notify (G_OBJECT (node), "state");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_report_error:
|
||||
* @node: a #PinosNode
|
||||
* @error: a #GError
|
||||
*
|
||||
* Report an error from within @node.
|
||||
*/
|
||||
void
|
||||
pinos_node_report_error (PinosNode *node,
|
||||
GError *error)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
priv = node->priv;
|
||||
|
||||
g_clear_error (&priv->error);
|
||||
remove_idle_timeout (node);
|
||||
priv->error = error;
|
||||
priv->state = PINOS_NODE_STATE_ERROR;
|
||||
g_debug ("node %p: got error state %s", node, error->message);
|
||||
g_object_notify (G_OBJECT (node), "state");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
idle_timeout (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv = node->priv;
|
||||
|
||||
priv->idle_timeout = 0;
|
||||
g_debug ("node %p: idle timeout", node);
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_report_idle:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Mark @node as being idle. This will start a timeout that will
|
||||
* set the node to SUSPENDED.
|
||||
*/
|
||||
void
|
||||
pinos_node_report_idle (PinosNode *node)
|
||||
{
|
||||
PinosNodePrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
priv = node->priv;
|
||||
|
||||
g_debug ("node %p: report idle", node);
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_IDLE);
|
||||
|
||||
priv->idle_timeout = g_timeout_add_seconds (3,
|
||||
(GSourceFunc) idle_timeout,
|
||||
node);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_node_report_busy:
|
||||
* @node: a #PinosNode
|
||||
*
|
||||
* Mark @node as being busy. This will set the state of the node
|
||||
* to the RUNNING state.
|
||||
*/
|
||||
void
|
||||
pinos_node_report_busy (PinosNode *node)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_NODE (node));
|
||||
|
||||
g_debug ("node %p: report busy", node);
|
||||
pinos_node_set_state (node, PINOS_NODE_STATE_RUNNING);
|
||||
}
|
||||
108
pinos/server/node.h
Normal file
108
pinos/server/node.h
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/* 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_NODE_H__
|
||||
#define __PINOS_NODE_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosNode PinosNode;
|
||||
typedef struct _PinosNodeClass PinosNodeClass;
|
||||
typedef struct _PinosNodePrivate PinosNodePrivate;
|
||||
|
||||
#include <pinos/client/introspect.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
#include <pinos/server/port.h>
|
||||
|
||||
#define PINOS_TYPE_NODE (pinos_node_get_type ())
|
||||
#define PINOS_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE))
|
||||
#define PINOS_IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_NODE))
|
||||
#define PINOS_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_NODE, PinosNodeClass))
|
||||
#define PINOS_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_NODE, PinosNode))
|
||||
#define PINOS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_NODE, PinosNodeClass))
|
||||
#define PINOS_NODE_CAST(obj) ((PinosNode*)(obj))
|
||||
#define PINOS_NODE_CLASS_CAST(klass) ((PinosNodeClass*)(klass))
|
||||
|
||||
/**
|
||||
* PinosNode:
|
||||
*
|
||||
* Pinos node class.
|
||||
*/
|
||||
struct _PinosNode {
|
||||
GObject object;
|
||||
|
||||
PinosNodePrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosNodeClass:
|
||||
* @set_state: called to change the current state of the node
|
||||
*
|
||||
* Pinos node class.
|
||||
*/
|
||||
struct _PinosNodeClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
gboolean (*set_state) (PinosNode *node,
|
||||
PinosNodeState state);
|
||||
|
||||
PinosPort * (*add_port) (PinosNode *node,
|
||||
PinosDirection direction,
|
||||
GError **error);
|
||||
void (*remove_port) (PinosNode *node,
|
||||
PinosPort *port);
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_node_get_type (void);
|
||||
|
||||
PinosNode * pinos_node_new (PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *properties);
|
||||
void pinos_node_remove (PinosNode *node);
|
||||
|
||||
|
||||
const gchar * pinos_node_get_name (PinosNode *node);
|
||||
PinosProperties * pinos_node_get_properties (PinosNode *node);
|
||||
|
||||
PinosDaemon * pinos_node_get_daemon (PinosNode *node);
|
||||
const gchar * pinos_node_get_sender (PinosNode *node);
|
||||
const gchar * pinos_node_get_object_path (PinosNode *node);
|
||||
|
||||
PinosPort * pinos_node_add_port (PinosNode *node,
|
||||
PinosDirection direction,
|
||||
GError **error);
|
||||
void pinos_node_remove_port (PinosNode *node,
|
||||
PinosPort *port);
|
||||
GList * pinos_node_get_ports (PinosNode *node);
|
||||
|
||||
PinosNodeState pinos_node_get_state (PinosNode *node);
|
||||
gboolean pinos_node_set_state (PinosNode *node, PinosNodeState state);
|
||||
void pinos_node_update_state (PinosNode *node, PinosNodeState state);
|
||||
|
||||
void pinos_node_report_error (PinosNode *node, GError *error);
|
||||
void pinos_node_report_idle (PinosNode *node);
|
||||
void pinos_node_report_busy (PinosNode *node);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_NODE_H__ */
|
||||
888
pinos/server/port.c
Normal file
888
pinos/server/port.c
Normal file
|
|
@ -0,0 +1,888 @@
|
|||
/* 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 <gst/gst.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/enumtypes.h"
|
||||
|
||||
#include "pinos/server/port.h"
|
||||
#include "pinos/server/node.h"
|
||||
|
||||
#define PINOS_PORT_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_PORT, PinosPortPrivate))
|
||||
|
||||
#if 0
|
||||
#define PINOS_DEBUG_TRANSPORT(format,args...) g_debug(format,##args)
|
||||
#else
|
||||
#define PINOS_DEBUG_TRANSPORT(format,args...)
|
||||
#endif
|
||||
|
||||
#define MAX_BUFFER_SIZE 1024
|
||||
#define MAX_FDS 16
|
||||
|
||||
struct _PinosPortPrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
|
||||
PinosNode *node;
|
||||
PinosDirection direction;
|
||||
GBytes *possible_formats;
|
||||
GBytes *format;
|
||||
PinosProperties *properties;
|
||||
|
||||
guint8 send_data[MAX_BUFFER_SIZE];
|
||||
int send_fds[MAX_FDS];
|
||||
|
||||
PinosBuffer *buffer;
|
||||
GPtrArray *peers;
|
||||
gchar **peer_paths;
|
||||
guint max_peers;
|
||||
|
||||
PinosReceivedBufferCallback received_buffer_cb;
|
||||
gpointer received_buffer_data;
|
||||
GDestroyNotify received_buffer_notify;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosPort, pinos_port, G_TYPE_OBJECT);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DAEMON,
|
||||
PROP_NODE,
|
||||
PROP_MAIN_CONTEXT,
|
||||
PROP_DIRECTION,
|
||||
PROP_MAX_PEERS,
|
||||
PROP_PEERS,
|
||||
PROP_POSSIBLE_FORMATS,
|
||||
PROP_FORMAT,
|
||||
PROP_PROPERTIES,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_FORMAT_REQUEST,
|
||||
SIGNAL_REMOVE,
|
||||
SIGNAL_LINKED,
|
||||
SIGNAL_UNLINKED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
|
||||
void
|
||||
pinos_port_set_received_buffer_cb (PinosPort *port,
|
||||
PinosReceivedBufferCallback cb,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
priv = port->priv;
|
||||
|
||||
g_debug ("port %p: set callback", port);
|
||||
|
||||
if (priv->received_buffer_notify)
|
||||
priv->received_buffer_notify (priv->received_buffer_data);;
|
||||
priv->received_buffer_cb = cb;
|
||||
priv->received_buffer_data = user_data;
|
||||
priv->received_buffer_notify = notify;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pinos_port_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (_object);
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
g_value_set_object (value, priv->daemon);
|
||||
break;
|
||||
|
||||
case PROP_NODE:
|
||||
g_value_set_object (value, priv->node);
|
||||
break;
|
||||
|
||||
case PROP_MAX_PEERS:
|
||||
g_value_set_uint (value, priv->max_peers);
|
||||
break;
|
||||
|
||||
case PROP_PEERS:
|
||||
g_value_set_boxed (value, priv->peer_paths);
|
||||
break;
|
||||
|
||||
case PROP_DIRECTION:
|
||||
g_value_set_enum (value, priv->direction);
|
||||
break;
|
||||
|
||||
case PROP_POSSIBLE_FORMATS:
|
||||
g_value_set_boxed (value, priv->possible_formats);
|
||||
break;
|
||||
|
||||
case PROP_FORMAT:
|
||||
g_value_set_boxed (value, priv->format);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
g_value_set_boxed (value, priv->properties);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (port, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (_object);
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
priv->daemon = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_NODE:
|
||||
priv->node = g_value_get_object (value);
|
||||
break;
|
||||
|
||||
case PROP_DIRECTION:
|
||||
priv->direction = g_value_get_enum (value);
|
||||
break;
|
||||
|
||||
case PROP_MAX_PEERS:
|
||||
priv->max_peers = g_value_get_uint (value);
|
||||
break;
|
||||
|
||||
case PROP_PEERS:
|
||||
if (priv->peer_paths)
|
||||
g_strfreev (priv->peer_paths);
|
||||
priv->peer_paths = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
case PROP_POSSIBLE_FORMATS:
|
||||
if (priv->possible_formats)
|
||||
g_bytes_unref (priv->possible_formats);
|
||||
priv->possible_formats = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
case PROP_FORMAT:
|
||||
if (priv->format)
|
||||
g_bytes_unref (priv->format);
|
||||
priv->format = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
if (priv->properties)
|
||||
pinos_properties_free (priv->properties);
|
||||
priv->properties = g_value_dup_boxed (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (port, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_constructed (GObject * object)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (object);
|
||||
|
||||
g_debug ("port %p: constructed", port);
|
||||
|
||||
G_OBJECT_CLASS (pinos_port_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_dispose (GObject * object)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (object);
|
||||
|
||||
g_debug ("port %p: dispose", port);
|
||||
|
||||
G_OBJECT_CLASS (pinos_port_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_finalize (GObject * object)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (object);
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
g_debug ("port %p: finalize", port);
|
||||
g_clear_pointer (&priv->possible_formats, g_bytes_unref);
|
||||
g_clear_pointer (&priv->format, g_bytes_unref);
|
||||
g_clear_pointer (&priv->properties, pinos_properties_free);
|
||||
if (priv->received_buffer_notify)
|
||||
priv->received_buffer_notify (priv->received_buffer_data);
|
||||
g_ptr_array_unref (priv->peers);
|
||||
g_clear_object (&priv->daemon);
|
||||
|
||||
G_OBJECT_CLASS (pinos_port_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_class_init (PinosPortClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
//PinosPortClass *port_class = PINOS_PORT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosPortPrivate));
|
||||
|
||||
gobject_class->constructed = pinos_port_constructed;
|
||||
gobject_class->dispose = pinos_port_dispose;
|
||||
gobject_class->finalize = pinos_port_finalize;
|
||||
gobject_class->set_property = pinos_port_set_property;
|
||||
gobject_class->get_property = pinos_port_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DAEMON,
|
||||
g_param_spec_object ("daemon",
|
||||
"Daemon",
|
||||
"The Daemon",
|
||||
PINOS_TYPE_DAEMON,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_NODE,
|
||||
g_param_spec_object ("node",
|
||||
"Node",
|
||||
"The Node",
|
||||
PINOS_TYPE_NODE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DIRECTION,
|
||||
g_param_spec_enum ("direction",
|
||||
"Direction",
|
||||
"The direction of the port",
|
||||
PINOS_TYPE_DIRECTION,
|
||||
PINOS_DIRECTION_INVALID,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_MAX_PEERS,
|
||||
g_param_spec_uint ("max-peers",
|
||||
"Max Peers",
|
||||
"The maximum number of peer ports",
|
||||
1, G_MAXUINT, G_MAXUINT,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_PEERS,
|
||||
g_param_spec_boxed ("peers",
|
||||
"Peers",
|
||||
"The peer ports of the port",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_POSSIBLE_FORMATS,
|
||||
g_param_spec_boxed ("possible-formats",
|
||||
"Possible Formats",
|
||||
"The possbile formats of the port",
|
||||
G_TYPE_BYTES,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_FORMAT,
|
||||
g_param_spec_boxed ("format",
|
||||
"Format",
|
||||
"The format of the port",
|
||||
G_TYPE_BYTES,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_PROPERTIES,
|
||||
g_param_spec_boxed ("properties",
|
||||
"Properties",
|
||||
"The properties of the port",
|
||||
PINOS_TYPE_PROPERTIES,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
|
||||
signals[SIGNAL_FORMAT_REQUEST] = g_signal_new ("format-request",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
|
||||
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
signals[SIGNAL_LINKED] = g_signal_new ("linked",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_BOOLEAN,
|
||||
1,
|
||||
PINOS_TYPE_PORT);
|
||||
signals[SIGNAL_UNLINKED] = g_signal_new ("unlinked",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
PINOS_TYPE_PORT);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_port_init (PinosPort * port)
|
||||
{
|
||||
PinosPortPrivate *priv = port->priv = PINOS_PORT_GET_PRIVATE (port);
|
||||
|
||||
g_debug ("port %p: new", port);
|
||||
priv->direction = PINOS_DIRECTION_INVALID;
|
||||
priv->peers = g_ptr_array_new_full (64, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_remove:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Trigger removal of @port
|
||||
*/
|
||||
void
|
||||
pinos_port_remove (PinosPort *port)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
|
||||
g_debug ("port %p: remove", port);
|
||||
g_signal_emit (port, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_get_node:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Get the parent #PinosNode of @port
|
||||
*
|
||||
* Returns: the parent node or %NULL
|
||||
*/
|
||||
PinosNode *
|
||||
pinos_port_get_node (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
return priv->node;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_get_direction:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Get the direction of @port
|
||||
*
|
||||
* Returns: the direction or %NULL
|
||||
*/
|
||||
PinosDirection
|
||||
pinos_port_get_direction (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), PINOS_DIRECTION_INVALID);
|
||||
priv = port->priv;
|
||||
|
||||
return priv->direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_get_possible_formats:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Get the possible formats of @port
|
||||
*
|
||||
* Returns: the possible formats or %NULL
|
||||
*/
|
||||
GBytes *
|
||||
pinos_port_get_possible_formats (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
g_signal_emit (port, signals[SIGNAL_FORMAT_REQUEST], 0, NULL);
|
||||
return priv->possible_formats;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_get_format:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Get the format of @port
|
||||
*
|
||||
* Returns: the format or %NULL
|
||||
*/
|
||||
GBytes *
|
||||
pinos_port_get_format (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
return priv->format;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_get_properties:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Get the properties of @port
|
||||
*
|
||||
* Returns: the properties or %NULL
|
||||
*/
|
||||
PinosProperties *
|
||||
pinos_port_get_properties (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
return priv->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_filter_formats:
|
||||
* @port: a #PinosPort
|
||||
* @filter: a #GBytes
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Get all the currently supported formats for @port and filter the
|
||||
* results with @filter.
|
||||
*
|
||||
* Returns: the list of supported format. If %NULL is returned, @error will
|
||||
* be set.
|
||||
*/
|
||||
GBytes *
|
||||
pinos_port_filter_formats (PinosPort *port,
|
||||
GBytes *filter,
|
||||
GError **error)
|
||||
{
|
||||
GstCaps *tmp, *caps, *cfilter;
|
||||
gchar *str;
|
||||
PinosPortPrivate *priv;
|
||||
GBytes *res;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
if (filter) {
|
||||
cfilter = gst_caps_from_string (g_bytes_get_data (filter, NULL));
|
||||
if (cfilter == NULL)
|
||||
goto invalid_filter;
|
||||
} else {
|
||||
cfilter = NULL;
|
||||
}
|
||||
|
||||
g_signal_emit (port, signals[SIGNAL_FORMAT_REQUEST], 0, NULL);
|
||||
|
||||
if (priv->possible_formats)
|
||||
caps = gst_caps_from_string (g_bytes_get_data (priv->possible_formats, NULL));
|
||||
else
|
||||
caps = gst_caps_new_any ();
|
||||
|
||||
if (caps && cfilter) {
|
||||
tmp = gst_caps_intersect_full (caps, cfilter, GST_CAPS_INTERSECT_FIRST);
|
||||
gst_caps_take (&caps, tmp);
|
||||
}
|
||||
g_clear_pointer (&cfilter, gst_caps_unref);
|
||||
|
||||
if (caps == NULL || gst_caps_is_empty (caps))
|
||||
goto no_format;
|
||||
|
||||
str = gst_caps_to_string (caps);
|
||||
gst_caps_unref (caps);
|
||||
res = g_bytes_new_take (str, strlen (str) + 1);
|
||||
|
||||
if (priv->direction == PINOS_DIRECTION_OUTPUT) {
|
||||
guint i;
|
||||
for (i = 0; i < priv->peers->len; i++) {
|
||||
PinosPort *peer = g_ptr_array_index (priv->peers, i);
|
||||
res = pinos_port_filter_formats (peer, res, error);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
invalid_filter:
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_ARGUMENT,
|
||||
"Invalid filter received");
|
||||
return NULL;
|
||||
}
|
||||
no_format:
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_FOUND,
|
||||
"No compatible format found");
|
||||
if (cfilter)
|
||||
gst_caps_unref (cfilter);
|
||||
if (caps)
|
||||
gst_caps_unref (caps);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
parse_control_buffer (PinosPort *port, PinosBuffer *buffer)
|
||||
{
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
PinosBufferIter it;
|
||||
|
||||
pinos_buffer_iter_init (&it, buffer);
|
||||
while (pinos_buffer_iter_next (&it)) {
|
||||
switch (pinos_buffer_iter_get_type (&it)) {
|
||||
case PINOS_PACKET_TYPE_FORMAT_CHANGE:
|
||||
{
|
||||
PinosPacketFormatChange change;
|
||||
|
||||
if (!pinos_buffer_iter_parse_format_change (&it, &change))
|
||||
continue;
|
||||
|
||||
if (priv->format)
|
||||
g_bytes_unref (priv->format);
|
||||
priv->format = g_bytes_new (change.format, strlen (change.format) + 1);
|
||||
g_object_notify (G_OBJECT (port), "format");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pinos_port_receive_buffer (PinosPort *port,
|
||||
PinosBuffer *buffer,
|
||||
GError **error)
|
||||
{
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
|
||||
if (priv->buffer)
|
||||
goto buffer_queued;
|
||||
|
||||
PINOS_DEBUG_TRANSPORT ("port %p: receive buffer %p", port, buffer);
|
||||
if (pinos_buffer_get_flags (buffer) & PINOS_BUFFER_FLAG_CONTROL)
|
||||
parse_control_buffer (port, buffer);
|
||||
|
||||
priv->buffer = buffer;
|
||||
if (priv->received_buffer_cb)
|
||||
priv->received_buffer_cb (port, priv->received_buffer_data);
|
||||
priv->buffer = NULL;
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
buffer_queued:
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_FOUND,
|
||||
"buffer was already queued on port");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_peer_paths (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
gchar **paths;
|
||||
guint i;
|
||||
gint path_index = 0;
|
||||
|
||||
paths = g_new0 (gchar *, priv->peers->len + 1);
|
||||
for (i = 0; i < priv->peers->len; i++) {
|
||||
PinosPort *peer;
|
||||
gchar *path;
|
||||
|
||||
peer = g_ptr_array_index (priv->peers, i);
|
||||
g_object_get (peer, "object-path", &path, NULL);
|
||||
paths[path_index++] = path;
|
||||
}
|
||||
|
||||
g_object_set (port, "peers", paths, NULL);
|
||||
g_strfreev (paths);
|
||||
}
|
||||
/**
|
||||
* pinos_port_link:
|
||||
* @source: a source #PinosPort
|
||||
* @destination: a destination #PinosPort
|
||||
*
|
||||
* Link two ports together.
|
||||
*
|
||||
* Returns: %TRUE if ports could be linked.
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_link (PinosPort *source, PinosPort *destination)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (source), FALSE);
|
||||
g_return_val_if_fail (PINOS_IS_PORT (destination), FALSE);
|
||||
g_return_val_if_fail (source->priv->direction != destination->priv->direction, FALSE);
|
||||
|
||||
if (source->priv->peers->len >= source->priv->max_peers)
|
||||
return FALSE;
|
||||
if (destination->priv->peers->len >= destination->priv->max_peers)
|
||||
return FALSE;
|
||||
|
||||
if (source->priv->direction != PINOS_DIRECTION_OUTPUT) {
|
||||
PinosPort *tmp;
|
||||
tmp = source;
|
||||
source = destination;
|
||||
destination = tmp;
|
||||
}
|
||||
|
||||
g_signal_emit (source, signals[SIGNAL_LINKED], 0, destination, &res);
|
||||
if (!res)
|
||||
return FALSE;
|
||||
g_signal_emit (destination, signals[SIGNAL_LINKED], 0, source, &res);
|
||||
if (!res)
|
||||
return FALSE;
|
||||
|
||||
g_debug ("port %p: linked to %p", source, destination);
|
||||
g_ptr_array_add (source->priv->peers, destination);
|
||||
g_ptr_array_add (destination->priv->peers, source);
|
||||
|
||||
update_peer_paths (source);
|
||||
update_peer_paths (destination);
|
||||
|
||||
|
||||
if (source->priv->format) {
|
||||
PinosBufferBuilder builder;
|
||||
PinosBuffer pbuf;
|
||||
PinosPacketFormatChange fc;
|
||||
GError *error = NULL;
|
||||
|
||||
pinos_port_buffer_builder_init (destination, &builder);
|
||||
fc.id = 0;
|
||||
fc.format = g_bytes_get_data (source->priv->format, NULL);
|
||||
pinos_buffer_builder_add_format_change (&builder, &fc);
|
||||
pinos_buffer_builder_end (&builder, &pbuf);
|
||||
|
||||
if (!pinos_port_receive_buffer (destination, &pbuf, &error)) {
|
||||
g_warning ("port %p: counld not receive format: %s", destination, error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
pinos_buffer_unref (&pbuf);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_unlink:
|
||||
* @source: a source #PinosPort
|
||||
* @destination: a destination #PinosPort
|
||||
*
|
||||
* Link two ports together.
|
||||
*
|
||||
* Returns: %TRUE if ports could be linked.
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_unlink (PinosPort *source, PinosPort *destination)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_PORT (source), FALSE);
|
||||
g_return_val_if_fail (PINOS_IS_PORT (destination), FALSE);
|
||||
|
||||
g_ptr_array_remove (source->priv->peers, destination);
|
||||
g_ptr_array_remove (destination->priv->peers, source);
|
||||
|
||||
update_peer_paths (source);
|
||||
update_peer_paths (destination);
|
||||
|
||||
g_debug ("port %p: unlinked from %p", source, destination);
|
||||
g_signal_emit (source, signals[SIGNAL_UNLINKED], 0, destination);
|
||||
g_signal_emit (destination, signals[SIGNAL_UNLINKED], 0, source);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
static void
|
||||
pinos_port_unlink_all (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv = port->priv;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < priv->peers->len; i++) {
|
||||
PinosPort *peer = g_ptr_array_index (priv->peers, i);
|
||||
|
||||
g_ptr_array_remove (peer->priv->peers, port);
|
||||
g_ptr_array_index (priv->peers, i) = NULL;
|
||||
|
||||
g_signal_emit (port, signals[SIGNAL_UNLINKED], 0, peer);
|
||||
g_signal_emit (peer, signals[SIGNAL_UNLINKED], 0, port);
|
||||
}
|
||||
g_ptr_array_set_size (priv->peers, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_get_links:
|
||||
* @port: a #PinosPort
|
||||
* @n_linkes: location to hold the result number of links
|
||||
*
|
||||
* Get the links and number of links on this port
|
||||
*
|
||||
* Returns: an array of @n_links elements of type #PinosPort.
|
||||
*/
|
||||
PinosPort *
|
||||
pinos_port_get_links (PinosPort *port, guint *n_links)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
if (n_links)
|
||||
*n_links = priv->peers->len;
|
||||
|
||||
return (PinosPort *) priv->peers->pdata;
|
||||
}
|
||||
/**
|
||||
* pinos_port_peek_buffer:
|
||||
* @port: a #PinosPort
|
||||
*
|
||||
* Peek the buffer on @port.
|
||||
*
|
||||
* Returns: a #PinosBuffer or %NULL when no buffer has arrived on the pad.
|
||||
*/
|
||||
PinosBuffer *
|
||||
pinos_port_peek_buffer (PinosPort *port)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
return priv->buffer;
|
||||
}
|
||||
|
||||
void
|
||||
pinos_port_buffer_builder_init (PinosPort *port,
|
||||
PinosBufferBuilder *builder)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_PORT (port));
|
||||
priv = port->priv;
|
||||
|
||||
pinos_buffer_builder_init_into (builder,
|
||||
priv->send_data, MAX_BUFFER_SIZE,
|
||||
priv->send_fds, MAX_FDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_port_send_buffer:
|
||||
* @port: a #PinosPort
|
||||
* @buffer: a #PinosBuffer
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Send @buffer to ports connected to @port
|
||||
*
|
||||
* Returns: %TRUE on success. @error is set when %FALSE is returned.
|
||||
*/
|
||||
gboolean
|
||||
pinos_port_send_buffer (PinosPort *port,
|
||||
PinosBuffer *buffer,
|
||||
GError **error)
|
||||
{
|
||||
PinosPortPrivate *priv;
|
||||
PinosPort *peer;
|
||||
gboolean res = TRUE;
|
||||
guint i;
|
||||
GError *err = NULL;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_PORT (port), FALSE);
|
||||
priv = port->priv;
|
||||
|
||||
if (pinos_buffer_get_flags (buffer) & PINOS_BUFFER_FLAG_CONTROL)
|
||||
parse_control_buffer (port, buffer);
|
||||
|
||||
PINOS_DEBUG_TRANSPORT ("port %p: send buffer %p", port, buffer);
|
||||
|
||||
for (i = 0; i < priv->peers->len; i++) {
|
||||
peer = g_ptr_array_index (priv->peers, i);
|
||||
res = pinos_port_receive_buffer (peer, buffer, &err);
|
||||
}
|
||||
if (!res) {
|
||||
if (error == NULL)
|
||||
g_warning ("could not send buffer: %s", err->message);
|
||||
g_propagate_error (error, err);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
109
pinos/server/port.h
Normal file
109
pinos/server/port.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/* 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_PORT_H__
|
||||
#define __PINOS_PORT_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosPort PinosPort;
|
||||
typedef struct _PinosPortClass PinosPortClass;
|
||||
typedef struct _PinosPortPrivate PinosPortPrivate;
|
||||
|
||||
#include <pinos/client/introspect.h>
|
||||
#include <pinos/client/buffer.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
|
||||
#define PINOS_TYPE_PORT (pinos_port_get_type ())
|
||||
#define PINOS_IS_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_PORT))
|
||||
#define PINOS_IS_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_PORT))
|
||||
#define PINOS_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_PORT, PinosPortClass))
|
||||
#define PINOS_PORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_PORT, PinosPort))
|
||||
#define PINOS_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_PORT, PinosPortClass))
|
||||
#define PINOS_PORT_CAST(obj) ((PinosPort*)(obj))
|
||||
#define PINOS_PORT_CLASS_CAST(klass)((PinosPortClass*)(klass))
|
||||
|
||||
/**
|
||||
* PinosPort:
|
||||
*
|
||||
* Pinos port object class.
|
||||
*/
|
||||
struct _PinosPort {
|
||||
GObject object;
|
||||
|
||||
PinosPortPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosPortClass:
|
||||
*
|
||||
* Pinos port object class.
|
||||
*/
|
||||
struct _PinosPortClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
typedef void (*PinosReceivedBufferCallback) (PinosPort *port, gpointer user_data);
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_port_get_type (void);
|
||||
|
||||
void pinos_port_set_received_buffer_cb (PinosPort *port,
|
||||
PinosReceivedBufferCallback cb,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
|
||||
void pinos_port_remove (PinosPort *port);
|
||||
|
||||
PinosNode * pinos_port_get_node (PinosPort *port);
|
||||
GSocket * pinos_port_get_socket (PinosPort *port);
|
||||
const gchar * pinos_port_get_name (PinosPort *port);
|
||||
PinosDirection pinos_port_get_direction (PinosPort *port);
|
||||
GBytes * pinos_port_get_possible_formats (PinosPort *port);
|
||||
GBytes * pinos_port_get_format (PinosPort *port);
|
||||
PinosProperties * pinos_port_get_properties (PinosPort *port);
|
||||
|
||||
GBytes * pinos_port_filter_formats (PinosPort *port,
|
||||
GBytes *filter,
|
||||
GError **error);
|
||||
|
||||
GSocket * pinos_port_get_socket_pair (PinosPort *port,
|
||||
GError **error);
|
||||
|
||||
gboolean pinos_port_link (PinosPort *source,
|
||||
PinosPort *destination);
|
||||
gboolean pinos_port_unlink (PinosPort *source,
|
||||
PinosPort *destination);
|
||||
PinosPort * pinos_port_get_links (PinosPort *port,
|
||||
guint *n_links);
|
||||
|
||||
PinosBuffer * pinos_port_peek_buffer (PinosPort *port);
|
||||
|
||||
void pinos_port_buffer_builder_init (PinosPort *port,
|
||||
PinosBufferBuilder *builder);
|
||||
|
||||
gboolean pinos_port_send_buffer (PinosPort *port,
|
||||
PinosBuffer *buffer,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_PORT_H__ */
|
||||
|
|
@ -1,627 +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 <stdlib.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/enumtypes.h"
|
||||
|
||||
#include "pinos/server/server-node.h"
|
||||
#include "pinos/server/daemon.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
|
||||
#define PINOS_SERVER_NODE_GET_PRIVATE(node) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((node), PINOS_TYPE_SERVER_NODE, PinosServerNodePrivate))
|
||||
|
||||
struct _PinosServerNodePrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
PinosNode1 *iface;
|
||||
|
||||
gchar *sender;
|
||||
gchar *object_path;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosServerNode, pinos_server_node, PINOS_TYPE_NODE);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DAEMON,
|
||||
PROP_SENDER,
|
||||
PROP_OBJECT_PATH,
|
||||
};
|
||||
|
||||
static gboolean
|
||||
server_node_set_state (PinosNode *node,
|
||||
PinosNodeState state)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static PinosServerPort *
|
||||
server_node_create_port_sync (PinosServerNode *node,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
GBytes *possible_formats,
|
||||
PinosProperties *props)
|
||||
{
|
||||
PinosServerNodePrivate *priv = node->priv;
|
||||
PinosServerPort *port;
|
||||
|
||||
port = g_object_new (PINOS_TYPE_SERVER_PORT,
|
||||
"daemon", priv->daemon,
|
||||
"node", node,
|
||||
"direction", direction,
|
||||
"name", name,
|
||||
"possible-formats", possible_formats,
|
||||
"properties", props,
|
||||
NULL);
|
||||
pinos_node_add_port (PINOS_NODE (node), PINOS_PORT (port));
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
static void
|
||||
server_node_create_port (PinosNode *node,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
GBytes *possible_formats,
|
||||
PinosProperties *props,
|
||||
GTask *task)
|
||||
{
|
||||
PinosServerPort *port;
|
||||
|
||||
port = pinos_server_node_create_port_sync (PINOS_SERVER_NODE (node),
|
||||
direction,
|
||||
name,
|
||||
possible_formats,
|
||||
props);
|
||||
|
||||
g_task_return_pointer (task, port, (GDestroyNotify) g_object_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
server_node_remove_port (PinosNode *node,
|
||||
PinosPort *port)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
remove_port (PinosPort *port)
|
||||
{
|
||||
guint n_links;
|
||||
|
||||
pinos_port_get_links (port, &n_links);
|
||||
if (n_links == 0) {
|
||||
pinos_port_remove (port);
|
||||
}
|
||||
g_object_unref (port);
|
||||
}
|
||||
|
||||
static void
|
||||
on_port_created (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = PINOS_NODE (source_object);
|
||||
PinosServerNodePrivate *priv = PINOS_SERVER_NODE (node)->priv;
|
||||
GDBusMethodInvocation *invocation = user_data;
|
||||
PinosPort *port, *peer;
|
||||
const gchar *object_path, *val;
|
||||
GError *error = NULL;
|
||||
GUnixFDList *fdlist;
|
||||
GSocket *socket;
|
||||
int fd, fdidx;
|
||||
PinosDirection direction;
|
||||
PinosProperties *props;
|
||||
gboolean autoconnect = FALSE;
|
||||
|
||||
port = pinos_node_create_port_finish (node, res, &error);
|
||||
if (port == NULL)
|
||||
goto no_port;
|
||||
|
||||
g_debug ("server-node %p: port %p created", node, port);
|
||||
|
||||
socket = pinos_port_get_socket_pair (port, &error);
|
||||
if (socket == NULL)
|
||||
goto no_sockets;
|
||||
|
||||
fd = g_socket_get_fd (socket);
|
||||
fdlist = g_unix_fd_list_new ();
|
||||
fdidx = g_unix_fd_list_append (fdlist, fd, &error);
|
||||
g_object_unref (socket);
|
||||
|
||||
if (fdidx == -1)
|
||||
goto no_fdlist;
|
||||
|
||||
props = pinos_port_get_properties (port);
|
||||
|
||||
if ((val = pinos_properties_get (props, "autoconnect"))) {
|
||||
autoconnect = atoi (val);
|
||||
} else
|
||||
autoconnect = TRUE;
|
||||
|
||||
if (autoconnect) {
|
||||
direction = pinos_port_get_direction (port);
|
||||
direction = pinos_direction_reverse (direction);
|
||||
|
||||
val = pinos_properties_get (props, "target-path");
|
||||
|
||||
peer = pinos_daemon_find_port (priv->daemon,
|
||||
direction,
|
||||
val,
|
||||
pinos_port_get_properties (port),
|
||||
pinos_port_get_possible_formats (port),
|
||||
&error);
|
||||
if (peer == NULL)
|
||||
goto no_port_found;
|
||||
|
||||
if (!pinos_port_link (port, peer))
|
||||
goto link_failed;
|
||||
|
||||
g_object_set_data_full (G_OBJECT (port),
|
||||
"autoconnect-peer-port",
|
||||
peer,
|
||||
(GDestroyNotify) remove_port);
|
||||
}
|
||||
|
||||
object_path = pinos_server_port_get_object_path (PINOS_SERVER_PORT (port));
|
||||
g_debug ("server-node %p: add port %p, remote fd %d, %s", node, port, fd, object_path);
|
||||
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
|
||||
g_variant_new ("(oh)",
|
||||
object_path,
|
||||
fdidx),
|
||||
fdlist);
|
||||
|
||||
return;
|
||||
|
||||
no_port:
|
||||
{
|
||||
g_debug ("server-node %p: could create port", node);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "can't create port");
|
||||
return;
|
||||
}
|
||||
no_sockets:
|
||||
{
|
||||
g_debug ("server-node %p: could create socketpair %s", node, error->message);
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
g_clear_error (&error);
|
||||
g_object_unref (port);
|
||||
return;
|
||||
}
|
||||
no_fdlist:
|
||||
{
|
||||
g_debug ("server-node %p: could add to fdlist", node);
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
g_clear_error (&error);
|
||||
g_object_unref (fdlist);
|
||||
g_object_unref (port);
|
||||
return;
|
||||
}
|
||||
no_port_found:
|
||||
{
|
||||
g_debug ("server-node %p: could not find matching port", node);
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
g_clear_error (&error);
|
||||
g_object_unref (fdlist);
|
||||
return;
|
||||
}
|
||||
link_failed:
|
||||
{
|
||||
g_debug ("server-node %p: could not link port", node);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "can't link port");
|
||||
g_object_unref (peer);
|
||||
g_object_unref (fdlist);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
handle_create_port (PinosNode1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
PinosDirection arg_direction,
|
||||
const gchar *arg_name,
|
||||
GVariant *arg_properties,
|
||||
const gchar *arg_possible_formats,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosServerNodePrivate *priv = PINOS_SERVER_NODE (node)->priv;
|
||||
const gchar *sender;
|
||||
PinosProperties *props;
|
||||
GBytes *formats;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
if (g_strcmp0 (priv->sender, sender) != 0)
|
||||
goto not_allowed;
|
||||
|
||||
formats = g_bytes_new (arg_possible_formats, strlen (arg_possible_formats) + 1);
|
||||
props = pinos_properties_from_variant (arg_properties);
|
||||
|
||||
g_debug ("server-node %p: create port", node);
|
||||
pinos_node_create_port (node,
|
||||
arg_direction,
|
||||
arg_name,
|
||||
formats,
|
||||
props,
|
||||
NULL,
|
||||
on_port_created,
|
||||
invocation);
|
||||
|
||||
g_bytes_unref (formats);
|
||||
pinos_properties_free (props);
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
not_allowed:
|
||||
{
|
||||
g_debug ("sender %s is not owner of node with sender %s", sender, priv->sender);
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pinos.Error", "not node owner");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_remove (PinosNode1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
|
||||
g_debug ("server-node %p: remove", node);
|
||||
pinos_node_remove (node);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("()"));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_node_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosServerNode *node = PINOS_SERVER_NODE (_object);
|
||||
PinosServerNodePrivate *priv = node->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
g_value_set_object (value, priv->daemon);
|
||||
break;
|
||||
|
||||
case PROP_SENDER:
|
||||
g_value_set_string (value, priv->sender);
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_PATH:
|
||||
g_value_set_string (value, priv->object_path);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (node, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_node_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosServerNode *node = PINOS_SERVER_NODE (_object);
|
||||
PinosServerNodePrivate *priv = node->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
priv->daemon = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_SENDER:
|
||||
priv->sender = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (node, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
node_register_object (PinosServerNode *node)
|
||||
{
|
||||
PinosServerNodePrivate *priv = node->priv;
|
||||
PinosDaemon *daemon = priv->daemon;
|
||||
PinosObjectSkeleton *skel;
|
||||
|
||||
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_NODE);
|
||||
|
||||
pinos_object_skeleton_set_node1 (skel, priv->iface);
|
||||
|
||||
g_free (priv->object_path);
|
||||
priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
|
||||
g_debug ("server-node %p: register object %s", node, priv->object_path);
|
||||
pinos_daemon_add_node (daemon, node);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
node_unregister_object (PinosServerNode *node)
|
||||
{
|
||||
PinosServerNodePrivate *priv = node->priv;
|
||||
|
||||
g_debug ("server-node %p: unregister object %s", node, priv->object_path);
|
||||
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||
pinos_daemon_remove_node (priv->daemon, node);
|
||||
}
|
||||
|
||||
static void
|
||||
on_property_notify (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosNode *node = user_data;
|
||||
PinosServerNodePrivate *priv = PINOS_SERVER_NODE (node)->priv;
|
||||
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "sender") == 0) {
|
||||
pinos_node1_set_owner (priv->iface, priv->sender);
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "name") == 0) {
|
||||
pinos_node1_set_name (priv->iface, pinos_node_get_name (node));
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "properties") == 0) {
|
||||
PinosProperties *props = pinos_node_get_properties (node);
|
||||
pinos_node1_set_properties (priv->iface, props ? pinos_properties_to_variant (props) : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_node_constructed (GObject * obj)
|
||||
{
|
||||
PinosServerNode *node = PINOS_SERVER_NODE (obj);
|
||||
PinosServerNodePrivate *priv = node->priv;
|
||||
|
||||
g_debug ("server-node %p: constructed", node);
|
||||
|
||||
g_signal_connect (node, "notify", (GCallback) on_property_notify, node);
|
||||
G_OBJECT_CLASS (pinos_server_node_parent_class)->constructed (obj);
|
||||
|
||||
if (priv->sender == NULL) {
|
||||
priv->sender = g_strdup (pinos_daemon_get_sender (priv->daemon));
|
||||
pinos_node1_set_owner (priv->iface, priv->sender);
|
||||
}
|
||||
|
||||
node_register_object (node);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_node_dispose (GObject * obj)
|
||||
{
|
||||
PinosServerNode *node = PINOS_SERVER_NODE (obj);
|
||||
|
||||
g_debug ("server-node %p: dispose", node);
|
||||
node_unregister_object (node);
|
||||
|
||||
G_OBJECT_CLASS (pinos_server_node_parent_class)->dispose (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_node_finalize (GObject * obj)
|
||||
{
|
||||
PinosServerNode *node = PINOS_SERVER_NODE (obj);
|
||||
PinosServerNodePrivate *priv = node->priv;
|
||||
|
||||
g_debug ("server-node %p: finalize", node);
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_free (priv->sender);
|
||||
|
||||
G_OBJECT_CLASS (pinos_server_node_parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_node_class_init (PinosServerNodeClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
PinosNodeClass *node_class = PINOS_NODE_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosServerNodePrivate));
|
||||
|
||||
gobject_class->constructed = pinos_server_node_constructed;
|
||||
gobject_class->dispose = pinos_server_node_dispose;
|
||||
gobject_class->finalize = pinos_server_node_finalize;
|
||||
gobject_class->set_property = pinos_server_node_set_property;
|
||||
gobject_class->get_property = pinos_server_node_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DAEMON,
|
||||
g_param_spec_object ("daemon",
|
||||
"Daemon",
|
||||
"The Daemon",
|
||||
PINOS_TYPE_DAEMON,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SENDER,
|
||||
g_param_spec_string ("sender",
|
||||
"Sender",
|
||||
"The Sender",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
g_param_spec_string ("object-path",
|
||||
"Object Path",
|
||||
"The object path",
|
||||
NULL,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
node_class->set_state = server_node_set_state;
|
||||
node_class->create_port = server_node_create_port;
|
||||
node_class->remove_port = server_node_remove_port;
|
||||
|
||||
klass->create_port_sync = server_node_create_port_sync;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_node_init (PinosServerNode * node)
|
||||
{
|
||||
PinosServerNodePrivate *priv = node->priv = PINOS_SERVER_NODE_GET_PRIVATE (node);
|
||||
|
||||
g_debug ("server-node %p: new", node);
|
||||
priv->iface = pinos_node1_skeleton_new ();
|
||||
g_signal_connect (priv->iface, "handle-create-port",
|
||||
(GCallback) handle_create_port,
|
||||
node);
|
||||
g_signal_connect (priv->iface, "handle-remove",
|
||||
(GCallback) handle_remove,
|
||||
node);
|
||||
pinos_node1_set_state (priv->iface, PINOS_NODE_STATE_SUSPENDED);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_server_node_new:
|
||||
* @daemon: a #PinosDaemon
|
||||
* @sender: the path of the owner
|
||||
* @name: a name
|
||||
* @properties: extra properties
|
||||
*
|
||||
* Create a new #PinosServerNode.
|
||||
*
|
||||
* Returns: a new #PinosServerNode
|
||||
*/
|
||||
PinosNode *
|
||||
pinos_server_node_new (PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *properties)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||
|
||||
return g_object_new (PINOS_TYPE_SERVER_NODE,
|
||||
"daemon", daemon,
|
||||
"sender", sender,
|
||||
"name", name,
|
||||
"properties", properties,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_server_node_get_daemon:
|
||||
* @node: a #PinosServerNode
|
||||
*
|
||||
* Get the daemon of @node.
|
||||
*
|
||||
* Returns: the daemon of @node.
|
||||
*/
|
||||
PinosDaemon *
|
||||
pinos_server_node_get_daemon (PinosServerNode *node)
|
||||
{
|
||||
PinosServerNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_SERVER_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->daemon;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_server_node_get_sender:
|
||||
* @node: a #PinosServerNode
|
||||
*
|
||||
* Get the owner path of @node.
|
||||
*
|
||||
* Returns: the owner path of @node.
|
||||
*/
|
||||
const gchar *
|
||||
pinos_server_node_get_sender (PinosServerNode *node)
|
||||
{
|
||||
PinosServerNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_SERVER_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->sender;
|
||||
}
|
||||
/**
|
||||
* pinos_server_node_get_object_path:
|
||||
* @node: a #PinosServerNode
|
||||
*
|
||||
* Get the object path of @node.
|
||||
*
|
||||
* Returns: the object path of @node.
|
||||
*/
|
||||
const gchar *
|
||||
pinos_server_node_get_object_path (PinosServerNode *node)
|
||||
{
|
||||
PinosServerNodePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_SERVER_NODE (node), NULL);
|
||||
priv = node->priv;
|
||||
|
||||
return priv->object_path;
|
||||
}
|
||||
|
||||
PinosServerPort *
|
||||
pinos_server_node_create_port_sync (PinosServerNode *node,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
GBytes *possible_formats,
|
||||
PinosProperties *props)
|
||||
{
|
||||
PinosServerNodeClass *klass;
|
||||
PinosServerPort *port;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_SERVER_NODE (node), NULL);
|
||||
|
||||
klass = PINOS_SERVER_NODE_GET_CLASS (node);
|
||||
if (!klass->create_port_sync)
|
||||
return NULL;
|
||||
|
||||
g_debug ("server-node %p: create port", node);
|
||||
port = klass->create_port_sync (node,
|
||||
direction,
|
||||
name,
|
||||
possible_formats,
|
||||
props);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
|
@ -1,91 +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_SERVER_NODE_H__
|
||||
#define __PINOS_SERVER_NODE_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosServerNode PinosServerNode;
|
||||
typedef struct _PinosServerNodeClass PinosServerNodeClass;
|
||||
typedef struct _PinosServerNodePrivate PinosServerNodePrivate;
|
||||
|
||||
#include <pinos/client/introspect.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
#include <pinos/server/server-port.h>
|
||||
|
||||
#define PINOS_TYPE_SERVER_NODE (pinos_server_node_get_type ())
|
||||
#define PINOS_IS_SERVER_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SERVER_NODE))
|
||||
#define PINOS_IS_SERVER_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_SERVER_NODE))
|
||||
#define PINOS_SERVER_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_SERVER_NODE, PinosServerNodeClass))
|
||||
#define PINOS_SERVER_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_SERVER_NODE, PinosServerNode))
|
||||
#define PINOS_SERVER_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_SERVER_NODE, PinosServerNodeClass))
|
||||
#define PINOS_SERVER_NODE_CAST(obj) ((PinosServerNode*)(obj))
|
||||
#define PINOS_SERVER_NODE_CLASS_CAST(klass) ((PinosServerNodeClass*)(klass))
|
||||
|
||||
/**
|
||||
* PinosServerServerNode:
|
||||
*
|
||||
* Pinos node class.
|
||||
*/
|
||||
struct _PinosServerNode {
|
||||
PinosNode object;
|
||||
|
||||
PinosServerNodePrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosServerNodeClass:
|
||||
* @set_state: called to change the current state of the node
|
||||
*
|
||||
* Pinos node class.
|
||||
*/
|
||||
struct _PinosServerNodeClass {
|
||||
PinosNodeClass parent_class;
|
||||
|
||||
PinosServerPort * (*create_port_sync) (PinosServerNode *node,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
GBytes *possible_formats,
|
||||
PinosProperties *props);
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_server_node_get_type (void);
|
||||
|
||||
PinosNode * pinos_server_node_new (PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *properties);
|
||||
|
||||
PinosDaemon * pinos_server_node_get_daemon (PinosServerNode *node);
|
||||
const gchar * pinos_server_node_get_sender (PinosServerNode *node);
|
||||
const gchar * pinos_server_node_get_object_path (PinosServerNode *node);
|
||||
|
||||
PinosServerPort * pinos_server_node_create_port_sync (PinosServerNode *node,
|
||||
PinosDirection direction,
|
||||
const gchar *name,
|
||||
GBytes *possible_formats,
|
||||
PinosProperties *props);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_SERVER_NODE_H__ */
|
||||
|
|
@ -1,278 +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 <sys/socket.h>
|
||||
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/enumtypes.h"
|
||||
|
||||
#include "pinos/server/server-port.h"
|
||||
#include "pinos/server/server-node.h"
|
||||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
#define PINOS_SERVER_PORT_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_SERVER_PORT, PinosServerPortPrivate))
|
||||
|
||||
struct _PinosServerPortPrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
PinosPort1 *iface;
|
||||
gchar *object_path;
|
||||
gboolean have_sockets;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosServerPort, pinos_server_port, PINOS_TYPE_PORT);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DAEMON,
|
||||
PROP_OBJECT_PATH,
|
||||
};
|
||||
|
||||
const gchar *
|
||||
pinos_server_port_get_object_path (PinosServerPort *port)
|
||||
{
|
||||
PinosServerPortPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_SERVER_PORT (port), NULL);
|
||||
priv = port->priv;
|
||||
|
||||
return priv->object_path;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_remove (PinosPort1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosPort *port = user_data;
|
||||
|
||||
g_debug ("server-port %p: remove", port);
|
||||
pinos_port_remove (port);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("()"));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_port_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosServerPort *port = PINOS_SERVER_PORT (_object);
|
||||
PinosServerPortPrivate *priv = port->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
g_value_set_object (value, priv->daemon);
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_PATH:
|
||||
g_value_set_string (value, priv->object_path);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (port, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_port_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosServerPort *port = PINOS_SERVER_PORT (_object);
|
||||
PinosServerPortPrivate *priv = port->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
priv->daemon = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (port, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
port_register_object (PinosServerPort *port)
|
||||
{
|
||||
PinosServerPortPrivate *priv = port->priv;
|
||||
PinosObjectSkeleton *skel;
|
||||
gchar *name;
|
||||
PinosNode *node;
|
||||
|
||||
node = pinos_port_get_node (PINOS_PORT (port));
|
||||
|
||||
name = g_strdup_printf ("%s/port", pinos_server_node_get_object_path (PINOS_SERVER_NODE (node)));
|
||||
skel = pinos_object_skeleton_new (name);
|
||||
g_free (name);
|
||||
|
||||
pinos_object_skeleton_set_port1 (skel, priv->iface);
|
||||
|
||||
g_free (priv->object_path);
|
||||
priv->object_path = pinos_daemon_export_uniquely (priv->daemon,
|
||||
G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
g_debug ("server-port %p: register object %s", port, priv->object_path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
port_unregister_object (PinosServerPort *port)
|
||||
{
|
||||
PinosServerPortPrivate *priv = port->priv;
|
||||
|
||||
g_debug ("server-port %p: unregister object %s", port, priv->object_path);
|
||||
pinos_daemon_unexport (priv->daemon, priv->object_path);
|
||||
}
|
||||
|
||||
static void
|
||||
on_property_notify (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosPort *port = PINOS_PORT (obj);
|
||||
PinosServerPortPrivate *priv = PINOS_SERVER_PORT (port)->priv;
|
||||
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "node") == 0) {
|
||||
PinosServerNode *node = PINOS_SERVER_NODE (pinos_port_get_node (port));
|
||||
pinos_port1_set_node (priv->iface, pinos_server_node_get_object_path (node));
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "direction") == 0) {
|
||||
pinos_port1_set_direction (priv->iface, pinos_port_get_direction (port));
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "name") == 0) {
|
||||
pinos_port1_set_name (priv->iface, pinos_port_get_name (port));
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "properties") == 0) {
|
||||
PinosProperties *props = pinos_port_get_properties (port);
|
||||
pinos_port1_set_properties (priv->iface, props ? pinos_properties_to_variant (props) : NULL);
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "possible-formats") == 0) {
|
||||
GBytes *bytes = pinos_port_get_possible_formats (port);
|
||||
pinos_port1_set_possible_formats (priv->iface, bytes ? g_bytes_get_data (bytes, NULL) : NULL);
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "format") == 0) {
|
||||
GBytes *bytes = pinos_port_get_format (port);
|
||||
pinos_port1_set_format (priv->iface, bytes ? g_bytes_get_data (bytes, NULL) : NULL);
|
||||
}
|
||||
if (pspec == NULL || strcmp (g_param_spec_get_name (pspec), "peers") == 0) {
|
||||
const gchar *const *paths;
|
||||
g_object_get (port, "peers", &paths, NULL);
|
||||
pinos_port1_set_peers (priv->iface, paths);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_port_constructed (GObject * object)
|
||||
{
|
||||
PinosServerPort *port = PINOS_SERVER_PORT (object);
|
||||
|
||||
g_debug ("server-port %p: constructed", port);
|
||||
|
||||
g_signal_connect (port, "notify", (GCallback) on_property_notify, port);
|
||||
G_OBJECT_CLASS (pinos_server_port_parent_class)->constructed (object);
|
||||
|
||||
port_register_object (port);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_port_dispose (GObject * object)
|
||||
{
|
||||
PinosServerPort *port = PINOS_SERVER_PORT (object);
|
||||
|
||||
g_debug ("server-port %p: dispose", port);
|
||||
port_unregister_object (port);
|
||||
|
||||
G_OBJECT_CLASS (pinos_server_port_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_port_finalize (GObject * object)
|
||||
{
|
||||
PinosServerPort *port = PINOS_SERVER_PORT (object);
|
||||
PinosServerPortPrivate *priv = port->priv;
|
||||
|
||||
g_debug ("server-port %p: finalize", port);
|
||||
g_free (priv->object_path);
|
||||
g_clear_object (&priv->iface);
|
||||
g_clear_object (&priv->daemon);
|
||||
|
||||
G_OBJECT_CLASS (pinos_server_port_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_port_class_init (PinosServerPortClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
//PinosPortClass *port_class = PINOS_PORT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosServerPortPrivate));
|
||||
|
||||
gobject_class->constructed = pinos_server_port_constructed;
|
||||
gobject_class->dispose = pinos_server_port_dispose;
|
||||
gobject_class->finalize = pinos_server_port_finalize;
|
||||
gobject_class->set_property = pinos_server_port_set_property;
|
||||
gobject_class->get_property = pinos_server_port_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DAEMON,
|
||||
g_param_spec_object ("daemon",
|
||||
"Daemon",
|
||||
"The Daemon",
|
||||
PINOS_TYPE_DAEMON,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
g_param_spec_string ("object-path",
|
||||
"Object Path",
|
||||
"The object path",
|
||||
NULL,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_server_port_init (PinosServerPort * port)
|
||||
{
|
||||
PinosServerPortPrivate *priv = port->priv = PINOS_SERVER_PORT_GET_PRIVATE (port);
|
||||
|
||||
g_debug ("server-port %p: new", port);
|
||||
priv->iface = pinos_port1_skeleton_new ();
|
||||
g_signal_connect (priv->iface, "handle-remove",
|
||||
(GCallback) handle_remove,
|
||||
port);
|
||||
|
||||
}
|
||||
|
|
@ -1,71 +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_SERVER_PORT_H__
|
||||
#define __PINOS_SERVER_PORT_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosServerPort PinosServerPort;
|
||||
typedef struct _PinosServerPortClass PinosServerPortClass;
|
||||
typedef struct _PinosServerPortPrivate PinosServerPortPrivate;
|
||||
|
||||
#include <pinos/client/introspect.h>
|
||||
#include <pinos/client/port.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
|
||||
#define PINOS_TYPE_SERVER_PORT (pinos_server_port_get_type ())
|
||||
#define PINOS_IS_SERVER_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SERVER_PORT))
|
||||
#define PINOS_IS_SERVER_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_SERVER_PORT))
|
||||
#define PINOS_SERVER_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_SERVER_PORT, PinosServerPortClass))
|
||||
#define PINOS_SERVER_PORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_SERVER_PORT, PinosServerPort))
|
||||
#define PINOS_SERVER_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_SERVER_PORT, PinosServerPortClass))
|
||||
#define PINOS_SERVER_PORT_CAST(obj) ((PinosServerPort*)(obj))
|
||||
#define PINOS_SERVER_PORT_CLASS_CAST(klass)((PinosServerPortClass*)(klass))
|
||||
|
||||
/**
|
||||
* PinosServerPort:
|
||||
*
|
||||
* Pinos port object class.
|
||||
*/
|
||||
struct _PinosServerPort {
|
||||
PinosPort object;
|
||||
|
||||
PinosServerPortPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosServerPortClass:
|
||||
*
|
||||
* Pinos port object class.
|
||||
*/
|
||||
struct _PinosServerPortClass {
|
||||
PinosPortClass parent_class;
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_server_port_get_type (void);
|
||||
|
||||
const gchar * pinos_server_port_get_object_path (PinosServerPort *port);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_SERVER_PORT_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue