X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=score.c;h=19cfef86212dd867d6dea3c924a0f40ca897a2cd;hb=5ae1a5bb9732d777f856d5bb003585f81e3c519a;hp=983589333f088b600d85d9c0271044d7a21f8eb7;hpb=2031b9cab9304b02c0372f73eef54d9501277031;p=paraslash.git diff --git a/score.c b/score.c index 98358933..19cfef86 100644 --- a/score.c +++ b/score.c @@ -21,15 +21,11 @@ static int ptr_compare(const struct osl_object *obj1, const struct osl_object *o return NUM_COMPARE(d1, d2); } -/** - * Compare the score of two audio files - * - * \param obj1 Pointer to the first score object. - * \param obj2 Pointer to the second score object. - * - * This function first compares the score values as usual integers. If they compare as - * equal, the address of \a obj1 and \a obj2 are compared. So this compare function - * returns zero if and only if \a obj1 and \a obj2 point to the same memory area. +/* + * This function first compares the score values. If they are equal, the + * addresses of the two objects are compared. Thus, the function returns + * "equal" only if the two objects alias each other, i.e., point to the same + * memory address. */ static int score_compare(const struct osl_object *obj1, const struct osl_object *obj2) { @@ -80,28 +76,7 @@ static struct osl_table_description score_table_desc = { .column_descriptions = score_cols }; -/** - * Compute the number of files in score table. - * - * \param num Result is returned here. - * - * \return Positive on success, negative on errors. - */ -int get_num_admissible_files(unsigned *num) -{ - return osl(osl_get_num_rows(score_table, num)); -} - -/** - * Get the score of the audio file associated with given row of the score table. - * - * \param score_row Pointer to the row in the score table. - * \param score Result is returned here on success. - * - * On errors (negative return value) the content of \a score is undefined. - * - * \return The return value of the underlying call to osl_get_object(). - */ +/* On errors (negative return value) the content of score is undefined. */ static int get_score_of_row(void *score_row, long *score) { struct osl_object obj; @@ -132,7 +107,7 @@ int score_add(const struct osl_row *aft_row, long score) score_objs[SCORECOL_AFT_ROW].size = size; size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size; - score_objs[SCORECOL_SCORE].data = para_malloc(size); + score_objs[SCORECOL_SCORE].data = alloc(size); score_objs[SCORECOL_SCORE].size = size; *(long *)(score_objs[SCORECOL_SCORE].data) = score; @@ -145,16 +120,6 @@ int score_add(const struct osl_row *aft_row, long score) return ret; } -static int get_nth_score(unsigned n, long *score) -{ - struct osl_row *row; - int ret = osl(osl_get_nth_row(score_table, SCORECOL_SCORE, n, &row)); - - if (ret < 0) - return ret; - return get_score_of_row(row, score); -} - /** * Replace a row of the score table. * @@ -169,7 +134,7 @@ static int get_nth_score(unsigned n, long *score) */ int score_update(const struct osl_row *aft_row, long percent) { - struct osl_row *row; + struct osl_row *row, *rrow; /* score row, reference row */ long new_score; unsigned n, new_pos; struct osl_object obj = {.data = (struct osl_row *)aft_row, @@ -180,16 +145,19 @@ int score_update(const struct osl_row *aft_row, long percent) return 1; if (ret < 0) return ret; - ret = get_num_admissible_files(&n); + ret = osl(osl_get_num_rows(score_table, &n)); if (ret < 0) return ret; new_pos = 1 + (n - 1) * percent / 100; - ret = get_nth_score(new_pos, &new_score); + ret = osl(osl_get_nth_row(score_table, SCORECOL_SCORE, new_pos, &rrow)); + if (ret < 0) + return ret; + ret = get_score_of_row(rrow, &new_score); if (ret < 0) return ret; new_score--; obj.size = sizeof(long); - obj.data = para_malloc(obj.size); + obj.data = alloc(obj.size); *(long *)obj.data = new_score; PARA_DEBUG_LOG("new score: %ld, rank %u/%u\n", new_score, new_pos, n); return osl(osl_update_object(score_table, row, SCORECOL_SCORE, &obj)); @@ -202,8 +170,7 @@ int score_update(const struct osl_row *aft_row, long percent) * \param score Result pointer. * \param aft_row Result pointer. * - * \return Negative on errors, positive on success. Possible errors: Errors - * returned by osl_get_object(). + * \return Standard. */ int get_score_and_aft_row(struct osl_row *score_row, long *score, struct osl_row **aft_row) @@ -229,17 +196,15 @@ static int get_score_row_from_aft_row(const struct osl_row *aft_row, } /** - * Loop over all files in the score table. + * Call the given function for each row of the score table. * - * \param data A pointer to arbitrary data. - * \param func Function to be called for each admissible file. + * \param func Callback, called once per row. + * \param data Passed verbatim to the callback. * - * \return The return value of the underlying call to osl_rbtree_loop(). - * - * This is used for the ls command. The \a data parameter is passed as the - * second argument to \a func. + * \return The return value of the underlying call to osl_rbtree_loop(). The + * loop terminates early if the callback returns negative. */ -int admissible_file_loop(void *data, osl_rbtree_loop_func *func) +int score_loop(osl_rbtree_loop_func *func, void *data) { return osl(osl_rbtree_loop(score_table, SCORECOL_SCORE, data, func)); } @@ -250,8 +215,7 @@ int admissible_file_loop(void *data, osl_rbtree_loop_func *func) * \param aft_row Points to the row in the aft of the "best" audio file. * \param score Highest score value in the score table. * - * \return Positive on success, negative on errors. Possible errors: Errors - * returned by osl_rbtree_last_row(), osl_get_object(). + * \return Standard. */ int score_get_best(struct osl_row **aft_row, long *score) { @@ -273,8 +237,7 @@ int score_get_best(struct osl_row **aft_row, long *score) * * \param aft_row The file which is no longer admissible. * - * \return Positive on success, negative on errors. Possible errors: - * Errors returned by osl_get_row() and osl_del_row(). + * \return Standard. * * \sa \ref score_add(). */ @@ -315,23 +278,14 @@ int row_belongs_to_score_table(const struct osl_row *aft_row, unsigned *rank) return 1; } -/* Close the score table. */ static void score_close(void) { osl_close_table(score_table, OSL_FREE_VOLATILE); score_table = NULL; } -/** - * Open the score table. - * - * \param dir Unused. - * - * \return The return value of the underlying call to osl_open_table(). - */ static int score_open(__a_unused const char *dir) { - score_table_desc.dir = NULL; /* this table has only volatile columns */ return osl(osl_open_table(&score_table_desc, &score_table)); } @@ -346,12 +300,6 @@ int clear_score_table(void) return score_open(NULL); } -static int score_event_handler(__a_unused enum afs_events event, - __a_unused struct para_buffer *pb, __a_unused void *data) -{ - return 1; -} - /** * Initialize the scoring subsystem. * @@ -362,5 +310,4 @@ void score_init(struct afs_table *t) t->name = score_table_desc.name; t->open = score_open; t->close = score_close; - t->event_handler = score_event_handler; }