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
;
49 ASSERT(cmd_ptr
->command
.state
== LADISH_COMMAND_STATE_PENDING
);
51 log_info("remove app command. opath='%s'", cmd_ptr
->opath
);
53 supervisor
= ladish_studio_find_app_supervisor(cmd_ptr
->opath
);
54 if (supervisor
== NULL
)
56 log_error("cannot find supervisor '%s' to remove app from", cmd_ptr
->opath
);
57 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH
, "Cannot remove app because of internal error (unknown supervisor)", NULL
);
61 app
= ladish_app_supervisor_find_app_by_id(supervisor
, cmd_ptr
->id
);
64 log_error("App with ID %"PRIu64
" not found and (remove)", cmd_ptr
->id
);
65 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH
, "Cannot remove app because it is not found", NULL
);
69 app_name
= ladish_app_get_name(app
);
71 if (ladish_app_is_running(app
))
73 if (cmd_ptr
->command
.state
== LADISH_COMMAND_STATE_PENDING
)
75 log_info("App %s is not stopped as it should", app_name
);
76 ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH
, "Cannot remove app because it is not stopped (because of internal error)", NULL
);
81 /* remove jclient and vclient for this app */
82 log_info("Removing graph objects for app '%s'", app_name
);
83 ladish_virtualizer_remove_app(ladish_studio_get_jack_graph(), app_name
);
85 ladish_app_supervisor_remove_app(supervisor
, app
);
86 cmd_ptr
->command
.state
= LADISH_COMMAND_STATE_DONE
;
90 static void destructor(void * context
)
92 log_info("remove_app command destructor");
98 bool ladish_command_remove_app(void * call_ptr
, struct ladish_cqueue
* queue_ptr
, const char * opath
, uint64_t id
)
100 struct ladish_command_remove_app
* cmd_ptr
;
103 if (!ladish_command_change_app_state(call_ptr
, queue_ptr
, opath
, id
, LADISH_APP_STATE_STOPPED
))
108 opath_dup
= strdup(opath
);
109 if (opath_dup
== NULL
)
111 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "strdup('%s') failed.", opath
);
112 goto fail_drop_stop_command
;
115 cmd_ptr
= ladish_command_new(sizeof(struct ladish_command_remove_app
));
118 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_command_new() failed.");
119 goto fail_free_opath
;
122 cmd_ptr
->command
.run
= run
;
123 cmd_ptr
->command
.destructor
= destructor
;
124 cmd_ptr
->opath
= opath_dup
;
127 if (!ladish_cqueue_add_command(queue_ptr
, &cmd_ptr
->command
))
129 lash_dbus_error(call_ptr
, LASH_DBUS_ERROR_GENERIC
, "ladish_cqueue_add_command() failed.");
130 goto fail_destroy_command
;
135 fail_destroy_command
:
139 fail_drop_stop_command
:
140 ladish_cqueue_drop_command(queue_ptr
);