pipewire/pinos/server/node-factory.c

182 lines
5.2 KiB
C
Raw Normal View History

/* Pinos
* Copyright (C) 2016 Axis Communications AB
*
* 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 "pinos/client/pinos.h"
#include "pinos/server/node-factory.h"
#define PINOS_NODE_FACTORY_GET_PRIVATE(factory) \
(G_TYPE_INSTANCE_GET_PRIVATE ((factory), PINOS_TYPE_NODE_FACTORY, PinosNodeFactoryPrivate))
struct _PinosNodeFactoryPrivate
{
gchar *name;
};
G_DEFINE_ABSTRACT_TYPE (PinosNodeFactory, pinos_node_factory, G_TYPE_OBJECT);
enum
{
PROP_0,
PROP_NAME,
};
static void
pinos_node_factory_get_property (GObject *_object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PinosNodeFactory *factory = PINOS_NODE_FACTORY (_object);
PinosNodeFactoryPrivate *priv = factory->priv;
switch (prop_id) {
case PROP_NAME:
g_value_set_string (value, priv->name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (factory, prop_id, pspec);
break;
}
}
static void
pinos_node_factory_set_property (GObject *_object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PinosNodeFactory *factory = PINOS_NODE_FACTORY (_object);
PinosNodeFactoryPrivate *priv = factory->priv;
switch (prop_id) {
case PROP_NAME:
priv->name = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (factory, prop_id, pspec);
break;
}
}
static void
pinos_node_factory_constructed (GObject * obj)
{
PinosNodeFactory *factory = PINOS_NODE_FACTORY (obj);
g_debug ("node factory %p: constructed", factory);
G_OBJECT_CLASS (pinos_node_factory_parent_class)->constructed (obj);
}
static void
pinos_node_factory_finalize (GObject * obj)
{
PinosNodeFactory *factory = PINOS_NODE_FACTORY (obj);
PinosNodeFactoryPrivate *priv = factory->priv;
g_debug ("node factory %p: finalize", factory);
g_free (priv->name);
G_OBJECT_CLASS (pinos_node_factory_parent_class)->finalize (obj);
}
static void
pinos_node_factory_class_init (PinosNodeFactoryClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (PinosNodeFactoryPrivate));
gobject_class->constructed = pinos_node_factory_constructed;
gobject_class->finalize = pinos_node_factory_finalize;
gobject_class->set_property = pinos_node_factory_set_property;
gobject_class->get_property = pinos_node_factory_get_property;
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name",
"Name",
"The node factory name",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}
static void
pinos_node_factory_init (PinosNodeFactory * factory)
{
factory->priv = PINOS_NODE_FACTORY_GET_PRIVATE (factory);
g_debug ("node_factory %p: new", factory);
}
/**
* pinos_node_factory_get_name:
* @factory: a #PinosNodeFactory
*
* Get the name of @factory
*
* Returns: the name of @factory
*/
const gchar *
pinos_node_factory_get_name (PinosNodeFactory *factory)
{
PinosNodeFactoryPrivate *priv;
g_return_val_if_fail (PINOS_IS_NODE_FACTORY (factory), NULL);
priv = factory->priv;
return priv->name;
}
/**
* pinos_node_factory_create_node:
* @factory: A #PinosNodeFactory
* @daemon: a #PinosDaemon
* @sender: the path of the owner
* @name: node name
* @props: #PinosProperties for the node
*
* Create a #PinosNode
*
* Returns: (transfer full) (nullable): a new #PinosNode.
*/
PinosNode *
pinos_node_factory_create_node (PinosNodeFactory *factory,
PinosDaemon *daemon,
const gchar *sender,
const gchar *name,
PinosProperties *props)
{
PinosNodeFactoryClass *klass;
g_return_val_if_fail (PINOS_IS_NODE_FACTORY (factory), NULL);
klass = PINOS_NODE_FACTORY_GET_CLASS (factory);
if (!klass->create_node)
return NULL;
g_debug ("node factory %p: create node", factory);
return klass->create_node (factory, daemon, sender, name, props);
}