Move jack handling into studio object; fix race
[ladish.git] / daemon / control.c
blob99d889eb1581d8ce5ab174862478d9c3db6ae119
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
8 **************************************************************************
9 * This file contains code of the D-Bus control interface helpers
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 #include "common.h"
30 #include "../dbus/interface.h"
31 #include "../dbus/error.h"
32 #include "control.h"
33 #include "../dbus_constants.h"
35 #define INTERFACE_NAME IFACE_CONTROL
37 static void ladish_is_studio_loaded(method_call_t * call_ptr)
39 DBusMessageIter iter;
40 dbus_bool_t is_loaded;
42 is_loaded = studio_is_loaded();
44 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
45 if (call_ptr->reply == NULL)
47 goto fail;
50 dbus_message_iter_init_append(call_ptr->reply, &iter);
52 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &is_loaded))
54 goto fail_unref;
57 return;
59 fail_unref:
60 dbus_message_unref(call_ptr->reply);
61 call_ptr->reply = NULL;
63 fail:
64 lash_error("Ran out of memory trying to construct method return");
67 static void ladish_get_studio_list(method_call_t * call_ptr)
69 DBusMessageIter iter, array_iter;
70 //DBusMessageIter struct_iter, dict_iter;
71 //struct list_head * node_ptr;
72 //project_t * project_ptr;
74 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
75 if (call_ptr->reply == NULL)
77 goto fail;
80 dbus_message_iter_init_append(call_ptr->reply, &iter);
82 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sa{sv})", &array_iter))
84 goto fail_unref;
87 #if 0
88 list_for_each (node_ptr, &g_server->all_projects)
90 project_ptr = list_entry(node_ptr, project_t, siblings_all);
92 if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
93 goto fail_unref;
95 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &project_ptr->name))
97 dbus_message_iter_close_container(&iter, &array_iter);
98 goto fail_unref;
101 if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
102 goto fail_unref;
104 if (!maybe_add_dict_entry_string(&dict_iter, "Description", project_ptr->description))
105 goto fail_unref;
107 if (!add_dict_entry_uint32(&dict_iter, "Modification Time", project_ptr->last_modify_time))
108 goto fail_unref;
110 if (!dbus_message_iter_close_container(&struct_iter, &dict_iter))
111 goto fail_unref;
113 if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
114 goto fail_unref;
116 #endif
118 if (!dbus_message_iter_close_container(&iter, &array_iter))
120 goto fail_unref;
123 return;
125 fail_unref:
126 dbus_message_unref(call_ptr->reply);
127 call_ptr->reply = NULL;
129 fail:
130 lash_error("Ran out of memory trying to construct method return");
133 static void ladish_load_studio(method_call_t * call_ptr)
135 const char * name;
137 dbus_error_init(&g_dbus_error);
139 if (!dbus_message_get_args(call_ptr->message, &g_dbus_error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
141 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
142 dbus_error_free(&g_dbus_error);
143 return;
146 lash_info("Loading studio '%s'", name);
149 static void ladish_get_application_list(method_call_t * call_ptr)
151 DBusMessageIter iter;
152 DBusMessageIter array_iter;
153 #if 0
154 DBusMessageIter struct_iter;
155 DBusMessageIter dict_iter;
156 struct list_head * node_ptr;
157 struct lash_appdb_entry * entry_ptr;
158 #endif
160 lash_info("Getting applications list");
162 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
163 if (call_ptr->reply == NULL)
165 goto fail;
168 dbus_message_iter_init_append(call_ptr->reply, &iter);
170 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sa{sv})", &array_iter))
172 goto fail_unref;
175 #if 0
176 list_for_each(node_ptr, &g_server->appdb)
178 entry_ptr = list_entry(node_ptr, struct lash_appdb_entry, siblings);
180 if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
181 goto fail_unref;
183 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, (const void *) &entry_ptr->name))
185 dbus_message_iter_close_container(&iter, &array_iter);
186 goto fail_unref;
189 if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
190 goto fail_unref;
192 if (!maybe_add_dict_entry_string(&dict_iter, "GenericName", entry_ptr->generic_name))
193 goto fail_unref;
195 if (!maybe_add_dict_entry_string(&dict_iter, "Comment", entry_ptr->comment))
196 goto fail_unref;
198 if (!maybe_add_dict_entry_string(&dict_iter, "Icon", entry_ptr->icon))
199 goto fail_unref;
201 if (!dbus_message_iter_close_container(&struct_iter, &dict_iter))
202 goto fail_unref;
204 if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
205 goto fail_unref;
207 #endif
209 if (!dbus_message_iter_close_container(&iter, &array_iter))
211 goto fail_unref;
214 return;
216 fail_unref:
217 dbus_message_unref(call_ptr->reply);
218 call_ptr->reply = NULL;
219 fail:
220 return;
223 static void ladish_exit(method_call_t * call_ptr)
225 lash_info("Exit command received through D-Bus");
226 g_quit = true;
229 void emit_studio_appeared()
231 signal_new_valist(g_dbus_connection, CONTROL_OBJECT_PATH, INTERFACE_NAME, "StudioAppeared", DBUS_TYPE_INVALID);
234 void emit_studio_disappeared()
236 signal_new_valist(g_dbus_connection, CONTROL_OBJECT_PATH, INTERFACE_NAME, "StudioDisappeared", DBUS_TYPE_INVALID);
239 METHOD_ARGS_BEGIN(IsStudioLoaded, "Check whether studio D-Bus object is present")
240 METHOD_ARG_DESCRIBE_OUT("present", "b", "Whether studio D-Bus object is present")
241 METHOD_ARGS_END
243 METHOD_ARGS_BEGIN(GetStudioList, "Get list of studios")
244 METHOD_ARG_DESCRIBE_OUT("studio_list", "a(sa{sv})", "List of studios, name and properties")
245 METHOD_ARGS_END
247 METHOD_ARGS_BEGIN(LoadStudio, "Load studio")
248 METHOD_ARG_DESCRIBE_IN("studio_name", "s", "Name of studio to load")
249 METHOD_ARG_DESCRIBE_IN("options", "a{sv}", "Load options")
250 METHOD_ARGS_END
252 METHOD_ARGS_BEGIN(GetApplicationList, "Get list of applications that can be launched")
253 METHOD_ARG_DESCRIBE_OUT("applications", "a(sa{sv})", "List of applications, name and properties")
254 METHOD_ARGS_END
256 METHOD_ARGS_BEGIN(Exit, "Tell ladish D-Bus service to exit")
257 METHOD_ARGS_END
259 METHODS_BEGIN
260 METHOD_DESCRIBE(IsStudioLoaded, ladish_is_studio_loaded)
261 METHOD_DESCRIBE(GetStudioList, ladish_get_studio_list)
262 METHOD_DESCRIBE(LoadStudio, ladish_load_studio)
263 METHOD_DESCRIBE(GetApplicationList, ladish_get_application_list)
264 METHOD_DESCRIBE(Exit, ladish_exit)
265 METHODS_END
267 SIGNAL_ARGS_BEGIN(StudioAppeared, "Studio D-Bus object appeared")
268 SIGNAL_ARGS_END
270 SIGNAL_ARGS_BEGIN(StudioDisappeared, "Studio D-Bus object disappeared")
271 SIGNAL_ARGS_END
273 SIGNALS_BEGIN
274 SIGNAL_DESCRIBE(StudioAppeared)
275 SIGNAL_DESCRIBE(StudioDisappeared)
276 SIGNALS_END
279 * Interface description.
282 INTERFACE_BEGIN(g_lashd_interface_control, INTERFACE_NAME)
283 INTERFACE_DEFAULT_HANDLER
284 INTERFACE_EXPOSE_METHODS
285 INTERFACE_EXPOSE_SIGNALS
286 INTERFACE_END