diff options
author | Max Kellermann <max@musicpd.org> | 2017-02-11 22:18:28 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-02-11 23:02:17 +0100 |
commit | 78ca5491e603d2fb257f3e4a4278fb6f63debbbf (patch) | |
tree | 2ea143457f0de04054208aec87fa6ee273b84eba /src | |
parent | 4146475c73ebc1a30194d7a7671cd6858235e45d (diff) |
db/Interface: GetUpdateStamp() returns std::chrono::system_clock::time_point
Diffstat (limited to 'src')
-rw-r--r-- | src/Stats.cxx | 7 | ||||
-rw-r--r-- | src/db/Interface.hxx | 6 | ||||
-rw-r--r-- | src/db/plugins/ProxyDatabasePlugin.cxx | 8 | ||||
-rw-r--r-- | src/db/plugins/simple/SimpleDatabasePlugin.cxx | 6 | ||||
-rw-r--r-- | src/db/plugins/simple/SimpleDatabasePlugin.hxx | 6 | ||||
-rw-r--r-- | src/db/plugins/upnp/UpnpDatabasePlugin.cxx | 4 |
6 files changed, 19 insertions, 18 deletions
diff --git a/src/Stats.cxx b/src/Stats.cxx index f558646e0..43988bbbc 100644 --- a/src/Stats.cxx +++ b/src/Stats.cxx @@ -28,6 +28,7 @@ #include "db/Stats.hxx" #include "system/Clock.hxx" #include "Log.hxx" +#include "util/ChronoUtil.hxx" #include <chrono> @@ -101,10 +102,10 @@ db_stats_print(Response &r, const Database &db) stats.song_count, total_duration_s); - const time_t update_stamp = db.GetUpdateStamp(); - if (update_stamp > 0) + const auto update_stamp = db.GetUpdateStamp(); + if (!IsNegative(update_stamp)) r.Format("db_update: %lu\n", - (unsigned long)update_stamp); + (unsigned long)std::chrono::system_clock::to_time_t(update_stamp)); } #endif diff --git a/src/db/Interface.hxx b/src/db/Interface.hxx index bfdf1590a..a10b1ffbb 100644 --- a/src/db/Interface.hxx +++ b/src/db/Interface.hxx @@ -24,7 +24,7 @@ #include "tag/Type.h" #include "Compiler.h" -#include <time.h> +#include <chrono> struct DatabasePlugin; struct DatabaseStats; @@ -129,10 +129,10 @@ public: /** * Returns the time stamp of the last database update. - * Returns 0 if that is not not known/available. + * Returns a negative value if that is not not known/available. */ gcc_pure - virtual time_t GetUpdateStamp() const = 0; + virtual std::chrono::system_clock::time_point GetUpdateStamp() const = 0; }; #endif diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx index ba3818e76..6c793054a 100644 --- a/src/db/plugins/ProxyDatabasePlugin.cxx +++ b/src/db/plugins/ProxyDatabasePlugin.cxx @@ -89,7 +89,7 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor { struct mpd_connection *connection; /* this is mutable because GetStats() must be "const" */ - mutable time_t update_stamp; + mutable std::chrono::system_clock::time_point update_stamp; /** * The libmpdclient idle mask that was removed from the other @@ -128,7 +128,7 @@ public: unsigned Update(const char *uri_utf8, bool discard) override; - time_t GetUpdateStamp() const override { + std::chrono::system_clock::time_point GetUpdateStamp() const override { return update_stamp; } @@ -347,7 +347,7 @@ ProxyDatabase::Create(EventLoop &loop, DatabaseListener &listener, void ProxyDatabase::Open() { - update_stamp = 0; + update_stamp = std::chrono::system_clock::time_point::min(); try { Connect(); @@ -818,7 +818,7 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection) const if (stats2 == nullptr) ThrowError(connection); - update_stamp = (time_t)mpd_stats_get_db_update_time(stats2); + update_stamp = std::chrono::system_clock::from_time_t(mpd_stats_get_db_update_time(stats2)); DatabaseStats stats; stats.song_count = mpd_stats_get_number_of_songs(stats2); diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index 6395c81bb..2f72b4101 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -157,7 +157,7 @@ SimpleDatabase::Load() FileInfo fi; if (GetFileInfo(path, fi)) - mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime()); + mtime = fi.GetModificationTime(); } void @@ -166,7 +166,7 @@ SimpleDatabase::Open() assert(prefixed_light_song == nullptr); root = Directory::NewRoot(); - mtime = 0; + mtime = std::chrono::system_clock::time_point::min(); #ifndef NDEBUG borrowed_song_count = 0; @@ -358,7 +358,7 @@ SimpleDatabase::Save() FileInfo fi; if (GetFileInfo(path, fi)) - mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime()); + mtime = fi.GetModificationTime(); } void diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.hxx b/src/db/plugins/simple/SimpleDatabasePlugin.hxx index 306e590f4..7acaffd1f 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.hxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.hxx @@ -50,7 +50,7 @@ class SimpleDatabase : public Database { Directory *root; - time_t mtime; + std::chrono::system_clock::time_point mtime; /** * A buffer for GetSong() when prefixing the #LightSong @@ -88,7 +88,7 @@ public: * Returns true if there is a valid database file on the disk. */ bool FileExists() const { - return mtime > 0; + return mtime >= std::chrono::system_clock::time_point(std::chrono::system_clock::duration::zero()); } /** @@ -125,7 +125,7 @@ public: DatabaseStats GetStats(const DatabaseSelection &selection) const override; - time_t GetUpdateStamp() const override { + std::chrono::system_clock::time_point GetUpdateStamp() const override { return mtime; } diff --git a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx index 90b80c8cb..385ad5adf 100644 --- a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx +++ b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx @@ -94,8 +94,8 @@ public: DatabaseStats GetStats(const DatabaseSelection &selection) const override; - time_t GetUpdateStamp() const override { - return 0; + std::chrono::system_clock::time_point GetUpdateStamp() const override { + return std::chrono::system_clock::time_point::min(); } private: |