Commit c064e8d6 authored by Max Kellermann's avatar Max Kellermann

DatabasePlugin: add method GetUpdateStamp()

Refactor SimpleDatabase::GetLastModified() to be generic for all plugins. Remove the SimpleDatabase assumption from db_stats_print(), allowing it to be implemented by all database plugins.
parent 099a2cb5
......@@ -148,12 +148,12 @@ DatabaseGlobalOpen(Error &error)
return true;
}
time_t
db_get_mtime(void)
bool
db_exists()
{
assert(db != nullptr);
assert(db_is_open);
assert(db_is_simple());
return ((SimpleDatabase *)db)->GetLastModified();
return ((SimpleDatabase *)db)->GetUpdateStamp() > 0;
}
......@@ -30,6 +30,8 @@
#include "tag/TagType.h"
#include "Compiler.h"
#include <time.h>
struct config_param;
struct DatabaseSelection;
struct db_visitor;
......@@ -132,6 +134,13 @@ public:
virtual bool GetStats(const DatabaseSelection &selection,
DatabaseStats &stats,
Error &error) const = 0;
/**
* Returns the time stamp of the last database update.
* Returns 0 if that is not not known/available.
*/
gcc_pure
virtual time_t GetUpdateStamp() const = 0;
};
struct DatabasePlugin {
......
......@@ -63,24 +63,12 @@ bool
db_save(Error &error);
/**
* May only be used if db_is_simple() returns true.
*/
gcc_pure
time_t
db_get_mtime(void);
/**
* Returns true if there is a valid database file on the disk.
*
* May only be used if db_is_simple() returns true.
*/
gcc_pure
static inline bool
db_exists(void)
{
/* mtime is set only if the database file was loaded or saved
successfully */
return db_get_mtime() > 0;
}
bool
db_exists();
#endif
......@@ -83,10 +83,11 @@ db_stats_print(Client &client)
stats.song_count,
stats.total_duration);
if (db_is_simple())
const time_t update_stamp = GetDatabase()->GetUpdateStamp();
if (update_stamp > 0)
client_printf(client,
"db_update: %lu\n",
(unsigned long)db_get_mtime());
(unsigned long)update_stamp);
}
void
......
......@@ -71,6 +71,11 @@ public:
DatabaseStats &stats,
Error &error) const override;
virtual time_t GetUpdateStamp() const override {
// TODO: implement
return 0;
}
private:
bool Configure(const config_param &param, Error &error);
......
......@@ -26,8 +26,6 @@
#include <cassert>
#include <time.h>
struct Directory;
class SimpleDatabase : public Database {
......@@ -55,11 +53,6 @@ public:
bool Save(Error &error);
gcc_pure
time_t GetLastModified() const {
return mtime;
}
static Database *Create(const config_param &param,
Error &error);
......@@ -85,6 +78,10 @@ public:
DatabaseStats &stats,
Error &error) const override;
virtual time_t GetUpdateStamp() const override {
return mtime;
}
protected:
bool Configure(const config_param &param, Error &error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment