From e9a85aa4e4d0634548b5c97461beb27ae5559338 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 26 Feb 2014 08:39:44 +0100 Subject: db/simple: mount points A SimpleDatabase instance can now "mount" other Database instances at certain locations. This is used to use a new SimpleDatabase instance for each storage mount (issued with the "mount" protocol command). Each such instance has its own database file, stored in the directory that is specified with the "cache_directory" option. --- src/db/plugins/simple/SimpleDatabasePlugin.hxx | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/db/plugins/simple/SimpleDatabasePlugin.hxx') diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.hxx b/src/db/plugins/simple/SimpleDatabasePlugin.hxx index 9836a6bcf..a03969f92 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.hxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.hxx @@ -32,15 +32,27 @@ struct Directory; struct DatabasePlugin; class EventLoop; class DatabaseListener; +class PrefixedLightSong; class SimpleDatabase : public Database { AllocatedPath path; std::string path_utf8; + /** + * The path where cache files for Mount() are located. + */ + AllocatedPath cache_path; + Directory *root; time_t mtime; + /** + * A buffer for GetSong() when prefixing the #LightSong + * instance from a mounted #Database. + */ + mutable PrefixedLightSong *prefixed_light_song; + /** * A buffer for GetSong(). */ @@ -52,6 +64,8 @@ class SimpleDatabase : public Database { SimpleDatabase(); + SimpleDatabase(AllocatedPath &&_path); + public: static Database *Create(EventLoop &loop, DatabaseListener &listener, const config_param ¶m, @@ -73,6 +87,20 @@ public: return mtime > 0; } + /** + * @param db the #Database to be mounted; must be "open"; on + * success, this object gains ownership of the given #Database + */ + gcc_nonnull_all + bool Mount(const char *uri, Database *db, Error &error); + + gcc_nonnull_all + bool Mount(const char *local_uri, const char *storage_uri, + Error &error); + + gcc_nonnull_all + bool Unmount(const char *uri); + /* virtual methods from class Database */ virtual bool Open(Error &error) override; virtual void Close() override; @@ -107,6 +135,8 @@ private: bool Check(Error &error) const; bool Load(Error &error); + + Database *LockUmountSteal(const char *uri); }; extern const DatabasePlugin simple_db_plugin; -- cgit v1.2.3