mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
node-factory: a class for creating nodes
This commit is contained in:
parent
6fcd0985a3
commit
90dbf50042
3 changed files with 263 additions and 0 deletions
|
|
@ -215,6 +215,7 @@ libpinoscore_@PINOS_MAJORMINOR@_la_SOURCES = \
|
|||
server/daemon.c server/daemon.h \
|
||||
server/server-node.c server/server-node.h \
|
||||
server/server-port.c server/server-port.h \
|
||||
server/node-factory.c server/node-factory.h \
|
||||
modules/gst/gst-manager.c modules/gst/gst-manager.h \
|
||||
modules/gst/gst-source.c modules/gst/gst-source.h \
|
||||
modules/gst/gst-sink.c modules/gst/gst-sink.h \
|
||||
|
|
|
|||
181
pinos/server/node-factory.c
Normal file
181
pinos/server/node-factory.c
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
/* 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);
|
||||
}
|
||||
81
pinos/server/node-factory.h
Normal file
81
pinos/server/node-factory.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef __PINOS_NODE_FACTORY_H__
|
||||
#define __PINOS_NODE_FACTORY_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosNodeFactory PinosNodeFactory;
|
||||
typedef struct _PinosNodeFactoryClass PinosNodeFactoryClass;
|
||||
typedef struct _PinosNodeFactoryPrivate PinosNodeFactoryPrivate;
|
||||
|
||||
#include <server/daemon.h>
|
||||
|
||||
#define PINOS_TYPE_NODE_FACTORY (pinos_node_factory_get_type ())
|
||||
#define PINOS_IS_NODE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_NODE_FACTORY))
|
||||
#define PINOS_IS_NODE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_NODE_FACTORY))
|
||||
#define PINOS_NODE_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_NODE_FACTORY, PinosNodeFactoryClass))
|
||||
#define PINOS_NODE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_NODE_FACTORY, PinosNodeFactory))
|
||||
#define PINOS_NODE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_NODE_FACTORY, PinosNodeFactoryClass))
|
||||
#define PINOS_NODE_FACTORY_CAST(obj) ((PinosNodeFactory*)(obj))
|
||||
#define PINOS_NODE_FACTORY_CLASS_CAST(klass) ((PinosNodeFactoryClass*)(klass))
|
||||
|
||||
/**
|
||||
* PinosNodeFactory:
|
||||
*
|
||||
* Pinos node factory class.
|
||||
*/
|
||||
struct _PinosNodeFactory {
|
||||
GObject object;
|
||||
|
||||
PinosNodeFactoryPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* PinosNodeFactoryClass:
|
||||
* @create_node: make a new node
|
||||
*
|
||||
* Pinos node factory class.
|
||||
*/
|
||||
struct _PinosNodeFactoryClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
PinosNode * (*create_node) (PinosNodeFactory *factory,
|
||||
PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *properties);
|
||||
};
|
||||
|
||||
/* normal GObject stuff */
|
||||
GType pinos_node_factory_get_type (void);
|
||||
|
||||
const gchar * pinos_node_factory_get_name (PinosNodeFactory *node_factory);
|
||||
PinosNode * pinos_node_factory_create_node (PinosNodeFactory *factory,
|
||||
PinosDaemon *daemon,
|
||||
const gchar *sender,
|
||||
const gchar *name,
|
||||
PinosProperties *props);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_NODE_FACTORY_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue