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) ...@@ -148,12 +148,12 @@ DatabaseGlobalOpen(Error &error)
return true; return true;
} }
time_t bool
db_get_mtime(void) db_exists()
{ {
assert(db != nullptr); assert(db != nullptr);
assert(db_is_open); assert(db_is_open);
assert(db_is_simple()); assert(db_is_simple());
return ((SimpleDatabase *)db)->GetLastModified(); return ((SimpleDatabase *)db)->GetUpdateStamp() > 0;
} }
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "tag/TagType.h" #include "tag/TagType.h"
#include "Compiler.h" #include "Compiler.h"
#include <time.h>
struct config_param; struct config_param;
struct DatabaseSelection; struct DatabaseSelection;
struct db_visitor; struct db_visitor;
...@@ -132,6 +134,13 @@ public: ...@@ -132,6 +134,13 @@ public:
virtual bool GetStats(const DatabaseSelection &selection, virtual bool GetStats(const DatabaseSelection &selection,
DatabaseStats &stats, DatabaseStats &stats,
Error &error) const = 0; 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 { struct DatabasePlugin {
......
...@@ -63,24 +63,12 @@ bool ...@@ -63,24 +63,12 @@ bool
db_save(Error &error); 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. * Returns true if there is a valid database file on the disk.
* *
* May only be used if db_is_simple() returns true. * May only be used if db_is_simple() returns true.
*/ */
gcc_pure gcc_pure
static inline bool bool
db_exists(void) db_exists();
{
/* mtime is set only if the database file was loaded or saved
successfully */
return db_get_mtime() > 0;
}
#endif #endif
...@@ -83,10 +83,11 @@ db_stats_print(Client &client) ...@@ -83,10 +83,11 @@ db_stats_print(Client &client)
stats.song_count, stats.song_count,
stats.total_duration); stats.total_duration);
if (db_is_simple()) const time_t update_stamp = GetDatabase()->GetUpdateStamp();
if (update_stamp > 0)
client_printf(client, client_printf(client,
"db_update: %lu\n", "db_update: %lu\n",
(unsigned long)db_get_mtime()); (unsigned long)update_stamp);
} }
void void
......
...@@ -71,6 +71,11 @@ public: ...@@ -71,6 +71,11 @@ public:
DatabaseStats &stats, DatabaseStats &stats,
Error &error) const override; Error &error) const override;
virtual time_t GetUpdateStamp() const override {
// TODO: implement
return 0;
}
private: private:
bool Configure(const config_param &param, Error &error); bool Configure(const config_param &param, Error &error);
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
#include <cassert> #include <cassert>
#include <time.h>
struct Directory; struct Directory;
class SimpleDatabase : public Database { class SimpleDatabase : public Database {
...@@ -55,11 +53,6 @@ public: ...@@ -55,11 +53,6 @@ public:
bool Save(Error &error); bool Save(Error &error);
gcc_pure
time_t GetLastModified() const {
return mtime;
}
static Database *Create(const config_param &param, static Database *Create(const config_param &param,
Error &error); Error &error);
...@@ -85,6 +78,10 @@ public: ...@@ -85,6 +78,10 @@ public:
DatabaseStats &stats, DatabaseStats &stats,
Error &error) const override; Error &error) const override;
virtual time_t GetUpdateStamp() const override {
return mtime;
}
protected: protected:
bool Configure(const config_param &param, Error &error); 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