paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
afs.h File Reference

Exported symbols of the audio file selector. More...

Data Structures

struct  afs_info
 Audio file selector data stored in the audio file table. More...
 
struct  rmatt_event_data
 Used as data for afs_event() for events of type ATTRIBUTE_ADD. More...
 
struct  afsi_change_event_data
 Used as data for afs_event() for events of type ATTRIBUTE_AFSI_CHANGE. More...
 
struct  afs_table_operations
 Methods for table startup/shutdown and event handling. More...
 
struct  pattern_match_data
 Structure passed to for_each_matching_row(). More...
 
struct  afs_callback_arg
 Arguments passed to each afs callback. More...
 
struct  afs_max_size_handler_data
 Structure passed to the AFS max_size handler. More...
 

Macros

#define NUM_COMPARE(x, y)   ((int)((x) < (y)) - (int)((x) > (y)))
 evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y More...
 
#define DECLARE_BLOB_SYMBOLS(table_name, cmd_prefix)
 Define exported functions and a table pointer for an osl blob table. More...
 

Typedefs

typedef int afs_callback(struct afs_callback_arg *aca)
 The "top half" of an afs command. More...
 
typedef int callback_result_handler(struct osl_object *result, uint8_t band, void *private)
 Dispatch the output of an afs callback. More...
 

Enumerations

enum  afs_events {
  ATTRIBUTE_ADD, ATTRIBUTE_RENAME, ATTRIBUTE_REMOVE, AFSI_CHANGE,
  AFHI_CHANGE, AUDIO_FILE_RENAME, AUDIO_FILE_ADD, AUDIO_FILE_REMOVE,
  BLOB_ADD, BLOB_RENAME, BLOB_REMOVE
}
 Events caused by changes to an afs table. More...
 
enum  play_mode { PLAY_MODE_MOOD, PLAY_MODE_PLAYLIST }
 How audio files are selected by afs. More...
 
enum  afs_server_code { NEXT_AUDIO_FILE, NO_ADMISSIBLE_FILES }
 Codes used for communication between the server and the afs process. More...
 
enum  pattern_match_flags { PM_REVERSE_LOOP = 1, PM_NO_PATTERN_MATCHES_EVERYTHING = 2, PM_SKIP_EMPTY_NAME = 4 }
 Flags passed to for_each_matching_row(). More...
 
enum  blob_table_columns { BLOBCOL_ID, BLOBCOL_NAME, BLOBCOL_DEF, NUM_BLOB_COLUMNS }
 blob_symbols More...
 

Functions

int afs_cb_result_handler (struct osl_object *result, uint8_t band, void *private)
 Result handler for sending data to the para_client process. More...
 
int pass_buffer_as_shm (int fd, uint8_t band, const char *buf, size_t size)
 Send data as shared memory to a file descriptor. More...
 
_static_inline_ int afs_max_size_handler (char *buf, size_t size, void *private)
 Standard max_size handler for AFS commands. More...
 
__noreturn void afs_init (int socket_fd)
 Initialize the audio file selector process. More...
 
__must_check int afs_event (enum afs_events event, struct para_buffer *pb, void *data)
 The afs event dispatcher. More...
 
int send_callback_request (afs_callback *f, struct osl_object *query, callback_result_handler *result_handler, void *private_result_data)
 Ask the afs process to call a given function. More...
 
int send_lls_callback_request (afs_callback *f, const struct lls_command *const cmd, struct lls_parse_result *lpr, void *private_result_data)
 Wrapper for send_callback_request() which passes a lopsub parse result. More...
 
__printf_2_3 void afs_error (const struct afs_callback_arg *aca, const char *fmt,...)
 Format and send an error message to the command handler. More...
 
int string_compare (const struct osl_object *obj1, const struct osl_object *obj2)
 Compare two osl objects of string type. More...
 
int for_each_matching_row (struct pattern_match_data *pmd)
 Execute the given function for each matching row. More...
 
void score_open (struct osl_table **result)
 Allocate a score table instance. More...
 
void score_close (struct osl_table *t)
 Free all volatile objects, then close the table. 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 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_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 new_score)
 Replace a row of the score table. More...
 
int score_delete (const struct osl_row *aft_row)
 Remove an entry from the rbtree of admissible files. More...
 
void score_clear (void)
 Remove all entries from the score table, but keep the table open. 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 get_attribute_bitmap (const uint64_t *atts, char *buf)
 Return a binary representation of the given attribute value. More...
 
int get_attribute_bitnum_by_name (const char *att_name, unsigned char *bitnum)
 Retrieve the identifier (number) of an attribute. More...
 
int get_attribute_text (uint64_t *atts, const char *delim, char **text)
 Get a string containing the set attributes in text form. More...
 
int attribute_check_callback (struct afs_callback_arg *aca)
 Compute the attribute bit mask and check each afs info bitmap. More...
 
int aft_get_row_of_path (const char *path, struct osl_row **row)
 Get the row of the audio file table corresponding to the given path. More...
 
int aft_check_attributes (uint64_t att_mask, struct para_buffer *pb)
 Iterate over all audio files and check the attribute bit mask. More...
 
int open_and_update_audio_file (int *fd)
 Open the audio file with highest score and set up an afd structure. More...
 
int load_afd (int shmid, struct audio_file_data *afd)
 Extract a afd stored in a shared memory area. More...
 
int get_afsi_of_row (const struct osl_row *row, struct afs_info *afsi)
 Get the audio file selector info, given a row of the audio file table. More...
 
int get_afhi_of_row (const struct osl_row *row, struct afh_info *afhi)
 Get the audio format handler info, given a row of the audio file table. More...
 
int get_audio_file_path_of_row (const struct osl_row *row, char **path)
 Get the path of an audio file, given a row of the audio file table. More...
 
int audio_file_loop (void *private_data, osl_rbtree_loop_func *func)
 Call the given function for each file in the audio file table. More...
 
int aft_check_callback (struct afs_callback_arg *aca)
 Check the audio file table for inconsistencies. More...
 
void free_status_items (void)
 Deallocate and invalidate the status item strings. More...
 
int mood_load (const char *mood_name, struct mood_instance **result, char **msg)
 Populate a score table with admissible files for the given mood. More...
 
int mood_loop (struct mood_instance *m, osl_rbtree_loop_func *func, void *data)
 Iterate over the admissible files of a mood instance. More...
 
void mood_unload (struct mood_instance *m)
 Free all resources of a mood instance. More...
 
int mood_check_callback (struct afs_callback_arg *aca)
 Check all moods for syntax errors. More...
 
int playlist_load (const char *name, struct playlist_instance **result, char **msg)
 Populate the score table from the paths of a playlist database object. More...
 
int playlist_loop (struct playlist_instance *pi, osl_rbtree_loop_func *func, void *data)
 Iterate over all admissible audio files of a playlist instance. More...
 
void playlist_unload (struct playlist_instance *pi)
 Free all resources of the given/current playlist. More...
 
int playlist_check_callback (struct afs_callback_arg *aca)
 Check the playlist table for inconsistencies. More...
 

Variables

const struct afs_table_operations score_ops
 The score table stores (aft row, score) pairs in memory. More...
 
const struct afs_table_operations attr_ops
 The attribute table stores name/bitnum pairs. More...
 
const struct afs_table_operations aft_ops
 The audio file table contains information about known audio files. More...
 

Detailed Description

Exported symbols of the audio file selector.

Macro Definition Documentation

◆ NUM_COMPARE

#define NUM_COMPARE (   x,
 
)    ((int)((x) < (y)) - (int)((x) > (y)))

evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y

◆ DECLARE_BLOB_SYMBOLS

#define DECLARE_BLOB_SYMBOLS (   table_name,
  cmd_prefix 
)
Value:
int cmd_prefix ## _get_name_by_id(uint32_t id, char **name); \
int cmd_prefix ## _get_def_by_id(uint32_t id, struct osl_object *def); \
int cmd_prefix ## _get_def_by_name(const char *name, struct osl_object *def); \
int cmd_prefix ## _get_name_and_def_by_row(const struct osl_row *row, \
char **name, struct osl_object *def); \
int table_name ##_event_handler(enum afs_events event, \
struct para_buffer *pb, void *data); \
extern struct osl_table *table_name ## _table; \
extern const struct afs_table_operations table_name ## _ops;

Define exported functions and a table pointer for an osl blob table.

Typedef Documentation

◆ afs_callback

typedef int afs_callback(struct afs_callback_arg *aca)

The "top half" of an afs command.

Afs command handlers run as a process which is not related to the afs process, i.e. they can not change the address space of afs directly. Therefore afs commands typically consist of two functions: The command handler and the corresponding callback function that runs in afs context.

See also
send_callback_request().

◆ callback_result_handler

typedef int callback_result_handler(struct osl_object *result, uint8_t band, void *private)

Dispatch the output of an afs callback.

Some AFS callbacks need to send data back to the command handler. Pointers to this type of function are passed to send_callback_request() and related functions to dispatch the data in the command handler process. Most (but not all) afs commands pass afs_cb_result_handler(), which sends the output of the callback to the connected client.

Enumeration Type Documentation

◆ afs_events

enum afs_events

Events caused by changes to an afs table.

Whenever an afs table changes, an event is generated which causes afs to call the event handlers of all other tables. For example, if an audio file is added, the event handler of the mood table checks the new file for admissibility.

Enumerator
ATTRIBUTE_ADD 

An attribute was added.

ATTRIBUTE_RENAME 

An attribute was renamed.

ATTRIBUTE_REMOVE 

An attribute was removed.

AFSI_CHANGE 

The afs info struct of an audio file changed.

AFHI_CHANGE 

The afh info struct of an audio file changed.

AUDIO_FILE_RENAME 

An audio file was renamed.

AUDIO_FILE_ADD 

An audio file was added.

AUDIO_FILE_REMOVE 

An audio file is about to be removed.

BLOB_ADD 

A new blob was added.

BLOB_RENAME 

A blob was renamed.

BLOB_REMOVE 

A blob is about to be removed.

◆ play_mode

enum play_mode

How audio files are selected by afs.

Enumerator
PLAY_MODE_MOOD 

Admissible files are determined by a mood definition.

PLAY_MODE_PLAYLIST 

All listed files are admissible.

◆ afs_server_code

Codes used for communication between the server and the afs process.

Before forking the afs child, para_server creates a bidirectional pipe through which both processes communicate. Usually para_server requests a new audio file in order to start streaming or when the end of the current audio file has been reached. The afs process responds to such a request by sending back an eight byte buffer. The first four bytes is the uint32_t representation of the code, usually NEXT_AUDIO_FILE if an admissible audio file was found, successfully opened and verified. The other four bytes represent the shared memory id of the shared memory area that contains details about the audio file to be streamed next. The open file descriptor of that file is also passed from afs to para_server through the same pipe.

Enumerator
NEXT_AUDIO_FILE 

An audio file was successfully opened.

NO_ADMISSIBLE_FILES 

No admissible audio file was found.

◆ pattern_match_flags

Flags passed to for_each_matching_row().

Enumerator
PM_REVERSE_LOOP 

Loop in reverse order.

PM_NO_PATTERN_MATCHES_EVERYTHING 

If no pattern is given, loop over all rows.

PM_SKIP_EMPTY_NAME 

If the data in match_column is the empty string, skip this row.

◆ blob_table_columns

blob_symbols

The columns of an abstract blob table.

Enumerator
BLOBCOL_ID 

The identifier, a positive integer that never repeats.

BLOBCOL_NAME 

The unique name of the blob.

BLOBCOL_DEF 

The actual blob contents.

NUM_BLOB_COLUMNS 

A blob table has that many columns.

Function Documentation

◆ afs_cb_result_handler()

int afs_cb_result_handler ( struct osl_object *  result,
uint8_t  band,
void *  private 
)

Result handler for sending data to the para_client process.

Parameters
resultThe data to be sent.
bandThe band designator.
privatePointer to the command context.
Returns
The return value of the underlying call to command::c::send_sb.
See also
callback_result_handler, command::c::send_sb.

References SBD_CRIT_LOG, SBD_DEBUG_LOG, SBD_EMERG_LOG, SBD_ERROR_LOG, SBD_INFO_LOG, SBD_NOTICE_LOG, SBD_OUTPUT, and SBD_WARNING_LOG.

◆ pass_buffer_as_shm()

int pass_buffer_as_shm ( int  fd,
uint8_t  band,
const char *  buf,
size_t  size 
)

Send data as shared memory to a file descriptor.

Parameters
fdFile descriptor to send the shmid to.
bandThe band designator for this data.
bufThe buffer holding the data to be sent.
sizeThe size of buf.

This function creates a shared memory area large enough to hold the content given by buf and size and sends the identifier of this area to the file descriptor fd.

It is called by the AFS max_size handler as well as directly by the AFS command callbacks to send command output to the command handlers.

Returns
Zero if buf is NULL or size is zero. Negative on errors, and positive on success.

References ATTACH_RW, PARA_ERROR_LOG, SBD_OUTPUT, shm_attach(), shm_destroy(), shm_detach(), shm_new(), and write_all().

Referenced by afs_error(), and afs_max_size_handler().

◆ afs_max_size_handler()

_static_inline_ int afs_max_size_handler ( char *  buf,
size_t  size,
void *  private 
)

Standard max_size handler for AFS commands.

Parameters
bufContains (part of) the AFS command output.
sizeThe number of bytes in buf.
privatePointer to a afs_max_size_handler_data structure.

Whenever the output of an AFS command exceeds the maximal size of a shared memory area, the max size handler of the para_buffer which holds the command output is called with private being a pointer to a structure of type afs_max_size_handler_data.

Returns
The return value of the underlying call to pass_buffer_as_shm().

References afs_max_size_handler_data::band, afs_max_size_handler_data::fd, and pass_buffer_as_shm().

◆ afs_init()

__noreturn void afs_init ( int  socket_fd)

Initialize the audio file selector process.

Parameters
socket_fdFile descriptor used for communication with the server.

◆ afs_event()

__must_check int afs_event ( enum afs_events  event,
struct para_buffer pb,
void *  data 
)

The afs event dispatcher.

Parameters
eventType of the event.
pbMay be NULL.
dataType depends on event.

This function calls each table event handler, passing pb and data verbatim. It's up to the handlers to interpret the data pointer. If a handler returns negative, the loop is aborted.

Returns
The (negative) error code of the first handler that failed, or non-negative if all handlers succeeded.

References NUM_AFS_TABLES.

◆ send_callback_request()

int send_callback_request ( afs_callback f,
struct osl_object *  query,
callback_result_handler result_handler,
void *  private_result_data 
)

Ask the afs process to call a given function.

Parameters
fThe function to be called.
queryPointer to arbitrary data for the callback.
result_handlerCalled for each shm area sent by the callback.
private_result_dataPassed verbatim to result_handler.

This function creates a socket for communication with the afs process and a shared memory area (sma) to which the buffer pointed to by query is copied. It then notifies the afs process that the callback function f should be executed by sending the shared memory identifier (shmid) to the socket.

If the callback produces a result, it sends any number of shared memory identifiers back via the socket. For each such identifier received, result_handler is called. The contents of the sma identified by the received shmid are passed to that function as an osl object. The private_result_data pointer is passed as the second argument to result_handler.

Returns
Number of shared memory areas dispatched on success, negative on errors.

References afs_socket_cookie, ATTACH_RW, connect_local_socket(), OPT_STRING_VAL, recv_bin_buffer(), shm_attach(), shm_detach(), shm_new(), and write_all().

Referenced by send_afs_status().

◆ send_lls_callback_request()

int send_lls_callback_request ( afs_callback f,
const struct lls_command *const  cmd,
struct lls_parse_result *  lpr,
void *  private_result_data 
)

Wrapper for send_callback_request() which passes a lopsub parse result.

Parameters
fThe callback function.
cmdNeeded for (de-)serialization.
lprMust match cmd.
private_result_dataPassed to send_callback_request().

This function serializes the parse result given by the lpr pointer into a buffer. The buffer is sent as the query to the afs process with the callback mechanism.

Returns
The return value of the underlying call to send_callback_request().

◆ afs_error()

__printf_2_3 void afs_error ( const struct afs_callback_arg aca,
const char *  fmt,
  ... 
)

Format and send an error message to the command handler.

To pass an error message from the callback of an afs command to the client, this function should be called. It formats the message into a buffer which is passed as a shared memory area to the command handler from where it propagates to the client.

The message will be tagged with the ERROR_LOG sideband designator so that the client writes it to its stderr stream rather than to stdout as with aca->pbout. In analogy to the default Unix semantics of stderr, the message is sent without buffering.

If sending the error message fails, an error is logged on the server side, but no other action is taken.

Parameters
acaUsed to obtain the fd to send the shmid to.
fmtUsual format string.

References afs_callback_arg::fd, PARA_ERROR_LOG, para_strerror(), pass_buffer_as_shm(), SBD_ERROR_LOG, and xvasprintf().

◆ string_compare()

int string_compare ( const struct osl_object *  obj1,
const struct osl_object *  obj2 
)

Compare two osl objects of string type.

Parameters
obj1Pointer to the first object.
obj2Pointer to the second object.

In any case, only MIN(obj1->size, obj2->size) characters of each string are taken into account.

Returns
It returns an integer less than, equal to, or greater than zero if obj1 is found, respectively, to be less than, to match, or be greater than obj2.
See also
strcmp(3), strncmp(3).

References PARA_MIN.

◆ for_each_matching_row()

int for_each_matching_row ( struct pattern_match_data pmd)

Execute the given function for each matching row.

Parameters
pmdDescribes what to match and how.
Returns
Standard.

References pattern_match_data::loop_col_num, osl(), pattern_match_data::pm_flags, PM_REVERSE_LOOP, and pattern_match_data::table.

◆ 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_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_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().

◆ 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_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().

◆ 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().

◆ score_clear()

void score_clear ( void  )

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

◆ 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.

◆ get_attribute_bitmap()

void get_attribute_bitmap ( const uint64_t *  atts,
char *  buf 
)

Return a binary representation of the given attribute value.

Parameters
attsPointer to the attribute value.
bufResult.

This function prints a string of at most 64 characters plus the terminating NULL character into buf which must be provided by the caller and at least 65 bytes long. The "x" character is used for set attributes and "-" is used for unset attributes.

In practice, not all 64 attributes are defined. In this case, the function only prints N + 1 characters where N is the greatest id of a defined attribute.

◆ get_attribute_bitnum_by_name()

int get_attribute_bitnum_by_name ( const char *  att_name,
unsigned char *  bitnum 
)

Retrieve the identifier (number) of an attribute.

Parameters
att_nameThe name of the attribute.
bitnumResult pointer.
Returns
Positive on success, negative on errors.

References osl().

Referenced by mp_is_set().

◆ get_attribute_text()

int get_attribute_text ( uint64_t *  atts,
const char *  delim,
char **  text 
)

Get a string containing the set attributes in text form.

Parameters
attsThe attribute bitmap.
delimThe delimiter to separate matching attribute names.
textResult pointer.
Returns
Positive on success, negative on errors. If no attributes have been defined, *text is NULL.

◆ attribute_check_callback()

int attribute_check_callback ( struct afs_callback_arg aca)

Compute the attribute bit mask and check each afs info bitmap.

Parameters
acaThe query field of aca is ignored.

This iterates over all attributes in the attribute table and computes the logical or of 1 << b where b is the bit number of the attribute. The resulting bit mask is passed to aft_check_attributes() which performs the actual check.

Returns
Standard.
See also
aft_check_attributes().

◆ aft_get_row_of_path()

int aft_get_row_of_path ( const char *  path,
struct osl_row **  row 
)

Get the row of the audio file table corresponding to the given path.

Parameters
pathThe full path of the audio file.
rowResult pointer.
Returns
Standard.

References osl().

◆ aft_check_attributes()

int aft_check_attributes ( uint64_t  att_mask,
struct para_buffer pb 
)

Iterate over all audio files and check the attribute bit mask.

Parameters
att_maskThe mask of all valid attributes.
pbUsed for reporting inconsistencies.

This reads the attribute bit mask of each audio file from the afs info structure stored in the audio file table and verifies that all set bits are also turned on in att_mask, i.e., correspond to an attribute of the attribute table. Audio files for which this is not the case are reported via pb.

Returns
Standard. Inconsistencies are not regarded as errors.
See also
attribute_check_callback().

References audio_file_loop(), and para_printf().

◆ open_and_update_audio_file()

int open_and_update_audio_file ( int *  fd)

Open the audio file with highest score and set up an afd structure.

This determines and opens the next audio file, verifies that it did not change by comparing the recomputed the hash value of the file contents against the value stored in the audio file table. If all goes well, it creates a shared memory area containing the serialized version of the afd structure, including the chunk table, if any. The caller can then send the ID of this area and the open fd to the server process.

Parameters
fdResult pointer for the file descriptor of the audio file.

On success, the numplayed field of the audio file selector info is increased and the lastplayed time is set to the current time. Finally, the score of the audio file is updated.

Returns
Positive shmid on success, negative on errors.

References HASH2_SIZE.

◆ load_afd()

int load_afd ( int  shmid,
struct audio_file_data afd 
)

Extract a afd stored in a shared memory area.

Attach the shared memory area given by shmid, load the audio file data stored therein and detach the area afterwards. Called by vss, after receiving a positive response to the request for the next audio file.

  • Parameters
    shmidThe identifier of the shared memory area containing the afd.
    afdResult pointer.
    Returns
    Standard.

References ATTACH_RO, shm_attach(), and shm_size().

◆ get_afsi_of_row()

int get_afsi_of_row ( const struct osl_row *  row,
struct afs_info afsi 
)

Get the audio file selector info, given a row of the audio file table.

Parameters
rowPointer to a row in the audio file table.
afsiResult pointer.
Returns
Positive on success, negative on errors.

◆ get_afhi_of_row()

int get_afhi_of_row ( const struct osl_row *  row,
struct afh_info afhi 
)

Get the audio format handler info, given a row of the audio file table.

Parameters
rowPointer to a row of the audio file table.
afhiResult pointer.
Returns
The return value of the underlying call to osl_get_object().

After the call the members of the afhi structure point to mapped memory which is owned by the osl table, Hence the caller must not attempt to free this memory by calling clear_afhi().

References osl().

◆ get_audio_file_path_of_row()

int get_audio_file_path_of_row ( const struct osl_row *  row,
char **  path 
)

Get the path of an audio file, given a row of the audio file table.

Parameters
rowPointer to a row in the audio file table.
pathResult pointer.

The result is a pointer to memory-mapped data. The caller must not attempt to free it.

Returns
Standard.

References osl().

Referenced by mp_path().

◆ audio_file_loop()

int audio_file_loop ( void *  private_data,
osl_rbtree_loop_func *  func 
)

Call the given function for each file in the audio file table.

Parameters
private_dataAn arbitrary data pointer, passed to func.
funcThe custom function to be called.
Returns
Standard.

References osl().

Referenced by aft_check_attributes(), and aft_check_callback().

◆ aft_check_callback()

int aft_check_callback ( struct afs_callback_arg aca)

Check the audio file table for inconsistencies.

Parameters
acaOnly ->pbout is used for diagnostics.
Returns
Standard. Inconsistencies are reported but not regarded as an error.

References audio_file_loop(), para_printf(), and afs_callback_arg::pbout.

◆ free_status_items()

void free_status_items ( void  )

Deallocate and invalidate the status item strings.

This needs to be a public function so that afs.c can call it on shutdown.

References freep().

◆ mood_load()

int mood_load ( const char *  mood_name,
struct mood_instance **  result,
char **  msg 
)

Populate a score table with admissible files for the given mood.

This consults the mood table to initialize the mood parser with the mood expression stored in the blob object which corresponds to the given name. A score table is allocated and populated with references to those entries of the audio file table which evaluate as admissible with respect to the mood expression. For each audio file a score value is computed and stored along with the file reference.

Parameters
mood_nameThe name of the mood to load.
resultOpaque, refers to the mood parser and the score table.
msgError message or mood info is returned here.

If the mood name is NULL, the dummy mood is loaded. This mood regards every audio file as admissible.

A NULL result pointer instructs the function to operate on the current mood. That is, on the mood instance which is used by the server to select the next audio file for streaming. In this mode of operation, the mood which was active before the call, if any, is unloaded on success.

If result is not NULL, the current mood is unaffected and *result points to an initialized mood instance on success. The caller can pass this reference to mood_loop() to iterate over the admissible files, and should call mood_unload() to free the mood instance afterwards.

If the message pointer is not NULL, a suitable message is returned there in all cases. The caller must free this string.

Returns
The number of admissible files on success, negative on errors. On errors, the current mood remains unaffected even if result is NULL. It is not considered an error if no files are admissible.
See also
mp_eval_row().

◆ mood_loop()

int mood_loop ( struct mood_instance *  m,
osl_rbtree_loop_func *  func,
void *  data 
)

Iterate over the admissible files of a mood instance.

This wrapper around score_loop() is the mood counterpart of playlist_loop().

Parameters
mDetermines the score table to iterate. Must not be NULL.
funcSee score_loop().
dataSee score_loop().
Returns
See score_loop(), playlist_loop().

References score_loop().

◆ mood_unload()

void mood_unload ( struct mood_instance *  m)

Free all resources of a mood instance.

Parameters
mAs obtained by mood_load(). If NULL, unload the current mood.

It's OK to call this with m == NULL even if no current mood is loaded.

◆ mood_check_callback()

int mood_check_callback ( struct afs_callback_arg aca)

Check all moods for syntax errors.

Parameters
acaOutput goes to ->pbout, errors to ->fd on the error band.
Returns
Negative on fatal errors. Inconsistent mood definitions are not considered an error.

References BLOBCOL_ID, osl(), para_printf(), and afs_callback_arg::pbout.

◆ playlist_load()

int playlist_load ( const char *  name,
struct playlist_instance **  result,
char **  msg 
)

Populate the score table from the paths of a playlist database object.

This loads the blob object which corresponds to the given name from the playlist table. Each line of the blob is regarded as a path which is looked 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.

Parameters
nameThe name of the playlist to load.
resultOpaque, refers to the underlying score table.
msgError message or playlist info is returned here.
Returns
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.

References ERRNO_TO_PARA_ERROR, FELF_READ_ONLY, for_each_line(), make_message(), score_open(), and zalloc().

◆ playlist_loop()

int playlist_loop ( struct playlist_instance *  pi,
osl_rbtree_loop_func *  func,
void *  data 
)

Iterate over all admissible audio files of a playlist instance.

This wrapper around score_loop() is the playlist counterpart of mood_loop().

Parameters
piDetermines the score table to iterate. Must not be NULL.
funcSee score_loop().
dataSee score_loop().
Returns
See score_loop(), mood_loop().

References score_loop().

◆ playlist_unload()

void playlist_unload ( struct playlist_instance *  pi)

Free all resources of the given/current playlist.

Parameters
piNULL means to unload the current playlist.

References score_close().

◆ playlist_check_callback()

int playlist_check_callback ( struct afs_callback_arg aca)

Check the playlist table for inconsistencies.

Parameters
acaThis callback ignores ->query.
Returns
Standard. Invalid paths are reported, but are not considered an error.

References BLOBCOL_ID, osl(), para_printf(), and afs_callback_arg::pbout.

Variable Documentation

◆ score_ops

const struct afs_table_operations score_ops
extern

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

◆ attr_ops

const struct afs_table_operations attr_ops
extern

The attribute table stores name/bitnum pairs.

◆ aft_ops

const struct afs_table_operations aft_ops
extern

The audio file table contains information about known audio files.

afs_events
afs_events
Events caused by changes to an afs table.
Definition: afs.h:31
para_buffer
A string buffer used for para_printf().
Definition: string.h:12
afs_table_operations
Methods for table startup/shutdown and event handling.
Definition: afs.h:77