1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the "delete room" 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"
29 #include "../dbus/error.h"
31 struct ladish_command_delete_room
33 struct ladish_command command
; /* must be the first member */
37 #define cmd_ptr ((struct ladish_command_delete_room *)context)
39 static bool run(void * context
)
41 struct list_head
* node_ptr
;
42 ladish_room_handle room
;
44 if (cmd_ptr
->command
.state
== LADISH_COMMAND_STATE_PENDING
)
46 log_info("Delete studio room request (%s)", cmd_ptr
->name
);
49 list_for_each(node_ptr
, &g_studio
.rooms
)
51 room
= ladish_room_from_list_node(node_ptr
);
52 if (strcmp(ladish_room_get_name(room
), cmd_ptr
->name
) == 0)
58 log_error("Cannot delete room with name \"%s\" because it is unknown", cmd_ptr
->name
);
62 if (cmd_ptr
->command
.state
== LADISH_COMMAND_STATE_PENDING
)
64 ladish_room_initiate_stop(room
, true);
65 cmd_ptr
->command
.state
= LADISH_COMMAND_STATE_WAITING
;
69 ASSERT(cmd_ptr
->command
.state
== LADISH_COMMAND_STATE_WAITING
);
71 if (!ladish_room_stopped(room
))
76 /* ladish_graph_dump(g_studio.studio_graph); */
77 /* ladish_graph_dump(g_studio.jack_graph); */
79 ladish_room_destroy(room
);
81 ladish_graph_dump(g_studio
.studio_graph
);
82 ladish_graph_dump(g_studio
.jack_graph
);
84 cmd_ptr
->command
.state
= LADISH_COMMAND_STATE_DONE
;
88 static void destructor(void * context
)
90 log_info("delete_room command destructor");
96 bool ladish_command_delete_room(void * call_ptr
, struct ladish_cqueue
* queue_ptr
, const char * room_name
)
98 struct ladish_command_delete_room
* cmd_ptr
;
101 room_name_dup
= strdup(room_name
);
102 if (room_name_dup
== NULL
)
104 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "strdup('%s') failed.", room_name
);
108 cmd_ptr
= ladish_command_new(sizeof(struct ladish_command_delete_room
));
111 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_command_new() failed.");
115 cmd_ptr
->command
.run
= run
;
116 cmd_ptr
->command
.destructor
= destructor
;
117 cmd_ptr
->name
= room_name_dup
;
119 if (!ladish_cqueue_add_command(queue_ptr
, &cmd_ptr
->command
))
121 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_cqueue_add_command() failed.");
122 goto fail_destroy_command
;
127 fail_destroy_command
: