153a5a1b3Sopenharmony_ci#ifndef foopulsecoredatabasehfoo 253a5a1b3Sopenharmony_ci#define foopulsecoredatabasehfoo 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci/*** 553a5a1b3Sopenharmony_ci This file is part of PulseAudio. 653a5a1b3Sopenharmony_ci 753a5a1b3Sopenharmony_ci Copyright 2009 Lennart Poettering 853a5a1b3Sopenharmony_ci 953a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 1053a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as 1153a5a1b3Sopenharmony_ci published by the Free Software Foundation; either version 2.1 of the 1253a5a1b3Sopenharmony_ci License, or (at your option) any later version. 1353a5a1b3Sopenharmony_ci 1453a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1553a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1653a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1753a5a1b3Sopenharmony_ci Lesser General Public License for more details. 1853a5a1b3Sopenharmony_ci 1953a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public 2053a5a1b3Sopenharmony_ci License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 2153a5a1b3Sopenharmony_ci***/ 2253a5a1b3Sopenharmony_ci 2353a5a1b3Sopenharmony_ci#include <sys/types.h> 2453a5a1b3Sopenharmony_ci 2553a5a1b3Sopenharmony_ci#include <pulsecore/macro.h> 2653a5a1b3Sopenharmony_ci 2753a5a1b3Sopenharmony_ci/* A little abstraction over simple databases, such as gdbm, tdb, and 2853a5a1b3Sopenharmony_ci * so on. We only make minimal assumptions about the supported 2953a5a1b3Sopenharmony_ci * backend: it does not need to support locking, it does not have to 3053a5a1b3Sopenharmony_ci * be arch independent. */ 3153a5a1b3Sopenharmony_ci 3253a5a1b3Sopenharmony_citypedef struct pa_database pa_database; 3353a5a1b3Sopenharmony_ci 3453a5a1b3Sopenharmony_citypedef struct pa_datum { 3553a5a1b3Sopenharmony_ci void *data; 3653a5a1b3Sopenharmony_ci size_t size; 3753a5a1b3Sopenharmony_ci} pa_datum; 3853a5a1b3Sopenharmony_ci 3953a5a1b3Sopenharmony_civoid pa_datum_free(pa_datum *d); 4053a5a1b3Sopenharmony_ci 4153a5a1b3Sopenharmony_ci/* Database implementation; returns non-empty database filename extension string */ 4253a5a1b3Sopenharmony_ciconst char* pa_database_get_filename_suffix(void); 4353a5a1b3Sopenharmony_ci 4453a5a1b3Sopenharmony_ci/* Opens a database file. The file is loaded from the directory indicated by 4553a5a1b3Sopenharmony_ci * path. The file name is constructed by using fn as the base and then adding 4653a5a1b3Sopenharmony_ci * several parts: 4753a5a1b3Sopenharmony_ci * 1) If prependmid is true, the machine id is prepended to the file name. 4853a5a1b3Sopenharmony_ci * 2) The database implementation specific suffix is added. 4953a5a1b3Sopenharmony_ci * 3) Older versions of PulseAudio in some cases added the CPU architecture 5053a5a1b3Sopenharmony_ci * to the file name, which was later deemed unnecessary, but for 5153a5a1b3Sopenharmony_ci * compatibility reasons we still need to look for those files, so we scan 5253a5a1b3Sopenharmony_ci * the directory for files that match the prefix (possible machine id plus 5353a5a1b3Sopenharmony_ci * fn) and the suffix, and if any matches are found, we use the first one. 5453a5a1b3Sopenharmony_ci * 5553a5a1b3Sopenharmony_ci * When no existing file is found, we create a new file for the database 5653a5a1b3Sopenharmony_ci * (without the CPU architecture part in the name). 5753a5a1b3Sopenharmony_ci * 5853a5a1b3Sopenharmony_ci * For a read-only database, set for_write to false. */ 5953a5a1b3Sopenharmony_ci 6053a5a1b3Sopenharmony_cipa_database* pa_database_open(const char *path, const char *fn, bool prependmid, bool for_write); 6153a5a1b3Sopenharmony_ci 6253a5a1b3Sopenharmony_ci/* Database implementation; opens specified database file using provided path. */ 6353a5a1b3Sopenharmony_cipa_database* pa_database_open_internal(const char *path, bool for_write); 6453a5a1b3Sopenharmony_civoid pa_database_close(pa_database *db); 6553a5a1b3Sopenharmony_ci 6653a5a1b3Sopenharmony_cipa_datum* pa_database_get(pa_database *db, const pa_datum *key, pa_datum* data); 6753a5a1b3Sopenharmony_ci 6853a5a1b3Sopenharmony_ciint pa_database_set(pa_database *db, const pa_datum *key, const pa_datum* data, bool overwrite); 6953a5a1b3Sopenharmony_ciint pa_database_unset(pa_database *db, const pa_datum *key); 7053a5a1b3Sopenharmony_ci 7153a5a1b3Sopenharmony_ciint pa_database_clear(pa_database *db); 7253a5a1b3Sopenharmony_ci 7353a5a1b3Sopenharmony_cisigned pa_database_size(pa_database *db); 7453a5a1b3Sopenharmony_ci 7553a5a1b3Sopenharmony_cipa_datum* pa_database_first(pa_database *db, pa_datum *key, pa_datum *data /* may be NULL */); 7653a5a1b3Sopenharmony_cipa_datum* pa_database_next(pa_database *db, const pa_datum *key, pa_datum *next, pa_datum *data /* may be NULL */); 7753a5a1b3Sopenharmony_ci 7853a5a1b3Sopenharmony_ciint pa_database_sync(pa_database *db); 7953a5a1b3Sopenharmony_ci 8053a5a1b3Sopenharmony_ci#endif 81