1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009, 2010 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.
33 uuid_t uuid
; /* The UUID of the port */
34 bool link
; /* Whether the port is studio-room link port */
35 uint64_t jack_id
; /* JACK port ID. */
36 uint64_t jack_id_room
; /* JACK port ID in room. valid only for link ports */
38 ladish_dict_handle dict
;
43 const uuid_t uuid_ptr
,
45 ladish_port_handle
* port_handle_ptr
)
47 struct ladish_port
* port_ptr
;
49 port_ptr
= malloc(sizeof(struct ladish_port
));
52 log_error("malloc() failed to allocate struct ladish_port");
56 if (!ladish_dict_create(&port_ptr
->dict
))
58 log_error("ladish_dict_create() failed for port");
65 uuid_generate(port_ptr
->uuid
);
69 uuid_copy(port_ptr
->uuid
, uuid_ptr
);
72 port_ptr
->jack_id
= 0;
73 port_ptr
->jack_id_room
= 0;
74 port_ptr
->link
= link
;
75 port_ptr
->refcount
= 0;
77 log_info("port %p created", port_ptr
);
78 *port_handle_ptr
= (ladish_port_handle
)port_ptr
;
82 #define port_ptr ((struct ladish_port * )port_handle)
84 bool ladish_port_create_copy(ladish_port_handle port_handle
, ladish_port_handle
* port_handle_ptr
)
86 return ladish_port_create(port_ptr
->uuid
, port_ptr
->link
, port_handle_ptr
);
89 void ladish_port_destroy(ladish_port_handle port_handle
)
91 log_info("port %p destroy", port_ptr
);
92 ASSERT(port_ptr
->refcount
== 0);
93 ladish_dict_destroy(port_ptr
->dict
);
97 ladish_dict_handle
ladish_port_get_dict(ladish_port_handle port_handle
)
99 return port_ptr
->dict
;
102 void ladish_port_get_uuid(ladish_port_handle port_handle
, uuid_t uuid
)
104 uuid_copy(uuid
, port_ptr
->uuid
);
107 void ladish_port_set_jack_id(ladish_port_handle port_handle
, uint64_t jack_id
)
109 log_info("port %p jack id set to %"PRIu64
, port_handle
, jack_id
);
110 port_ptr
->jack_id
= jack_id
;
113 uint64_t ladish_port_get_jack_id(ladish_port_handle port_handle
)
115 return port_ptr
->jack_id
;
118 void ladish_port_set_jack_id_room(ladish_port_handle port_handle
, uint64_t jack_id
)
120 log_info("port %p jack id (room) set to %"PRIu64
, port_handle
, jack_id
);
121 ASSERT(port_ptr
->link
);
122 port_ptr
->jack_id_room
= jack_id
;
125 uint64_t ladish_port_get_jack_id_room(ladish_port_handle port_handle
)
129 return port_ptr
->jack_id_room
;
133 return port_ptr
->jack_id
;
137 void ladish_port_add_ref(ladish_port_handle port_handle
)
139 port_ptr
->refcount
++;
142 void ladish_port_del_ref(ladish_port_handle port_handle
)
144 ASSERT(port_ptr
->refcount
> 0);
145 port_ptr
->refcount
--;
147 if (port_ptr
->refcount
== 0)
149 ladish_port_destroy(port_handle
);
153 bool ladish_port_is_link(ladish_port_handle port_handle
)
155 return port_ptr
->link
;