X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mood.c;h=bcc9bc57d1a37520ca71f93d5d93a7fe1e2e2927;hb=be5daec66f163725489f42d512659a8af5c3fd59;hp=bbe84734deffd189d7fb8d05ac3e58877b356f8f;hpb=27e8c0dca96754834fcc358cfbab548e0be69eb6;p=paraslash.git diff --git a/mood.c b/mood.c index bbe84734..bcc9bc57 100644 --- a/mood.c +++ b/mood.c @@ -138,7 +138,7 @@ static void destroy_mood(struct mood *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; @@ -163,6 +163,8 @@ static int load_mood(const struct osl_row *mood_row, struct mood **m, PARA_INFO_LOG("opening mood %s\n", mood_name); ret = mp_init(mood_def.data, mood_def.size, &(*m)->parser_context, errmsg); osl_close_disk_object(&mood_def); + if (ret < 0) + destroy_mood(*m); return ret; } @@ -361,8 +363,8 @@ static int add_if_admissible(struct osl_row *aft_row, void *data) 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); @@ -605,8 +607,7 @@ static void compute_correction_factors(int64_t sse) * * 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(). */ @@ -626,10 +627,14 @@ int change_current_mood(const char *mood_name, char **errmsg) if (mood_name) { struct mood *m; struct osl_row *row; - struct osl_object obj = { - .data = (char *)mood_name, - .size = strlen(mood_name) + 1 - }; + struct osl_object obj; + + if (!*mood_name) { + *errmsg = make_message("empty mood name"); + return -ERRNO_TO_PARA_ERROR(EINVAL); + } + obj.data = (char *)mood_name; + obj.size = strlen(mood_name) + 1; ret = osl(osl_get_row(moods_table, BLOBCOL_NAME, &obj, &row)); if (ret < 0) { if (errmsg) @@ -652,7 +657,7 @@ int change_current_mood(const char *mood_name, char **errmsg) if (ret < 0) { if (errmsg) *errmsg = make_message("audio file loop failed"); - return ret; + goto out; } clock_get_realtime(&rnow); compute_correction_factors(rnow.tv_sec); @@ -669,6 +674,8 @@ int change_current_mood(const char *mood_name, char **errmsg) ret = statistics.num; out: free(aa.array); + if (ret < 0) + close_current_mood(); return ret; } @@ -708,9 +715,17 @@ static int reload_current_mood(void) * \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. */