2010-05-09 12:54:45 +03:00
|
|
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
|
|
|
* LADI Session Handler (ladish)
|
|
|
|
*
|
2011-11-05 23:37:58 +02:00
|
|
|
* Copyright (C) 2010,2011 Nedko Arnaudov <nedko@arnaudov.name>
|
2010-05-09 12:54:45 +03:00
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
* This file contains implementation of the "delete room" command
|
|
|
|
**************************************************************************
|
|
|
|
*
|
|
|
|
* LADI Session Handler is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LADI Session Handler is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
* or write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "studio_internal.h"
|
|
|
|
|
|
|
|
struct ladish_command_delete_room
|
|
|
|
{
|
|
|
|
struct ladish_command command; /* must be the first member */
|
|
|
|
char * name;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define cmd_ptr ((struct ladish_command_delete_room *)context)
|
|
|
|
|
|
|
|
static bool run(void * context)
|
|
|
|
{
|
|
|
|
struct list_head * node_ptr;
|
|
|
|
ladish_room_handle room;
|
|
|
|
|
2010-05-09 16:00:28 +03:00
|
|
|
if (cmd_ptr->command.state == LADISH_COMMAND_STATE_PENDING)
|
|
|
|
{
|
|
|
|
log_info("Delete studio room request (%s)", cmd_ptr->name);
|
|
|
|
}
|
2010-05-09 12:54:45 +03:00
|
|
|
|
|
|
|
list_for_each(node_ptr, &g_studio.rooms)
|
|
|
|
{
|
|
|
|
room = ladish_room_from_list_node(node_ptr);
|
|
|
|
if (strcmp(ladish_room_get_name(room), cmd_ptr->name) == 0)
|
|
|
|
{
|
2010-05-09 16:00:28 +03:00
|
|
|
goto found;
|
2010-05-09 12:54:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_error("Cannot delete room with name \"%s\" because it is unknown", cmd_ptr->name);
|
|
|
|
return false;
|
2010-05-09 16:00:28 +03:00
|
|
|
|
|
|
|
found:
|
|
|
|
if (cmd_ptr->command.state == LADISH_COMMAND_STATE_PENDING)
|
|
|
|
{
|
2010-07-20 01:31:37 +03:00
|
|
|
ladish_room_initiate_stop(room, true);
|
2010-05-09 16:00:28 +03:00
|
|
|
cmd_ptr->command.state = LADISH_COMMAND_STATE_WAITING;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(cmd_ptr->command.state == LADISH_COMMAND_STATE_WAITING);
|
|
|
|
|
2010-07-20 01:31:37 +03:00
|
|
|
if (!ladish_room_stopped(room))
|
2010-05-09 16:00:28 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ladish_graph_dump(g_studio.studio_graph); */
|
|
|
|
/* ladish_graph_dump(g_studio.jack_graph); */
|
|
|
|
|
|
|
|
ladish_room_destroy(room);
|
|
|
|
|
2010-05-10 20:40:53 +03:00
|
|
|
ladish_graph_dump(g_studio.studio_graph);
|
|
|
|
ladish_graph_dump(g_studio.jack_graph);
|
|
|
|
|
2010-05-09 16:00:28 +03:00
|
|
|
cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE;
|
|
|
|
return true;
|
2010-05-09 12:54:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void destructor(void * context)
|
|
|
|
{
|
|
|
|
log_info("delete_room command destructor");
|
|
|
|
free(cmd_ptr->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef cmd_ptr
|
|
|
|
|
|
|
|
bool ladish_command_delete_room(void * call_ptr, struct ladish_cqueue * queue_ptr, const char * room_name)
|
|
|
|
{
|
|
|
|
struct ladish_command_delete_room * cmd_ptr;
|
|
|
|
char * room_name_dup;
|
|
|
|
|
|
|
|
room_name_dup = strdup(room_name);
|
|
|
|
if (room_name_dup == NULL)
|
|
|
|
{
|
2011-11-05 23:37:58 +02:00
|
|
|
cdbus_error(call_ptr, DBUS_ERROR_FAILED, "strdup('%s') failed.", room_name);
|
2010-05-09 12:54:45 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_ptr = ladish_command_new(sizeof(struct ladish_command_delete_room));
|
|
|
|
if (cmd_ptr == NULL)
|
|
|
|
{
|
2011-11-05 23:37:58 +02:00
|
|
|
cdbus_error(call_ptr, DBUS_ERROR_FAILED, "ladish_command_new() failed.");
|
2010-05-09 12:54:45 +03:00
|
|
|
goto fail_free_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_ptr->command.run = run;
|
|
|
|
cmd_ptr->command.destructor = destructor;
|
|
|
|
cmd_ptr->name = room_name_dup;
|
|
|
|
|
|
|
|
if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command))
|
|
|
|
{
|
2011-11-05 23:37:58 +02:00
|
|
|
cdbus_error(call_ptr, DBUS_ERROR_FAILED, "ladish_cqueue_add_command() failed.");
|
2010-05-09 12:54:45 +03:00
|
|
|
goto fail_destroy_command;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fail_destroy_command:
|
|
|
|
free(cmd_ptr);
|
|
|
|
fail_free_name:
|
|
|
|
free(room_name_dup);
|
|
|
|
fail:
|
|
|
|
return false;
|
|
|
|
}
|