1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the "remove app" 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.
30 #include "../dbus/error.h"
31 #include "../proxies/notify_proxy.h"
32 #include "virtualizer.h"
34 struct ladish_command_remove_app
36 struct ladish_command command
; /* must be the first member */
41 #define cmd_ptr ((struct ladish_command_remove_app *)context)
43 static bool run(void * context
)
45 ladish_app_supervisor_handle supervisor
;
46 ladish_app_handle app
;
47 const char * app_name
;
50 ASSERT(cmd_ptr
->command
.state
== LADISH_COMMAND_STATE_PENDING
);
52 log_info("remove app command. opath='%s'", cmd_ptr
->opath
);
54 supervisor
= ladish_studio_find_app_supervisor(cmd_ptr
->opath
);
55 if (supervisor
== NULL
)
57 log_error("cannot find supervisor '%s' to remove app from", cmd_ptr
->opath
);
58 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH
, "Cannot remove app because of internal error (unknown supervisor)", NULL
);
62 app
= ladish_app_supervisor_find_app_by_id(supervisor
, cmd_ptr
->id
);
65 log_error("App with ID %"PRIu64
" not found and (remove)", cmd_ptr
->id
);
66 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH
, "Cannot remove app because it is not found", NULL
);
70 app_name
= ladish_app_get_name(app
);
71 ladish_app_get_uuid(app
, app_uuid
);
73 if (ladish_app_is_running(app
))
75 if (cmd_ptr
->command
.state
== LADISH_COMMAND_STATE_PENDING
)
77 log_info("App %s is not stopped as it should", app_name
);
78 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH
, "Cannot remove app because it is not stopped (because of internal error)", NULL
);
83 /* remove jclient and vclient for this app */
84 log_info("Removing graph objects for app '%s'", app_name
);
85 ladish_virtualizer_remove_app(ladish_studio_get_jack_graph(), app_uuid
, app_name
);
87 ladish_app_supervisor_remove_app(supervisor
, app
);
88 cmd_ptr
->command
.state
= LADISH_COMMAND_STATE_DONE
;
92 static void destructor(void * context
)
94 log_info("remove_app command destructor");
100 bool ladish_command_remove_app(void * call_ptr
, struct ladish_cqueue
* queue_ptr
, const char * opath
, uint64_t id
)
102 struct ladish_command_remove_app
* cmd_ptr
;
105 if (!ladish_command_change_app_state(call_ptr
, queue_ptr
, opath
, id
, LADISH_APP_STATE_STOPPED
))
110 opath_dup
= strdup(opath
);
111 if (opath_dup
== NULL
)
113 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "strdup('%s') failed.", opath
);
114 goto fail_drop_stop_command
;
117 cmd_ptr
= ladish_command_new(sizeof(struct ladish_command_remove_app
));
120 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_command_new() failed.");
121 goto fail_free_opath
;
124 cmd_ptr
->command
.run
= run
;
125 cmd_ptr
->command
.destructor
= destructor
;
126 cmd_ptr
->opath
= opath_dup
;
129 if (!ladish_cqueue_add_command(queue_ptr
, &cmd_ptr
->command
))
131 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_cqueue_add_command() failed.");
132 goto fail_destroy_command
;
137 fail_destroy_command
:
141 fail_drop_stop_command
:
142 ladish_cqueue_drop_command(queue_ptr
);