1 #ifndef foopulsecoredatabasehfoo 2 #define foopulsecoredatabasehfoo 3 4 /*** 5 This file is part of PulseAudio. 6 7 Copyright 2009 Lennart Poettering 8 9 PulseAudio is free software; you can redistribute it and/or modify 10 it under the terms of the GNU Lesser General Public License as 11 published by the Free Software Foundation; either version 2.1 of the 12 License, or (at your option) any later version. 13 14 PulseAudio is distributed in the hope that it will be useful, but 15 WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Lesser General Public 20 License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 21 ***/ 22 23 #include <sys/types.h> 24 25 #include <pulsecore/macro.h> 26 27 /* A little abstraction over simple databases, such as gdbm, tdb, and 28 * so on. We only make minimal assumptions about the supported 29 * backend: it does not need to support locking, it does not have to 30 * be arch independent. */ 31 32 typedef struct pa_database pa_database; 33 34 typedef struct pa_datum { 35 void *data; 36 size_t size; 37 } pa_datum; 38 39 void pa_datum_free(pa_datum *d); 40 41 /* Database implementation; returns non-empty database filename extension string */ 42 const char* pa_database_get_filename_suffix(void); 43 44 /* Opens a database file. The file is loaded from the directory indicated by 45 * path. The file name is constructed by using fn as the base and then adding 46 * several parts: 47 * 1) If prependmid is true, the machine id is prepended to the file name. 48 * 2) The database implementation specific suffix is added. 49 * 3) Older versions of PulseAudio in some cases added the CPU architecture 50 * to the file name, which was later deemed unnecessary, but for 51 * compatibility reasons we still need to look for those files, so we scan 52 * the directory for files that match the prefix (possible machine id plus 53 * fn) and the suffix, and if any matches are found, we use the first one. 54 * 55 * When no existing file is found, we create a new file for the database 56 * (without the CPU architecture part in the name). 57 * 58 * For a read-only database, set for_write to false. */ 59 60 pa_database* pa_database_open(const char *path, const char *fn, bool prependmid, bool for_write); 61 62 /* Database implementation; opens specified database file using provided path. */ 63 pa_database* pa_database_open_internal(const char *path, bool for_write); 64 void pa_database_close(pa_database *db); 65 66 pa_datum* pa_database_get(pa_database *db, const pa_datum *key, pa_datum* data); 67 68 int pa_database_set(pa_database *db, const pa_datum *key, const pa_datum* data, bool overwrite); 69 int pa_database_unset(pa_database *db, const pa_datum *key); 70 71 int pa_database_clear(pa_database *db); 72 73 signed pa_database_size(pa_database *db); 74 75 pa_datum* pa_database_first(pa_database *db, pa_datum *key, pa_datum *data /* may be NULL */); 76 pa_datum* pa_database_next(pa_database *db, const pa_datum *key, pa_datum *next, pa_datum *data /* may be NULL */); 77 78 int pa_database_sync(pa_database *db); 79 80 #endif 81