From 9055c71be97f1095dcdbd83da305b600f204f763 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 23 Mar 2022 18:42:08 +0100 Subject: [PATCH] Rename mood_switch(), mood_close(), playlist_{open/close}. This naming is unfortunate because we also have the static {mood,pl}_{open,close}() in blob.c which operate on the osl table. In contrast, the functions renamed in this commit operate on blob objects and change the current mood or playlist. Let's call these operations load/unload to avoid confusion. --- afs.c | 12 ++++++------ afs.h | 8 ++++---- mood.c | 34 ++++++++++++++-------------------- mp.c | 2 +- playlist.c | 14 +++++--------- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/afs.c b/afs.c index b2cdb6c4..cea8f270 100644 --- a/afs.c +++ b/afs.c @@ -438,13 +438,13 @@ static int activate_mood_or_playlist(const char *arg, struct para_buffer *pb) char *msg; if (!arg) { - ret = mood_switch(NULL, &msg); + ret = mood_load(NULL, &msg); mode = PLAY_MODE_MOOD; } else if (!strncmp(arg, "p/", 2)) { - ret = playlist_open(arg + 2, &msg); + ret = playlist_load(arg + 2, &msg); mode = PLAY_MODE_PLAYLIST; } else if (!strncmp(arg, "m/", 2)) { - ret = mood_switch(arg + 2, &msg); + ret = mood_load(arg + 2, &msg); mode = PLAY_MODE_MOOD; } else { ret = -ERRNO_TO_PARA_ERROR(EINVAL); @@ -536,9 +536,9 @@ static int com_select_callback(struct afs_callback_arg *aca) arg = lls_input(0, aca->lpr); score_clear(); if (current_play_mode == PLAY_MODE_MOOD) - close_current_mood(); + mood_unload(); else - playlist_close(); + playlist_unload(); ret = activate_mood_or_playlist(arg, &aca->pbout); if (ret >= 0) goto free_lpr; @@ -972,7 +972,7 @@ __noreturn void afs_init(int socket_fd) } ret = schedule(&s); sched_shutdown(&s); - close_current_mood(); + mood_unload(); out_close: close_afs_tables(); out: diff --git a/afs.h b/afs.h index 760ed756..a6394fa6 100644 --- a/afs.h +++ b/afs.h @@ -260,13 +260,13 @@ int aft_check_callback(struct afs_callback_arg *aca); void free_status_items(void); /* mood */ -int mood_switch(const char *mood_name, char **msg); -void close_current_mood(void); +int mood_load(const char *mood_name, char **msg); +void mood_unload(void); int mood_check_callback(struct afs_callback_arg *aca); /* playlist */ -int playlist_open(const char *name, char **msg); -void playlist_close(void); +int playlist_load(const char *name, char **msg); +void playlist_unload(void); int playlist_check_callback(struct afs_callback_arg *aca); /** evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y */ diff --git a/mood.c b/mood.c index 3df8c1db..50a67793 100644 --- a/mood.c +++ b/mood.c @@ -48,9 +48,9 @@ struct afs_statistics { }; /** - * Stores an instance of an open mood (parser and statistics). + * Stores an instance of a loaded mood (parser and statistics). * - * A structure of this type is allocated and initialized at mood open time. + * A structure of this type is allocated and initialized when a mood is loaded. */ struct mood_instance { /** NULL means that this is the "dummy" mood. */ @@ -62,8 +62,8 @@ struct mood_instance { }; /* - * If current_mood is NULL then no mood is currently open. If - * current_mood->name is NULL, the dummy mood is currently open. + * If current_mood is NULL then no mood is currently loaded. If + * current_mood->name is NULL, the current mood is the dummy mood. * * The statistics are adjusted dynamically through this pointer as files are * added, removed or played. @@ -164,7 +164,7 @@ static int init_mood_parser(const char *mood_name, struct mood_instance **m, return ret; } *m = alloc_new_mood(mood_name); - PARA_INFO_LOG("opening mood %s\n", mood_name); + PARA_INFO_LOG("loading mood %s\n", mood_name); ret = mp_init(mood_def.data, mood_def.size, &(*m)->parser_context, err); osl_close_disk_object(&mood_def); if (ret < 0) @@ -338,7 +338,7 @@ static int del_afs_statistics(const struct osl_row *row) } /* - * At mood open time we determine the set of admissible files for the given + * At mood load time we determine the set of admissible files for the given * mood where each file is identified by a pointer to a row of the audio file * table. In the first pass the pointers are added to a temporary array and * statistics are computed. When all admissible files have been processed in @@ -543,12 +543,8 @@ static char *get_statistics(struct mood_instance *m, int64_t sse) ); } -/** - * Close the current mood. - * - * Frees all resources of the current mood. - */ -void close_current_mood(void) +/** Free all resources of the current mood, if any. */ +void mood_unload(void) { destroy_mood(current_mood); current_mood = NULL; @@ -573,9 +569,7 @@ static void compute_correction_factors(int64_t sse, struct afs_statistics *s) /** * Change the current mood. * - * If there is already an open mood, it will be closed first. - * - * \param mood_name The name of the mood to open. + * \param mood_name The name of the mood to load. * \param msg Error message or mood info is returned here. * * If \a mood_name is \a NULL, load the dummy mood that accepts every audio file @@ -589,7 +583,7 @@ static void compute_correction_factors(int64_t sse, struct afs_statistics *s) * * \sa struct \ref afs_info::last_played, \ref mp_eval_row(). */ -int mood_switch(const char *mood_name, char **msg) +int mood_load(const char *mood_name, char **msg) { int i, ret; struct admissible_array aa = {.size = 0}; @@ -633,7 +627,7 @@ int mood_switch(const char *mood_name, char **msg) if (msg) *msg = get_statistics(aa.m, rnow.tv_sec); ret = aa.m->stats.num; - close_current_mood(); + mood_unload(); current_mood = aa.m; out: free(aa.array); @@ -643,7 +637,7 @@ out: } /* - * Close and re-open the current mood. + * Empty the score table and start over. * * This function is called on events which render the current list of * admissible files useless, for example if an attribute is removed from the @@ -660,8 +654,8 @@ static int reload_current_mood(void) current_mood->name : "(dummy)"); if (current_mood->name) mood_name = para_strdup(current_mood->name); - close_current_mood(); - ret = mood_switch(mood_name, NULL); + mood_unload(); + ret = mood_load(mood_name, NULL); free(mood_name); return ret; } diff --git a/mp.c b/mp.c index df030ead..a068b043 100644 --- a/mp.c +++ b/mp.c @@ -557,7 +557,7 @@ int mp_init(const char *definition, int nbytes, struct mp_context **result, * function returns true (without looking at the audio file metadata) to * indicate that the given audio file should be considered admissible. * - * \sa \ref mood_switch(), \ref mp_eval_ast(). + * \sa \ref mood_load(), \ref mp_eval_ast(). */ bool mp_eval_row(const struct osl_row *aft_row, struct mp_context *ctx) { diff --git a/playlist.c b/playlist.c index 5150d380..9a6e4829 100644 --- a/playlist.c +++ b/playlist.c @@ -102,12 +102,8 @@ int playlist_check_callback(struct afs_callback_arg *aca) check_playlist)); } -/** - * Close the current playlist. - * - * \sa \ref playlist_open(). - */ -void playlist_close(void) +/** Free all resources of the current playlist, if any. */ +void playlist_unload(void) { if (!current_playlist.name) return; @@ -124,14 +120,14 @@ void playlist_close(void) * up in the audio file table. If the path lookup succeeds, a reference to the * corresponding row of the audio file table is added to the score table. * - * \param name The name of the playlist to open. + * \param name The name of the playlist to load. * \param msg Error message or playlist info is returned here. * * \return The length of the loaded playlist on success, negative error code * else. Files which are listed in the playlist, but are not contained in the * database are ignored. This is not considered an error. */ -int playlist_open(const char *name, char **msg) +int playlist_load(const char *name, char **msg) { int ret; struct playlist_instance *playlist = ¤t_playlist; @@ -142,7 +138,7 @@ int playlist_open(const char *name, char **msg) *msg = make_message("could not read playlist %s\n", name); return ret; } - playlist_close(); + playlist_unload(); ret = for_each_line(FELF_READ_ONLY, playlist_def.data, playlist_def.size, add_playlist_entry, playlist); osl_close_disk_object(&playlist_def); -- 2.39.5