From 1f33eda05b3e96b32817a133287bcfc5e99ed6b4 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 30 Aug 2022 13:55:48 +0200 Subject: [PATCH] afs.c: Move com_select() and its callback down. Preparation for the upcoming introduction of afs_error(), which will be called by the select callback and should therefore be located above the callback. No code changes, nothing to see here. --- afs.c | 94 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/afs.c b/afs.c index cea8f270..6493586a 100644 --- a/afs.c +++ b/afs.c @@ -525,53 +525,6 @@ static void flush_and_free_pb(struct para_buffer *pb) free(pb->buf); } -static int com_select_callback(struct afs_callback_arg *aca) -{ - const struct lls_command *cmd = SERVER_CMD_CMD_PTR(SELECT); - const char *arg; - int ret; - - ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr); - assert(ret >= 0); - arg = lls_input(0, aca->lpr); - score_clear(); - if (current_play_mode == PLAY_MODE_MOOD) - mood_unload(); - else - playlist_unload(); - ret = activate_mood_or_playlist(arg, &aca->pbout); - if (ret >= 0) - goto free_lpr; - /* ignore subsequent errors (but log them) */ - if (current_mop && strcmp(current_mop, arg) != 0) { - int ret2; - para_printf(&aca->pbout, "switching back to %s\n", current_mop); - ret2 = activate_mood_or_playlist(current_mop, &aca->pbout); - if (ret2 >= 0) - goto free_lpr; - para_printf(&aca->pbout, "could not reactivate %s: %s\n", - current_mop, para_strerror(-ret2)); - } - activate_mood_or_playlist(NULL, &aca->pbout); -free_lpr: - lls_free_parse_result(aca->lpr, cmd); - return ret; -} - -static int com_select(struct command_context *cc, struct lls_parse_result *lpr) -{ - const struct lls_command *cmd = SERVER_CMD_CMD_PTR(SELECT); - char *errctx; - int ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx)); - - 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(const char *arg) { int ret = activate_mood_or_playlist(arg, NULL); @@ -985,6 +938,53 @@ out: exit(EXIT_FAILURE); } +static int com_select_callback(struct afs_callback_arg *aca) +{ + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(SELECT); + const char *arg; + int ret; + + ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr); + assert(ret >= 0); + arg = lls_input(0, aca->lpr); + score_clear(); + if (current_play_mode == PLAY_MODE_MOOD) + mood_unload(); + else + playlist_unload(); + ret = activate_mood_or_playlist(arg, &aca->pbout); + if (ret >= 0) + goto free_lpr; + /* ignore subsequent errors (but log them) */ + if (current_mop && strcmp(current_mop, arg) != 0) { + int ret2; + para_printf(&aca->pbout, "switching back to %s\n", current_mop); + ret2 = activate_mood_or_playlist(current_mop, &aca->pbout); + if (ret2 >= 0) + goto free_lpr; + para_printf(&aca->pbout, "could not reactivate %s: %s\n", + current_mop, para_strerror(-ret2)); + } + activate_mood_or_playlist(NULL, &aca->pbout); +free_lpr: + lls_free_parse_result(aca->lpr, cmd); + return ret; +} + +static int com_select(struct command_context *cc, struct lls_parse_result *lpr) +{ + const struct lls_command *cmd = SERVER_CMD_CMD_PTR(SELECT); + char *errctx; + int ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx)); + + 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 int com_init_callback(struct afs_callback_arg *aca) { uint32_t table_mask = *(uint32_t *)aca->query.data; -- 2.39.5