2016-11-24 17:00:42 +01: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/server/resource.h"
|
|
|
|
|
|
|
|
|
|
PinosResource *
|
|
|
|
|
pinos_resource_new (PinosClient *client,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
uint32_t type,
|
|
|
|
|
void *object,
|
|
|
|
|
PinosDestroy destroy)
|
|
|
|
|
{
|
2016-11-30 19:09:09 +01:00
|
|
|
PinosResource *this;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
this = calloc (1, sizeof (PinosResource));
|
|
|
|
|
this->core = client->core;
|
|
|
|
|
this->client = client;
|
|
|
|
|
this->id = id;
|
|
|
|
|
this->type = type;
|
|
|
|
|
this->object = object;
|
|
|
|
|
this->destroy = destroy;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
this->send_func = client->send_func;
|
|
|
|
|
this->send_data = client->send_data;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
pinos_signal_init (&this->destroy_signal);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
this->id = pinos_map_insert_new (&client->objects, this);
|
|
|
|
|
pinos_log_debug ("resource %p: new for client %p id %u", this, client, this->id);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
return this;
|
2016-11-24 17:00:42 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
static void
|
|
|
|
|
sync_destroy (void *object,
|
|
|
|
|
void *data,
|
|
|
|
|
SpaResult res,
|
|
|
|
|
uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
PinosResource *resource = object;
|
|
|
|
|
pinos_log_debug ("resource %p: sync destroy", resource);
|
|
|
|
|
free (resource);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
SpaResult
|
|
|
|
|
pinos_resource_destroy (PinosResource *resource)
|
|
|
|
|
{
|
|
|
|
|
pinos_log_debug ("resource %p: destroy", resource);
|
|
|
|
|
pinos_signal_emit (&resource->destroy_signal, resource);
|
|
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
pinos_map_remove (&resource->client->objects, resource->id);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
|
|
|
|
if (resource->destroy)
|
2016-11-30 19:09:09 +01:00
|
|
|
resource->destroy (resource);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
pinos_main_loop_defer (resource->core->main_loop,
|
|
|
|
|
resource,
|
|
|
|
|
SPA_RESULT_WAIT_SYNC,
|
|
|
|
|
sync_destroy,
|
|
|
|
|
resource);
|
2016-11-24 17:00:42 +01:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SpaResult
|
|
|
|
|
pinos_resource_send_message (PinosResource *resource,
|
2016-12-02 13:38:43 +01:00
|
|
|
uint32_t opcode,
|
2016-11-24 17:00:42 +01:00
|
|
|
void *message,
|
|
|
|
|
bool flush)
|
|
|
|
|
{
|
|
|
|
|
if (resource->send_func)
|
|
|
|
|
return resource->send_func (resource,
|
|
|
|
|
resource->id,
|
2016-12-02 13:38:43 +01:00
|
|
|
opcode,
|
2016-11-24 17:00:42 +01:00
|
|
|
message,
|
|
|
|
|
flush,
|
|
|
|
|
resource->send_data);
|
|
|
|
|
|
|
|
|
|
pinos_log_error ("resource %p: send func not implemented", resource);
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|