gui: remove unused and duplicate dbus helper code
[ladish.git] / daemon / port.c
blob70d8a743973d71e49b41e125bb124bf23c2e1fc3
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009 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 or virtual port */
30 struct ladish_port
32 struct list_head siblings_studio_all; /* link for the studio::all_ports list */
33 struct list_head siblings_studio; /* link for the studio::ports list */
34 struct list_head siblings_room; /* link for the room::ports list */
35 struct list_head siblings_client; /* link for the port list of the client */
36 struct list_head siblings_vclient; /* link for the port list of the virtual client */
38 uuid_t uuid; /* The UUID of the port */
39 bool virtual; /* Whether the port is virtual or JACK port */
40 char * jack_name; /* JACK name (short). Not valid for virtual ports. */
41 uint64_t jack_id; /* JACK port ID. Not valid for virtual ports. */
42 char * human_name; /* User assigned name */
44 struct client * client_ptr; /* JACK client this port belongs to. Not valid for virtual ports. */
45 struct client * vclient_ptr; /* Virtual client this port belongs to. NULL if there is no virtual client associated. */
47 /* superconnections are not in these lists */
48 struct list_head input_connections; /* list of input connections, i.e. connections that play to this port */
49 struct list_head output_connections; /* list of output connections, i.e. connections that capture from this port */
51 ladish_dict_handle dict;
54 bool
55 ladish_port_create(
56 uuid_t uuid_ptr,
57 ladish_port_handle * port_handle_ptr)
59 struct ladish_port * port_ptr;
61 port_ptr = malloc(sizeof(struct ladish_port));
62 if (port_ptr == NULL)
64 log_error("malloc() failed to allocate struct ladish_port");
65 return false;
68 if (!ladish_dict_create(&port_ptr->dict))
70 log_error("ladish_dict_create() failed for port");
71 free(port_ptr);
72 return false;
75 if (uuid_ptr == NULL)
77 uuid_generate(port_ptr->uuid);
79 else
81 uuid_copy(port_ptr->uuid, uuid_ptr);
84 INIT_LIST_HEAD(&port_ptr->siblings_studio_all);
85 INIT_LIST_HEAD(&port_ptr->siblings_room);
86 port_ptr->jack_id = 0;
87 port_ptr->jack_name = NULL;
88 port_ptr->human_name = NULL;
89 port_ptr->virtual = true;
91 log_info("port %p created", port_ptr);
92 *port_handle_ptr = (ladish_port_handle)port_ptr;
93 return true;
96 #define port_ptr ((struct ladish_port * )port_handle)
98 void ladish_port_destroy(ladish_port_handle port_handle)
100 log_info("port %p destroy", port_ptr);
101 ladish_dict_destroy(port_ptr->dict);
102 free(port_ptr);
105 ladish_dict_handle ladish_port_get_dict(ladish_port_handle port_handle)
107 return port_ptr->dict;
110 void ladish_port_get_uuid(ladish_port_handle port_handle, uuid_t uuid)
112 uuid_copy(uuid, port_ptr->uuid);
115 void ladish_port_set_jack_id(ladish_port_handle port_handle, uint64_t jack_id)
117 log_info("port jack id set to %"PRIu64, jack_id);
118 port_ptr->jack_id = jack_id;
121 uint64_t ladish_port_get_jack_id(ladish_port_handle port_handle)
123 return port_ptr->jack_id;
126 #undef port_ptr