1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009 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 struct list_head siblings_studio_all
; /* link for the studio::all_clients list */
33 struct list_head siblings_room
; /* link for the room::clients list */
34 struct list_head ports
; /* List of ports that belong to the client */
35 uuid_t uuid
; /* The UUID of the client */
36 uint64_t jack_id
; /* JACK client ID */
37 char * jack_name
; /* JACK name, not valid for virtual clients */
38 bool virtual:1; /* Whether client is virtual */
39 bool link
:1; /* Whether client is a studio-room link */
40 bool system
:1; /* Whether client is system (server in-process) */
41 pid_t pid
; /* process id. Not valid for system and virtual clients */
42 struct room
* room_ptr
; /* Room this client belongs to. If NULL, client belongs only to studio guts. */
43 ladish_dict_handle dict
;
48 const uuid_t uuid_ptr
,
52 ladish_client_handle
* client_handle_ptr
)
54 struct ladish_client
* client_ptr
;
56 client_ptr
= malloc(sizeof(struct ladish_client
));
57 if (client_ptr
== NULL
)
59 log_error("malloc() failed to allocate struct ladish_client");
63 if (!ladish_dict_create(&client_ptr
->dict
))
65 log_error("ladish_dict_create() failed for client");
72 uuid_generate(client_ptr
->uuid
);
76 uuid_copy(client_ptr
->uuid
, uuid_ptr
);
79 INIT_LIST_HEAD(&client_ptr
->siblings_studio_all
);
80 INIT_LIST_HEAD(&client_ptr
->siblings_room
);
81 INIT_LIST_HEAD(&client_ptr
->ports
);
82 client_ptr
->jack_id
= 0;
83 client_ptr
->jack_name
= NULL
;
84 client_ptr
->virtual = virtual;
85 client_ptr
->link
= link
;
86 client_ptr
->system
= system
;
88 client_ptr
->room_ptr
= NULL
;
93 uuid_unparse(client_ptr
->uuid
, str
);
94 log_info("Created client %s", str
);
98 log_info("client %p created", client_ptr
);
99 *client_handle_ptr
= (ladish_client_handle
)client_ptr
;
103 #define client_ptr ((struct ladish_client *)client_handle)
106 ladish_client_destroy(
107 ladish_client_handle client_handle
)
109 log_info("client %p destroy", client_ptr
);
111 ASSERT(list_empty(&client_ptr
->ports
));
112 ASSERT(list_empty(&client_ptr
->siblings_studio_all
));
113 ASSERT(list_empty(&client_ptr
->siblings_room
));
115 ladish_dict_destroy(client_ptr
->dict
);
117 if (client_ptr
->jack_name
!= NULL
)
119 free(client_ptr
->jack_name
);
125 ladish_dict_handle
ladish_client_get_dict(ladish_client_handle client_handle
)
127 return client_ptr
->dict
;
130 void ladish_client_get_uuid(ladish_client_handle client_handle
, uuid_t uuid
)
132 uuid_copy(uuid
, client_ptr
->uuid
);
135 void ladish_client_set_jack_id(ladish_client_handle client_handle
, uint64_t jack_id
)
137 log_info("client jack id set to %"PRIu64
, jack_id
);
138 client_ptr
->jack_id
= jack_id
;
141 uint64_t ladish_client_get_jack_id(ladish_client_handle client_handle
)
143 return client_ptr
->jack_id
;