pipewire/pinos/server/client.c

95 lines
2.4 KiB
C
Raw Normal View History

/* 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 "pinos/client/pinos.h"
#include "pinos/server/client.h"
#include "pinos/server/resource.h"
2016-11-10 15:42:14 +01:00
typedef struct
{
2016-11-14 12:42:00 +01:00
PinosClient this;
2016-11-10 15:42:14 +01:00
} PinosClientImpl;
/**
* pinos_client_new:
* @daemon: a #PinosDaemon
* @properties: extra client properties
*
* Make a new #PinosClient object and register it to @core
*
* Returns: a new #PinosClient
*/
PinosClient *
2016-11-10 15:42:14 +01:00
pinos_client_new (PinosCore *core,
PinosProperties *properties)
{
2016-11-14 12:42:00 +01:00
PinosClient *this;
2016-11-10 15:42:14 +01:00
PinosClientImpl *impl;
2016-11-14 12:42:00 +01:00
impl = calloc (1, sizeof (PinosClientImpl));
pinos_log_debug ("client %p: new", impl);
2016-11-14 12:42:00 +01:00
this = &impl->this;
this->core = core;
this->properties = properties;
2016-11-15 17:06:09 +01:00
spa_list_init (&this->resource_list);
2016-11-14 12:42:00 +01:00
pinos_signal_init (&this->destroy_signal);
spa_list_insert (core->client_list.prev, &this->link);
this->global = pinos_core_add_global (core,
core->uri.client,
this);
2016-11-14 12:42:00 +01:00
return this;
}
/**
2016-11-10 15:42:14 +01:00
* pinos_client_destroy:
* @client: a #PinosClient
*
2016-11-10 15:42:14 +01:00
* Trigger removal of @client
*/
2016-11-15 17:06:09 +01:00
SpaResult
2016-11-14 12:42:00 +01:00
pinos_client_destroy (PinosClient * client)
{
2016-11-14 12:42:00 +01:00
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, this);
2016-11-15 17:06:09 +01:00
PinosResource *resource, *tmp;
2016-11-10 15:42:14 +01:00
pinos_log_debug ("client %p: destroy", client);
2016-11-14 12:42:00 +01:00
pinos_signal_emit (&client->destroy_signal, client);
pinos_global_destroy (client->global);
2016-11-15 17:06:09 +01:00
spa_list_for_each_safe (resource, tmp, &client->resource_list, link)
pinos_resource_destroy (resource);
2016-11-14 12:42:00 +01:00
spa_list_remove (&client->link);
2016-11-14 12:42:00 +01:00
if (client->properties)
pinos_properties_free (client->properties);
free (impl);
2016-11-15 17:06:09 +01:00
return SPA_RESULT_OK;
}