| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #include "cmd.h" |
|---|
| 28 | #include "studio_internal.h" |
|---|
| 29 | #include "../dbus/error.h" |
|---|
| 30 | #include "control.h" |
|---|
| 31 | |
|---|
| 32 | struct ladish_command_create_room |
|---|
| 33 | { |
|---|
| 34 | struct ladish_command command; |
|---|
| 35 | char * room_name; |
|---|
| 36 | char * template_name; |
|---|
| 37 | }; |
|---|
| 38 | |
|---|
| 39 | #define cmd_ptr ((struct ladish_command_create_room *)cmd_context) |
|---|
| 40 | |
|---|
| 41 | static 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 | |
|---|
| 74 | fail_destroy_room: |
|---|
| 75 | ladish_room_destroy(room); |
|---|
| 76 | fail: |
|---|
| 77 | return false; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | static 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 | |
|---|
| 89 | bool 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 | |
|---|
| 129 | fail_destroy_command: |
|---|
| 130 | free(cmd_ptr); |
|---|
| 131 | fail_free_template_name: |
|---|
| 132 | free(room_name_dup); |
|---|
| 133 | fail_free_room_name: |
|---|
| 134 | free(room_name_dup); |
|---|
| 135 | fail: |
|---|
| 136 | return false; |
|---|
| 137 | } |
|---|