DALIB(3)

NAME
da_add_callback - Add a callback

SYNOPSIS
#include dataudiolib.h

int
da_add_callback( int datfd,enum da_cb_type type, enum da_cb_granularity granularity, void (*cbfun)(DA_CB_PROTO));

void (*cbfun)(DA_CB_PROTO);

#define DA_CB_PROTO int datfd,enum da_cb_type type,union da_callback_data *data

DESCRIPTION
The da_add_callback() function adds a notification callback. The specified function will be called, when the condition (as specified by type and granularity ) triggers. A callback may trigger after a frame has been read from the tape and the subcode has been decoded (so a single da_read() may trigger multiple callbacks of the same type).

The callbackfunction gets as arguments:

datfd
    The associated datfiledescriptor.

type
    The callback type. See below for a list of types.

data
    A union da_callback_data Only the respective part will be filled out.

Following callback types are possible (enumerated in enum da_cb_type ):

DA_CB_SAMPLERATE
    Generates a callback if the samplerate changed in the last decoded frame. There are no granularity differences. The union member samplerate is set to the new samplerate.

DA_CB_CHANNELS
    Generates a callback if the number of channels changed in the last decoded frame. There are no granularity differences. The union member channels is set to the new number of channels.

DA_CB_PROGNR
    Generates a callback if the programnumer changed in the last decoded frame. There are no granularity differences. The union member prognr is set to the new program number.

DA_CB_PROGTIME
    Generates a callback if the program time changes (or becomes invalid). Granularities possible are DA_CB_FRAMES,DA_CB_SECONDS,DA_CB_MINUTES,DA_CB_HOURS and DA_CB_INDEXNR. The callback triggers only, when the specified component (or one of the components with coarse granularity) changes.
    The union member time will be filled with the new programtime.
    If the program time did become invalid, a NULL ptr will be passed to the callback function.
    The struct da_time is described in the da_control manpage.

DA_CB_ABSTIME
    Generates a callback if the absolute time changes (or becomes invalid). Granularities possible are DA_CB_FRAMES,DA_CB_SECONDS,DA_CB_MINUTES,DA_CB_HOURS and DA_CB_INDEXNR. The callback triggers only, when the specified component (or one of the components with coarse granularity) changes.
    The union member time will be filled with the new absolute time.
    If the absolute time did become invalid, a NULL ptr will be passed to the callback function.

DA_CB_RUNTIME
    Generates a callback if the runtime changes (or becomes invalid). Granularities possible are DA_CB_FRAMES,DA_CB_SECONDS,DA_CB_MINUTES,DA_CB_HOURS and DA_CB_INDEXNR. The callback triggers only, when the specified component (or one of the components with coarse granularity) changes.
    The union member time will be filled with the new runtime.
    If the runtime did become invalid, a NULL ptr will be passed to the callback function.

DA_CB_TRACKTIME
    Generates a callback if the track changes (or becomes invalid). Granularities possible are DA_CB_FRAMES,DA_CB_SECONDS,DA_CB_MINUTES,DA_CB_HOURS and DA_CB_INDEXNR. The callback triggers only, when the specified component (or one of the components with coarse granularity) changes.
    The union member time will be filled with the new tracktime.
    If the tracktime did become invalid, a NULL ptr will be passed to the callback function.
    Note that the granularities here are rather useless, for the tracktime won't change over the length of one track.

DA_CB_TRACKNAME
    Generates a callback if the current trackname has changed. There are no granularity differences. The union member trackname will point to the current trackname. If the current trackname has become invalid, the passed pointer is NULL.

DA_CB_RECORDDATE
    Generates a callback if the current recorddate has changed by the specified granularity (or became invalid). Possible granularities are: DA_CB_SECONDS, DA_CB_MINUTES, DA_CB_HOURS, DA_CB_DAYS, DA_CB_WEEKDAYS, DA_CB_MONTHS, DA_CB_YEARS. The union member date will be filled out. If the recorddate became invalid, a NULL pointer is passed to the callback function.

DA_CB_TOC
    Generates a callback if the current table of contents has changed. There is no granularity difference. This callback will also be generated when the trackname list changes.

DA_CB_SUBID
    Generates a callback if the subid changed. There are no different granularities.

PARAMETERS

  Input Parameters

datfd
    A datfiledescriptor returned by da_open or da_init.

type
    The type of the callback.

granularity
    The granularity of the callback (if there are granularity differences).

cbfun
    The callback function.

RETURN VALUE
This function does return 0 on success. When an error condition arises, this routine returns -1 and sets errno to indicate the reason for the error. Possible values of errno are:

ENOENT
    The datfiledescriptor is invalid.

EBADF
    An internal error occured.

USAGE EXAMPLE

Add a callback to display changing programnumber.

	#include "dataudiolib.h"
		da_add_callback(datfd,DA_CB_PROGNR,0,cb_prognr);
	cb_prognr(int datfd,enum da_cb_type type,union da_cb_data *data) {
		printf("Prognr: %d,data->prognr);
	}

Add a callback to display changing programtime.

	#include "dataudiolib.h"
		da_add_callback(datfd,DA_CB_PROGTIME,DA_CB_SEONDS,cb_progtime);
	cb_progtime(int datfd,enum da_cb_type type,union da_cb_data *data) {
		if (data)
			printf("Progtime: %02d:%02d:%02d\n",
				data->time.hour,
				data->time.minute,
				data->time.second
			);
		else
			printf("Progtime: --:--:--\n");
	}

SEE ALSO
da_intro(3),da_open(3)

AUTHOR
Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>