]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
server: Convert com_select() to lopsub.
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 2 Oct 2015 21:15:06 +0000 (21:15 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 26 Mar 2017 09:02:28 +0000 (11:02 +0200)
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
afs.cmd
m4/lls/server_cmd.suite.m4

diff --git a/afs.c b/afs.c
index 1084b715354d3532d5a3be038186a04fdd41f1c8..761a637cfe00caf14bc1850219cf139282bfc3bc 100644 (file)
--- 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 bf6d47341b500cc153c37c5bc07ceebdd51d35b9..74ad7df9babb251e80942954f527a2f5c691767c 100644 (file)
--- 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);
index 71beaa3da628807f43c5733f59df37df506ddd98..eda1ba6123178310bf6ac688df8b6bf05f491034 100644 (file)
@@ -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]]