X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mood.c;h=46337f28f3f42145c54b6fbed34c8088b16e2222;hp=08c2c222e84f69bd794ea7c4598b83fe0051ac06;hb=5e54609eda6f4417e8b7042db59ecf47fd720751;hpb=8ee99fd28639d1b2aeee1312cc15388565a40280 diff --git a/mood.c b/mood.c index 08c2c222..46337f28 100644 --- a/mood.c +++ b/mood.c @@ -912,6 +912,20 @@ static void log_statistics(void) (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. * @@ -951,10 +965,10 @@ int change_current_mood(char *mood_name) 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; @@ -972,25 +986,11 @@ int change_current_mood(char *mood_name) 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. * @@ -1007,7 +1007,7 @@ static void close_current_mood(void) int reload_current_mood(void) { int ret; - char *mood_name; + char *mood_name = NULL; PARA_NOTICE_LOG("reloading current mood\n"); if (!current_mood) @@ -1015,15 +1015,12 @@ int reload_current_mood(void) 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) {