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 client 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.
32 uuid_t uuid
; /* The UUID of the client */
33 uuid_t uuid_interlink
; /* The UUID of the linked client (vgraph <-> jack graph) */
34 uuid_t uuid_app
; /* The UUID of the app that owns this client */
35 uint64_t jack_id
; /* JACK client ID */
36 pid_t pid
; /* process id. */
37 ladish_dict_handle dict
;
38 void * vgraph
; /* virtual graph */
43 const uuid_t uuid_ptr
,
44 ladish_client_handle
* client_handle_ptr
)
46 struct ladish_client
* client_ptr
;
48 client_ptr
= malloc(sizeof(struct ladish_client
));
49 if (client_ptr
== NULL
)
51 log_error("malloc() failed to allocate struct ladish_client");
55 if (!ladish_dict_create(&client_ptr
->dict
))
57 log_error("ladish_dict_create() failed for client");
64 uuid_generate(client_ptr
->uuid
);
68 uuid_copy(client_ptr
->uuid
, uuid_ptr
);
71 uuid_clear(client_ptr
->uuid_interlink
);
72 uuid_clear(client_ptr
->uuid_app
);
74 client_ptr
->jack_id
= 0;
76 client_ptr
->vgraph
= NULL
;
81 uuid_unparse(client_ptr
->uuid
, str
);
82 log_info("Created client %s", str
);
86 log_info("client %p created", client_ptr
);
87 *client_handle_ptr
= (ladish_client_handle
)client_ptr
;
91 #define client_ptr ((struct ladish_client *)client_handle)
94 ladish_client_create_copy(
95 ladish_client_handle client_handle
,
96 ladish_client_handle
* client_handle_ptr
)
98 return ladish_client_create(client_ptr
->uuid
, client_handle_ptr
);
102 ladish_client_destroy(
103 ladish_client_handle client_handle
)
105 log_info("client %p destroy", client_ptr
);
107 ladish_dict_destroy(client_ptr
->dict
);
112 ladish_dict_handle
ladish_client_get_dict(ladish_client_handle client_handle
)
114 return client_ptr
->dict
;
117 void ladish_client_get_uuid(ladish_client_handle client_handle
, uuid_t uuid
)
119 uuid_copy(uuid
, client_ptr
->uuid
);
122 void ladish_client_set_jack_id(ladish_client_handle client_handle
, uint64_t jack_id
)
124 log_info("client jack id set to %"PRIu64
, jack_id
);
125 client_ptr
->jack_id
= jack_id
;
128 uint64_t ladish_client_get_jack_id(ladish_client_handle client_handle
)
130 return client_ptr
->jack_id
;
133 void ladish_client_set_pid(ladish_client_handle client_handle
, pid_t pid
)
135 client_ptr
->pid
= pid
;
138 pid_t
ladish_client_get_pid(ladish_client_handle client_handle
)
140 return client_ptr
->pid
;
143 void ladish_client_set_vgraph(ladish_client_handle client_handle
, void * vgraph
)
145 client_ptr
->vgraph
= vgraph
;
148 void * ladish_client_get_vgraph(ladish_client_handle client_handle
)
150 return client_ptr
->vgraph
;
153 #define client2_ptr ((struct ladish_client *)client2_handle)
155 void ladish_client_interlink(ladish_client_handle client_handle
, ladish_client_handle client2_handle
)
157 uuid_copy(client_ptr
->uuid_interlink
, client2_ptr
->uuid
);
158 uuid_copy(client2_ptr
->uuid_interlink
, client_ptr
->uuid
);
163 bool ladish_client_get_interlink(ladish_client_handle client_handle
, uuid_t uuid
)
165 if (uuid_is_null(client_ptr
->uuid_interlink
))
170 uuid_copy(uuid
, client_ptr
->uuid_interlink
);
174 void ladish_client_clear_interlink(ladish_client_handle client_handle
)
176 uuid_clear(client_ptr
->uuid_interlink
);
179 void ladish_client_set_app(ladish_client_handle client_handle
, const uuid_t uuid
)
181 uuid_copy(client_ptr
->uuid_app
, uuid
);
184 bool ladish_client_get_app(ladish_client_handle client_handle
, uuid_t uuid
)
186 if (uuid_is_null(client_ptr
->uuid_app
))
191 uuid_copy(uuid
, client_ptr
->uuid_app
);
195 bool ladish_client_has_app(ladish_client_handle client_handle
)
197 return !uuid_is_null(client_ptr
->uuid_app
);