From 144c8da3fb211847623e6d258b4c1f55112e2779 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 28 Sep 2014 17:02:46 +0000 Subject: [PATCH] server: Add com_tasks(). It is sometimes useful to see the task list of para_server. The infrastructure for obtaining this information is already in sched.c, so this is a rather simple matter. --- client.c | 1 + command.c | 10 ++++++++++ server.c | 13 +++++++++++++ server.cmd | 6 ++++++ server.h | 1 + 5 files changed, 31 insertions(+) diff --git a/client.c b/client.c index 4c4806f9..e0c97826 100644 --- a/client.c +++ b/client.c @@ -208,6 +208,7 @@ I9E_DUMMY_COMPLETER(version); I9E_DUMMY_COMPLETER(stop); I9E_DUMMY_COMPLETER(addatt); I9E_DUMMY_COMPLETER(init); +I9E_DUMMY_COMPLETER(tasks); static struct i9e_completer completers[]; diff --git a/command.c b/command.c index 09f00f2f..6880cb40 100644 --- a/command.c +++ b/command.c @@ -759,6 +759,16 @@ out: return ret; } +static int com_tasks(struct command_context *cc) +{ + char *tl = server_get_tasks(); + int ret = 1; + + if (tl) + ret = send_sb(&cc->scc, tl, strlen(tl), SBD_OUTPUT, false); + return ret; +} + /* * check if perms are sufficient to exec a command having perms cmd_perms. * Returns 0 if perms are sufficient, -E_PERM otherwise. diff --git a/server.c b/server.c index b5063e2d..fc81b944 100644 --- a/server.c +++ b/server.c @@ -113,6 +113,19 @@ struct server_command_task { struct task *task; }; +/** + * Return the list of tasks for the server process. + * + * This is called from \a com_tasks(). The helper is necessary since command + * handlers can not access the scheduler structure directly. + * + * \return A dynamically allocated string that must be freed by the caller. + */ +char *server_get_tasks(void) +{ + return get_task_list(&sched); +} + static int want_colors(void) { if (conf.color_arg == color_arg_no) diff --git a/server.cmd b/server.cmd index ebe372b7..5f46ba1e 100644 --- a/server.cmd +++ b/server.cmd @@ -108,6 +108,12 @@ U: stop H: Clear the 'P' (playing) bit and set the 'N' (next audio file) bit of the vss H: status flags, effectively stopping playback. --- +N: tasks +P: 0 +D: List server tasks. +U: tasks +H: For each task, print ID, status and name. +--- N: term P: VSS_READ | VSS_WRITE D: Ask the server to terminate. diff --git a/server.h b/server.h index 16449e6d..e24dd834 100644 --- a/server.h +++ b/server.h @@ -98,3 +98,4 @@ extern struct server_args_info conf; __noreturn void handle_connect(int fd, const char *peername); void parse_config_or_die(int override); +char *server_get_tasks(void); -- 2.39.2