daemon: handle jack server crashes and unexpected stops
[ladish.git] / daemon / studio_internal.h
blob043052026a1a69ee844a3bc86b67899e1c49a566
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 declaration of internal stuff used by
9 * studio object implementation
10 **************************************************************************
12 * LADI Session Handler is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * LADI Session Handler is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
24 * or write to the Free Software Foundation, Inc.,
25 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 #ifndef STUDIO_INTERNAL_H__B4CB73EC_8E89_401A_9E49_F0AEEF361D09__INCLUDED
29 #define STUDIO_INTERNAL_H__B4CB73EC_8E89_401A_9E49_F0AEEF361D09__INCLUDED
31 #include "../../proxies/jack_proxy.h"
32 #include "../dbus/error.h"
33 #include "virtualizer.h"
34 #include "app_supervisor.h"
35 #include "cmd.h"
37 #define JACK_CONF_MAX_ADDRESS_SIZE 1024
39 typedef int ladish_environment_id;
41 typedef struct
43 uint64_t state;
44 uint64_t changed;
45 } ladish_environment_store;
47 #define ladish_environment_jack_server_present ((ladish_environment_id)0)
48 #define ladish_environment_jack_server_started ((ladish_environment_id)1)
50 static inline void ladish_environment_init(ladish_environment_store * store_ptr)
52 store_ptr->state = 0;
53 store_ptr->changed = 0;
56 static inline uint64_t ladish_environment_state(ladish_environment_id id)
58 ASSERT(sizeof(id) < 8);
59 return (uint64_t)1 << id;
62 static inline void ladish_environment_set(ladish_environment_store * store_ptr, ladish_environment_id id)
64 uint64_t state = ladish_environment_state(id);
65 store_ptr->state |= state;
66 store_ptr->changed |= state;
69 static inline void ladish_environment_set_stealth(ladish_environment_store * store_ptr, ladish_environment_id id)
71 uint64_t state = ladish_environment_state(id);
72 store_ptr->state |= state;
75 static inline void ladish_environment_reset(ladish_environment_store * store_ptr, ladish_environment_id id)
77 uint64_t state = ladish_environment_state(id);
78 store_ptr->state &= ~state;
79 store_ptr->changed |= state;
82 static inline void ladish_environment_reset_stealth(ladish_environment_store * store_ptr, ladish_environment_id id)
84 uint64_t state = ladish_environment_state(id);
85 store_ptr->state &= ~state;
88 static inline bool ladish_environment_get(ladish_environment_store * store_ptr, ladish_environment_id id)
90 uint64_t state = ladish_environment_state(id);
92 return (store_ptr->state & state) == state;
95 static inline bool ladish_environment_consume_change(ladish_environment_store * store_ptr, ladish_environment_id id, bool * new_state)
97 uint64_t state = ladish_environment_state(id);
99 if ((store_ptr->changed & state) == 0)
101 return false;
104 *new_state = (store_ptr->state & state) == state;
105 store_ptr->changed &= ~state;
106 return true;
109 static inline void ladish_environment_ignore(ladish_environment_store * store_ptr, ladish_environment_id id)
111 uint64_t state = ladish_environment_state(id);
113 if ((store_ptr->changed & state) != 0)
115 store_ptr->changed &= ~state;
119 #define ladish_environment_assert_consumed(store_ptr) ASSERT((store_ptr)->changed == 0)
121 struct studio
123 struct list_head all_connections; /* All connections (studio guts and all rooms). Including superconnections. */
124 struct list_head all_ports; /* All ports (studio guts and all rooms) */
125 struct list_head all_clients; /* All clients (studio guts and all rooms) */
126 struct list_head jack_connections; /* JACK connections (studio guts and all rooms). Including superconnections, excluding virtual connections. */
127 struct list_head jack_ports; /* JACK ports (studio guts and all rooms). Excluding virtual ports. */
128 struct list_head jack_clients; /* JACK clients (studio guts and all rooms). Excluding virtual clients. */
129 struct list_head rooms; /* Rooms connected to the studio */
130 struct list_head clients; /* studio clients (studio guts and room links) */
131 struct list_head ports; /* studio ports (studio guts and room links) */
133 bool automatic:1; /* Studio was automatically created because of external JACK start */
134 bool persisted:1; /* Studio has on-disk representation, i.e. can be reloaded from disk */
135 bool modified:1; /* Studio needs saving */
136 bool jack_conf_valid:1; /* JACK server configuration obtained successfully */
138 struct list_head jack_conf; /* root of the conf tree */
139 struct list_head jack_params; /* list of conf tree leaves */
141 dbus_object_path dbus_object;
143 struct ladish_cqueue cmd_queue;
144 ladish_environment_store env_store;
146 char * name;
147 char * filename;
149 graph_proxy_handle jack_graph_proxy;
150 ladish_graph_handle jack_graph;
151 ladish_graph_handle studio_graph;
152 ladish_virtualizer_handle virtualizer;
153 ladish_app_supervisor_handle app_supervisor;
156 struct jack_conf_parameter
158 struct list_head siblings; /* siblings in container children list */
159 struct list_head leaves; /* studio::jack_param siblings */
160 char * name;
161 struct jack_conf_container * parent_ptr;
162 char address[JACK_CONF_MAX_ADDRESS_SIZE];
163 struct jack_parameter_variant parameter;
166 struct jack_conf_container
168 struct list_head siblings;
169 char * name;
170 struct jack_conf_container * parent_ptr;
171 bool children_leafs; /* if true, children are "jack_conf_parameter"s, if false, children are "jack_conf_container"s */
172 struct list_head children;
175 struct conf_callback_context
177 char address[JACK_CONF_MAX_ADDRESS_SIZE];
178 struct list_head * container_ptr;
179 struct jack_conf_container * parent_ptr;
182 extern struct studio g_studio;
184 extern const struct dbus_interface_descriptor g_interface_studio;
186 void jack_conf_clear(void);
187 bool studio_fetch_jack_settings(void);
188 bool studio_compose_filename(const char * name, char ** filename_ptr_ptr, char ** backup_filename_ptr_ptr);
189 bool studio_publish(void);
190 bool studio_name_generate(char ** name_ptr);
191 bool studio_is_started(void);
192 void emit_studio_started(void);
193 void emit_studio_stopped(void);
194 void emit_studio_renamed(void);
195 void on_event_jack_started(void);
196 void on_event_jack_stopped(void);
198 #endif /* #ifndef STUDIO_INTERNAL_H__B4CB73EC_8E89_401A_9E49_F0AEEF361D09__INCLUDED */