daemon: refuse to delete room if it has active apps. Fix for #85

This commit is contained in:
Nedko Arnaudov 2010-04-26 03:47:10 +03:00
parent f94badb5fb
commit 8948f99d7c
3 changed files with 31 additions and 0 deletions

View File

@ -436,6 +436,25 @@ const char * ladish_app_supervisor_get_name(ladish_app_supervisor_handle supervi
return supervisor_ptr->name;
}
unsigned int ladish_app_supervisor_get_running_app_count(ladish_app_supervisor_handle supervisor_handle)
{
struct list_head * node_ptr;
struct ladish_app * app_ptr;
unsigned int counter;
counter = 0;
list_for_each(node_ptr, &supervisor_ptr->applist)
{
app_ptr = list_entry(node_ptr, struct ladish_app, siblings);
if (app_ptr->pid != 0)
{
counter++;
}
}
return counter;
}
#undef supervisor_ptr
#define supervisor_ptr ((struct ladish_app_supervisor *)call_ptr->iface_context)

View File

@ -81,6 +81,7 @@ ladish_app_supervisor_search_app(
pid_t pid);
const char * ladish_app_supervisor_get_name(ladish_app_supervisor_handle supervisor_handle);
unsigned int ladish_app_supervisor_get_running_app_count(ladish_app_supervisor_handle supervisor_handle);
extern const struct dbus_interface_descriptor g_iface_app_supervisor;

View File

@ -1129,6 +1129,7 @@ static void ladish_studio_delete_room(struct dbus_method_call * call_ptr)
ladish_room_handle room;
uuid_t room_uuid;
ladish_client_handle room_client;
unsigned int running_app_count;
dbus_error_init(&g_dbus_error);
@ -1146,6 +1147,16 @@ static void ladish_studio_delete_room(struct dbus_method_call * call_ptr)
room = ladish_room_from_list_node(node_ptr);
if (strcmp(ladish_room_get_name(room), name) == 0)
{
running_app_count = ladish_app_supervisor_get_running_app_count(ladish_room_get_app_supervisor(room));
if (running_app_count != 0)
{
/* TODO: instead of rejecting the room deletion, use the command queue and wait for room apps to stop.
This requires proper "project in room" implementation because project needs to be
unloaded anyway and unloading project should initiate and wait apps termination */
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot delete room \"%s\" because it has %u app(s) running", name, running_app_count);
return;
}
list_del(node_ptr);
emit_room_disappeared(room);