ladishd: hide connections unless remove is explicitly requested
[ladish.git] / daemon / cmd_stop_studio.c
blob9efda034a7bd760974fb042febed984412c4de0a
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 "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.
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 /* nothing to do, studio is not running */
42 cmd_ptr->state = LADISH_COMMAND_STATE_DONE;
43 return true;
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.");
53 return false;
56 cmd_ptr->state = LADISH_COMMAND_STATE_WAITING;
57 /* fall through */
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? */
63 return true;
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;
75 return true;
78 ASSERT_NO_PASS;
79 return false;
82 #undef cmd_ptr
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));
89 if (cmd_ptr == NULL)
91 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_command_new() failed.");
92 goto fail;
95 cmd_ptr->run = run;
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;
103 return true;
105 fail_destroy_command:
106 free(cmd_ptr);
108 fail:
109 return false;