![]() |
DVBCore
22.3.0
Open Source DVB Engine
|
Database access public functions. More...
#include <string.h>
#include "techtype.h"
#include "dbgfuncs.h"
#include "stbhwos.h"
#include "dba.h"
#include "dba_nvm.h"
#include "stbdbram.h"
#include "stbdbnvm.h"
#include "stbnvm.h"
#include "stbcsum.h"
#include "stbheap.h"
#include "stbuni.h"
Classes | |
struct | DATABASE_FORMAT |
struct | DATABASE_DESCRIPTOR |
struct | RECORD_DESCRIPTOR |
struct | FIELD_DESCRIPTOR |
struct | FIELD_TYPE |
struct | FIELD_ACCESS |
struct | RECORD_ACCESS |
Macros | |
#define | FORMAT_VERSION_NUM 4 |
#define | FORMAT_ID_STRING "STB DB 01" |
#define | FORMAT_ID_STRING_SIZE 10 |
#define | NUM_FIELDS(X) (sizeof(X) / sizeof(FIELD_ACCESS)) |
#define | DBA_GROUP_NAME_LEN 35 |
#define | DBA_SERV_NAME_LEN 32 |
#define | DBA_TIMER_NAME_LEN 255 /* Max length of an event name is 255 chars */ |
#define | DBA_FAVLIST_NAME_LEN 128 /* Arbitrary length */ |
#define | DBA_TIMER_ADDINFO_LEN 255 |
#define | DBA_LNB_NAME_LEN 24 |
#define | DBA_CRID_LEN 65 |
#define | DBA_PROFILE_NAME_LEN 255 |
Functions | |
BOOLEAN | DBA_Initialise (void) |
Performs any initialisation required prior to the database being loaded. More... | |
void | DBA_Terminate (void) |
Releases any resources acquired by initialisation and clears any currently loaded database, including a backup, if one has been created. | |
BOOLEAN | DBA_LoadDatabase (U8BIT *pathname) |
Reads a database from non-volatile storage, creating any structures in memory that will be required to access it and the records it contains and makes this the working database. If the database is found to be invalid, or doesn't exist at all, then an empty database should be created. More... | |
BOOLEAN | DBA_SaveDatabase (void) |
Saves any changes made to the working database to non-volatile storage. If saving to a file, the pathname used to open it will be used. More... | |
BOOLEAN | DBA_ClearDatabase (void) |
Clears the working database of all records. Following this call, it should still be possible to access the database, but it will be empty, and new records can be added to it. More... | |
BOOLEAN | DBA_BackupDatabase (U8BIT *pathname) |
Creates a backup copy of the working database. Whether the backup database is saved to non-volatile storage is implementation dependant and so the backup database may not survive a system reboot. More... | |
BOOLEAN | DBA_CanRestoreDatabase (void) |
Checks whether the working database can be restored from a backup copy. More... | |
BOOLEAN | DBA_RestoreDatabase (void) |
Restores the working database from a previously made backup copy. More... | |
void | DBA_EraseBackupDatabase (void) |
Erases the backup copy of the database. If data was stored in non-volatile storage then this should be deleted too. | |
BOOLEAN | DBA_ExportToXML (U8BIT *xml_pathname) |
Export the working database to an XML file. More... | |
BOOLEAN | DBA_ImportFromXML (U8BIT *xml_pathname) |
Imports records from the given XML file into the working database. If a record already exists in the database then it will be updated, and if it doesn't then a new record will be created. More... | |
void | DBA_LockDatabase (void) |
Locks the database to prevent access from other threads or processes. | |
void | DBA_UnlockDatabase (void) |
Unlocks the database to allow other threads or processes to access it. | |
U8BIT * | DBA_DatabaseVersion (void) |
Returns a version string representing the working database. More... | |
U32BIT | DBA_DatabaseFileSize (U32BIT *max_size) |
Returns the size in bytes of the database as stored in non-volatile storage. More... | |
void * | DBA_CreateRecord (U32BIT record_id, void *parent) |
Creates a new record of the given type, adding it to the database as a child of the given parent record, if provided. More... | |
void | DBA_DestroyRecord (void *record) |
Destroys the given record, removing it from the database and freeing any memory associated with it. More... | |
void * | DBA_FindRecord (U32BIT record_id, void *parent, void *last_rec) |
Finds the next record, of the given type, that comes after last_rec. last_rec must be the same type of record as the one being found. Parent is optional, but if provided, a record will only be returned if the parent of the one found is the same. More... | |
void | DBA_SetRecordParent (void *record, void *parent) |
Set of change the parent of the given record. More... | |
void * | DBA_GetRecordParent (void *record) |
Returns the handle to the parent of the given record. More... | |
void | DBA_SaveRecord (void *record) |
Forces a record to be saved to non-volatile storage. Depending on the implementation, this function may not do anything if the data is updated to non-volatile storage as any records and/or fields are created or updated. More... | |
BOOLEAN | DBA_SetFieldValue (void *record, U32BIT field_id, U32BIT value) |
Set the value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is a string value. More... | |
BOOLEAN | DBA_SetFieldString (void *record, U32BIT field_id, U8BIT *string, U16BIT num_bytes) |
Set the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is an integer value. The string data provided will be copied and no interpretation is made of the format of the string. More... | |
BOOLEAN | DBA_SetFieldLangString (void *record, U32BIT field_id, U32BIT lang_code, U8BIT *string, U16BIT num_bytes) |
Set the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a string field. The string data provided will be copied and no interpretation is made of the format of the string. More... | |
BOOLEAN | DBA_SetFieldData (void *record, U32BIT field_id, U8BIT *data, U16BIT num_bytes) |
Set a variable amount of data of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field doesn't hold data. The data provided will be copied. More... | |
BOOLEAN | DBA_GetFieldValue (void *record, U32BIT field_id, U32BIT *value) |
Gets the value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is a string value. More... | |
BOOLEAN | DBA_GetFieldString (void *record, U32BIT field_id, U8BIT **string, U16BIT *num_bytes) |
Gets the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is an integer value. The pointer to the string returned will be to the data held by the database, so the data must not be changed. More... | |
BOOLEAN | DBA_GetFieldLangString (void *record, U32BIT field_id, U32BIT lang_code, U8BIT **string, U16BIT *num_bytes) |
Gets the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is an integer value. The pointer to the string returned will be to the data held by the database, so the data must not be changed. More... | |
BOOLEAN | DBA_GetFieldData (void *record, U32BIT field_id, U8BIT **data, U16BIT *num_bytes) |
Gets the data of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a data field. The pointer to the data returned will be to the data held by the database, so the data must not be changed. More... | |
U32BIT | DBA_DataBlockSize (U32BIT data_block_id) |
Returns the number of bytes available for the given data block. More... | |
U32BIT | DBA_DataBlockRead (U32BIT data_block_id, U8BIT *data, U32BIT num_bytes) |
Read a block of data from the database into the given buffer. More... | |
BOOLEAN | DBA_DataBlockWrite (U32BIT data_block_id, U8BIT *data, U32BIT num_bytes) |
Writes a block of data into the database from the given buffer. More... | |
Database access public functions.
BOOLEAN DBA_BackupDatabase | ( | U8BIT * | pathname | ) |
Creates a backup copy of the working database. Whether the backup database is saved to non-volatile storage is implementation dependant and so the backup database may not survive a system reboot.
pathname | full pathname of the file to save the backup to if this is supported by the database implementation. |
BOOLEAN DBA_CanRestoreDatabase | ( | void | ) |
Checks whether the working database can be restored from a backup copy.
BOOLEAN DBA_ClearDatabase | ( | void | ) |
Clears the working database of all records. Following this call, it should still be possible to access the database, but it will be empty, and new records can be added to it.
void* DBA_CreateRecord | ( | U32BIT | record_id, |
void * | parent | ||
) |
Creates a new record of the given type, adding it to the database as a child of the given parent record, if provided.
record_id | type of record to be created |
parent | create a record that is a child of this parent, can be passed as NULL |
U32BIT DBA_DatabaseFileSize | ( | U32BIT * | max_size | ) |
Returns the size in bytes of the database as stored in non-volatile storage.
max_size | returns the maximum size in bytes that the database can grow to. This value may be returned as 0 if this can't be determined. |
U8BIT* DBA_DatabaseVersion | ( | void | ) |
Returns a version string representing the working database.
U32BIT DBA_DataBlockRead | ( | U32BIT | data_block_id, |
U8BIT * | data, | ||
U32BIT | num_bytes | ||
) |
Read a block of data from the database into the given buffer.
data_block_id | id of the data block to be read |
data | pointer to the buffer into which the data will be read |
num_bytes | the number of bytes to be read |
U32BIT DBA_DataBlockSize | ( | U32BIT | data_block_id | ) |
Returns the number of bytes available for the given data block.
data_block_id | the data block whose size is to be returned |
BOOLEAN DBA_DataBlockWrite | ( | U32BIT | data_block_id, |
U8BIT * | data, | ||
U32BIT | num_bytes | ||
) |
Writes a block of data into the database from the given buffer.
data_block_id | id of the data block being written |
data | pointer to the data to be written |
num_bytes | number of bytes of data to be written |
void DBA_DestroyRecord | ( | void * | record | ) |
Destroys the given record, removing it from the database and freeing any memory associated with it.
record | database record to be deleted |
BOOLEAN DBA_ExportToXML | ( | U8BIT * | xml_pathname | ) |
Export the working database to an XML file.
xml_pathname | full pathname of the file to export to |
void* DBA_FindRecord | ( | U32BIT | record_id, |
void * | parent, | ||
void * | last_rec | ||
) |
Finds the next record, of the given type, that comes after last_rec. last_rec must be the same type of record as the one being found. Parent is optional, but if provided, a record will only be returned if the parent of the one found is the same.
record_id | - type of record to look for |
parent | if not NULL, this must be the parent of the record found for it to be returned |
last_rec | previous record of the type being looked for, if NULL then the first record will be returned. |
BOOLEAN DBA_GetFieldData | ( | void * | record, |
U32BIT | field_id, | ||
U8BIT ** | data, | ||
U16BIT * | num_bytes | ||
) |
Gets the data of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a data field. The pointer to the data returned will be to the data held by the database, so the data must not be changed.
record | handle of the record being queried |
field_id | field within the record being queried |
data | pointer to the returned data in the field |
num_bytes | number of bytes of data |
BOOLEAN DBA_GetFieldLangString | ( | void * | record, |
U32BIT | field_id, | ||
U32BIT | lang_code, | ||
U8BIT ** | string, | ||
U16BIT * | num_bytes | ||
) |
Gets the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is an integer value. The pointer to the string returned will be to the data held by the database, so the data must not be changed.
Gets the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a string field. The pointer to the string returned will be to the string data held by the database, so the data must not be changed.
record | handle of the record being queried |
field_id | field within the record being queried |
lang_code | language code of the string to be returned |
string | pointer to the returned string value in the field |
num_bytes | number of bytes in the string |
BOOLEAN DBA_GetFieldString | ( | void * | record, |
U32BIT | field_id, | ||
U8BIT ** | string, | ||
U16BIT * | num_bytes | ||
) |
Gets the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is an integer value. The pointer to the string returned will be to the data held by the database, so the data must not be changed.
Gets the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a string field. The pointer to the string returned will be to the string data held by the database, so the data must not be changed.
record | handle of the record being queried |
field_id | field within the record being queried |
string | pointer to the returned string value in the field |
num_bytes | number of bytes in the string |
BOOLEAN DBA_GetFieldValue | ( | void * | record, |
U32BIT | field_id, | ||
U32BIT * | value | ||
) |
Gets the value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is a string value.
Gets the value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a value field.
record | handle of the record being queried |
field_id | field within the record being queried |
value | pointer to the returned value if function returns TRUE |
void* DBA_GetRecordParent | ( | void * | record | ) |
Returns the handle to the parent of the given record.
record | handle of record whose parent is to be returned |
BOOLEAN DBA_ImportFromXML | ( | U8BIT * | xml_pathname | ) |
Imports records from the given XML file into the working database. If a record already exists in the database then it will be updated, and if it doesn't then a new record will be created.
xml_pathname | full pathname of the file to be imported |
BOOLEAN DBA_Initialise | ( | void | ) |
Performs any initialisation required prior to the database being loaded.
BOOLEAN DBA_LoadDatabase | ( | U8BIT * | pathname | ) |
Reads a database from non-volatile storage, creating any structures in memory that will be required to access it and the records it contains and makes this the working database. If the database is found to be invalid, or doesn't exist at all, then an empty database should be created.
pathname | full pathname of the file to be loaded containing the database. This argument is only relevant where the system being used is file based. |
BOOLEAN DBA_RestoreDatabase | ( | void | ) |
Restores the working database from a previously made backup copy.
BOOLEAN DBA_SaveDatabase | ( | void | ) |
Saves any changes made to the working database to non-volatile storage. If saving to a file, the pathname used to open it will be used.
void DBA_SaveRecord | ( | void * | record | ) |
Forces a record to be saved to non-volatile storage. Depending on the implementation, this function may not do anything if the data is updated to non-volatile storage as any records and/or fields are created or updated.
record | handle of record to be saved |
BOOLEAN DBA_SetFieldData | ( | void * | record, |
U32BIT | field_id, | ||
U8BIT * | data, | ||
U16BIT | num_bytes | ||
) |
Set a variable amount of data of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field doesn't hold data. The data provided will be copied.
record | handle of the record to be changed |
field_id | field within the record to be changed |
data | data to be stored in the field |
num_bytes | number of bytes of data |
BOOLEAN DBA_SetFieldLangString | ( | void * | record, |
U32BIT | field_id, | ||
U32BIT | lang_code, | ||
U8BIT * | string, | ||
U16BIT | num_bytes | ||
) |
Set the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a string field. The string data provided will be copied and no interpretation is made of the format of the string.
record | handle of the record to be changed |
field_id | field within the record to be changed |
lang_code | language code of the string |
string | string value of the field |
num_bytes | number of bytes in the string, should include null terminator if present |
BOOLEAN DBA_SetFieldString | ( | void * | record, |
U32BIT | field_id, | ||
U8BIT * | string, | ||
U16BIT | num_bytes | ||
) |
Set the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is an integer value. The string data provided will be copied and no interpretation is made of the format of the string.
Set the string value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a string field. The string data provided will be copied and no interpretation is made of the format of the string.
record | handle of the record to be changed |
field_id | field within the record to be changed |
string | string value of the field |
num_bytes | number of bytes in the string, should include null terminator if present |
BOOLEAN DBA_SetFieldValue | ( | void * | record, |
U32BIT | field_id, | ||
U32BIT | value | ||
) |
Set the value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field is a string value.
Set the value of a record's field. The function will fail if the record doesn't exist, the record doesn't include the given field, or the field isn't a value field.
record | handle of the record to be changed |
field_id | field within the record to be changed |
value | new value of the field |
void DBA_SetRecordParent | ( | void * | record, |
void * | parent | ||
) |
Set of change the parent of the given record.
record | handle of the record whose parent is to be changed |
parent | handle of the new parent record, can be NULL |