fix compiler warning
[ladish.git] / daemon / port.c
blob6b81ad0a75742d9068173a63c5ec4b930c5af9e2
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains the implementation of the port objects
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "port.h"
29 /* JACK port */
30 struct ladish_port
32 int refcount;
33 uuid_t uuid; /* The UUID of the port */
34 uuid_t app_uuid; /* The UUID of the app that owns this client */
35 bool link; /* Whether the port is studio-room link port */
36 uint64_t jack_id; /* JACK port ID. */
37 uint64_t jack_id_room; /* JACK port ID in room. valid only for link ports */
39 pid_t pid; /* process id. */
41 void * vgraph; /* virtual graph */
43 ladish_dict_handle dict;
46 bool
47 ladish_port_create(
48 const uuid_t uuid_ptr,
49 bool link,
50 ladish_port_handle * port_handle_ptr)
52 struct ladish_port * port_ptr;
54 port_ptr = malloc(sizeof(struct ladish_port));
55 if (port_ptr == NULL)
57 log_error("malloc() failed to allocate struct ladish_port");
58 return false;
61 if (!ladish_dict_create(&port_ptr->dict))
63 log_error("ladish_dict_create() failed for port");
64 free(port_ptr);
65 return false;
68 if (uuid_ptr == NULL)
70 uuid_generate(port_ptr->uuid);
72 else
74 uuid_copy(port_ptr->uuid, uuid_ptr);
77 uuid_clear(port_ptr->app_uuid);
79 port_ptr->jack_id = 0;
80 port_ptr->jack_id_room = 0;
81 port_ptr->link = link;
82 port_ptr->refcount = 0;
84 port_ptr->vgraph = NULL;
86 log_info("port %p created", port_ptr);
87 *port_handle_ptr = (ladish_port_handle)port_ptr;
88 return true;
91 #define port_ptr ((struct ladish_port * )port_handle)
93 bool ladish_port_create_copy(ladish_port_handle port_handle, ladish_port_handle * port_handle_ptr)
95 return ladish_port_create(port_ptr->uuid, port_ptr->link, port_handle_ptr);
98 void ladish_port_destroy(ladish_port_handle port_handle)
100 log_info("port %p destroy", port_ptr);
101 ASSERT(port_ptr->refcount == 0);
102 ladish_dict_destroy(port_ptr->dict);
103 free(port_ptr);
106 ladish_dict_handle ladish_port_get_dict(ladish_port_handle port_handle)
108 return port_ptr->dict;
111 void ladish_port_get_uuid(ladish_port_handle port_handle, uuid_t uuid)
113 uuid_copy(uuid, port_ptr->uuid);
116 void ladish_port_set_jack_id(ladish_port_handle port_handle, uint64_t jack_id)
118 log_info("port %p jack id set to %"PRIu64, port_handle, jack_id);
119 port_ptr->jack_id = jack_id;
122 uint64_t ladish_port_get_jack_id(ladish_port_handle port_handle)
124 return port_ptr->jack_id;
127 void ladish_port_set_jack_id_room(ladish_port_handle port_handle, uint64_t jack_id)
129 log_info("port %p jack id (room) set to %"PRIu64, port_handle, jack_id);
130 ASSERT(port_ptr->link);
131 port_ptr->jack_id_room = jack_id;
134 uint64_t ladish_port_get_jack_id_room(ladish_port_handle port_handle)
136 if (port_ptr->link)
138 return port_ptr->jack_id_room;
140 else
142 return port_ptr->jack_id;
146 void ladish_port_add_ref(ladish_port_handle port_handle)
148 port_ptr->refcount++;
151 void ladish_port_del_ref(ladish_port_handle port_handle)
153 ASSERT(port_ptr->refcount > 0);
154 port_ptr->refcount--;
156 if (port_ptr->refcount == 0)
158 ladish_port_destroy(port_handle);
162 bool ladish_port_is_link(ladish_port_handle port_handle)
164 return port_ptr->link;
167 void ladish_port_set_vgraph(ladish_port_handle port_handle, void * vgraph)
169 port_ptr->vgraph = vgraph;
172 void * ladish_port_get_vgraph(ladish_port_handle port_handle)
174 return port_ptr->vgraph;
177 void ladish_port_set_app(ladish_port_handle port_handle, const uuid_t app_uuid)
179 uuid_copy(port_ptr->app_uuid, app_uuid);
182 bool ladish_port_get_app(ladish_port_handle port_handle, uuid_t app_uuid)
184 if (uuid_is_null(port_ptr->app_uuid))
186 return false;
189 uuid_copy(app_uuid, port_ptr->app_uuid);
190 return true;
193 bool ladish_port_has_app(ladish_port_handle port_handle)
195 return !uuid_is_null(port_ptr->app_uuid);
198 bool ladish_port_belongs_to_app(ladish_port_handle port_handle, const uuid_t app_uuid)
200 if (uuid_is_null(port_ptr->app_uuid))
202 return false;
205 return uuid_compare(port_ptr->app_uuid, app_uuid) == 0;
208 void ladish_port_set_pid(ladish_port_handle port_handle, pid_t pid)
210 port_ptr->pid = pid;
213 pid_t ladish_port_get_pid(ladish_port_handle port_handle)
215 return port_ptr->pid;
218 #undef port_ptr