+ if (num_admissible)
+ *num_admissible = ret;
+ current_play_mode = mode;
+ if (arg != current_mop) {
+ free(current_mop);
+ if (arg) {
+ current_mop = para_strdup(arg);
+ mutex_lock(mmd_mutex);
+ strncpy(mmd->afs_mode_string, arg,
+ sizeof(mmd->afs_mode_string));
+ mmd->afs_mode_string[sizeof(mmd->afs_mode_string) - 1] = '\0';
+ mutex_unlock(mmd_mutex);
+ } else {
+ mutex_lock(mmd_mutex);
+ strcpy(mmd->afs_mode_string, "dummy");
+ mutex_unlock(mmd_mutex);
+ current_mop = NULL;
+ }
+ }
+ return 1;
+}
+
+static void com_select_callback(int fd, const struct osl_object *query)
+{
+ struct para_buffer pb = {
+ .max_size = SHMMAX,
+ .private_data = &fd,
+ .max_size_handler = pass_buffer_as_shm
+ };
+ char *arg = query->data;
+ int num_admissible, ret, ret2;
+
+ ret = clear_score_table();
+ if (ret < 0) {
+ ret2 = para_printf(&pb, "%s\n", para_strerror(-ret));
+ goto out;
+ }
+ if (current_play_mode == PLAY_MODE_MOOD)
+ close_current_mood();
+ else
+ playlist_close();
+ ret = activate_mood_or_playlist(arg, &num_admissible);
+ if (ret < 0) {
+ ret2 = para_printf(&pb, "%s\nswitching back to %s\n",
+ para_strerror(-ret), current_mop?
+ current_mop : "dummy");
+ ret = activate_mood_or_playlist(current_mop, &num_admissible);
+ if (ret < 0) {
+ if (ret2 >= 0)
+ ret2 = para_printf(&pb, "failed, switching to dummy\n");
+ activate_mood_or_playlist(NULL, &num_admissible);
+ }
+ } else
+ ret2 = para_printf(&pb, "activated %s (%d admissible files)\n", current_mop?
+ current_mop : "dummy mood", num_admissible);
+out:
+ if (ret2 >= 0 && pb.offset)
+ pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ free(pb.buf);