daemon: handle apps with same name in different vgraphs
[ladish.git] / daemon / cmd_rename_studio.c
blob39aad1dfb590f1fea465283daf32a325bf99f06d
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the "rename studio" 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"
30 struct ladish_command_rename_studio
32 struct ladish_command command; /* must be the first member */
33 char * studio_name;
36 #define cmd_ptr ((struct ladish_command_rename_studio *)context)
38 static bool run(void * context)
40 ASSERT(cmd_ptr->command.state == LADISH_COMMAND_STATE_PENDING);
42 if (g_studio.name == NULL)
44 log_error("cannot rename not loaded studio");
45 return false;
48 free(g_studio.name);
49 g_studio.name = cmd_ptr->studio_name;
50 cmd_ptr->studio_name = NULL;
51 ladish_studio_emit_renamed();
52 cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE;
53 return true;
56 static void destructor(void * context)
58 log_info("rename studio command destructor");
59 if (cmd_ptr->studio_name != NULL)
61 free(cmd_ptr->studio_name);
65 #undef cmd_ptr
67 bool ladish_command_rename_studio(void * call_ptr, struct ladish_cqueue * queue_ptr, const char * studio_name)
69 struct ladish_command_rename_studio * cmd_ptr;
70 char * studio_name_dup;
72 studio_name_dup = strdup(studio_name);
73 if (studio_name_dup == NULL)
75 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup('%s') failed.", studio_name);
76 goto fail;
79 cmd_ptr = ladish_command_new(sizeof(struct ladish_command_rename_studio));
80 if (cmd_ptr == NULL)
82 log_error("ladish_command_new() failed.");
83 goto fail_free_name;
86 cmd_ptr->command.run = run;
87 cmd_ptr->command.destructor = destructor;
88 cmd_ptr->studio_name = studio_name_dup;
90 if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command))
92 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_cqueue_add_command() failed.");
93 goto fail_destroy_command;
96 return true;
98 fail_destroy_command:
99 free(cmd_ptr);
101 fail_free_name:
102 free(studio_name_dup);
104 fail:
105 return false;