-/**
- * 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));
-}
-
- int ret = osl(osl_get_object(score_table, score_row, SCORECOL_SCORE, &obj));
+ int ret = osl(osl_get_object(t, score_row, SCORECOL_SCORE, &obj));
- * \param aft_row The audio file to be added.
- * \param score The score for this file.
+ * \param aft_row Identifies the audio file to be added.
+ * \param score The score value of the audio file.
+ * \param t NULL means to operate on the currently active table.
score_objs[SCORECOL_AFT_ROW].size = size;
size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size;
score_objs[SCORECOL_AFT_ROW].size = size;
size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size;
score_objs[SCORECOL_SCORE].size = size;
*(long *)(score_objs[SCORECOL_SCORE].data) = score;
// PARA_DEBUG_LOG("adding %p\n", *(void **) (score_objs[SCORECOL_AFT_ROW].data));
score_objs[SCORECOL_SCORE].size = size;
*(long *)(score_objs[SCORECOL_SCORE].data) = score;
// PARA_DEBUG_LOG("adding %p\n", *(void **) (score_objs[SCORECOL_AFT_ROW].data));
if (ret < 0) {
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
free(score_objs[SCORECOL_SCORE].data);
if (ret < 0) {
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
free(score_objs[SCORECOL_SCORE].data);
-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);
-}
-
- 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(score_table, rrow, &new_score);
*(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));
*(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));
*/
int get_score_and_aft_row(struct osl_row *score_row, long *score,
struct osl_row **aft_row)
{
struct osl_object obj;
*/
int get_score_and_aft_row(struct osl_row *score_row, long *score,
struct osl_row **aft_row)
{
struct osl_object obj;
-static int get_score_row_from_aft_row(const struct osl_row *aft_row,
- struct osl_row **score_row)
+static int get_score_row_from_aft_row(struct osl_table *t,
+ const struct osl_row *aft_row, struct osl_row **score_row)
{
struct osl_object obj = {.data = (struct osl_row *)aft_row,
.size = sizeof(aft_row)};
{
struct osl_object obj = {.data = (struct osl_row *)aft_row,
.size = sizeof(aft_row)};
- return osl(osl_get_row(score_table, SCORECOL_AFT_ROW, &obj, score_row));
+ return osl(osl_get_row(t, SCORECOL_AFT_ROW, &obj, score_row));
- * Loop over all files in the score table.
- *
- * \param data A pointer to arbitrary data.
- * \param func Function to be called for each admissible file.
+ * Call the given function for each row of the score table.
- * \return The return value of the underlying call to osl_rbtree_loop().
+ * \param func Callback, called once per row.
+ * \param t NULL means to use the currently active score table.
+ * \param data Passed verbatim to the callback.
- * 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.
- return osl(osl_rbtree_loop(score_table, SCORECOL_SCORE, data, func));
+ return osl(osl_rbtree_loop(t? t : score_table, SCORECOL_SCORE, data,
+ 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.
*
* \param aft_row Points to the row in the aft of the "best" audio file.
* \param score Highest score value in the score table.
*
* Find out whether an audio file is contained in the score table.
*
* \param aft_row The row of the audio file table.
* Find out whether an audio file is contained in the score table.
*
* \param aft_row The row of the audio file table.
- * \return Positive, if \a aft_row belongs to the audio file table,
- * zero if not, negative on errors. If \a aft_row was found, and \a rank
- * is not \p NULL, the rank of \a aft_row is returned in \a rank.
+ * \return If the lookup operation fails for any other reason than "not found",
+ * the function aborts the current process (afs), since this is considered a
+ * fatal error that should never happen.
-static void score_close(void)
+/**
+ * Free all volatile objects, then close the table.
+ *
+ * \param t As returned from \ref score_open().
+ *
+ * This either succeeds or terminates the calling process.
+ */
+void score_close(struct osl_table *t)
-static int score_event_handler(__a_unused enum afs_events event,
- __a_unused struct para_buffer *pb, __a_unused void *data)
+/**
+ * Allocate a score table instance.
+ *
+ * \param result NULL means to open the currently active score table.
+ *
+ * Since the score table does no filesystem I/O, this function always succeeds.
+ * \sa \ref score_close().
+ */
+void score_open(struct osl_table **result)
+
+/** The score table stores (aft row, score) pairs in memory. */
+const struct afs_table_operations score_ops = {
+ .open = open_global_table,
+ .close = close_global_table,
+};