daemon: improve log
[ladish.git] / daemon / cmd_start_studio.c
blob8cd31b5ca6e59ec6c722cc076dab8618a83d22c4
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 implementation of the "start studio" command
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 "cmd.h"
28 #include "studio_internal.h"
30 #define cmd_ptr ((struct ladish_command *)context)
32 static bool run(void * context)
34 bool jack_server_started;
36 switch (cmd_ptr->state)
38 case LADISH_COMMAND_STATE_PENDING:
39 if (studio_is_started())
41 log_info("Ignoring start request because studio is already started.");
42 /* nothing to do, studio is already running */
43 cmd_ptr->state = LADISH_COMMAND_STATE_DONE;
44 return true;
47 log_info("Starting JACK server.");
49 ladish_graph_dump(g_studio.studio_graph);
51 if (!jack_proxy_start_server())
53 log_error("Starting JACK server failed.");
54 return false;
57 cmd_ptr->state = LADISH_COMMAND_STATE_WAITING;
58 /* fall through */
59 case LADISH_COMMAND_STATE_WAITING:
60 if (!ladish_environment_consume_change(&g_studio.env_store, ladish_environment_jack_server_started, &jack_server_started))
62 /* we are still waiting for the JACK server start */
63 ASSERT(!ladish_environment_get(&g_studio.env_store, ladish_environment_jack_server_started)); /* someone else consumed the state change? */
64 return true;
67 log_info("Wait for JACK server start complete.");
69 ASSERT(jack_server_started);
71 on_event_jack_started(); /* fetch configuration and announce start */
73 cmd_ptr->state = LADISH_COMMAND_STATE_DONE;
74 return true;
77 ASSERT_NO_PASS;
78 return false;
81 #undef cmd_ptr
83 bool ladish_command_start_studio(void * call_ptr, struct ladish_cqueue * queue_ptr)
85 struct ladish_command * cmd_ptr;
87 cmd_ptr = ladish_command_new(sizeof(struct ladish_command));
88 if (cmd_ptr == NULL)
90 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_command_new() failed.");
91 goto fail;
94 cmd_ptr->run = run;
96 if (!ladish_cqueue_add_command(queue_ptr, cmd_ptr))
98 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_cqueue_add_command() failed.");
99 goto fail_destroy_command;
102 return true;
104 fail_destroy_command:
105 free(cmd_ptr);
107 fail:
108 return false;