From 6a977edeee287e354cd8cc013271c3ba40e13b4a Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 6 Feb 2019 10:41:33 +0100 Subject: [PATCH] Vfs: Remove VfsDefaults That just complicated things. It's ok if Vfs is not a fully abstract interface class. The pinstate-in-db methods are instead provided directly on Vfs and VfsSuffix and VfsOff use them to implement pin states. The start() method is simply non-virtual and calls into startImpl() for the plugin-specific startup code. --- src/common/vfs.cpp | 14 +++----- src/common/vfs.h | 52 +++++++++++++++------------ src/libsync/vfs/suffix/vfs_suffix.cpp | 2 +- src/libsync/vfs/suffix/vfs_suffix.h | 10 +++++- 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/common/vfs.cpp b/src/common/vfs.cpp index e9d4ca081..a40b396a7 100644 --- a/src/common/vfs.cpp +++ b/src/common/vfs.cpp @@ -60,17 +60,13 @@ Optional Vfs::modeFromString(const QString &str) return {}; } -VfsDefaults::VfsDefaults(QObject *parent) - : Vfs(parent) -{ -} - -void VfsDefaults::start(const VfsSetupParams ¶ms) +void Vfs::start(const VfsSetupParams ¶ms) { _setupParams = params; + startImpl(params); } -bool VfsDefaults::setPinState(const QString &folderPath, PinState state) +bool Vfs::setPinStateInDb(const QString &folderPath, PinState state) { auto path = folderPath.toUtf8(); _setupParams.journal->internalPinStates().wipeForPathAndBelow(path); @@ -78,13 +74,13 @@ bool VfsDefaults::setPinState(const QString &folderPath, PinState state) return true; } -Optional VfsDefaults::pinState(const QString &folderPath) +Optional Vfs::pinStateInDb(const QString &folderPath) { return _setupParams.journal->internalPinStates().effectiveForPath(folderPath.toUtf8()); } VfsOff::VfsOff(QObject *parent) - : VfsDefaults(parent) + : Vfs(parent) { } diff --git a/src/common/vfs.h b/src/common/vfs.h index fe4945b5b..e4017639e 100644 --- a/src/common/vfs.h +++ b/src/common/vfs.h @@ -108,17 +108,15 @@ public: /// For WithSuffix modes: the suffix (including the dot) virtual QString fileSuffix() const = 0; + /// Access to the parameters the instance was start()ed with. + const VfsSetupParams ¶ms() const { return _setupParams; } + /** Initializes interaction with the VFS provider. * - * For example, the VFS provider might monitor files to be able to start a file - * hydration (download of a file's remote contents) when the user wants to open - * it. - * - * Usually some registration needs to be done with the backend. This function - * should take care of it if necessary. + * The plugin-specific work is done in startImpl(). */ - virtual void start(const VfsSetupParams ¶ms) = 0; + void start(const VfsSetupParams ¶ms); /// Stop interaction with VFS provider. Like when the client application quits. virtual void stop() = 0; @@ -221,29 +219,29 @@ signals: void beginHydrating(); /// Emitted when the hydration ends void doneHydrating(); -}; -class OCSYNC_EXPORT VfsDefaults : public Vfs -{ -public: - explicit VfsDefaults(QObject* parent = nullptr); - - // stores the params - void start(const VfsSetupParams ¶ms) override; - - // use the journal to back the pinstates - bool setPinState(const QString &folderPath, PinState state) override; - Optional pinState(const QString &folderPath) override; +protected: + /** Setup the plugin for the folder. + * + * For example, the VFS provider might monitor files to be able to start a file + * hydration (download of a file's remote contents) when the user wants to open + * it. + * + * Usually some registration needs to be done with the backend. This function + * should take care of it if necessary. + */ + virtual void startImpl(const VfsSetupParams ¶ms) = 0; - // access initial setup data - const VfsSetupParams ¶ms() const { return _setupParams; } + // Db-backed pin state handling. Derived classes may use it to implement pin states. + bool setPinStateInDb(const QString &folderPath, PinState state); + Optional pinStateInDb(const QString &folderPath); -protected: + // the parameters passed to start() VfsSetupParams _setupParams; }; /// Implementation of Vfs for Vfs::Off mode - does nothing -class OCSYNC_EXPORT VfsOff : public VfsDefaults +class OCSYNC_EXPORT VfsOff : public Vfs { Q_OBJECT @@ -269,8 +267,16 @@ public: bool isDehydratedPlaceholder(const QString &) override { return false; } bool statTypeVirtualFile(csync_file_stat_t *, void *) override { return false; } + bool setPinState(const QString &folderPath, PinState state) override + { return setPinStateInDb(folderPath, state); } + Optional pinState(const QString &folderPath) override + { return pinStateInDb(folderPath); } + public slots: void fileStatusChanged(const QString &, SyncFileStatus) override {} + +protected: + void startImpl(const VfsSetupParams &) override {} }; /// Check whether the plugin for the mode is available. diff --git a/src/libsync/vfs/suffix/vfs_suffix.cpp b/src/libsync/vfs/suffix/vfs_suffix.cpp index f489aa407..ca5da6d25 100644 --- a/src/libsync/vfs/suffix/vfs_suffix.cpp +++ b/src/libsync/vfs/suffix/vfs_suffix.cpp @@ -22,7 +22,7 @@ namespace OCC { VfsSuffix::VfsSuffix(QObject *parent) - : VfsDefaults(parent) + : Vfs(parent) { } diff --git a/src/libsync/vfs/suffix/vfs_suffix.h b/src/libsync/vfs/suffix/vfs_suffix.h index 4abf3920a..45aad10b4 100644 --- a/src/libsync/vfs/suffix/vfs_suffix.h +++ b/src/libsync/vfs/suffix/vfs_suffix.h @@ -21,7 +21,7 @@ namespace OCC { -class VfsSuffix : public VfsDefaults +class VfsSuffix : public Vfs { Q_OBJECT @@ -47,8 +47,16 @@ public: bool isDehydratedPlaceholder(const QString &filePath) override; bool statTypeVirtualFile(csync_file_stat_t *stat, void *stat_data) override; + bool setPinState(const QString &folderPath, PinState state) override + { return setPinStateInDb(folderPath, state); } + Optional pinState(const QString &folderPath) override + { return pinStateInDb(folderPath); } + public slots: void fileStatusChanged(const QString &, SyncFileStatus) override {} + +protected: + void startImpl(const VfsSetupParams &) override {} }; class SuffixVfsPluginFactory : public QObject, public DefaultPluginFactory -- 2.30.2