X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mood.c;h=d9ae48bf967e61b0c4c0ca499d75f0b47eb47b96;hp=b5047d3745056703b8afab1ac85e81777cadaca7;hb=c5670af5c1f784fe6c3d46d0281f2ba7c47af75e;hpb=43e0a7f669d782e73513119b7140dc4e56bcc3d7 diff --git a/mood.c b/mood.c index b5047d37..d9ae48bf 100644 --- a/mood.c +++ b/mood.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 Andre Noll + * Copyright (C) 2007-2011 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -79,13 +79,13 @@ struct mood { static struct mood *current_mood; /** - * Rough approximation to sqrt. + * Rough approximation to sqrt. * - * \param x Integer of which to calculate the sqrt. + * \param x Integer of which to calculate the sqrt. * - * \return An integer res with res * res <= x. + * \return An integer res with res * res <= x. */ -static uint64_t int_sqrt(uint64_t x) +__a_const static uint64_t int_sqrt(uint64_t x) { uint64_t op, res, one = 1; op = x; @@ -422,7 +422,7 @@ out: void mood_check_callback(int fd, __a_unused const struct osl_object *query) { struct para_buffer pb = { - .max_size = SHMMAX, + .max_size = shm_get_shmmax(), .private_data = &fd, .max_size_handler = pass_buffer_as_shm }; @@ -873,7 +873,7 @@ out: * * \sa mood_open(), mood_close(). */ -int reload_current_mood(void) +static int reload_current_mood(void) { int ret; char *mood_name = NULL; @@ -890,10 +890,25 @@ int reload_current_mood(void) return ret; } +/** + * Notification callback for the moods table. + * + * \param event Type of the event just occurred. + * \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. + */ int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb, void *data) { - switch(event) { + int ret; + + if (!current_mood) + return 0; + switch (event) { /* * The three blob events might change the set of admissible files, * so we must reload the score list. @@ -903,6 +918,10 @@ int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb case BLOB_ADD: if (data == moods_table || data == playlists_table) return 1; /* no reload necessary for these */ + ret = clear_score_table(); + if (ret < 0) + PARA_CRIT_LOG("clear score table returned %s\n", + para_strerror(-ret)); return reload_current_mood(); /* these also require reload of the score table */ case ATTRIBUTE_ADD: @@ -924,4 +943,3 @@ int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb return 1; } } -