2016-07-20 17:29:34 +02:00
|
|
|
/* 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"
|
2016-11-24 17:00:42 +01:00
|
|
|
#include "pinos/server/resource.h"
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
typedef struct
|
2016-07-20 17:29:34 +02:00
|
|
|
{
|
2016-11-14 12:42:00 +01:00
|
|
|
PinosClient this;
|
2016-11-10 15:42:14 +01:00
|
|
|
} PinosClientImpl;
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-12-02 13:38:43 +01:00
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
client_dispatch_func (void *object,
|
|
|
|
|
PinosMessageType type,
|
|
|
|
|
void *message,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
PinosResource *resource = object;
|
|
|
|
|
PinosClient *client = resource->object;
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
default:
|
|
|
|
|
pinos_log_warn ("client %p: unhandled message %d", client, type);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
client_bind_func (PinosGlobal *global,
|
|
|
|
|
PinosClient *client,
|
|
|
|
|
uint32_t version,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
PinosClient *this = global->object;
|
|
|
|
|
PinosResource *resource;
|
|
|
|
|
PinosMessageClientInfo m;
|
|
|
|
|
PinosClientInfo info;
|
|
|
|
|
|
|
|
|
|
resource = pinos_resource_new (client,
|
|
|
|
|
id,
|
|
|
|
|
global->core->uri.client,
|
|
|
|
|
global->object,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
resource->dispatch_func = client_dispatch_func;
|
|
|
|
|
resource->dispatch_data = global;
|
|
|
|
|
|
|
|
|
|
pinos_log_debug ("client %p: bound to %d", global->object, resource->id);
|
|
|
|
|
|
|
|
|
|
m.info = &info;
|
|
|
|
|
info.id = resource->id;
|
|
|
|
|
info.change_mask = ~0;
|
|
|
|
|
info.props = this->properties ? &this->properties->dict : NULL;
|
|
|
|
|
|
|
|
|
|
pinos_resource_send_message (resource,
|
|
|
|
|
PINOS_MESSAGE_CLIENT_INFO,
|
|
|
|
|
&m,
|
|
|
|
|
true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 17:29:34 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_client_new:
|
|
|
|
|
* @daemon: a #PinosDaemon
|
|
|
|
|
* @properties: extra client properties
|
|
|
|
|
*
|
2016-11-16 16:57:47 +01:00
|
|
|
* Make a new #PinosClient object and register it to @core
|
2016-07-20 17:29:34 +02:00
|
|
|
*
|
|
|
|
|
* Returns: a new #PinosClient
|
|
|
|
|
*/
|
|
|
|
|
PinosClient *
|
2016-11-10 15:42:14 +01:00
|
|
|
pinos_client_new (PinosCore *core,
|
2016-07-20 17:29:34 +02:00
|
|
|
PinosProperties *properties)
|
|
|
|
|
{
|
2016-11-14 12:42:00 +01:00
|
|
|
PinosClient *this;
|
2016-11-10 15:42:14 +01:00
|
|
|
PinosClientImpl *impl;
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
impl = calloc (1, sizeof (PinosClientImpl));
|
|
|
|
|
pinos_log_debug ("client %p: new", impl);
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
this = &impl->this;
|
|
|
|
|
this->core = core;
|
|
|
|
|
this->properties = properties;
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
pinos_map_init (&this->objects, 64);
|
2016-11-14 12:42:00 +01:00
|
|
|
pinos_signal_init (&this->destroy_signal);
|
2016-07-20 17:29:34 +02:00
|
|
|
|
2016-11-15 20:12:31 +01:00
|
|
|
spa_list_insert (core->client_list.prev, &this->link);
|
2016-09-16 13:13:41 +02:00
|
|
|
|
2016-11-16 16:57:47 +01:00
|
|
|
this->global = pinos_core_add_global (core,
|
2016-11-21 16:29:15 +01:00
|
|
|
core->uri.client,
|
2016-12-02 13:38:43 +01:00
|
|
|
0,
|
|
|
|
|
this,
|
|
|
|
|
client_bind_func);
|
2016-11-16 16:57:47 +01:00
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
return this;
|
2016-09-16 13:13:41 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
static void
|
|
|
|
|
sync_destroy (void *object,
|
|
|
|
|
void *data,
|
|
|
|
|
SpaResult res,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
PinosClientImpl *impl = SPA_CONTAINER_OF (object, PinosClientImpl, this);
|
|
|
|
|
PinosClient *client = &impl->this;
|
|
|
|
|
|
|
|
|
|
pinos_log_debug ("client %p: sync destroy", impl);
|
|
|
|
|
|
|
|
|
|
if (client->properties)
|
|
|
|
|
pinos_properties_free (client->properties);
|
|
|
|
|
|
|
|
|
|
free (impl);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
static void
|
|
|
|
|
destroy_resource (void *object,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
pinos_resource_destroy (object);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 17:29:34 +02:00
|
|
|
/**
|
2016-11-10 15:42:14 +01:00
|
|
|
* pinos_client_destroy:
|
2016-07-20 17:29:34 +02:00
|
|
|
* @client: a #PinosClient
|
|
|
|
|
*
|
2016-11-10 15:42:14 +01:00
|
|
|
* Trigger removal of @client
|
2016-07-20 17:29:34 +02:00
|
|
|
*/
|
2016-11-25 13:06:23 +01:00
|
|
|
void
|
2016-11-14 12:42:00 +01:00
|
|
|
pinos_client_destroy (PinosClient * client)
|
2016-07-20 17:29:34 +02:00
|
|
|
{
|
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);
|
|
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
pinos_map_for_each (&client->objects, destroy_resource, client);
|
2016-11-14 12:42:00 +01:00
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
pinos_global_destroy (client->global);
|
2016-11-15 20:12:31 +01:00
|
|
|
spa_list_remove (&client->link);
|
2016-11-14 12:42:00 +01:00
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
pinos_main_loop_defer (client->core->main_loop,
|
|
|
|
|
client,
|
|
|
|
|
SPA_RESULT_WAIT_SYNC,
|
|
|
|
|
sync_destroy,
|
|
|
|
|
client);
|
2016-07-20 17:29:34 +02:00
|
|
|
}
|