// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "vfsservice.h" #include "projectstore/projectstore.h" #include #include #if ZEN_WITH_VFS # include # include namespace zen { struct VfsOplogDataSource : public VfsTreeDataSource { VfsOplogDataSource(std::string_view ProjectId, std::string_view OplogId, Ref InProjectStore); virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override; private: std::string m_ProjectId; std::string m_OplogId; Ref m_ProjectStore; }; struct VfsCacheDataSource : public VfsTreeDataSource { VfsCacheDataSource(std::string_view NamespaceId, std::string_view BucketId, Ref InCacheStore); ~VfsCacheDataSource(); virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override; private: std::string m_NamespaceId; std::string m_BucketId; Ref m_CacheStore; }; struct VfsServiceDataSource : public VfsTreeDataSource { VfsServiceDataSource(VfsService::Impl* VfsImpl) : m_VfsImpl(VfsImpl) {} virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override; private: VfsService::Impl* m_VfsImpl = nullptr; RwLock m_Lock; std::unordered_map> m_OplogSourceMap; std::unordered_map> m_CacheSourceMap; Ref GetOplogDataSource(std::string_view ProjectId, std::string_view OplogId); Ref GetCacheDataSource(std::string_view NamespaceId, std::string_view BucketId); }; ////////////////////////////////////////////////////////////////////////// struct VfsService::Impl { Impl(); ~Impl(); void Mount(std::string_view MountPoint); void Unmount(); void AddService(Ref&&); void AddService(Ref&&); inline std::string GetMountpointPath() { return m_MountpointPath; } inline bool IsVfsRunning() const { return !!m_VfsHost.get(); } private: Ref m_ProjectStore; Ref m_ZenCacheStore; Ref m_VfsDataSource; std::string m_MountpointPath; std::unique_ptr m_VfsHost; std::thread m_VfsThread; Event m_VfsThreadRunning; std::exception_ptr m_VfsThreadException; void RefreshVfs(); void VfsThread(); friend struct VfsServiceDataSource; }; } // namespace zen #endif