daemon: handle apps with same name in different vgraphs
[ladish.git] / daemon / room.c
blobe1793fbd43dbb8eb12db82e3fb2f2b109ec71fcd
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains the core parts of room object implementation
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 "room_internal.h"
28 #include "../dbus_constants.h"
29 #include "graph_dict.h"
30 #include "../lib/wkports.h"
31 #include "studio.h"
32 #include "../proxies/jmcore_proxy.h"
33 #include "cmd.h"
34 #include "../dbus/error.h"
36 extern const struct dbus_interface_descriptor g_interface_room;
38 /* implemented in studio.c */
39 void ladish_on_app_renamed(void * context, const char * old_name, const char * new_app_name);
41 static bool port_is_input(uint32_t flags)
43 bool playback;
45 playback = JACKDBUS_PORT_IS_INPUT(flags);
46 ASSERT(playback || JACKDBUS_PORT_IS_OUTPUT(flags)); /* playback or capture */
47 ASSERT(!(playback && JACKDBUS_PORT_IS_OUTPUT(flags))); /* but not both */
49 return playback;
52 struct ladish_room * ladish_room_create_internal(const uuid_t uuid_ptr, const char * name, const char * object_path)
54 struct ladish_room * room_ptr;
56 room_ptr = malloc(sizeof(struct ladish_room));
57 if (room_ptr == NULL)
59 log_error("malloc() failed to allocate struct ladish_room");
60 goto fail;
63 if (uuid_ptr != NULL)
65 uuid_copy(room_ptr->uuid, uuid_ptr);
67 else
69 uuid_generate(room_ptr->uuid);
72 room_ptr->name = strdup(name);
73 if (room_ptr->name == NULL)
75 log_error("strdup() failed for room name");
76 goto free_room;
79 if (object_path != NULL)
81 room_ptr->object_path = strdup(object_path);
82 if (room_ptr->object_path == NULL)
84 log_error("strdup() failed for room name");
85 goto free_name;
89 if (!ladish_graph_create(&room_ptr->graph, object_path))
91 goto free_opath;
94 return room_ptr;
96 free_opath:
97 if (object_path != NULL)
99 free(room_ptr->object_path);
101 free_name:
102 free(room_ptr->name);
103 free_room:
104 free(room_ptr);
105 fail:
106 return NULL;
109 bool
110 ladish_room_create_template(
111 const uuid_t uuid_ptr,
112 const char * name,
113 ladish_room_handle * room_handle_ptr)
115 struct ladish_room * room_ptr;
117 room_ptr = ladish_room_create_internal(uuid_ptr, name, NULL);
118 if (room_ptr == NULL)
120 return false;
123 room_ptr->template = true;
125 *room_handle_ptr = (ladish_room_handle)room_ptr;
126 return true;
129 #define room_ptr ((struct ladish_room *)context)
131 static
132 bool
133 create_shadow_port(
134 void * context,
135 ladish_port_handle port_handle,
136 const char * port_name,
137 uint32_t port_type,
138 uint32_t port_flags)
140 //log_info("Studio room port \"%s\"", port_name);
142 if (port_is_input(port_flags))
144 JACKDBUS_PORT_CLEAR_INPUT(port_flags);
145 JACKDBUS_PORT_SET_OUTPUT(port_flags);
147 else
149 JACKDBUS_PORT_CLEAR_OUTPUT(port_flags);
150 JACKDBUS_PORT_SET_INPUT(port_flags);
153 if (!ladish_graph_add_port(room_ptr->owner, room_ptr->client, port_handle, port_name, port_type, port_flags, true))
155 log_error("ladish_graph_add_port() failed to add link port to room owner graph");
156 return false;
159 return true;
162 static
163 bool
164 create_port_link(
165 void * context,
166 ladish_port_handle port_handle,
167 const char * port_name,
168 uint32_t port_type,
169 uint32_t port_flags)
171 uuid_t uuid_in_owner;
172 uuid_t uuid_in_room;
173 char uuid_in_owner_str[37];
174 char uuid_in_room_str[37];
175 const char * input_port;
176 const char * output_port;
178 //log_info("Room port \"%s\"", port_name);
180 ladish_graph_get_port_uuid(room_ptr->graph, port_handle, uuid_in_room);
181 ladish_graph_get_port_uuid(room_ptr->owner, port_handle, uuid_in_owner);
183 uuid_unparse(uuid_in_room, uuid_in_room_str);
184 uuid_unparse(uuid_in_owner, uuid_in_owner_str);
186 if (port_is_input(port_flags))
188 input_port = uuid_in_room_str;
189 output_port = uuid_in_owner_str;
190 log_info("room input port %s is linked to owner graph output port %s", input_port, output_port);
192 else
194 input_port = uuid_in_owner_str;
195 output_port = uuid_in_room_str;
196 log_info("owner graph input port %s is linked to room output port %s", input_port, output_port);
199 if (!jmcore_proxy_create_link(port_type == JACKDBUS_PORT_TYPE_MIDI, input_port, output_port))
201 log_error("jmcore_proxy_create_link() failed.");
202 return false;
205 return true;
208 static
209 bool
210 destroy_port_link(
211 void * context,
212 ladish_graph_handle graph_handle,
213 void * client_iteration_context_ptr,
214 ladish_client_handle client_handle,
215 const char * client_name,
216 ladish_port_handle port_handle,
217 const char * port_name,
218 uint32_t port_type,
219 uint32_t port_flags)
221 uuid_t uuid_in_room;
222 char uuid_in_room_str[37];
224 if (ladish_port_is_link(port_handle))
226 log_info("link port %s", port_name);
228 ladish_graph_get_port_uuid(ladish_room_get_graph(context), port_handle, uuid_in_room);
229 uuid_unparse(uuid_in_room, uuid_in_room_str);
230 jmcore_proxy_destroy_link(uuid_in_room_str);
232 else
234 log_info("jack port %s", port_name);
237 return true;
240 #undef room_ptr
242 static void remove_port_callback(ladish_port_handle port)
244 ladish_graph_handle jack_graph;
245 ladish_client_handle jack_client;
247 jack_graph = ladish_studio_get_jack_graph();
249 jack_client = ladish_graph_remove_port(jack_graph, port);
250 if (jack_client == NULL)
251 { /* room app port not found in jack graph */
252 /* this can happen if the port is hidden in the vgraph */
253 return;
256 if (ladish_graph_client_is_empty(jack_graph, jack_client))
258 ladish_graph_remove_client(jack_graph, jack_client);
262 bool
263 ladish_room_create(
264 const uuid_t uuid_ptr,
265 const char * name,
266 ladish_room_handle template,
267 ladish_graph_handle owner,
268 ladish_room_handle * room_handle_ptr)
270 struct ladish_room * room_ptr;
271 char object_path[1024];
272 unsigned int index;
274 index = ladish_studio_get_room_index();
275 sprintf(object_path, DBUS_BASE_PATH "/Room%u", index);
277 room_ptr = ladish_room_create_internal(uuid_ptr, name, object_path);
278 if (room_ptr == NULL)
280 goto release_index;
283 room_ptr->template = false;
284 room_ptr->index = index;
285 room_ptr->owner = owner;
286 room_ptr->started = false;
288 room_ptr->project_name = NULL;
289 room_ptr->project_dir = NULL;
290 room_ptr->project_unloading = false;
292 if (template != NULL)
294 ladish_room_get_uuid(template, room_ptr->template_uuid);
295 if (!ladish_graph_copy(ladish_room_get_graph(template), room_ptr->graph, false))
297 goto destroy;
300 else
302 uuid_clear(room_ptr->template_uuid);
305 if (!ladish_app_supervisor_create(&room_ptr->app_supervisor, object_path, room_ptr->name, room_ptr->graph, ladish_on_app_renamed))
307 log_error("ladish_app_supervisor_create() failed.");
308 goto destroy;
311 room_ptr->dbus_object = dbus_object_path_new(
312 object_path,
313 &g_interface_room, room_ptr,
314 &g_interface_patchbay, ladish_graph_get_dbus_context(room_ptr->graph),
315 &g_iface_graph_dict, room_ptr->graph,
316 &g_iface_app_supervisor, room_ptr->app_supervisor,
317 NULL);
318 if (room_ptr->dbus_object == NULL)
320 log_error("dbus_object_path_new() failed");
321 goto destroy_app_supervisor;
324 if (!dbus_object_path_register(g_dbus_connection, room_ptr->dbus_object))
326 log_error("object_path_register() failed");
327 goto destroy_dbus_object;
330 log_info("D-Bus object \"%s\" created for room \"%s\".", object_path, room_ptr->name);
332 if (!ladish_client_create(room_ptr->uuid, &room_ptr->client))
334 log_error("ladish_client_create() failed.");
335 goto unregister_dbus_object;
338 if (!ladish_graph_add_client(owner, room_ptr->client, room_ptr->name, true))
340 log_error("ladish_graph_add_client() failed to add room client to owner graph.");
341 goto destroy_client;
344 if (!ladish_room_iterate_link_ports((ladish_room_handle)room_ptr, room_ptr, create_shadow_port))
346 log_error("Creation of studio room link ports failed.");
347 goto remove_client;
350 ladish_studio_room_appeared((ladish_room_handle)room_ptr);
352 *room_handle_ptr = (ladish_room_handle)room_ptr;
353 return true;
355 remove_client:
356 ladish_graph_remove_client(owner, room_ptr->client);
357 destroy_client:
358 ladish_client_destroy(room_ptr->client);
359 unregister_dbus_object:
360 dbus_object_path_unregister(g_dbus_connection, room_ptr->dbus_object);
361 destroy_dbus_object:
362 dbus_object_path_destroy(g_dbus_connection, room_ptr->dbus_object);
363 destroy_app_supervisor:
364 ladish_app_supervisor_destroy(room_ptr->app_supervisor);
365 destroy:
366 ladish_graph_destroy(room_ptr->graph);
367 free(room_ptr->name);
368 free(room_ptr);
369 release_index:
370 ladish_studio_release_room_index(index);
371 return false;
374 #define room_ptr ((struct ladish_room *)room_handle)
376 void ladish_room_destroy(ladish_room_handle room_handle)
378 /* project has either both name and dir no none of them */
379 ASSERT((room_ptr->project_dir == NULL && room_ptr->project_name == NULL) || (room_ptr->project_dir != NULL && room_ptr->project_name != NULL));
380 if (room_ptr->project_dir == NULL)
382 free(room_ptr->project_dir);
384 if (room_ptr->project_name == NULL)
386 free(room_ptr->project_name);
389 if (!room_ptr->template)
391 ASSERT(!room_ptr->started); /* attempt to destroy not stopped room */
393 /* ladish_graph_dump(graph); */
395 if (ladish_studio_is_started())
397 ladish_graph_clear(room_ptr->graph, remove_port_callback);
400 dbus_object_path_destroy(g_dbus_connection, room_ptr->dbus_object);
401 ladish_app_supervisor_destroy(room_ptr->app_supervisor);
403 ladish_graph_remove_client(room_ptr->owner, room_ptr->client);
404 ladish_client_destroy(room_ptr->client);
406 ladish_studio_room_disappeared((ladish_room_handle)room_ptr);
407 ladish_studio_release_room_index(room_ptr->index);
410 ladish_graph_destroy(room_ptr->graph);
411 free(room_ptr->name);
412 free(room_ptr);
415 struct list_head * ladish_room_get_list_node(ladish_room_handle room_handle)
417 return &room_ptr->siblings;
420 const char * ladish_room_get_name(ladish_room_handle room_handle)
422 return room_ptr->name;
425 const char * ladish_room_get_opath(ladish_room_handle room_handle)
427 return ladish_graph_get_opath(room_ptr->graph);
430 bool ladish_room_get_template_uuid(ladish_room_handle room_handle, uuid_t uuid_ptr)
432 if (uuid_is_null(room_ptr->template_uuid))
434 return false;
437 uuid_copy(uuid_ptr, room_ptr->template_uuid);
438 return true;
441 void ladish_room_get_uuid(ladish_room_handle room_handle, uuid_t uuid_ptr)
443 uuid_copy(uuid_ptr, room_ptr->uuid);
446 ladish_graph_handle ladish_room_get_graph(ladish_room_handle room_handle)
448 return room_ptr->graph;
451 ladish_app_supervisor_handle ladish_room_get_app_supervisor(ladish_room_handle room_handle)
453 return room_ptr->app_supervisor;
456 struct ladish_room_iterate_link_ports_context
458 void * context;
459 bool
460 (* callback)(
461 void * context,
462 ladish_port_handle port_handle,
463 const char * port_name,
464 uint32_t port_type,
465 uint32_t port_flags);
468 #define context_ptr ((struct ladish_room_iterate_link_ports_context *)context)
470 static
471 bool
472 ladish_room_iterate_link_ports_client_callback(
473 void * context,
474 ladish_graph_handle graph_handle,
475 ladish_client_handle client_handle,
476 const char * client_name,
477 void ** client_iteration_context_ptr_ptr)
479 uuid_t uuid;
481 ladish_client_get_uuid(client_handle, uuid);
483 if (uuid_compare(uuid, ladish_wkclient_capture) == 0 ||
484 uuid_compare(uuid, ladish_wkclient_playback) == 0)
486 *client_iteration_context_ptr_ptr = (void *)1;
488 else
490 *client_iteration_context_ptr_ptr = (void *)0;
493 return true;
496 static
497 bool
498 ladish_room_iterate_link_ports_port_callback(
499 void * context,
500 ladish_graph_handle graph_handle,
501 void * client_iteration_context_ptr,
502 ladish_client_handle client_handle,
503 const char * client_name,
504 ladish_port_handle port_handle,
505 const char * port_name,
506 uint32_t port_type,
507 uint32_t port_flags)
509 if (client_iteration_context_ptr == (void *)0)
511 /* port of non-link client */
512 return true;
515 return context_ptr->callback(context_ptr->context, port_handle, port_name, port_type, port_flags);
518 #undef context_ptr
520 bool
521 ladish_room_iterate_link_ports(
522 ladish_room_handle room_handle,
523 void * callback_context,
524 bool
525 (* callback)(
526 void * context,
527 ladish_port_handle port_handle,
528 const char * port_name,
529 uint32_t port_type,
530 uint32_t port_flags))
532 struct ladish_room_iterate_link_ports_context context;
534 context.context = callback_context;
535 context.callback = callback;
537 return ladish_graph_iterate_nodes(
538 room_ptr->graph,
539 false,
540 NULL,
541 &context,
542 ladish_room_iterate_link_ports_client_callback,
543 ladish_room_iterate_link_ports_port_callback,
544 NULL);
547 bool ladish_room_start(ladish_room_handle room_handle, ladish_virtualizer_handle virtualizer)
549 if (!ladish_room_iterate_link_ports(room_handle, room_ptr, create_port_link))
551 log_error("Creation of room port links failed.");
552 return false;
555 ladish_virtualizer_set_graph_connection_handlers(virtualizer, room_ptr->graph);
556 room_ptr->started = true;
558 return true;
561 void ladish_room_initiate_stop(ladish_room_handle room_handle, bool clear_persist)
563 if (!room_ptr->started)
565 return;
568 ladish_graph_set_connection_handlers(room_ptr->graph, NULL, NULL, NULL);
570 if (clear_persist)
572 ladish_graph_clear_persist(room_ptr->graph);
575 ladish_graph_iterate_nodes(room_ptr->graph, false, NULL, room_ptr, NULL, destroy_port_link, NULL);
576 ladish_app_supervisor_stop(room_ptr->app_supervisor);
579 bool ladish_room_stopped(ladish_room_handle room_handle)
581 unsigned int running_app_count;
583 if (!room_ptr->started)
585 return true;
588 running_app_count = ladish_app_supervisor_get_running_app_count(room_ptr->app_supervisor);
589 if (running_app_count != 0)
591 log_info("there are %u running app(s) in room \"%s\"", running_app_count, room_ptr->name);
592 return false;
595 if (!ladish_graph_looks_empty(room_ptr->graph))
597 log_info("the room \"%s\" graph is still not empty", room_ptr->name);
598 return false;
601 if (!ladish_graph_client_looks_empty(room_ptr->owner, room_ptr->client))
603 log_info("the room \"%s\" client in owner still does not look empty", room_ptr->name);
604 return false;
607 room_ptr->started = false;
608 return true;
611 static
612 bool
613 ladish_room_app_is_stopped(
614 void * context,
615 const char * name,
616 bool running,
617 const char * command,
618 bool terminal,
619 uint8_t level,
620 pid_t pid,
621 const uuid_t uuid)
623 if (pid != 0)
625 log_info("App '%s' is still running pid=%u", name, (unsigned int)pid);
626 return false;
629 if (!ladish_virtualizer_is_hidden_app(ladish_studio_get_jack_graph(), uuid, name))
631 log_info("App '%s' is still visible in the jack graph", name);
632 return false;
635 return true;
638 bool ladish_room_unload_project(ladish_room_handle room_handle)
640 if (!room_ptr->project_unloading)
642 if (!ladish_app_supervisor_has_apps(room_ptr->app_supervisor))
644 return true;
647 log_info("Stopping room apps...");
648 ladish_graph_dump(room_ptr->graph);
649 room_ptr->project_unloading = true;
650 ladish_graph_clear_persist(room_ptr->graph);
651 ladish_app_supervisor_stop(room_ptr->app_supervisor);
652 return false;
655 if (!ladish_app_supervisor_enum(room_ptr->app_supervisor, room_ptr, ladish_room_app_is_stopped))
657 return false;
660 ladish_app_supervisor_clear(room_ptr->app_supervisor);
661 ASSERT(!ladish_app_supervisor_has_apps(room_ptr->app_supervisor));
663 ladish_graph_set_persist(room_ptr->graph);
665 log_info("Room apps stopped.");
666 ladish_graph_dump(room_ptr->graph);
667 room_ptr->project_unloading = false;
668 if (room_ptr->project_name != NULL)
670 free(room_ptr->project_name);
671 room_ptr->project_name = NULL;
673 if (room_ptr->project_dir != NULL)
675 free(room_ptr->project_dir);
676 room_ptr->project_dir = NULL;
678 return true;
681 ladish_port_handle
682 ladish_room_add_port(
683 ladish_room_handle room_handle,
684 const uuid_t uuid_ptr,
685 const char * name,
686 uint32_t type,
687 uint32_t flags)
689 ladish_port_handle port;
690 bool playback;
691 ladish_client_handle client;
692 const char * client_name;
693 uuid_t client_uuid;
694 bool new_client;
696 playback = port_is_input(flags);
698 ASSERT(!uuid_is_null(uuid_ptr));
699 if (!ladish_port_create(uuid_ptr, true, &port))
701 log_error("Creation of room port \"%s\" failed.", name);
702 goto fail;
705 client_name = playback ? "Playback" : "Capture";
706 uuid_copy(client_uuid, playback ? ladish_wkclient_playback : ladish_wkclient_capture);
708 /* if client is not found, create it and add it to graph */
709 client = ladish_graph_find_client_by_uuid(room_ptr->graph, client_uuid);
710 new_client = client == NULL;
711 if (new_client)
713 if (!ladish_client_create(client_uuid, &client))
715 log_error("ladish_client_create() failed to create %s room client.", playback ? "playback" : "capture");
716 goto fail_destroy_port;
719 if (!ladish_graph_add_client(room_ptr->graph, client, client_name, true))
721 log_error("ladish_graph_add_client() failed to add %s room client to room graph.", playback ? "playback" : "capture");
722 goto fail_destroy_client;
726 if (!ladish_graph_add_port(room_ptr->graph, client, port, name, type, flags, true))
728 log_error("ladish_graph_add_port() failed to add %s room port \"%s\" to room graph.", playback ? "playback" : "capture", name);
729 goto fail_destroy_client;
732 if (!create_shadow_port(room_ptr, port, name, type, flags))
734 log_error("ladish_graph_add_port() failed to add port \"%s\" to room owner graph.", name);
735 goto fail_remove_port;
738 return port;
740 fail_remove_port:
741 ASSERT(client != NULL);
742 if (ladish_graph_remove_port(room_ptr->graph, port) != client)
744 ASSERT_NO_PASS;
746 fail_destroy_client:
747 if (new_client)
749 ladish_client_destroy(client);
751 fail_destroy_port:
752 ladish_port_destroy(port);
753 fail:
754 return NULL;
757 #undef room_ptr
759 ladish_room_handle ladish_room_from_list_node(struct list_head * node_ptr)
761 return (ladish_room_handle)list_entry(node_ptr, struct ladish_room, siblings);
764 static bool ladish_room_fill_project_properties(DBusMessageIter * iter_ptr, struct ladish_room * room_ptr)
766 DBusMessageIter dict_iter;
768 if (!dbus_message_iter_open_container(iter_ptr, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
770 log_error("dbus_message_iter_open_container() failed.");
771 return false;
774 if (!dbus_maybe_add_dict_entry_string(&dict_iter, "name", room_ptr->project_name))
776 log_error("dbus_maybe_add_dict_entry_string() failed.");
777 return false;
780 if (!dbus_maybe_add_dict_entry_string(&dict_iter, "dir", room_ptr->project_dir))
782 log_error("dbus_maybe_add_dict_entry_string() failed.");
783 return false;
786 if (!dbus_message_iter_close_container(iter_ptr, &dict_iter))
788 log_error("dbus_message_iter_close_container() failed.");
789 return false;
792 return true;
795 void ladish_room_emit_project_properties_changed(struct ladish_room * room_ptr)
797 DBusMessage * message_ptr;
798 DBusMessageIter iter;
800 message_ptr = dbus_message_new_signal(room_ptr->object_path, IFACE_ROOM, "ProjectPropertiesChanged");
801 if (message_ptr == NULL)
803 log_error("dbus_message_new_signal() failed.");
804 return;
807 dbus_message_iter_init_append(message_ptr, &iter);
809 if (ladish_room_fill_project_properties(&iter, room_ptr))
811 dbus_signal_send(g_dbus_connection, message_ptr);
814 dbus_message_unref(message_ptr);
817 /**********************************************************************************/
818 /* D-Bus methods */
819 /**********************************************************************************/
821 #define room_ptr ((struct ladish_room *)call_ptr->iface_context)
823 static void ladish_room_dbus_get_name(struct dbus_method_call * call_ptr)
825 method_return_new_single(call_ptr, DBUS_TYPE_STRING, &room_ptr->name);
828 static void ladish_room_dbus_save_project(struct dbus_method_call * call_ptr)
830 const char * dir;
831 const char * name;
833 log_info("Save project request");
835 if (!dbus_message_get_args(call_ptr->message, &g_dbus_error, DBUS_TYPE_STRING, &dir, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
837 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
838 dbus_error_free(&g_dbus_error);
839 return;
842 if (ladish_command_save_project(call_ptr, ladish_studio_get_cmd_queue(), room_ptr->uuid, dir, name))
844 method_return_new_void(call_ptr);
848 static void ladish_room_dbus_unload_project(struct dbus_method_call * call_ptr)
850 log_info("Unload project request");
852 if (ladish_command_unload_project(call_ptr, ladish_studio_get_cmd_queue(), room_ptr->uuid))
854 method_return_new_void(call_ptr);
858 static void ladish_room_dbus_load_project(struct dbus_method_call * call_ptr)
860 const char * dir;
862 log_info("Load project request");
864 if (!dbus_message_get_args(call_ptr->message, &g_dbus_error, DBUS_TYPE_STRING, &dir, DBUS_TYPE_INVALID))
866 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
867 dbus_error_free(&g_dbus_error);
868 return;
871 if (ladish_command_load_project(call_ptr, ladish_studio_get_cmd_queue(), room_ptr->uuid, dir))
873 method_return_new_void(call_ptr);
877 static void ladish_room_dbus_get_project_properties(struct dbus_method_call * call_ptr)
879 DBusMessageIter iter;
881 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
882 if (call_ptr->reply == NULL)
884 goto fail;
887 dbus_message_iter_init_append(call_ptr->reply, &iter);
889 if (!ladish_room_fill_project_properties(&iter, room_ptr))
891 goto fail_unref;
894 return;
896 fail_unref:
897 dbus_message_unref(call_ptr->reply);
898 call_ptr->reply = NULL;
900 fail:
901 log_error("Ran out of memory trying to construct method return");
904 #undef room_ptr
906 METHOD_ARGS_BEGIN(GetName, "Get room name")
907 METHOD_ARG_DESCRIBE_OUT("room_name", "s", "Name of room")
908 METHOD_ARGS_END
910 METHOD_ARGS_BEGIN(SaveProject, "Save the current project")
911 METHOD_ARG_DESCRIBE_IN("project_dir", "s", "Project directory. Can be an empty string if project has a path associated already")
912 METHOD_ARG_DESCRIBE_IN("project_name", "s", "Name of the project. Can be an empty string if project has a name associated already")
913 METHOD_ARGS_END
915 METHOD_ARGS_BEGIN(UnloadProject, "Unload project, if any")
916 METHOD_ARGS_END
918 METHOD_ARGS_BEGIN(LoadProject, "Load project")
919 METHOD_ARG_DESCRIBE_IN("project_dir", "s", "Project directory")
920 METHOD_ARGS_END
922 METHOD_ARGS_BEGIN(GetProjectProperties, "Get project properties")
923 SIGNAL_ARG_DESCRIBE("properties", "a{sv}", "project properties")
924 METHOD_ARGS_END
926 METHODS_BEGIN
927 METHOD_DESCRIBE(GetName, ladish_room_dbus_get_name) /* sync */
928 METHOD_DESCRIBE(SaveProject, ladish_room_dbus_save_project) /* async */
929 METHOD_DESCRIBE(UnloadProject, ladish_room_dbus_unload_project) /* async */
930 METHOD_DESCRIBE(LoadProject, ladish_room_dbus_load_project) /* async */
931 METHOD_DESCRIBE(GetProjectProperties, ladish_room_dbus_get_project_properties) /* sync */
932 METHODS_END
934 SIGNAL_ARGS_BEGIN(ProjectPropertiesChanged, "Project properties changed")
935 SIGNAL_ARG_DESCRIBE("properties", "a{sv}", "project properties")
936 SIGNAL_ARGS_END
938 SIGNALS_BEGIN
939 SIGNAL_DESCRIBE(ProjectPropertiesChanged)
940 SIGNALS_END
942 INTERFACE_BEGIN(g_interface_room, IFACE_ROOM)
943 INTERFACE_DEFAULT_HANDLER
944 INTERFACE_EXPOSE_METHODS
945 INTERFACE_EXPOSE_SIGNALS
946 INTERFACE_END