DatabaseGlue: add function db_is_simple()
Preparing for non-"simple" database plugins.
This commit is contained in:
parent
2043579f71
commit
aa55d759f5
@ -87,10 +87,19 @@ GetDatabase()
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
db_is_simple(void)
|
||||||
|
{
|
||||||
|
assert(db == NULL || db_is_open);
|
||||||
|
|
||||||
|
return dynamic_cast<SimpleDatabase *>(db) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
struct directory *
|
struct directory *
|
||||||
db_get_root(void)
|
db_get_root(void)
|
||||||
{
|
{
|
||||||
assert(db != NULL);
|
assert(db != NULL);
|
||||||
|
assert(db_is_simple());
|
||||||
|
|
||||||
return ((SimpleDatabase *)db)->GetRoot();
|
return ((SimpleDatabase *)db)->GetRoot();
|
||||||
}
|
}
|
||||||
@ -128,6 +137,7 @@ db_save(GError **error_r)
|
|||||||
{
|
{
|
||||||
assert(db != NULL);
|
assert(db != NULL);
|
||||||
assert(db_is_open);
|
assert(db_is_open);
|
||||||
|
assert(db_is_simple());
|
||||||
|
|
||||||
return ((SimpleDatabase *)db)->Save(error_r);
|
return ((SimpleDatabase *)db)->Save(error_r);
|
||||||
}
|
}
|
||||||
@ -153,6 +163,7 @@ db_get_mtime(void)
|
|||||||
{
|
{
|
||||||
assert(db != NULL);
|
assert(db != NULL);
|
||||||
assert(db_is_open);
|
assert(db_is_open);
|
||||||
|
assert(db_is_simple());
|
||||||
|
|
||||||
return ((SimpleDatabase *)db)->GetLastModified();
|
return ((SimpleDatabase *)db)->GetLastModified();
|
||||||
}
|
}
|
||||||
|
@ -119,14 +119,18 @@ int stats_print(struct client *client)
|
|||||||
"songs: %i\n"
|
"songs: %i\n"
|
||||||
"uptime: %li\n"
|
"uptime: %li\n"
|
||||||
"playtime: %li\n"
|
"playtime: %li\n"
|
||||||
"db_playtime: %li\n"
|
"db_playtime: %li\n",
|
||||||
"db_update: %li\n",
|
|
||||||
stats.artist_count,
|
stats.artist_count,
|
||||||
stats.album_count,
|
stats.album_count,
|
||||||
stats.song_count,
|
stats.song_count,
|
||||||
(long)g_timer_elapsed(stats.timer, NULL),
|
(long)g_timer_elapsed(stats.timer, NULL),
|
||||||
(long)(pc_get_total_play_time(client->player_control) + 0.5),
|
(long)(pc_get_total_play_time(client->player_control) + 0.5),
|
||||||
stats.song_duration,
|
stats.song_duration);
|
||||||
|
|
||||||
|
if (db_is_simple())
|
||||||
|
client_printf(client,
|
||||||
|
"db_update: %li\n",
|
||||||
(long)db_get_mtime());
|
(long)db_get_mtime());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,19 @@ db_init(const struct config_param *path, GError **error_r);
|
|||||||
void
|
void
|
||||||
db_finish(void);
|
db_finish(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the default #SimpleDatabasePlugin is used. This
|
||||||
|
* allows using db_get_root(), db_save(), db_get_mtime() and
|
||||||
|
* db_exists().
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
db_is_simple(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the root directory object. Returns NULL if there is no
|
* Returns the root directory object. Returns NULL if there is no
|
||||||
* configured music directory.
|
* configured music directory.
|
||||||
|
*
|
||||||
|
* May only be used if db_is_simple() returns true.
|
||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
struct directory *
|
struct directory *
|
||||||
@ -64,18 +74,26 @@ gcc_pure
|
|||||||
struct song *
|
struct song *
|
||||||
db_get_song(const char *file);
|
db_get_song(const char *file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May only be used if db_is_simple() returns true.
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
db_save(GError **error_r);
|
db_save(GError **error_r);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
db_load(GError **error);
|
db_load(GError **error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* May only be used if db_is_simple() returns true.
|
||||||
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
time_t
|
time_t
|
||||||
db_get_mtime(void);
|
db_get_mtime(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if there is a valid database file on the disk.
|
* Returns true if there is a valid database file on the disk.
|
||||||
|
*
|
||||||
|
* May only be used if db_is_simple() returns true.
|
||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static inline bool
|
static inline bool
|
||||||
|
@ -118,7 +118,7 @@ update_enqueue(const char *path, bool _discard)
|
|||||||
{
|
{
|
||||||
assert(g_thread_self() == main_task);
|
assert(g_thread_self() == main_task);
|
||||||
|
|
||||||
if (!mapper_has_music_directory())
|
if (!db_is_simple() || !mapper_has_music_directory())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (progress != UPDATE_PROGRESS_IDLE) {
|
if (progress != UPDATE_PROGRESS_IDLE) {
|
||||||
|
Loading…
Reference in New Issue
Block a user