fix compiler warning
[ladish.git] / daemon / cmd_load_project.c
blob58143fe0f0c5f9115317e433c31b3aee1a6722fe
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 "load project" 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"
29 #include "cmd.h"
30 #include "../dbus/error.h"
31 #include "room.h"
32 #include "studio.h"
33 #include "../proxies/notify_proxy.h"
35 struct ladish_command_load_project
37 struct ladish_command command;
38 uuid_t room_uuid;
39 char * project_dir;
42 #define cmd_ptr ((struct ladish_command_load_project *)command_context)
44 static bool run(void * command_context)
46 ladish_room_handle room;
48 room = ladish_studio_find_room_by_uuid(cmd_ptr->room_uuid);
49 if (room == NULL)
51 log_error("Cannot load project in unknown room");
52 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "Cannot load project in unknown room", NULL);
53 return false;
56 if (!ladish_room_load_project(room, cmd_ptr->project_dir))
58 log_error("Project load failed.");
59 return false;
62 ladish_notify_simple(LADISH_NOTIFY_URGENCY_NORMAL, "Project loaded successfully.", NULL);
63 cmd_ptr->command.state = LADISH_COMMAND_STATE_DONE;
65 return true;
68 static void destructor(void * command_context)
70 log_info("load project command destructor");
71 free(cmd_ptr->project_dir);
74 #undef cmd_ptr
76 bool
77 ladish_command_load_project(
78 void * call_ptr,
79 struct ladish_cqueue * queue_ptr,
80 const uuid_t room_uuid_ptr,
81 const char * project_dir)
83 char * project_dir_dup;
84 struct ladish_command_load_project * cmd_ptr;
86 if (!ladish_command_unload_project(call_ptr, queue_ptr, room_uuid_ptr))
88 goto fail;
91 project_dir_dup = strdup(project_dir);
92 if (project_dir_dup == NULL)
94 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup('%s') failed.", project_dir);
95 goto fail_drop_unload_command;
98 cmd_ptr = ladish_command_new(sizeof(struct ladish_command_load_project));
99 if (cmd_ptr == NULL)
101 log_error("ladish_command_new() failed.");
102 goto fail_free_dir;
105 cmd_ptr->command.run = run;
106 cmd_ptr->command.destructor = destructor;
107 uuid_copy(cmd_ptr->room_uuid, room_uuid_ptr);
108 cmd_ptr->project_dir = project_dir_dup;
110 if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command))
112 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_cqueue_add_command() failed.");
113 goto fail_destroy_command;
116 return true;
118 fail_destroy_command:
119 free(cmd_ptr);
120 fail_free_dir:
121 free(project_dir_dup);
122 fail_drop_unload_command:
123 ladish_cqueue_drop_command(queue_ptr);
124 fail:
125 return false;