database: renamed functions, "db_" prefix and no CamelCase

Yet another CamelCase removal patch.
This commit is contained in:
Max Kellermann 2008-10-08 11:07:55 +02:00
parent 7a023eb0b2
commit bb8a9533b1
11 changed files with 79 additions and 68 deletions

View File

@ -579,7 +579,7 @@ static int handleLsInfo(struct client *client,
if (argc == 2) if (argc == 2)
path = argv[1]; path = argv[1];
directory = getDirectory(path); directory = db_get_directory(path);
if (directory == NULL) { if (directory == NULL) {
command_error(client, ACK_ERROR_NO_EXIST, command_error(client, ACK_ERROR_NO_EXIST,
"directory not found"); "directory not found");

View File

@ -36,7 +36,8 @@ static struct directory *music_root;
static time_t directory_dbModTime; static time_t directory_dbModTime;
void directory_init(void) void
db_init(void)
{ {
music_root = newDirectory(NULL, NULL); music_root = newDirectory(NULL, NULL);
updateDirectory(music_root); updateDirectory(music_root);
@ -44,13 +45,14 @@ void directory_init(void)
stats.dbPlayTime = sumSongTimesIn(NULL); stats.dbPlayTime = sumSongTimesIn(NULL);
} }
void directory_finish(void) void
db_finish(void)
{ {
freeDirectory(music_root); freeDirectory(music_root);
} }
struct directory * struct directory *
directory_get_root(void) db_get_root(void)
{ {
assert(music_root != NULL); assert(music_root != NULL);
@ -58,7 +60,7 @@ directory_get_root(void)
} }
struct directory * struct directory *
getDirectory(const char *name) db_get_directory(const char *name)
{ {
if (name == NULL) if (name == NULL)
return music_root; return music_root;
@ -67,7 +69,7 @@ getDirectory(const char *name)
} }
struct song * struct song *
getSongFromDB(const char *file) get_get_song(const char *file)
{ {
struct song *song = NULL; struct song *song = NULL;
struct directory *directory; struct directory *directory;
@ -85,7 +87,7 @@ getSongFromDB(const char *file)
dir = duplicated; dir = duplicated;
} }
if (!(directory = getDirectory(dir))) if (!(directory = db_get_directory(dir)))
goto out; goto out;
if (!(song = songvec_find(&directory->songs, shortname))) if (!(song = songvec_find(&directory->songs, shortname)))
goto out; goto out;
@ -97,15 +99,15 @@ out:
} }
int int
traverseAllIn(const char *name, db_walk(const char *name,
int (*forEachSong)(struct song *, void *), int (*forEachSong)(struct song *, void *),
int (*forEachDir)(struct directory *, void *), void *data) int (*forEachDir)(struct directory *, void *), void *data)
{ {
struct directory *directory; struct directory *directory;
if ((directory = getDirectory(name)) == NULL) { if ((directory = db_get_directory(name)) == NULL) {
struct song *song; struct song *song;
if ((song = getSongFromDB(name)) && forEachSong) { if ((song = get_get_song(name)) && forEachSong) {
return forEachSong(song, data); return forEachSong(song, data);
} }
return -1; return -1;
@ -115,7 +117,8 @@ traverseAllIn(const char *name,
data); data);
} }
static char *getDbFile(void) static char *
db_get_file(void)
{ {
ConfigParam *param = parseConfigFilePath(CONF_DB_FILE, 1); ConfigParam *param = parseConfigFilePath(CONF_DB_FILE, 1);
@ -125,10 +128,11 @@ static char *getDbFile(void)
return param->value; return param->value;
} }
int checkDirectoryDB(void) int
db_check(void)
{ {
struct stat st; struct stat st;
char *dbFile = getDbFile(); char *dbFile = db_get_file();
/* Check if the file exists */ /* Check if the file exists */
if (access(dbFile, F_OK)) { if (access(dbFile, F_OK)) {
@ -185,10 +189,11 @@ int checkDirectoryDB(void)
return 0; return 0;
} }
int writeDirectoryDB(void) int
db_save(void)
{ {
FILE *fp; FILE *fp;
char *dbFile = getDbFile(); char *dbFile = db_get_file();
struct stat st; struct stat st;
DEBUG("removing empty directories from DB\n"); DEBUG("removing empty directories from DB\n");
@ -228,10 +233,11 @@ int writeDirectoryDB(void)
return 0; return 0;
} }
int readDirectoryDB(void) int
db_load(void)
{ {
FILE *fp = NULL; FILE *fp = NULL;
char *dbFile = getDbFile(); char *dbFile = db_get_file();
struct stat st; struct stat st;
if (!music_root) if (!music_root)
@ -308,7 +314,8 @@ int readDirectoryDB(void)
return 0; return 0;
} }
time_t getDbModTime(void) time_t
db_get_mtime(void)
{ {
return directory_dbModTime; return directory_dbModTime;
} }

View File

@ -24,29 +24,35 @@
struct directory; struct directory;
void directory_init(void); void
db_init(void);
void directory_finish(void); void
db_finish(void);
struct directory * struct directory *
directory_get_root(void); db_get_root(void);
struct directory * struct directory *
getDirectory(const char *name); db_get_directory(const char *name);
struct song * struct song *
getSongFromDB(const char *file); get_get_song(const char *file);
int traverseAllIn(const char *name, int db_walk(const char *name,
int (*forEachSong)(struct song *, void *), int (*forEachSong)(struct song *, void *),
int (*forEachDir)(struct directory *, void *), void *data); int (*forEachDir)(struct directory *, void *), void *data);
int checkDirectoryDB(void); int
db_check(void);
int writeDirectoryDB(void); int
db_save(void);
int readDirectoryDB(void); int
db_load(void);
time_t getDbModTime(void); time_t
db_get_mtime(void);
#endif #endif

View File

@ -110,7 +110,7 @@ int searchForSongsIn(struct client *client, const char *name,
data.array.numItems = numItems; data.array.numItems = numItems;
data.array.items = items; data.array.items = items;
ret = traverseAllIn(name, searchInDirectory, NULL, &data); ret = db_walk(name, searchInDirectory, NULL, &data);
for (i = 0; i < numItems; i++) { for (i = 0; i < numItems; i++) {
free(items[i].needle); free(items[i].needle);
@ -143,7 +143,7 @@ int findSongsIn(struct client *client, const char *name,
data.array.numItems = numItems; data.array.numItems = numItems;
data.array.items = items; data.array.items = items;
return traverseAllIn(name, findInDirectory, NULL, &data); return db_walk(name, findInDirectory, NULL, &data);
} }
static void printSearchStats(struct client *client, SearchStats *stats) static void printSearchStats(struct client *client, SearchStats *stats)
@ -178,7 +178,7 @@ int searchStatsForSongsIn(struct client *client, const char *name,
stats.numberOfSongs = 0; stats.numberOfSongs = 0;
stats.playTime = 0; stats.playTime = 0;
ret = traverseAllIn(name, searchStatsInDirectory, NULL, &stats); ret = db_walk(name, searchStatsInDirectory, NULL, &stats);
if (ret == 0) if (ret == 0)
printSearchStats(client, &stats); printSearchStats(client, &stats);
@ -187,7 +187,7 @@ int searchStatsForSongsIn(struct client *client, const char *name,
int printAllIn(struct client *client, const char *name) int printAllIn(struct client *client, const char *name)
{ {
return traverseAllIn(name, printSongInDirectory, return db_walk(name, printSongInDirectory,
printDirectoryInDirectory, client); printDirectoryInDirectory, client);
} }
@ -213,7 +213,7 @@ directoryAddSongToStoredPlaylist(struct song *song, void *_data)
int addAllIn(const char *name) int addAllIn(const char *name)
{ {
return traverseAllIn(name, directoryAddSongToPlaylist, NULL, NULL); return db_walk(name, directoryAddSongToPlaylist, NULL, NULL);
} }
int addAllInToStoredPlaylist(const char *name, const char *utf8file) int addAllInToStoredPlaylist(const char *name, const char *utf8file)
@ -222,8 +222,7 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file)
.path = utf8file, .path = utf8file,
}; };
return traverseAllIn(name, directoryAddSongToStoredPlaylist, NULL, return db_walk(name, directoryAddSongToStoredPlaylist, NULL, &data);
&data);
} }
static int static int
@ -247,7 +246,7 @@ sumSongTime(struct song *song, void *data)
int printInfoForAllIn(struct client *client, const char *name) int printInfoForAllIn(struct client *client, const char *name)
{ {
return traverseAllIn(name, directoryPrintSongInfo, return db_walk(name, directoryPrintSongInfo,
printDirectoryInDirectory, client); printDirectoryInDirectory, client);
} }
@ -256,7 +255,7 @@ int countSongsIn(const char *name)
int count = 0; int count = 0;
void *ptr = (void *)&count; void *ptr = (void *)&count;
traverseAllIn(name, NULL, countSongsInDirectory, ptr); db_walk(name, NULL, countSongsInDirectory, ptr);
return count; return count;
} }
@ -266,7 +265,7 @@ unsigned long sumSongTimesIn(const char *name)
unsigned long dbPlayTime = 0; unsigned long dbPlayTime = 0;
void *ptr = (void *)&dbPlayTime; void *ptr = (void *)&dbPlayTime;
traverseAllIn(name, sumSongTime, NULL, ptr); db_walk(name, sumSongTime, NULL, ptr);
return dbPlayTime; return dbPlayTime;
} }
@ -347,8 +346,7 @@ int listAllUniqueTags(struct client *client, int type, int numConditionals,
data.set = strset_new(); data.set = strset_new();
} }
ret = traverseAllIn(NULL, listUniqueTagsInDirectory, NULL, ret = db_walk(NULL, listUniqueTagsInDirectory, NULL, &data);
&data);
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
const char *value; const char *value;
@ -396,7 +394,7 @@ void printSavedMemoryFromFilenames(void)
{ {
int sum = 0; int sum = 0;
traverseAllIn(NULL, sumSavedFilenameMemoryInSong, db_walk(NULL, sumSavedFilenameMemoryInSong,
sumSavedFilenameMemoryInDirectory, (void *)&sum); sumSavedFilenameMemoryInDirectory, (void *)&sum);
DEBUG("saved memory from filenames: %i\n", sum); DEBUG("saved memory from filenames: %i\n", sum);

View File

@ -182,7 +182,7 @@ readDirectoryInfo(FILE * fp, struct directory * directory)
if (prefixcmp(buffer, DIRECTORY_BEGIN)) if (prefixcmp(buffer, DIRECTORY_BEGIN))
FATAL("Error reading db at line: %s\n", buffer); FATAL("Error reading db at line: %s\n", buffer);
name = &(buffer[strlen(DIRECTORY_BEGIN)]); name = &(buffer[strlen(DIRECTORY_BEGIN)]);
if ((subdir = getDirectory(name))) { if ((subdir = db_get_directory(name))) {
assert(subdir->parent == directory); assert(subdir->parent == directory);
} else { } else {
subdir = newDirectory(name, directory); subdir = newDirectory(name, directory);

View File

@ -272,17 +272,17 @@ static void changeToUser(void)
static void openDB(Options * options, char *argv0) static void openDB(Options * options, char *argv0)
{ {
if (options->createDB > 0 || readDirectoryDB() < 0) { if (options->createDB > 0 || db_load() < 0) {
if (options->createDB < 0) { if (options->createDB < 0) {
FATAL("can't open db file and using " FATAL("can't open db file and using "
"\"--no-create-db\" command line option\n" "\"--no-create-db\" command line option\n"
"try running \"%s --create-db\"\n", argv0); "try running \"%s --create-db\"\n", argv0);
} }
flushWarningLog(); flushWarningLog();
if (checkDirectoryDB() < 0) if (db_check() < 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
directory_init(); db_init();
if (writeDirectoryDB() < 0) if (db_save() < 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (options->createDB) if (options->createDB)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
@ -456,8 +456,8 @@ int main(int argc, char *argv[])
finishPlaylist(); finishPlaylist();
start = clock(); start = clock();
directory_finish(); db_finish();
DEBUG("directory_finish took %f seconds\n", DEBUG("db_finish took %f seconds\n",
((float)(clock()-start))/CLOCKS_PER_SEC); ((float)(clock()-start))/CLOCKS_PER_SEC);
deinit_main_notify(); deinit_main_notify();

View File

@ -559,7 +559,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id)
DEBUG("add to playlist: %s\n", url); DEBUG("add to playlist: %s\n", url);
if ((song = getSongFromDB(url))) { if ((song = get_get_song(url))) {
} else if (!(isValidRemoteUtf8Url(url) && } else if (!(isValidRemoteUtf8Url(url) &&
(song = song_remote_new(url)))) { (song = song_remote_new(url)))) {
return PLAYLIST_RESULT_NO_SUCH_SONG; return PLAYLIST_RESULT_NO_SUCH_SONG;
@ -574,7 +574,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file)
DEBUG("add to stored playlist: %s\n", url); DEBUG("add to stored playlist: %s\n", url);
song = getSongFromDB(url); song = get_get_song(url);
if (song) if (song)
return appendSongToStoredPlaylistByPath(utf8file, song); return appendSongToStoredPlaylistByPath(utf8file, song);
@ -1360,7 +1360,7 @@ int PlaylistInfo(struct client *client, const char *utf8file, int detail)
int wrote = 0; int wrote = 0;
if (detail) { if (detail) {
struct song *song = getSongFromDB(temp); struct song *song = get_get_song(temp);
if (song) { if (song) {
song_print_info(client, song); song_print_info(client, song);
wrote = 1; wrote = 1;

View File

@ -40,7 +40,7 @@ int handlePendingSignals(void)
DEBUG("got SIGHUP, rereading DB\n"); DEBUG("got SIGHUP, rereading DB\n");
signal_clear(SIGHUP); signal_clear(SIGHUP);
if (!isUpdatingDB()) { if (!isUpdatingDB()) {
readDirectoryDB(); db_load();
playlistVersionChange(); playlistVersionChange();
} }
if (cycle_log_files() < 0) if (cycle_log_files() < 0)

View File

@ -66,7 +66,7 @@ static unsigned int getNumberOfTagItems(int type)
}; };
unsigned int ret; unsigned int ret;
traverseAllIn(NULL, visit_tag_items, NULL, &data); db_walk(NULL, visit_tag_items, NULL, &data);
ret = strset_size(data.set); ret = strset_size(data.set);
strset_free(data.set); strset_free(data.set);
@ -89,6 +89,6 @@ int printStats(struct client *client)
time(NULL) - stats.daemonStart, time(NULL) - stats.daemonStart,
(long)(getPlayerTotalPlayTime() + 0.5), (long)(getPlayerTotalPlayTime() + 0.5),
stats.dbPlayTime, stats.dbPlayTime,
getDbModTime()); db_get_mtime());
return 0; return 0;
} }

View File

@ -116,7 +116,7 @@ List *loadStoredPlaylist(const char *utf8path)
!strncmp(s, musicDir, musicDir_len)) !strncmp(s, musicDir, musicDir_len))
memmove(s, s + musicDir_len + 1, memmove(s, s + musicDir_len + 1,
strlen(s + musicDir_len + 1) + 1); strlen(s + musicDir_len + 1) + 1);
if ((song = getSongFromDB(s))) { if ((song = get_get_song(s))) {
song_get_url(song, path_max_tmp); song_get_url(song, path_max_tmp);
insertInListWithoutKey(list, xstrdup(path_max_tmp)); insertInListWithoutKey(list, xstrdup(path_max_tmp));
} else if (isValidRemoteUtf8Url(s)) } else if (isValidRemoteUtf8Url(s))

View File

@ -321,7 +321,7 @@ addDirectoryPathToDB(const char *utf8path)
parent = parent_path(path_max_tmp, utf8path); parent = parent_path(path_max_tmp, utf8path);
if (strlen(parent) == 0) if (strlen(parent) == 0)
parentDirectory = directory_get_root(); parentDirectory = db_get_root();
else else
parentDirectory = addDirectoryPathToDB(parent); parentDirectory = addDirectoryPathToDB(parent);
@ -361,7 +361,7 @@ addParentPathToDB(const char *utf8path)
parent = parent_path(path_max_tmp, utf8path); parent = parent_path(path_max_tmp, utf8path);
if (strlen(parent) == 0) if (strlen(parent) == 0)
parentDirectory = directory_get_root(); parentDirectory = db_get_root();
else else
parentDirectory = addDirectoryPathToDB(parent); parentDirectory = addDirectoryPathToDB(parent);
@ -385,7 +385,7 @@ static enum update_return updatePath(const char *utf8path)
return UPDATE_RETURN_ERROR; return UPDATE_RETURN_ERROR;
/* if path is in the DB try to update it, or else delete it */ /* if path is in the DB try to update it, or else delete it */
if ((directory = getDirectory(path))) { if ((directory = db_get_directory(path))) {
parentDirectory = directory->parent; parentDirectory = directory->parent;
/* if this update directory is successfull, we are done */ /* if this update directory is successfull, we are done */
@ -396,7 +396,7 @@ static enum update_return updatePath(const char *utf8path)
return ret; return ret;
} }
/* we don't want to delete the root directory */ /* we don't want to delete the root directory */
else if (directory == directory_get_root()) { else if (directory == db_get_root()) {
free(path); free(path);
return UPDATE_RETURN_NOUPDATE; return UPDATE_RETURN_NOUPDATE;
} }
@ -407,7 +407,7 @@ static enum update_return updatePath(const char *utf8path)
ret = UPDATE_RETURN_UPDATED; ret = UPDATE_RETURN_UPDATED;
/* don't return, path maybe a song now */ /* don't return, path maybe a song now */
} }
} else if ((song = getSongFromDB(path))) { } else if ((song = get_get_song(path))) {
parentDirectory = song->parent; parentDirectory = song->parent;
if (!parentDirectory->stat if (!parentDirectory->stat
&& statDirectory(parentDirectory) < 0) { && statDirectory(parentDirectory) < 0) {
@ -467,10 +467,10 @@ static void * update_task(void *_path)
ret = updatePath((char *)_path); ret = updatePath((char *)_path);
free(_path); free(_path);
} else { } else {
ret = updateDirectory(directory_get_root()); ret = updateDirectory(db_get_root());
} }
if (ret == UPDATE_RETURN_UPDATED && writeDirectoryDB() < 0) if (ret == UPDATE_RETURN_UPDATED && db_save() < 0)
ret = UPDATE_RETURN_ERROR; ret = UPDATE_RETURN_ERROR;
progress = UPDATE_PROGRESS_DONE; progress = UPDATE_PROGRESS_DONE;
wakeup_main_task(); wakeup_main_task();