return res;
}
-/* returns 1 if row admissible, 0 if not, negative on errors */
-static int row_is_admissible(const struct osl_row *aft_row, struct mood *m)
-{
- if (!m)
- return -E_NO_MOOD;
- return mp_eval_row(aft_row, m->parser_context);
-}
-
static void destroy_mood(struct mood *m)
{
if (!m)
static struct mood *alloc_new_mood(const char *name)
{
- struct mood *m = para_calloc(sizeof(struct mood));
+ struct mood *m = zalloc(sizeof(struct mood));
if (name)
m->name = para_strdup(name);
return m;
static int add_if_admissible(struct osl_row *aft_row, void *data)
{
struct admissible_array *aa = data;
- int ret;
- ret = row_is_admissible(aft_row, aa->m);
- if (ret <= 0)
- return ret;
+ if (!mp_eval_row(aft_row, aa->m->parser_context))
+ return 0;
if (statistics.num >= aa->size) {
aa->size *= 2;
aa->size += 100;
- aa->array = para_realloc(aa->array,
- aa->size * sizeof(struct osl_row *));
+ aa->array = arr_realloc(aa->array, aa->size,
+ sizeof(struct osl_row *));
}
aa->array[statistics.num] = aft_row;
return add_afs_statistics(aft_row);
if (ret < 0)
return ret;
was_admissible = ret;
- ret = row_is_admissible(aft_row, current_mood);
- if (ret < 0)
- return ret;
- is_admissible = (ret > 0);
+ is_admissible = mp_eval_row(aft_row, current_mood->parser_context);
if (!was_admissible && !is_admissible)
return 1;
if (was_admissible && !is_admissible)
*
* If there is already an open mood, it will be closed first.
*
- * \return Positive on success, negative on errors. Loading the dummy mood
- * always succeeds.
+ * \return Positive on success, negative on errors.
*
* \sa struct \ref afs_info::last_played, \ref mp_eval_row().
*/
* This function is called on events which render the current list of
* admissible files useless, for example if an attribute is removed from the
* attribute table.
- *
- * If no mood is currently open, the function returns success.
*/
static int reload_current_mood(void)
{
int ret;
char *mood_name = NULL;
+ assert(current_mood);
ret = clear_score_table();
if (ret < 0)
return ret;
- if (!current_mood)
- return 1;
PARA_NOTICE_LOG("reloading %s\n", current_mood->name?
current_mood->name : "(dummy)");
if (current_mood->name)
* \param pb Unused.
* \param data Its type depends on the event.
*
- * This function performs actions required due to the occurrence of the given
- * event. Possible actions include reload of the current mood and update of the
- * score of an audio file.
+ * This function updates the score table according to the event that has
+ * occurred. Two actions are possible: (a) reload the current mood, or (b)
+ * add/remove/update the row of the score table which corresponds to the audio
+ * file that has been modified or whose afs info has been changed. It depends
+ * on the type of the event which action (if any) is performed.
+ *
+ * The callbacks of command handlers such as com_add() or com_touch() which
+ * modify the audio file table call this function. The virtual streaming system
+ * also calls this after it has updated the afs info of the file it is about to
+ * stream (the one with the highest score). If the file stays admissible, its
+ * score is recomputed so that a different file is picked next time.
*
* \return Standard.
*/