From 1f31fcdd74ab1aab01cbc70942f9d69bb779156a Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 22 Oct 2022 21:54:29 +0200 Subject: [PATCH] server: Implement select -verbose. Just set ->pbout to NULL if the new option is not given. This supresses normal output while error messages still make it to the client because those are sent with afs_error(). --- afs.c | 9 ++++++--- m4/lls/server_cmd.suite.m4 | 3 +++ mood.c | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/afs.c b/afs.c index 78e42eae..cb3ead27 100644 --- a/afs.c +++ b/afs.c @@ -980,29 +980,32 @@ 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; + struct para_buffer *pbout; ret = lls_deserialize_parse_result(aca->query.data, cmd, &aca->lpr); assert(ret >= 0); arg = lls_input(0, aca->lpr); + pbout = SERVER_CMD_OPT_GIVEN(SELECT, VERBOSE, aca->lpr)? + &aca->pbout : NULL; score_clear(); if (current_play_mode == PLAY_MODE_MOOD) mood_unload(); else playlist_unload(); - ret = activate_mood_or_playlist(arg, &aca->pbout); + ret = activate_mood_or_playlist(arg, pbout); if (ret >= 0) goto free_lpr; /* ignore subsequent errors (but log them) */ if (current_mop && strcmp(current_mop, arg) != 0) { int ret2; afs_error(aca, "switching back to %s\n", current_mop); - ret2 = activate_mood_or_playlist(current_mop, &aca->pbout); + ret2 = activate_mood_or_playlist(current_mop, pbout); if (ret2 >= 0) goto free_lpr; afs_error(aca, "could not reactivate %s: %s\n", current_mop, para_strerror(-ret2)); } - activate_mood_or_playlist(NULL, &aca->pbout); + activate_mood_or_playlist(NULL, pbout); free_lpr: lls_free_parse_result(aca->lpr, cmd); return ret; diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index 8200c624..8784fe78 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -407,6 +407,9 @@ m4_include(`com_ll.m4') activates the mood named 'foo'. [/description] + [option verbose] + short_opt = v + summary = print information about the loaded mood or playlist [subcommand sender] purpose = control paraslash senders diff --git a/mood.c b/mood.c index e85cf36a..7c0d2b4f 100644 --- a/mood.c +++ b/mood.c @@ -535,12 +535,15 @@ static char *get_statistics(struct mood_instance *m, int64_t sse) "loaded mood %s (%u files)\n" "last_played mean/sigma: %d/%d days\n" "num_played mean/sigma: %" PRId64 "/%" PRIu64 "\n" + "correction factor ratio: %.2lf\n" , m->name? m->name : "(dummy)", n, mean_days, sigma_days, m->stats.num_played_sum / n, - int_sqrt(m->stats.num_played_qd / n) + int_sqrt(m->stats.num_played_qd / n), + 86400.0 * m->stats.last_played_correction / + m->stats.num_played_correction ); } -- 2.39.5