fix compiler warning
[ladish.git] / daemon / cmd_create_room.c
blobe44af371d2b9b7776db885467493ce7b7081604b
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the "create 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.
27 #include "cmd.h"
28 #include "studio_internal.h"
29 #include "../dbus/error.h"
30 #include "control.h"
31 #include "../proxies/notify_proxy.h"
33 struct ladish_command_create_room
35 struct ladish_command command; /* must be the first member */
36 char * room_name;
37 char * template_name;
40 #define cmd_ptr ((struct ladish_command_create_room *)cmd_context)
42 static bool run(void * cmd_context)
44 ladish_room_handle room;
46 ASSERT(cmd_ptr->command.state == LADISH_COMMAND_STATE_PENDING);
48 log_info("Request to create new studio room \"%s\" from template \"%s\".", cmd_ptr->room_name, cmd_ptr->template_name);
50 room = find_room_template_by_name(cmd_ptr->template_name);
51 if (room == NULL)
53 log_error("Unknown room template \"%s\"", cmd_ptr->template_name);
54 goto fail;
57 if (ladish_studio_check_room_name(cmd_ptr->room_name))
59 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "Room with requested name already exists", cmd_ptr->room_name);
60 goto fail;
63 if (!ladish_room_create(NULL, cmd_ptr->room_name, room, g_studio.studio_graph, &room))
65 log_error("ladish_room_create() failed.");
66 goto fail;
69 if (ladish_studio_is_started())
71 if (!ladish_room_start(room, ladish_studio_get_virtualizer()))
73 log_error("ladish_room_start() failed");
74 goto fail_destroy_room;
78 cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE;
79 return true;
81 fail_destroy_room:
82 ladish_room_destroy(room);
83 fail:
84 return false;
87 static void destructor(void * cmd_context)
89 log_info("create_room command destructor");
90 free(cmd_ptr->room_name);
91 free(cmd_ptr->template_name);
94 #undef cmd_ptr
96 bool ladish_command_create_room(void * call_ptr, struct ladish_cqueue * queue_ptr, const char * room_name, const char * template_name)
98 struct ladish_command_create_room * cmd_ptr;
99 char * room_name_dup;
100 char * template_name_dup;
102 room_name_dup = strdup(room_name);
103 if (room_name_dup == NULL)
105 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup('%s') failed.", room_name);
106 goto fail;
109 template_name_dup = strdup(template_name);
110 if (template_name_dup == NULL)
112 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup('%s') failed.", template_name);
113 goto fail_free_room_name;
116 cmd_ptr = ladish_command_new(sizeof(struct ladish_command_create_room));
117 if (cmd_ptr == NULL)
119 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_command_new() failed.");
120 goto fail_free_template_name;
123 cmd_ptr->command.run = run;
124 cmd_ptr->command.destructor = destructor;
125 cmd_ptr->room_name = room_name_dup;
126 cmd_ptr->template_name = template_name_dup;
128 if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command))
130 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_cqueue_add_command() failed.");
131 goto fail_destroy_command;
134 return true;
136 fail_destroy_command:
137 free(cmd_ptr);
138 fail_free_template_name:
139 free(room_name_dup);
140 fail_free_room_name:
141 free(room_name_dup);
142 fail:
143 return false;