From 15942e4836b212fd7f092f9df353ec54c872e2b8 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 2 Oct 2015 21:15:06 +0000 Subject: [PATCH] server: Convert com_select() to lopsub. Pretty straight-forward conversion since the command does not have any arguments. In the callback handler, we we can't return directly any more since we need to free the serialized parse result. --- afs.c | 31 +++++++++++++++++++------------ afs.cmd | 11 ----------- m4/lls/server_cmd.suite.m4 | 13 +++++++++++++ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/afs.c b/afs.c index 1084b715..761a637c 100644 --- a/afs.c +++ b/afs.c @@ -638,14 +638,17 @@ static void flush_and_free_pb(struct para_buffer *pb) static int com_select_callback(struct afs_callback_arg *aca) { - const char *arg = aca->query.data; + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(SELECT); + const char *arg; int num_admissible, ret; + ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr); + assert(ret >= 0); + arg = lls_input(0, aca->lpr); ret = clear_score_table(); if (ret < 0) { - para_printf(&aca->pbout, "could not clear score table: %s\n", - para_strerror(-ret)); - return ret; + para_printf(&aca->pbout, "could not clear score table\n"); + goto free_lpr; } if (current_play_mode == PLAY_MODE_MOOD) close_current_mood(); @@ -670,20 +673,24 @@ static int com_select_callback(struct afs_callback_arg *aca) out: para_printf(&aca->pbout, "activated %s (%d admissible files)\n", current_mop? current_mop : "dummy mood", num_admissible); +free_lpr: + lls_free_parse_result(aca->lpr, cmd); return ret; } -int com_select(struct command_context *cc) +static int com_select(struct command_context *cc, struct lls_parse_result *lpr) { - struct osl_object query; + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(SELECT); + char *errctx; + int ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx)); - if (cc->argc != 2) - return -E_AFS_SYNTAX; - query.data = cc->argv[1]; - query.size = strlen(cc->argv[1]) + 1; - return send_callback_request(com_select_callback, &query, - &afs_cb_result_handler, cc); + if (ret < 0) { + send_errctx(cc, errctx); + return ret; + } + return send_lls_callback_request(com_select_callback, cmd, lpr, cc); } +EXPORT_SERVER_CMD_HANDLER(select); static void init_admissible_files(char *arg) { diff --git a/afs.cmd b/afs.cmd index bf6d4734..74ad7df9 100644 --- a/afs.cmd +++ b/afs.cmd @@ -100,17 +100,6 @@ H: in pattern and not by an asterisk (*) or a question mark H: (?) metacharacter, nor by a bracket expression ([]) containing H: a slash (see fnmatch(3)). --- -N: select -P: AFS_READ | AFS_WRITE -D: Activate a mood or a playlist. -U: select specifier/name -H: The specifier is either 'm' or 'p' to indicate whether a playlist or -H: a mood should be activated. Example: -H: -H: select m/foo -H: -H: loads the mood named 'foo'. ---- T: add N: add@member@ O: int com_add@member@(struct command_context *cc); diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index 71beaa3d..eda1ba61 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -279,6 +279,19 @@ aux_info_prefix = Permissions: about the removed attributes in the audio file table is lost. [/description] +[subcommand select] + purpose = activate a mood or a playlist + non-opts-name = specifier/name + aux_info = AFS_READ | AFS_WRITE + [description] + The specifier is either 'm' or 'p' to indicate whether a playlist or + a mood should be activated. Example: + + select m/foo + + activates the mood named 'foo'. + [/description] + [subcommand sender] purpose = control paraslash senders synopsis = [sender cmd [arguments]] -- 2.39.5