db/Interface: GetUpdateStamp() returns std::chrono::system_clock::time_point
This commit is contained in:
parent
4146475c73
commit
78ca5491e6
@ -28,6 +28,7 @@
|
|||||||
#include "db/Stats.hxx"
|
#include "db/Stats.hxx"
|
||||||
#include "system/Clock.hxx"
|
#include "system/Clock.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
#include "util/ChronoUtil.hxx"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
@ -101,10 +102,10 @@ db_stats_print(Response &r, const Database &db)
|
|||||||
stats.song_count,
|
stats.song_count,
|
||||||
total_duration_s);
|
total_duration_s);
|
||||||
|
|
||||||
const time_t update_stamp = db.GetUpdateStamp();
|
const auto update_stamp = db.GetUpdateStamp();
|
||||||
if (update_stamp > 0)
|
if (!IsNegative(update_stamp))
|
||||||
r.Format("db_update: %lu\n",
|
r.Format("db_update: %lu\n",
|
||||||
(unsigned long)update_stamp);
|
(unsigned long)std::chrono::system_clock::to_time_t(update_stamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "tag/Type.h"
|
#include "tag/Type.h"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <chrono>
|
||||||
|
|
||||||
struct DatabasePlugin;
|
struct DatabasePlugin;
|
||||||
struct DatabaseStats;
|
struct DatabaseStats;
|
||||||
@ -129,10 +129,10 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the time stamp of the last database update.
|
* 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
|
gcc_pure
|
||||||
virtual time_t GetUpdateStamp() const = 0;
|
virtual std::chrono::system_clock::time_point GetUpdateStamp() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,7 +89,7 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
|
|||||||
struct mpd_connection *connection;
|
struct mpd_connection *connection;
|
||||||
|
|
||||||
/* this is mutable because GetStats() must be "const" */
|
/* 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
|
* The libmpdclient idle mask that was removed from the other
|
||||||
@ -128,7 +128,7 @@ public:
|
|||||||
|
|
||||||
unsigned Update(const char *uri_utf8, bool discard) override;
|
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;
|
return update_stamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ ProxyDatabase::Create(EventLoop &loop, DatabaseListener &listener,
|
|||||||
void
|
void
|
||||||
ProxyDatabase::Open()
|
ProxyDatabase::Open()
|
||||||
{
|
{
|
||||||
update_stamp = 0;
|
update_stamp = std::chrono::system_clock::time_point::min();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connect();
|
Connect();
|
||||||
@ -818,7 +818,7 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection) const
|
|||||||
if (stats2 == nullptr)
|
if (stats2 == nullptr)
|
||||||
ThrowError(connection);
|
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;
|
DatabaseStats stats;
|
||||||
stats.song_count = mpd_stats_get_number_of_songs(stats2);
|
stats.song_count = mpd_stats_get_number_of_songs(stats2);
|
||||||
|
@ -157,7 +157,7 @@ SimpleDatabase::Load()
|
|||||||
|
|
||||||
FileInfo fi;
|
FileInfo fi;
|
||||||
if (GetFileInfo(path, fi))
|
if (GetFileInfo(path, fi))
|
||||||
mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
|
mtime = fi.GetModificationTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -166,7 +166,7 @@ SimpleDatabase::Open()
|
|||||||
assert(prefixed_light_song == nullptr);
|
assert(prefixed_light_song == nullptr);
|
||||||
|
|
||||||
root = Directory::NewRoot();
|
root = Directory::NewRoot();
|
||||||
mtime = 0;
|
mtime = std::chrono::system_clock::time_point::min();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
borrowed_song_count = 0;
|
borrowed_song_count = 0;
|
||||||
@ -358,7 +358,7 @@ SimpleDatabase::Save()
|
|||||||
|
|
||||||
FileInfo fi;
|
FileInfo fi;
|
||||||
if (GetFileInfo(path, fi))
|
if (GetFileInfo(path, fi))
|
||||||
mtime = std::chrono::system_clock::to_time_t(fi.GetModificationTime());
|
mtime = fi.GetModificationTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -50,7 +50,7 @@ class SimpleDatabase : public Database {
|
|||||||
|
|
||||||
Directory *root;
|
Directory *root;
|
||||||
|
|
||||||
time_t mtime;
|
std::chrono::system_clock::time_point mtime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A buffer for GetSong() when prefixing the #LightSong
|
* 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.
|
* Returns true if there is a valid database file on the disk.
|
||||||
*/
|
*/
|
||||||
bool FileExists() const {
|
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;
|
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
||||||
|
|
||||||
time_t GetUpdateStamp() const override {
|
std::chrono::system_clock::time_point GetUpdateStamp() const override {
|
||||||
return mtime;
|
return mtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +94,8 @@ public:
|
|||||||
|
|
||||||
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
|
||||||
|
|
||||||
time_t GetUpdateStamp() const override {
|
std::chrono::system_clock::time_point GetUpdateStamp() const override {
|
||||||
return 0;
|
return std::chrono::system_clock::time_point::min();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user