root/daemon/cmd_create_room.c

Revision 5bb96d51e76bb0e2e2b41f5d3b3027aefefab452, 3.9 KB (checked in by Nedko Arnaudov <nedko@…>, 7 weeks ago)

damon: Proper room lifecycle

  • Room creation/destruction is now separeted from starting/stopping (creating/destroying jmcore links)
  • Rooms can now be created and destryed when studio is stopped
  • Rooms are started/stopped when studio is started/stopped

Apart from better interraction of studio start/stop and room
lifecycles, it is now possible to implement load of studio with rooms
because during studio load rooms have to be created in stopped state
and eventually started only at later stage, during studio start.

  • Property mode set to 100644
Line 
1/* -*- Mode: C ; c-basic-offset: 2 -*- */
2/*
3 * LADI Session Handler (ladish)
4 *
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
6 *
7 **************************************************************************
8 * This file contains implementation of the "create room" command
9 **************************************************************************
10 *
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.
15 *
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.
20 *
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.
25 */
26
27#include "cmd.h"
28#include "studio_internal.h"
29#include "../dbus/error.h"
30#include "control.h"
31
32struct ladish_command_create_room
33{
34  struct ladish_command command; /* must be the first member */
35  char * room_name;
36  char * template_name;
37};
38
39#define cmd_ptr ((struct ladish_command_create_room *)cmd_context)
40
41static bool run(void * cmd_context)
42{
43  ladish_room_handle room;
44
45  ASSERT(cmd_ptr->command.state == LADISH_COMMAND_STATE_PENDING);
46
47  log_info("Request to create new studio room \"%s\" from template \"%s\".", cmd_ptr->room_name, cmd_ptr->template_name);
48
49  room = find_room_template_by_name(cmd_ptr->template_name);
50  if (room == NULL)
51  {
52    log_error("Unknown room template \"%s\"",  cmd_ptr->template_name);
53    goto fail;
54  }
55
56  if (!ladish_room_create(NULL, cmd_ptr->room_name, room, g_studio.studio_graph, &room))
57  {
58    log_error("ladish_room_create() failed.");
59    goto fail;
60  }
61
62  if (ladish_studio_is_started())
63  {
64    if (!ladish_room_start(room, ladish_studio_get_virtualizer()))
65    {
66      log_error("ladish_room_start() failed");
67      goto fail_destroy_room;
68    }
69  }
70
71  cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE;
72  return true;
73
74fail_destroy_room:
75  ladish_room_destroy(room);
76fail:
77  return false;
78}
79
80static void destructor(void * cmd_context)
81{
82  log_info("create_room command destructor");
83  free(cmd_ptr->room_name);
84  free(cmd_ptr->template_name);
85}
86
87#undef cmd_ptr
88
89bool ladish_command_create_room(void * call_ptr, struct ladish_cqueue * queue_ptr, const char * room_name, const char * template_name)
90{
91  struct ladish_command_create_room * cmd_ptr;
92  char * room_name_dup;
93  char * template_name_dup;
94
95  room_name_dup = strdup(room_name);
96  if (room_name_dup == NULL)
97  {
98    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup('%s') failed.", room_name);
99    goto fail;
100  }
101
102  template_name_dup = strdup(template_name);
103  if (template_name_dup == NULL)
104  {
105    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup('%s') failed.", template_name);
106    goto fail_free_room_name;
107  }
108
109  cmd_ptr = ladish_command_new(sizeof(struct ladish_command_create_room));
110  if (cmd_ptr == NULL)
111  {
112    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_command_new() failed.");
113    goto fail_free_template_name;
114  }
115
116  cmd_ptr->command.run = run;
117  cmd_ptr->command.destructor = destructor;
118  cmd_ptr->room_name = room_name_dup;
119  cmd_ptr->template_name = template_name_dup;
120
121  if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command))
122  {
123    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_cqueue_add_command() failed.");
124    goto fail_destroy_command;
125  }
126
127  return true;
128
129fail_destroy_command:
130  free(cmd_ptr);
131fail_free_template_name:
132  free(room_name_dup);
133fail_free_room_name:
134  free(room_name_dup);
135fail:
136  return false;
137}
Note: See TracBrowser for help on using the browser.