use strings for app levels

With jack-session on the manege, strict L0-L3 classification
does not reflect the actual situation. LASH and jack-session
are still L2 though.
pull/1/head
Nedko Arnaudov 13 years ago
parent 78f07f7ad1
commit 997630bfb7

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2009,2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains stuff that is needed almost everywhere in ladish
@ -46,4 +46,14 @@
#define ladish_max(a, b) ((a) > (b) ? (a) : (b))
#define ladish_min(a, b) ((a) < (b) ? (a) : (b))
extern const char * g_app_L0_constant;
extern const char * g_app_L1_constant;
extern const char * g_app_L2_lash_constant;
extern const char * g_app_L2_js_constant;
#define LADISH_APP_LEVEL_0 g_app_L0_constant
#define LADISH_APP_LEVEL_1 g_app_L1_constant
#define LADISH_APP_LEVEL_LASH g_app_L2_lash_constant
#define LADISH_APP_LEVEL_JACKSESSION g_app_L2_js_constant
const char * ladish_map_app_level_constant(const char * level);
#endif /* #ifndef COMMON_H__82C9504A_ACD2_435D_9743_781943473E6A__INCLUDED */

@ -45,7 +45,7 @@ struct ladish_app
char * name;
char * commandline;
bool terminal;
uint8_t level;
char level[MAX_LEVEL_CHARCOUNT];
pid_t pid;
pid_t pgrp;
pid_t firstborn_pid;
@ -69,6 +69,29 @@ struct ladish_app_supervisor
ladish_app_supervisor_on_app_renamed_callback on_app_renamed;
};
bool ladish_check_app_level_validity(const char * level, size_t * len_ptr)
{
size_t len;
len = strlen(level);
if (len >= MAX_LEVEL_CHARCOUNT)
{
return false;
}
if (strcmp(level, LADISH_APP_LEVEL_0) != 0 &&
strcmp(level, LADISH_APP_LEVEL_1) != 0)
{
return false;
}
if (len_ptr != NULL)
{
*len_ptr = len;
}
return true;
}
bool
ladish_app_supervisor_create(
ladish_app_supervisor_handle * supervisor_handle_ptr,
@ -162,9 +185,11 @@ void emit_app_state_changed(struct ladish_app_supervisor * supervisor_ptr, struc
{
dbus_bool_t running;
dbus_bool_t terminal;
const char * level;
running = app_ptr->pid != 0;
terminal = app_ptr->terminal;
level = app_ptr->level;
supervisor_ptr->version++;
@ -173,13 +198,13 @@ void emit_app_state_changed(struct ladish_app_supervisor * supervisor_ptr, struc
supervisor_ptr->opath,
IFACE_APP_SUPERVISOR,
"AppStateChanged",
"ttsbby",
"ttsbbs",
&supervisor_ptr->version,
&app_ptr->id,
&app_ptr->name,
&running,
&terminal,
&app_ptr->level);
&level);
}
#define supervisor_ptr ((struct ladish_app_supervisor *)supervisor_handle)
@ -254,11 +279,18 @@ ladish_app_supervisor_add(
bool autorun,
const char * command,
bool terminal,
uint8_t level)
const char * level)
{
struct ladish_app * app_ptr;
dbus_bool_t running;
dbus_bool_t dbus_terminal;
size_t len;
if (!ladish_check_app_level_validity(level, &len))
{
log_error("invalid level '%s'", level);
return NULL;
}
app_ptr = malloc(sizeof(struct ladish_app));
if (app_ptr == NULL)
@ -285,7 +317,7 @@ ladish_app_supervisor_add(
}
app_ptr->terminal = terminal;
app_ptr->level = level;
memcpy(app_ptr->level, level, len + 1);
app_ptr->pid = 0;
app_ptr->pgrp = 0;
app_ptr->firstborn_pid = 0;
@ -311,18 +343,19 @@ ladish_app_supervisor_add(
running = false;
dbus_terminal = terminal;
level = app_ptr->level;
dbus_signal_emit(
g_dbus_connection,
supervisor_ptr->opath,
IFACE_APP_SUPERVISOR,
"AppAdded",
"ttsbby",
"ttsbbs",
&supervisor_ptr->version,
&app_ptr->id,
&app_ptr->name,
&running,
&dbus_terminal,
&app_ptr->level);
&level);
return (ladish_app_handle)app_ptr;
}
@ -614,7 +647,7 @@ ladish_app_supervisor_enum(
static inline void ladish_app_save_L1_internal(struct ladish_app * app_ptr)
{
if (app_ptr->level == 1)
if (strcmp(app_ptr->level, LADISH_APP_LEVEL_1) == 0)
{
ladish_app_send_signal(app_ptr, SIGUSR1, true);
}
@ -852,7 +885,7 @@ void ladish_app_supervisor_dump(ladish_app_supervisor_handle supervisor_handle)
uuid_unparse(app_ptr->uuid, uuid_str);
log_info("app '%s' with commandline '%s'", app_ptr->name, app_ptr->commandline);
log_info(" %s", uuid_str);
log_info(" %s, %s, level %u", app_ptr->terminal ? "terminal" : "shell", app_ptr->autorun ? "autorun" : "stopped", (unsigned int)app_ptr->level, app_ptr->commandline);
log_info(" %s, %s, level '%s'", app_ptr->terminal ? "terminal" : "shell", app_ptr->autorun ? "autorun" : "stopped", app_ptr->level, app_ptr->commandline);
}
}
@ -871,6 +904,7 @@ static void get_all(struct dbus_method_call * call_ptr)
struct ladish_app * app_ptr;
dbus_bool_t running;
dbus_bool_t terminal;
const char * level;
//log_info("get_all called");
@ -887,7 +921,7 @@ static void get_all(struct dbus_method_call * call_ptr)
goto fail_unref;
}
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(tsbby)", &array_iter))
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(tsbbs)", &array_iter))
{
goto fail_unref;
}
@ -925,7 +959,8 @@ static void get_all(struct dbus_method_call * call_ptr)
goto fail_unref;
}
if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE, &app_ptr->level))
level = app_ptr->level;
if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &level))
{
goto fail_unref;
}
@ -956,7 +991,7 @@ static void run_custom(struct dbus_method_call * call_ptr)
dbus_bool_t terminal;
const char * commandline;
const char * name;
uint8_t level;
const char * level;
if (!dbus_message_get_args(
call_ptr->message,
@ -964,7 +999,7 @@ static void run_custom(struct dbus_method_call * call_ptr)
DBUS_TYPE_BOOLEAN, &terminal,
DBUS_TYPE_STRING, &commandline,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_BYTE, &level,
DBUS_TYPE_STRING, &level,
DBUS_TYPE_INVALID))
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
@ -972,11 +1007,11 @@ static void run_custom(struct dbus_method_call * call_ptr)
return;
}
log_info("run_custom('%s', %s, '%s', %"PRIu8") called", name, terminal ? "terminal" : "shell", commandline, level);
log_info("run_custom('%s', %s, '%s', '%s') called", name, terminal ? "terminal" : "shell", commandline, level);
if (level != 0 && level != 1)
if (!ladish_check_app_level_validity(level, NULL))
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "invalid level %"PRIu8, level);
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "invalid level '%s'", level);
return;
}
@ -1062,6 +1097,7 @@ static void get_app_properties(struct dbus_method_call * call_ptr)
struct ladish_app * app_ptr;
dbus_bool_t running;
dbus_bool_t terminal;
const char * level;
if (!dbus_message_get_args(
call_ptr->message,
@ -1083,6 +1119,7 @@ static void get_app_properties(struct dbus_method_call * call_ptr)
running = app_ptr->pid != 0;
terminal = app_ptr->terminal;
level = app_ptr->level;
call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
if (call_ptr->reply == NULL)
@ -1096,7 +1133,7 @@ static void get_app_properties(struct dbus_method_call * call_ptr)
DBUS_TYPE_STRING, &app_ptr->commandline,
DBUS_TYPE_BOOLEAN, &running,
DBUS_TYPE_BOOLEAN, &terminal,
DBUS_TYPE_BYTE, &app_ptr->level,
DBUS_TYPE_STRING, &level,
DBUS_TYPE_INVALID))
{
goto fail_unref;
@ -1118,10 +1155,11 @@ static void set_app_properties(struct dbus_method_call * call_ptr)
dbus_bool_t terminal;
const char * name;
const char * commandline;
uint8_t level;
const char * level;
struct ladish_app * app_ptr;
char * name_buffer;
char * commandline_buffer;
size_t len;
if (!dbus_message_get_args(
call_ptr->message,
@ -1130,7 +1168,7 @@ static void set_app_properties(struct dbus_method_call * call_ptr)
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &commandline,
DBUS_TYPE_BOOLEAN, &terminal,
DBUS_TYPE_BYTE, &level,
DBUS_TYPE_STRING, &level,
DBUS_TYPE_INVALID))
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
@ -1145,6 +1183,12 @@ static void set_app_properties(struct dbus_method_call * call_ptr)
return;
}
if (!ladish_check_app_level_validity(level, &len))
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "invalid level '%s'", level);
return;
}
if (app_ptr->pid != 0 && strcmp(commandline, app_ptr->commandline) != 0)
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "Cannot change commandline when app is running. '%s' -> '%s'", app_ptr->commandline, commandline);
@ -1157,7 +1201,7 @@ static void set_app_properties(struct dbus_method_call * call_ptr)
return;
}
if (app_ptr->pid != 0 && app_ptr->level != level)
if (app_ptr->pid != 0 && strcmp(app_ptr->level, level) != 0)
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "Cannot change app level when app is running");
return;
@ -1208,7 +1252,7 @@ static void set_app_properties(struct dbus_method_call * call_ptr)
app_ptr->commandline = commandline_buffer;
}
app_ptr->level = level;
memcpy(app_ptr->level, level, len + 1);
app_ptr->terminal = terminal;
emit_app_state_changed(supervisor_ptr, app_ptr);
@ -1270,14 +1314,14 @@ static void is_app_running(struct dbus_method_call * call_ptr)
METHOD_ARGS_BEGIN(GetAll, "Get list of apps")
METHOD_ARG_DESCRIBE_OUT("list_version", DBUS_TYPE_UINT64_AS_STRING, "Version of the list")
METHOD_ARG_DESCRIBE_OUT("apps_list", "a(tsbby)", "List of apps")
METHOD_ARG_DESCRIBE_OUT("apps_list", "a(tsbbs)", "List of apps")
METHOD_ARGS_END
METHOD_ARGS_BEGIN(RunCustom, "Start application by supplying commandline")
METHOD_ARG_DESCRIBE_IN("terminal", DBUS_TYPE_BOOLEAN_AS_STRING, "Whether to run in terminal")
METHOD_ARG_DESCRIBE_IN("commandline", DBUS_TYPE_STRING_AS_STRING, "Commandline")
METHOD_ARG_DESCRIBE_IN("name", DBUS_TYPE_STRING_AS_STRING, "Name")
METHOD_ARG_DESCRIBE_IN("level", DBUS_TYPE_BYTE_AS_STRING, "Level")
METHOD_ARG_DESCRIBE_IN("level", DBUS_TYPE_STRING_AS_STRING, "Level")
METHOD_ARGS_END
METHOD_ARGS_BEGIN(StartApp, "Start application")
@ -1302,7 +1346,7 @@ METHOD_ARGS_BEGIN(GetAppProperties, "Get properties of an application")
METHOD_ARG_DESCRIBE_OUT("commandline", DBUS_TYPE_STRING_AS_STRING, "Commandline")
METHOD_ARG_DESCRIBE_OUT("running", DBUS_TYPE_BOOLEAN_AS_STRING, "")
METHOD_ARG_DESCRIBE_OUT("terminal", DBUS_TYPE_BOOLEAN_AS_STRING, "Whether to run in terminal")
METHOD_ARG_DESCRIBE_OUT("level", DBUS_TYPE_BYTE_AS_STRING, "Level")
METHOD_ARG_DESCRIBE_OUT("level", DBUS_TYPE_STRING_AS_STRING, "Level")
METHOD_ARGS_END
METHOD_ARGS_BEGIN(SetAppProperties, "Set properties of an application")
@ -1310,7 +1354,7 @@ METHOD_ARGS_BEGIN(SetAppProperties, "Set properties of an application")
METHOD_ARG_DESCRIBE_IN("name", DBUS_TYPE_STRING_AS_STRING, "")
METHOD_ARG_DESCRIBE_IN("commandline", DBUS_TYPE_STRING_AS_STRING, "Commandline")
METHOD_ARG_DESCRIBE_IN("terminal", DBUS_TYPE_BOOLEAN_AS_STRING, "Whether to run in terminal")
METHOD_ARG_DESCRIBE_IN("level", DBUS_TYPE_BYTE_AS_STRING, "Level")
METHOD_ARG_DESCRIBE_IN("level", DBUS_TYPE_STRING_AS_STRING, "Level")
METHOD_ARGS_END
METHOD_ARGS_BEGIN(IsAppRunning, "Check whether application is running")
@ -1337,7 +1381,7 @@ SIGNAL_ARGS_BEGIN(AppAdded, "")
SIGNAL_ARG_DESCRIBE("name", DBUS_TYPE_STRING_AS_STRING, "")
SIGNAL_ARG_DESCRIBE("running", DBUS_TYPE_BOOLEAN_AS_STRING, "")
SIGNAL_ARG_DESCRIBE("terminal", DBUS_TYPE_BOOLEAN_AS_STRING, "Whether to run in terminal")
SIGNAL_ARG_DESCRIBE("level", DBUS_TYPE_BYTE_AS_STRING, "Level")
SIGNAL_ARG_DESCRIBE("level", DBUS_TYPE_STRING_AS_STRING, "Level")
SIGNAL_ARGS_END
SIGNAL_ARGS_BEGIN(AppRemoved, "")
@ -1351,7 +1395,7 @@ SIGNAL_ARGS_BEGIN(AppStateChanged, "")
SIGNAL_ARG_DESCRIBE("name", DBUS_TYPE_STRING_AS_STRING, "")
SIGNAL_ARG_DESCRIBE("running", DBUS_TYPE_BOOLEAN_AS_STRING, "")
SIGNAL_ARG_DESCRIBE("terminal", DBUS_TYPE_BOOLEAN_AS_STRING, "Whether to run in terminal")
SIGNAL_ARG_DESCRIBE("level", DBUS_TYPE_BYTE_AS_STRING, "Level")
SIGNAL_ARG_DESCRIBE("level", DBUS_TYPE_STRING_AS_STRING, "Level")
SIGNAL_ARGS_END
SIGNALS_BEGIN

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains interface to app supervisor object
@ -35,6 +35,8 @@
#define LADISH_APP_STATE_STOPPING 2 /**< @brief app is stopping */
#define LADISH_APP_STATE_KILL 3 /**< @brief app is being force killed */
#define MAX_LEVEL_CHARCOUNT 10 /* includes terminating nul char */
/**
* App supervisor object handle (pointer to opaque data)
*/
@ -79,10 +81,22 @@ typedef bool (* ladish_app_supervisor_enum_callback)(
bool running,
const char * command,
bool terminal,
uint8_t level,
const char * level,
pid_t pid,
const uuid_t uuid);
/**
* Check whether app level string is valid.
*
* @param [in] app level string
* @param [out] len_ptr When not NULL, the pointed variable will receive length of the level string, excluding terminating nul char.
*
* @return whether level string is valid
*/
bool
ladish_check_app_level_validity(
const char * level,
size_t * len_ptr);
/**
* Create app supervisor object
*
@ -206,7 +220,7 @@ ladish_app_supervisor_add(
bool autorun,
const char * command,
bool terminal,
uint8_t level);
const char * level);
/**
* Initiate stop of all apps owned by this supervisor

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains interface to the command queue stuff
@ -78,7 +78,7 @@ ladish_command_new_app(
bool terminal,
const char * commandline,
const char * name,
uint8_t level);
const char * level);
bool ladish_command_change_app_state(void * call_ptr, struct ladish_cqueue * queue_ptr, const char * opath, uint64_t id, unsigned int target_state);
bool ladish_command_remove_app(void * call_ptr, struct ladish_cqueue * queue_ptr, const char * opath, uint64_t id);

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains implementation of the "load studio" command
@ -65,6 +65,7 @@ static void callback_chrdata(void * data, const XML_Char * s, int len)
static void callback_elstart(void * data, const char * el, const char ** attr)
{
const char * name;
const char * level;
char * name_dup;
const char * path;
const char * uuid_str;
@ -75,6 +76,7 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
ladish_port_handle port2;
uint32_t port_type;
uint32_t port_flags;
size_t len;
name_dup = NULL;
@ -551,13 +553,23 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
goto free;
}
if (ladish_get_byte_attribute(attr, "level", &context_ptr->level) == NULL)
level = ladish_get_string_attribute(attr, "level");
if (level == NULL)
{
log_error("application \"level\" attribute is not available. name=\"%s\"", name);
context_ptr->error = XML_TRUE;
goto free;
}
if (!ladish_check_app_level_validity(level, &len))
{
log_error("application \"level\" attribute has invalid value \"%s\", name=\"%s\"", level, name);
context_ptr->error = XML_TRUE;
goto free;
}
memcpy(context_ptr->level, level, len + 1);
context_ptr->str = strdup(name);
if (context_ptr->str == NULL)
{
@ -835,7 +847,7 @@ static void callback_elend(void * data, const char * el)
context_ptr->data[unescape(context_ptr->data, context_ptr->data_used, context_ptr->data)] = 0;
unescape_simple(context_ptr->str);
log_info("application '%s' (%s, %s, level %u) with commandline '%s'", context_ptr->str, context_ptr->terminal ? "terminal" : "shell", context_ptr->autorun ? "autorun" : "stopped", (unsigned int)context_ptr->level, context_ptr->data);
log_info("application '%s' (%s, %s, level '%s') with commandline '%s'", context_ptr->str, context_ptr->terminal ? "terminal" : "shell", context_ptr->autorun ? "autorun" : "stopped", context_ptr->level, context_ptr->data);
if (ladish_app_supervisor_add(
g_studio.app_supervisor,

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains implementation of the "new app" command
@ -36,7 +36,7 @@ struct ladish_command_new_app
bool terminal;
char * commandline;
char * name;
uint8_t level;
char * level;
};
#define cmd_ptr ((struct ladish_command_new_app *)context)
@ -53,7 +53,7 @@ static bool run(void * context)
ASSERT(cmd_ptr->command.state == LADISH_COMMAND_STATE_PENDING);
log_info("new_app command. opath='%s', name='%s', %s, commandline='%s', level=%"PRIu8") called", cmd_ptr->opath, cmd_ptr->name, cmd_ptr->terminal ? "terminal" : "shell", cmd_ptr->commandline, cmd_ptr->level);
log_info("new_app command. opath='%s', name='%s', %s, commandline='%s', level='%s') called", cmd_ptr->opath, cmd_ptr->name, cmd_ptr->terminal ? "terminal" : "shell", cmd_ptr->commandline, cmd_ptr->level);
supervisor = ladish_studio_find_app_supervisor(cmd_ptr->opath);
if (supervisor == NULL)
@ -154,6 +154,7 @@ static void destructor(void * context)
free(cmd_ptr->opath);
free(cmd_ptr->commandline);
free(cmd_ptr->name);
free(cmd_ptr->level);
}
#undef cmd_ptr
@ -166,12 +167,13 @@ ladish_command_new_app(
bool terminal,
const char * commandline,
const char * name,
uint8_t level)
const char * level)
{
struct ladish_command_new_app * cmd_ptr;
char * opath_dup;
char * commandline_dup;
char * name_dup;
char * level_dup;
opath_dup = strdup(opath);
if (opath_dup == NULL)
@ -194,11 +196,18 @@ ladish_command_new_app(
goto fail_free_commandline;
}
level_dup = strdup(level);
if (level_dup == NULL)
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup('%s') failed.", level);
goto fail_free_name;
}
cmd_ptr = ladish_command_new(sizeof(struct ladish_command_new_app));
if (cmd_ptr == NULL)
{
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_command_new() failed.");
goto fail_free_name;
goto fail_free_level;
}
cmd_ptr->command.run = run;
@ -207,7 +216,7 @@ ladish_command_new_app(
cmd_ptr->commandline = commandline_dup;
cmd_ptr->name = name_dup;
cmd_ptr->terminal = terminal;
cmd_ptr->level = level;
cmd_ptr->level = level_dup;
if (!ladish_cqueue_add_command(queue_ptr, &cmd_ptr->command))
{
@ -219,6 +228,8 @@ ladish_command_new_app(
fail_destroy_command:
free(cmd_ptr);
fail_free_level:
free(level_dup);
fail_free_name:
free(name_dup);
fail_free_commandline:

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains inteface for the load helper functions
@ -73,7 +73,7 @@ struct ladish_parse_context
uint64_t connection_id;
bool terminal;
bool autorun;
uint8_t level;
char level[MAX_LEVEL_CHARCOUNT];
void * parser;
};

@ -621,7 +621,7 @@ ladish_room_app_is_stopped(
bool running,
const char * command,
bool terminal,
uint8_t level,
const char * level,
pid_t pid,
const uuid_t uuid)
{
@ -648,7 +648,7 @@ ladish_remove_room_app(
bool running,
const char * command,
bool terminal,
uint8_t level,
const char * level,
pid_t pid,
const uuid_t uuid)
{

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains the parts of room object implementation
@ -70,6 +70,7 @@ static void callback_chrdata(void * data, const XML_Char * s, int len)
static void callback_elstart(void * data, const char * el, const char ** attr)
{
const char * name;
const char * level;
char * name_dup;
const char * uuid_str;
uuid_t uuid;
@ -551,13 +552,23 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
goto free;
}
if (ladish_get_byte_attribute(attr, "level", &context_ptr->level) == NULL)
level = ladish_get_string_attribute(attr, "level");
if (level == NULL)
{
log_error("application \"level\" attribute is not available. name=\"%s\"", name);
context_ptr->error = XML_TRUE;
goto free;
}
if (!ladish_check_app_level_validity(level, &len))
{
log_error("application \"level\" attribute has invalid value \"%s\", name=\"%s\"", level, name);
context_ptr->error = XML_TRUE;
goto free;
}
memcpy(context_ptr->level, level, len + 1);
context_ptr->str = strdup(name);
if (context_ptr->str == NULL)
{

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains implementation save releated helper functions
@ -735,11 +735,10 @@ ladish_save_app(
bool running,
const char * command,
bool terminal,
uint8_t level,
const char * level,
pid_t pid,
const uuid_t uuid)
{
char buf[100];
const char * unescaped_string;
char * escaped_string;
char * escaped_buffer;
@ -748,7 +747,7 @@ ladish_save_app(
uuid_unparse(uuid, str);
log_info("saving app: name='%s', %srunning, %s, level %u, commandline='%s'", name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level, command);
log_info("saving app: name='%s', %srunning, %s, level '%s', commandline='%s'", name, running ? "" : "not ", terminal ? "terminal" : "shell", level, command);
ret = false;
@ -798,9 +797,7 @@ ladish_save_app(
goto free_buffer;
}
sprintf(buf, "%u", (unsigned int)level);
if (!ladish_write_string(fd, buf))
if (!ladish_write_string(fd, level))
{
goto free_buffer;
}

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file implements dialogs that are not implemented in dedicated files
@ -40,9 +40,9 @@ void run_custom_command_dialog(void)
GtkToggleButton * terminal_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_terminal_check_button"));
GtkToggleButton * level0_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level0"));
GtkToggleButton * level1_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level1"));
GtkToggleButton * level2_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level2"));
GtkToggleButton * level3_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level3"));
uint8_t level;
GtkToggleButton * level2lash_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level2lash"));
GtkToggleButton * level2js_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level2js"));
const char * level;
view = get_current_view();
@ -65,28 +65,28 @@ void run_custom_command_dialog(void)
{
if (gtk_toggle_button_get_active(level0_button))
{
level = 0;
level = LADISH_APP_LEVEL_0;
}
else if (gtk_toggle_button_get_active(level1_button))
{
level = 1;
level = LADISH_APP_LEVEL_1;
}
else if (gtk_toggle_button_get_active(level2_button))
else if (gtk_toggle_button_get_active(level2lash_button))
{
level = 2;
level = LADISH_APP_LEVEL_LASH;
}
else if (gtk_toggle_button_get_active(level3_button))
else if (gtk_toggle_button_get_active(level2js_button))
{
level = 3;
level = LADISH_APP_LEVEL_JACKSESSION;
}
else
{
log_error("unknown level");
ASSERT_NO_PASS;
level = 0;
level = LADISH_APP_LEVEL_0;
}
log_info("'%s':'%s' %s level %"PRIu8, gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button) ? "terminal" : "shell", level);
log_info("'%s':'%s' %s level '%s'", gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button) ? "terminal" : "shell", level);
if (!app_run_custom(
view,
gtk_entry_get_text(command_entry),

@ -1231,8 +1231,8 @@ along with LADI Session Handler; if not, write to the Free Software Foundation,
</packing>
</child>
<child>
<object class="GtkRadioButton" id="app_level2">
<property name="label" translatable="yes">Level 2</property>
<object class="GtkRadioButton" id="app_level2lash">
<property name="label" translatable="yes">Level 2 (LASH)</property>
<property name="active">True</property>
<property name="can_focus">True</property>
<property name="draw_indicator">True</property>
@ -1250,8 +1250,8 @@ along with LADI Session Handler; if not, write to the Free Software Foundation,
</packing>
</child>
<child>
<object class="GtkRadioButton" id="app_level3">
<property name="label" translatable="yes">Level 3</property>
<object class="GtkRadioButton" id="app_level2js">
<property name="label" translatable="yes">Level 2 (jack session)</property>
<property name="active">True</property>
<property name="can_focus">True</property>
<property name="draw_indicator">True</property>

@ -103,15 +103,15 @@ static void detach_canvas(struct graph_view * view_ptr)
#define view_ptr ((struct graph_view *)context)
static void app_added(void * context, uint64_t id, const char * name, bool running, bool terminal, uint8_t level)
static void app_added(void * context, uint64_t id, const char * name, bool running, bool terminal, const char * level)
{
//log_info("app added. id=%"PRIu64", name='%s', %srunning, %s, level %u", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level);
//log_info("app added. id=%"PRIu64", name='%s', %srunning, %s, level '%s'", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", level);
world_tree_add_app(context, id, name, running, terminal, level);
}
static void app_state_changed(void * context, uint64_t id, const char * name, bool running, bool terminal, uint8_t level)
static void app_state_changed(void * context, uint64_t id, const char * name, bool running, bool terminal, const char * level)
{
//log_info("app state changed. id=%"PRIu64", name='%s', %srunning, %s, level %u", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level);
//log_info("app state changed. id=%"PRIu64", name='%s', %srunning, %s, level '%s'", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", level);
world_tree_app_state_changed(context, id, name, running, terminal, level);
}
@ -474,7 +474,7 @@ bool is_room_view(graph_view_handle view)
return view_ptr->room != NULL;
}
bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal, uint8_t level)
bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal, const char * level)
{
return ladish_app_supervisor_proxy_run_custom(view_ptr->app_supervisor, command, name, run_in_terminal, level);
}

@ -58,7 +58,7 @@ bool is_room_view(graph_view_handle view);
bool room_has_project(graph_view_handle view);
ladish_app_supervisor_proxy_handle graph_view_get_app_supervisor(graph_view_handle view);
bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal, uint8_t level);
bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal, const char * level);
ladish_room_proxy_handle graph_view_get_room(graph_view_handle view);

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2008, 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2008, 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains implementation of the project_list class
@ -231,15 +231,15 @@ void on_popup_menu_action_app_properties(GtkWidget * menuitem, gpointer userdata
char * command;
bool running;
bool terminal;
uint8_t level;
const char * level;
guint result;
GtkEntry * command_entry = GTK_ENTRY(get_gtk_builder_widget("app_command_entry"));
GtkEntry * name_entry = GTK_ENTRY(get_gtk_builder_widget("app_name_entry"));
GtkToggleButton * terminal_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_terminal_check_button"));
GtkToggleButton * level0_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level0"));
GtkToggleButton * level1_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level1"));
GtkToggleButton * level2_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level2"));
GtkToggleButton * level3_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level3"));
GtkToggleButton * level2lash_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level2lash"));
GtkToggleButton * level2js_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level2js"));
if (!get_selected_app_id(&view, &id))
{
@ -256,7 +256,7 @@ void on_popup_menu_action_app_properties(GtkWidget * menuitem, gpointer userdata
return;
}
log_info("'%s':'%s' %s level %"PRIu8, name, command, terminal ? "terminal" : "shell", level);
log_info("'%s':'%s' %s level '%s'", name, command, terminal ? "terminal" : "shell", level);
gtk_entry_set_text(name_entry, name);
gtk_entry_set_text(command_entry, command);
@ -267,21 +267,25 @@ void on_popup_menu_action_app_properties(GtkWidget * menuitem, gpointer userdata
gtk_widget_set_sensitive(GTK_WIDGET(level0_button), !running);
gtk_widget_set_sensitive(GTK_WIDGET(level1_button), !running);
switch (level)
/* comparing pointers here is ok, because ladish_map_app_level_constant() was called by ladish_app_supervisor_get_app_properties() */
if (level == LADISH_APP_LEVEL_0)
{
case 0:
gtk_toggle_button_set_active(level0_button, TRUE);
break;
case 1:
}
else if (level == LADISH_APP_LEVEL_1)
{
gtk_toggle_button_set_active(level1_button, TRUE);
break;
case 2:
gtk_toggle_button_set_active(level2_button, TRUE);
break;
case 3:
gtk_toggle_button_set_active(level3_button, TRUE);
break;
default:
}
else if (level == LADISH_APP_LEVEL_LASH)
{
gtk_toggle_button_set_active(level2lash_button, TRUE);
}
else if (level == LADISH_APP_LEVEL_JACKSESSION)
{
gtk_toggle_button_set_active(level2js_button, TRUE);
}
else
{
log_error("unknown level");
ASSERT_NO_PASS;
gtk_toggle_button_set_active(level0_button, TRUE);
@ -300,28 +304,28 @@ void on_popup_menu_action_app_properties(GtkWidget * menuitem, gpointer userdata
{
if (gtk_toggle_button_get_active(level0_button))
{
level = 0;
level = LADISH_APP_LEVEL_0;
}
else if (gtk_toggle_button_get_active(level1_button))
{
level = 1;
level = LADISH_APP_LEVEL_1;
}
else if (gtk_toggle_button_get_active(level2_button))
else if (gtk_toggle_button_get_active(level2lash_button))
{
level = 2;
level = LADISH_APP_LEVEL_LASH;
}
else if (gtk_toggle_button_get_active(level3_button))
else if (gtk_toggle_button_get_active(level2js_button))
{
level = 3;
level = LADISH_APP_LEVEL_JACKSESSION;
}
else
{
log_error("unknown level");
ASSERT_NO_PASS;
level = 0;
level = LADISH_APP_LEVEL_0;
}
log_info("'%s':'%s' %s level %"PRIu8, gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button) ? "terminal" : "shell", level);
log_info("'%s':'%s' %s level '%s'", gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button) ? "terminal" : "shell", level);
if (!ladish_app_supervisor_set_app_properties(proxy, id, gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button), level))
{
error_message_box(_("Cannot set app properties."));
@ -342,7 +346,7 @@ void popup_menu(GtkWidget * treeview, GdkEventButton * event)
uint64_t id;
gboolean running;
gboolean terminal;
uint8_t level;
const char * level;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_world_tree_widget));
if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
@ -505,7 +509,7 @@ void world_tree_init(void)
G_TYPE_UINT64,
G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN,
G_TYPE_CHAR);
G_TYPE_STRING);
gtk_tree_view_set_model(GTK_TREE_VIEW(g_world_tree_widget), GTK_TREE_MODEL(g_treestore));
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_world_tree_widget));
@ -634,20 +638,31 @@ void world_tree_name_changed(graph_view_handle view)
}
}
static char * get_app_name_string(const char * app_name, bool running, bool terminal, uint8_t level)
static char * get_app_name_string(const char * app_name, bool running, bool terminal, const char * level)
{
char * app_name_with_status;
const char * level_string;
switch (level)
level = ladish_map_app_level_constant(level);
/* comparing pointers here is ok, because ladish_map_app_level_constant() was called */
if (level == LADISH_APP_LEVEL_0)
{
case 0:
level_string = "[L0]";
break;
case 1:
}
else if (level == LADISH_APP_LEVEL_1)
{
level_string = "[L1]";
break;
default:
}
else if (level == LADISH_APP_LEVEL_LASH)
{
level_string = "[LASH]";
}
else if (level == LADISH_APP_LEVEL_JACKSESSION)
{
level_string = "[JS]";
}
else
{
level_string = "[L?]";
}
@ -661,7 +676,7 @@ static char * get_app_name_string(const char * app_name, bool running, bool term
return app_name_with_status;
}
void world_tree_add_app(graph_view_handle view, uint64_t id, const char * app_name, bool running, bool terminal, uint8_t level)
void world_tree_add_app(graph_view_handle view, uint64_t id, const char * app_name, bool running, bool terminal, const char * level)
{
GtkTreeIter iter;
const char * view_name;
@ -705,7 +720,7 @@ free_path:
gtk_tree_path_free(path);
}
void world_tree_app_state_changed(graph_view_handle view, uint64_t id, const char * app_name, bool running, bool terminal, uint8_t level)
void world_tree_app_state_changed(graph_view_handle view, uint64_t id, const char * app_name, bool running, bool terminal, const char * level)
{
GtkTreeIter view_iter;
GtkTreeIter app_iter;

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2008, 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2008, 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains the interface of the world tree widget
@ -36,8 +36,8 @@ void world_tree_remove(graph_view_handle view);
graph_view_handle world_tree_find_by_opath(const char * opath);
void world_tree_activate(graph_view_handle view);
void world_tree_name_changed(graph_view_handle view);
void world_tree_add_app(graph_view_handle view, uint64_t id, const char * name, bool running, bool terminal, uint8_t level);
void world_tree_app_state_changed(graph_view_handle view, uint64_t id, const char * name, bool running, bool terminal, uint8_t level);
void world_tree_add_app(graph_view_handle view, uint64_t id, const char * name, bool running, bool terminal, const char * level);
void world_tree_app_state_changed(graph_view_handle view, uint64_t id, const char * name, bool running, bool terminal, const char * level);
void world_tree_remove_app(graph_view_handle view, uint64_t id);
void world_tree_destroy_room_views(void);

@ -2,7 +2,7 @@
#
# LADI Session Handler (ladish)
#
# Copyright (C) 2008, 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
# Copyright (C) 2008, 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
#
#*************************************************************************
# This file contains code of the commandline control app
@ -102,7 +102,7 @@ def parse_new_app_args(params_array):
index = 1
name = ''
level = 0
level = '0'
term = False
if index < len(params_array):
@ -115,7 +115,7 @@ def parse_new_app_args(params_array):
if params_array[index] == '-':
return index + 1, cmdline, name, level, term
# direct conversion to dbus.Byte is wrong because ord() is used ("1" -> 0x31 instead of "1" -> 0x01)
level = int(params_array[index])
level = params_array[index]
index += 1
if index < len(params_array):

@ -2,7 +2,7 @@
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains implementation of code that interfaces
@ -34,8 +34,8 @@ struct ladish_app_supervisor_proxy
uint64_t version;
void * context;
void (* app_added)(void * context, uint64_t id, const char * name, bool running, bool terminal, uint8_t level);
void (* app_state_changed)(void * context, uint64_t id, const char * name, bool running, bool terminal, uint8_t level);
void (* app_added)(void * context, uint64_t id, const char * name, bool running, bool terminal, const char * level);
void (* app_state_changed)(void * context, uint64_t id, const char * name, bool running, bool terminal, const char * level);
void (* app_removed)(void * context, uint64_t id);
};
@ -48,7 +48,7 @@ static void on_app_added(void * context, DBusMessage * message_ptr)
const char * name;
dbus_bool_t running;
dbus_bool_t terminal;
uint8_t level;
const char * level;
if (!dbus_message_get_args(
message_ptr,
@ -58,7 +58,7 @@ static void on_app_added(void * context, DBusMessage * message_ptr)
DBUS_TYPE_STRING, &name,
DBUS_TYPE_BOOLEAN, &running,
DBUS_TYPE_BOOLEAN, &terminal,
DBUS_TYPE_BYTE, &level,
DBUS_TYPE_STRING, &level,
DBUS_TYPE_INVALID))
{
log_error("dbus_message_get_args() failed to extract AppAdded signal arguments (%s)", g_dbus_error.message);
@ -66,7 +66,7 @@ static void on_app_added(void * context, DBusMessage * message_ptr)
return;
}
//log_info("AppAdded signal received. id=%"PRIu64", name='%s', %srunning, %s, level %u", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level);
//log_info("AppAdded signal received. id=%"PRIu64", name='%s', %srunning, %s, level '%s'", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", level);
if (new_list_version <= proxy_ptr->version)
{
@ -76,7 +76,16 @@ static void on_app_added(void * context, DBusMessage * message_ptr)
{
//log_info("got new list version %llu", (unsigned long long)version);
proxy_ptr->version = new_list_version;
proxy_ptr->app_added(proxy_ptr->context, id, name, running, terminal, level);
level = ladish_map_app_level_constant(level);
if (level != NULL)
{
proxy_ptr->app_added(proxy_ptr->context, id, name, running, terminal, level);
}
else
{
log_error("Ignoring app added signal for '%s' because of invalid app level value", name);
}
}
}
@ -117,7 +126,7 @@ static void on_app_state_changed(void * context, DBusMessage * message_ptr)
const char * name;
dbus_bool_t running;
dbus_bool_t terminal;
uint8_t level;
const char * level;
if (!dbus_message_get_args(
message_ptr,
@ -127,7 +136,7 @@ static void on_app_state_changed(void * context, DBusMessage * message_ptr)
DBUS_TYPE_STRING, &name,
DBUS_TYPE_BOOLEAN, &running,
DBUS_TYPE_BOOLEAN, &terminal,
DBUS_TYPE_BYTE, &level,
DBUS_TYPE_STRING, &level,
DBUS_TYPE_INVALID))
{
log_error("dbus_message_get_args() failed to extract AppStateChanged signal arguments (%s)", g_dbus_error.message);
@ -145,7 +154,16 @@ static void on_app_state_changed(void * context, DBusMessage * message_ptr)
{
//log_info("got new list version %llu", (unsigned long long)version);
proxy_ptr->version = new_list_version;
proxy_ptr->app_state_changed(proxy_ptr->context, id, name, running, terminal, level);
level = ladish_map_app_level_constant(level);
if (level != NULL)
{
proxy_ptr->app_state_changed(proxy_ptr->context, id, name, running, terminal, level);
}
else
{
log_error("Ignoring app state changed signal for '%s' because of invalid app level value", name);
}
}
}
@ -173,7 +191,7 @@ static void refresh_internal(struct ladish_app_supervisor_proxy * proxy_ptr, boo
const char * name;
dbus_bool_t running;
dbus_bool_t terminal;
uint8_t level;
const char * level;
log_info("refresh_internal() called");
@ -187,7 +205,7 @@ static void refresh_internal(struct ladish_app_supervisor_proxy * proxy_ptr, boo
reply_signature = dbus_message_get_signature(reply_ptr);
if (strcmp(reply_signature, "ta(tsbby)") != 0)
if (strcmp(reply_signature, "ta(tsbbs)") != 0)
{
log_error("GetAll() reply signature mismatch. '%s'", reply_signature);
goto unref;
@ -228,8 +246,16 @@ static void refresh_internal(struct ladish_app_supervisor_proxy * proxy_ptr, boo
dbus_message_iter_get_basic(&struct_iter, &level);
dbus_message_iter_next(&struct_iter);
//log_info("App id=%"PRIu64", name='%s', %srunning, %s, level %u", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level);
proxy_ptr->app_added(proxy_ptr->context, id, name, running, terminal, level);
level = ladish_map_app_level_constant(level);
if (level != NULL)
{
//log_info("App id=%"PRIu64", name='%s', %srunning, %s, level '%s'", id, name, running ?