1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains the implementation of the port objects
**************************************************************************
*
* LADI Session Handler is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LADI Session Handler 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "port.h"
/* JACK port */
struct ladish_port
{
int refcount;
uuid_t uuid; /* The UUID of the port */
uuid_t app_uuid; /* The UUID of the app that owns this client */
bool link; /* Whether the port is studio-room link port */
uint64_t jack_id; /* JACK port ID. */
uint64_t jack_id_room; /* JACK port ID in room. valid only for link ports */
pid_t pid; /* process id. */
void * vgraph; /* virtual graph */
ladish_dict_handle dict;
};
bool
ladish_port_create(
const uuid_t uuid_ptr,
bool link,
ladish_port_handle * port_handle_ptr)
{
struct ladish_port * port_ptr;
port_ptr = malloc(sizeof(struct ladish_port));
if (port_ptr == NULL)
{
log_error("malloc() failed to allocate struct ladish_port");
return false;
}
if (!ladish_dict_create(&port_ptr->dict))
{
log_error("ladish_dict_create() failed for port");
free(port_ptr);
return false;
}
if (uuid_ptr == NULL)
{
uuid_generate(port_ptr->uuid);
}
else
{
uuid_copy(port_ptr->uuid, uuid_ptr);
}
uuid_clear(port_ptr->app_uuid);
port_ptr->jack_id = 0;
port_ptr->jack_id_room = 0;
port_ptr->link = link;
port_ptr->refcount = 0;
port_ptr->vgraph = NULL;
log_info("port %p created", port_ptr);
*port_handle_ptr = (ladish_port_handle)port_ptr;
return true;
}
#define port_ptr ((struct ladish_port * )port_handle)
bool ladish_port_create_copy(ladish_port_handle port_handle, ladish_port_handle * port_handle_ptr)
{
return ladish_port_create(port_ptr->uuid, port_ptr->link, port_handle_ptr);
}
void ladish_port_destroy(ladish_port_handle port_handle)
{
log_info("port %p destroy", port_ptr);
ASSERT(port_ptr->refcount == 0);
ladish_dict_destroy(port_ptr->dict);
free(port_ptr);
}
ladish_dict_handle ladish_port_get_dict(ladish_port_handle port_handle)
{
return port_ptr->dict;
}
void ladish_port_get_uuid(ladish_port_handle port_handle, uuid_t uuid)
{
uuid_copy(uuid, port_ptr->uuid);
}
void ladish_port_set_jack_id(ladish_port_handle port_handle, uint64_t jack_id)
{
log_info("port %p jack id set to %"PRIu64, port_handle, jack_id);
port_ptr->jack_id = jack_id;
}
uint64_t ladish_port_get_jack_id(ladish_port_handle port_handle)
{
return port_ptr->jack_id;
}
void ladish_port_set_jack_id_room(ladish_port_handle port_handle, uint64_t jack_id)
{
log_info("port %p jack id (room) set to %"PRIu64, port_handle, jack_id);
ASSERT(port_ptr->link);
port_ptr->jack_id_room = jack_id;
}
uint64_t ladish_port_get_jack_id_room(ladish_port_handle port_handle)
{
if (port_ptr->link)
{
return port_ptr->jack_id_room;
}
else
{
return port_ptr->jack_id;
}
}
void ladish_port_add_ref(ladish_port_handle port_handle)
{
port_ptr->refcount++;
}
void ladish_port_del_ref(ladish_port_handle port_handle)
{
ASSERT(port_ptr->refcount > 0);
port_ptr->refcount--;
if (port_ptr->refcount == 0)
{
ladish_port_destroy(port_handle);
}
}
bool ladish_port_is_link(ladish_port_handle port_handle)
{
return port_ptr->link;
}
void ladish_port_set_vgraph(ladish_port_handle port_handle, void * vgraph)
{
port_ptr->vgraph = vgraph;
}
void * ladish_port_get_vgraph(ladish_port_handle port_handle)
{
return port_ptr->vgraph;
}
void ladish_port_set_app(ladish_port_handle port_handle, const uuid_t app_uuid)
{
uuid_copy(port_ptr->app_uuid, app_uuid);
}
bool ladish_port_get_app(ladish_port_handle port_handle, uuid_t app_uuid)
{
if (uuid_is_null(port_ptr->app_uuid))
{
return false;
}
uuid_copy(app_uuid, port_ptr->app_uuid);
return true;
}
bool ladish_port_has_app(ladish_port_handle port_handle)
{
return !uuid_is_null(port_ptr->app_uuid);
}
bool ladish_port_belongs_to_app(ladish_port_handle port_handle, const uuid_t app_uuid)
{
if (uuid_is_null(port_ptr->app_uuid))
{
return false;
}
return uuid_compare(port_ptr->app_uuid, app_uuid) == 0;
}
void ladish_port_set_pid(ladish_port_handle port_handle, pid_t pid)
{
port_ptr->pid = pid;
}
pid_t ladish_port_get_pid(ladish_port_handle port_handle)
{
return port_ptr->pid;
}
#undef port_ptr
|