return 1;
}
-/*
- * Calls load_mood() and reverts its error value: It returns -E_MOOD_LOADED
- * on _success_, and 1 on errors. This way the loop over all moods stops at the
- * first valid mood.
- */
-static int load_mood_loop_func(struct osl_row *mood_row, void *data)
-{
- struct mood **m = data;
- int ret = load_mood(mood_row, m);
- if (ret < 0) {
- if (ret != -E_DUMMY_ROW)
- PARA_NOTICE_LOG("invalid mood (%d), trying next mood\n", ret);
- return 1;
- }
- return -E_MOOD_LOADED;
-}
-
-static int load_first_available_mood(struct mood **m)
-{
- int ret = osl_rbtree_loop(moods_table, BLOBCOL_NAME, m,
- load_mood_loop_func);
- if (ret == -E_MOOD_LOADED) /* success */
- return 1;
- if (ret < 0)
- return ret; /* error */
- PARA_NOTICE_LOG("no valid mood found\n");
- return -E_NO_MOOD;
-}
-
static int check_mood(struct osl_row *mood_row, void *data)
{
struct para_buffer *pb = data;
(long long unsigned)int_sqrt(statistics.num_played_qd / n));
}
+/**
+ * Close the current mood.
+ *
+ * Free all resources of the current mood which were allocated during
+ * mood_open().
+ */
+void close_current_mood(void)
+{
+ destroy_mood(current_mood);
+ current_mood = NULL;
+ memset(&statistics, 0, sizeof(statistics));
+}
+
+
/**
* Change the current mood.
*
* \param mood_name The name of the mood to open.
*
- * There are two special cases: If \a mood_name is \a NULL, load the
- * first available mood. If \a mood_name is the empty string "", load
- * the dummy mood that accepts every audio file and uses a scoring method
- * based only on the \a last_played information.
+ * If \a mood_name is \a NULL, load the dummy mood that accepts every audio file
+ * and uses a scoring method based only on the \a last_played information.
*
* If there is already an open mood, it will be closed first.
*
.array = NULL
};
- if (!mood_name) {
- struct mood *m;
- ret = load_first_available_mood(&m);
- if (ret < 0)
- return ret;
- destroy_mood(current_mood);
- current_mood = m;
- } else if (*mood_name) {
+ if (mood_name) {
struct mood *m;
struct osl_row *row;
struct osl_object obj = {
ret = load_mood(row, &m);
if (ret < 0)
return ret;
- destroy_mood(current_mood);
+ close_current_mood();
current_mood = m;
} else {
- destroy_mood(current_mood);
+ close_current_mood();
current_mood = alloc_new_mood("dummy");
}
aa.m = current_mood;
goto out;
}
PARA_NOTICE_LOG("score add complete\n");
- ret = 1;
+ ret = statistics.num;
out:
free(aa.array);
return ret;
}
-
-/**
- * Close the current mood.
- *
- * Free all resources of the current mood which were allocated during
- * mood_open().
- */
-static void close_current_mood(void)
-{
- destroy_mood(current_mood);
- current_mood = NULL;
- memset(&statistics, 0, sizeof(statistics));
-}
-
/**
* Close and re-open the current mood.
*
int reload_current_mood(void)
{
int ret;
- char *mood_name;
+ char *mood_name = NULL;
PARA_NOTICE_LOG("reloading current mood\n");
if (!current_mood)
return 1;
- mood_name = para_strdup(current_mood->name);
+ if (current_mood->name)
+ mood_name = para_strdup(current_mood->name);
close_current_mood();
- ret = clear_score_table();
- if (ret < 0)
- return ret;
ret = change_current_mood(mood_name);
free(mood_name);
return ret;
}
-int moods_event_handler(enum afs_events event, struct para_buffer *pb,
+int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb,
void *data)
{
switch(event) {