Merge branch 'stable' into 'main'
[ladish.git] / daemon / cmd_exit.c
blob1e85ed5984c7987414f8b48ebba9770b1f0a0c73
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009,2011 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the "deactivate daemon" 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"
29 #include "control.h"
31 #define cmd_ptr ((struct ladish_command *)context)
33 static bool run(void * context)
35 ASSERT(cmd_ptr->state == LADISH_COMMAND_STATE_PENDING);
36 cmd_ptr->state = LADISH_COMMAND_STATE_DONE;
37 g_quit = true; /* cause main loop quit */
38 return false; /* cause command queue clear */
41 #undef cmd_ptr
43 bool ladish_command_exit(void * call_ptr, struct ladish_cqueue * queue_ptr)
45 struct ladish_command * cmd_ptr;
47 if (!ladish_command_unload_studio(call_ptr, queue_ptr))
49 goto fail;
52 cmd_ptr = ladish_command_new(sizeof(struct ladish_command));
53 if (cmd_ptr == NULL)
55 log_error("ladish_command_new() failed.");
56 goto fail_drop_unload_command;
59 cmd_ptr->run = run;
61 if (!ladish_cqueue_add_command(queue_ptr, cmd_ptr))
63 cdbus_error(call_ptr, DBUS_ERROR_FAILED, "ladish_cqueue_add_command() failed.");
64 goto fail_destroy_command;
67 return true;
69 fail_destroy_command:
70 free(cmd_ptr);
72 fail_drop_unload_command:
73 ladish_cqueue_drop_command(queue_ptr);
75 fail:
76 return false;