paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Enumerations | Functions | Variables
score.c File Reference

Scoring functions to determine the audio file streaming order. More...

#include <regex.h>
#include <osl.h>
#include <lopsub.h>
#include "para.h"
#include "error.h"
#include "string.h"
#include "afh.h"
#include "afs.h"
#include "list.h"

Enumerations

enum  score_table_columns { SCORECOL_AFT_ROW, SCORECOL_SCORE, NUM_SCORE_COLUMNS }
 The score table consists of two columns: The aft_row column contains pointers to the rows of the audio file table, and the score column contains the current score of the audio file associated with that row. More...
 

Functions

int score_add (const struct osl_row *aft_row, long score, struct osl_table *t)
 Add a (row, score) pair to the score table. More...
 
int score_update (const struct osl_row *aft_row, long percent)
 Replace a row of the score table. More...
 
int get_score_and_aft_row (struct osl_row *score_row, long *score, struct osl_row **aft_row)
 Given an admissible file, get the corresponding row in the aft and the score. More...
 
int score_loop (osl_rbtree_loop_func *func, struct osl_table *t, void *data)
 Call the given function for each row of the score table. More...
 
int score_get_best (struct osl_row **aft_row, long *score)
 Get the admissible audio file with highest score. More...
 
int score_delete (const struct osl_row *aft_row)
 Remove an entry from the rbtree of admissible files. More...
 
bool row_belongs_to_score_table (const struct osl_row *aft_row)
 Find out whether an audio file is contained in the score table. More...
 
void score_close (struct osl_table *t)
 Free all volatile objects, then close the table. More...
 
void score_open (struct osl_table **result)
 Allocate a score table instance. More...
 
void score_clear (void)
 Remove all entries from the score table, but keep the table open. More...
 

Variables

const struct afs_table_operations score_ops
 The score table stores (aft row, score) pairs in memory. More...
 

Detailed Description

Scoring functions to determine the audio file streaming order.

Enumeration Type Documentation

◆ score_table_columns

The score table consists of two columns: The aft_row column contains pointers to the rows of the audio file table, and the score column contains the current score of the audio file associated with that row.

Enumerator
SCORECOL_AFT_ROW 

The row of the audio file.

SCORECOL_SCORE 

The score.

NUM_SCORE_COLUMNS 

This table has two columns.

Function Documentation

◆ score_add()

int score_add ( const struct osl_row *  aft_row,
long  score,
struct osl_table *  t 
)

Add a (row, score) pair to the score table.

Parameters
aft_rowIdentifies the audio file to be added.
scoreThe score value of the audio file.
tNULL means to operate on the currently active table.
Returns
The return value of the underlying call to osl_add_row().

References NUM_SCORE_COLUMNS.

◆ score_update()

int score_update ( const struct osl_row *  aft_row,
long  percent 
)

Replace a row of the score table.

Parameters
aft_rowDetermines the audio file to change.
percentThe position to re-insert the audio file.

The percent parameter must be between 0 and 100. A value of zero means to re-insert the audio file into the score table with a score lower than any other admissible file.

Returns
Positive on success, negative on errors.

References osl().

◆ get_score_and_aft_row()

int get_score_and_aft_row ( struct osl_row *  score_row,
long *  score,
struct osl_row **  aft_row 
)

Given an admissible file, get the corresponding row in the aft and the score.

Parameters
score_rowDetermines the admissible file.
scoreResult pointer.
aft_rowResult pointer.
Returns
Standard.

◆ score_loop()

int score_loop ( osl_rbtree_loop_func *  func,
struct osl_table *  t,
void *  data 
)

Call the given function for each row of the score table.

Parameters
funcCallback, called once per row.
tNULL means to use the currently active score table.
dataPassed verbatim to the callback.
Returns
The return value of the underlying call to osl_rbtree_loop(). The loop terminates early if the callback returns negative.

References osl().

Referenced by mood_loop(), and playlist_loop().

◆ score_get_best()

int score_get_best ( struct osl_row **  aft_row,
long *  score 
)

Get the admissible audio file with highest score.

Parameters
aft_rowPoints to the row in the aft of the "best" audio file.
scoreHighest score value in the score table.
Returns
Standard.

References osl().

◆ score_delete()

int score_delete ( const struct osl_row *  aft_row)

Remove an entry from the rbtree of admissible files.

Parameters
aft_rowThe file which is no longer admissible.
Returns
Standard.
See also
score_add().

◆ row_belongs_to_score_table()

bool row_belongs_to_score_table ( const struct osl_row *  aft_row)

Find out whether an audio file is contained in the score table.

Parameters
aft_rowThe row of the audio file table.
Returns
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.

◆ score_close()

void score_close ( struct osl_table *  t)

Free all volatile objects, then close the table.

Parameters
tAs returned from score_open().

This either succeeds or terminates the calling process.

Referenced by playlist_unload().

◆ score_open()

void score_open ( struct osl_table **  result)

Allocate a score table instance.

Parameters
resultNULL means to open the currently active score table.

Since the score table does no filesystem I/O, this function always succeeds.

See also
score_close().

References osl().

Referenced by playlist_load().

◆ score_clear()

void score_clear ( void  )

Remove all entries from the score table, but keep the table open.

Variable Documentation

◆ score_ops

const struct afs_table_operations score_ops
Initial value:
= {
.open = open_global_table,
.close = close_global_table,
}

The score table stores (aft row, score) pairs in memory.