// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "resourcemetrics.h" #include #include #include namespace zen { /** * Storage Server Instance * * This class manages the lifecycle of a storage server instance, and * provides functions to query its state. There should be one instance * per module ID. */ class StorageServerInstance { public: StorageServerInstance(ZenServerEnvironment& RunEnvironment, std::string_view ModuleId, std::filesystem::path FileHydrationPath, std::filesystem::path HydrationTempPath); ~StorageServerInstance(); void Provision(); void Deprovision(); void Hibernate(); void Wake(); const ResourceMetrics& GetResourceMetrics() const { return m_ResourceMetrics; } inline std::string_view GetModuleId() const { return m_ModuleId; } inline bool IsProvisioned() const { return m_IsProvisioned.load(); } inline uint16_t GetBasePort() const { return m_ServerInstance.GetBasePort(); } #if ZEN_PLATFORM_WINDOWS void SetJobObject(JobObject* InJobObject) { m_JobObject = InJobObject; } #endif private: void WakeLocked(); RwLock m_Lock; std::string m_ModuleId; std::atomic m_IsProvisioned{false}; std::atomic m_IsHibernated{false}; ZenServerInstance m_ServerInstance; std::filesystem::path m_BaseDir; std::filesystem::path m_TempDir; std::filesystem::path m_HydrationPath; ResourceMetrics m_ResourceMetrics; #if ZEN_PLATFORM_WINDOWS JobObject* m_JobObject = nullptr; #endif void SpawnServerProcess(); void Hydrate(); void Dehydrate(); }; } // namespace zen