mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-22 08:56:59 -05:00
some more rework
This commit is contained in:
parent
ca4f3d84cd
commit
eefe6aacb9
24 changed files with 849 additions and 2829 deletions
|
|
@ -22,7 +22,6 @@
|
|||
#include "pinos/client/context.h"
|
||||
#include "pinos/client/enumtypes.h"
|
||||
#include "pinos/client/subscribe.h"
|
||||
#include "pinos/client/client-node.h"
|
||||
|
||||
#include "pinos/client/private.h"
|
||||
|
||||
|
|
@ -619,177 +618,3 @@ pinos_context_get_error (PinosContext *context)
|
|||
|
||||
return priv->error;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
gchar *factory_name;
|
||||
gchar *name;
|
||||
PinosProperties *properties;
|
||||
} CreateNodeData;
|
||||
|
||||
static void
|
||||
create_node_data_free (CreateNodeData *data)
|
||||
{
|
||||
g_free (data->factory_name);
|
||||
g_free (data->name);
|
||||
if (data->properties)
|
||||
pinos_properties_free (data->properties);
|
||||
g_slice_free (CreateNodeData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_proxy (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
PinosContext *context = g_task_get_source_object (task);
|
||||
GError *error = NULL;
|
||||
GDBusProxy *proxy;
|
||||
PinosClientNode *node;
|
||||
|
||||
proxy = pinos_subscribe_get_proxy_finish (context->priv->subscribe,
|
||||
res,
|
||||
&error);
|
||||
if (proxy == NULL)
|
||||
goto node_failed;
|
||||
|
||||
node = pinos_client_node_new (context, proxy);
|
||||
|
||||
g_task_return_pointer (task, node, (GDestroyNotify) g_object_unref);
|
||||
g_object_unref (task);
|
||||
|
||||
return;
|
||||
|
||||
node_failed:
|
||||
{
|
||||
g_warning ("failed to get node proxy: %s", error->message);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_created (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
PinosContext *context = g_task_get_source_object (task);
|
||||
GVariant *ret;
|
||||
GError *error = NULL;
|
||||
const gchar *node_path;
|
||||
|
||||
g_assert (context->priv->daemon == G_DBUS_PROXY (source_object));
|
||||
|
||||
ret = g_dbus_proxy_call_finish (context->priv->daemon, res, &error);
|
||||
if (ret == NULL)
|
||||
goto create_failed;
|
||||
|
||||
g_variant_get (ret, "(&o)", &node_path);
|
||||
|
||||
pinos_subscribe_get_proxy (context->priv->subscribe,
|
||||
PINOS_DBUS_SERVICE,
|
||||
node_path,
|
||||
"org.pinos.Node1",
|
||||
NULL,
|
||||
on_node_proxy,
|
||||
task);
|
||||
g_variant_unref (ret);
|
||||
|
||||
return;
|
||||
|
||||
/* ERRORS */
|
||||
create_failed:
|
||||
{
|
||||
g_warning ("failed to create node: %s", error->message);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
do_create_node (GTask *task)
|
||||
{
|
||||
PinosContext *context = g_task_get_source_object (task);
|
||||
CreateNodeData *data = g_task_get_task_data (task);
|
||||
|
||||
g_dbus_proxy_call (context->priv->daemon,
|
||||
"CreateNode",
|
||||
g_variant_new ("(ss@a{sv})",
|
||||
data->factory_name,
|
||||
data->name,
|
||||
pinos_properties_to_variant (data->properties)),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
NULL, /* GCancellable *cancellable */
|
||||
on_node_created,
|
||||
task);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_context_create_node:
|
||||
* @context: a #PinosContext
|
||||
* @name: the name of the Node
|
||||
* @properties: properties of the node
|
||||
* @cancelable: a #GCancellable
|
||||
* @callback: a #GAsyncReadyCallback
|
||||
* @user_data: user data.
|
||||
*
|
||||
* Asynchronously create a new node in @context.
|
||||
*/
|
||||
void
|
||||
pinos_context_create_node (PinosContext *context,
|
||||
const gchar *factory_name,
|
||||
const gchar *name,
|
||||
PinosProperties *properties,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosContextPrivate *priv;
|
||||
GTask *task;
|
||||
CreateNodeData *data;
|
||||
|
||||
g_return_if_fail (PINOS_IS_CONTEXT (context));
|
||||
priv = context->priv;
|
||||
|
||||
task = g_task_new (context,
|
||||
cancellable,
|
||||
callback,
|
||||
user_data);
|
||||
|
||||
data = g_slice_new (CreateNodeData);
|
||||
data->factory_name = g_strdup (factory_name);
|
||||
data->name = g_strdup (name);
|
||||
data->properties = pinos_properties_merge (priv->properties, properties);
|
||||
|
||||
g_task_set_task_data (task, data, (GDestroyNotify) create_node_data_free);
|
||||
|
||||
g_main_context_invoke (context->priv->context,
|
||||
(GSourceFunc) do_create_node,
|
||||
task);
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_context_create_node_finish:
|
||||
* @context: a #PinosContext
|
||||
* @res: a #GAsyncResult
|
||||
* @error: a #GError or %NULL
|
||||
*
|
||||
* Get the newly created #PinosNode. This function should be called in the callback
|
||||
* of pinos_context_create_node() to get the result or error.
|
||||
*
|
||||
* Returns: a new #PinosNode. If %NULL is returned, @error will
|
||||
* be set.
|
||||
*/
|
||||
PinosNode *
|
||||
pinos_context_create_node_finish (PinosContext *context,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue