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 implementation of the "stop 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.
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 /* nothing to do, studio is not running */
42 cmd_ptr
->state
= LADISH_COMMAND_STATE_DONE
;
46 log_info("Stopping JACK server...");
48 ladish_graph_dump(g_studio
.studio_graph
);
50 if (!jack_proxy_stop_server())
52 log_error("Stopping JACK server failed.");
56 cmd_ptr
->state
= LADISH_COMMAND_STATE_WAITING
;
58 case LADISH_COMMAND_STATE_WAITING
:
59 if (!ladish_environment_consume_change(&g_studio
.env_store
, ladish_environment_jack_server_started
, &jack_server_started
))
61 /* we are still waiting for the JACK server stop */
62 ASSERT(ladish_environment_get(&g_studio
.env_store
, ladish_environment_jack_server_started
)); /* someone else consumed the state change? */
66 log_info("Wait for JACK server stop complete.");
68 ASSERT(!jack_server_started
);
70 ladish_graph_dump(g_studio
.studio_graph
);
72 on_event_jack_stopped();
74 cmd_ptr
->state
= LADISH_COMMAND_STATE_DONE
;
84 bool ladish_command_stop_studio(void * call_ptr
, struct ladish_cqueue
* queue_ptr
)
86 struct ladish_command
* cmd_ptr
;
88 cmd_ptr
= ladish_command_new(sizeof(struct ladish_command
));
91 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_command_new() failed.");
97 if (!ladish_cqueue_add_command(queue_ptr
, cmd_ptr
))
99 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_cqueue_add_command() failed.");
100 goto fail_destroy_command
;
105 fail_destroy_command
: