+ const struct lls_command *cmd = SERVER_CMD_CMD_PTR(SELECT);
+ const char *arg;
+ int num_admissible, ret;
+ char *errmsg;
+
+ 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\n");
+ goto free_lpr;
+ }
+ if (current_play_mode == PLAY_MODE_MOOD)
+ close_current_mood();
+ else
+ playlist_close();
+ ret = activate_mood_or_playlist(arg, &num_admissible, &errmsg);
+ if (ret >= 0)
+ goto out;
+ /* ignore subsequent errors (but log them) */
+ para_printf(&aca->pbout, "%s\n", errmsg);
+ free(errmsg);
+ para_printf(&aca->pbout, "could not activate %s\n", arg);
+ 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, &num_admissible,
+ &errmsg);
+ if (ret2 >= 0)
+ goto out;
+ para_printf(&aca->pbout, "%s\n", errmsg);
+ free(errmsg);
+ para_printf(&aca->pbout, "could not reactivate %s: %s\n",
+ current_mop, para_strerror(-ret2));
+ }
+ para_printf(&aca->pbout, "activating dummy mood\n");
+ activate_mood_or_playlist(NULL, &num_admissible, NULL);
+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;
+}
+
+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, NULL);
+ if (ret < 0) {
+ assert(arg);
+ PARA_WARNING_LOG("could not activate %s: %s\n", arg,
+ para_strerror(-ret));
+ activate_mood_or_playlist(NULL, NULL, NULL);
+ }