// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #include #include #include ZEN_THIRD_PARTY_INCLUDES_START #include ZEN_THIRD_PARTY_INCLUDES_END #include #include #include namespace zen { class SessionLogStore; class SessionLog; /** Session tracker * * Acts as a log and session info concentrator when dealing with multiple * servers and external processes acting as a group. */ class SessionsService { public: struct SessionInfo { Oid Id; std::string AppName; Oid JobId; CbObject Metadata; DateTime CreatedAt; DateTime UpdatedAt; }; class Session : public TRefCounted { public: Session(const SessionInfo& Info); ~Session(); Session(Session&&) = delete; Session& operator=(Session&&) = delete; const SessionInfo& Info() const { return m_Info; } void UpdateMetadata(CbObjectView Metadata) { // Should this be additive rather than replacing the whole thing? We'll see. m_Info.Metadata = CbObject::Clone(Metadata); m_Info.UpdatedAt = DateTime::Now(); } private: SessionInfo m_Info; Ref m_Log; }; SessionsService(); ~SessionsService(); bool RegisterSession(const Oid& SessionId, std::string AppName, const Oid& JobId, CbObjectView Metadata); bool UpdateSession(const Oid& SessionId, CbObjectView Metadata); Ref GetSession(const Oid& SessionId) const; std::vector> GetSessions() const; bool RemoveSession(const Oid& SessionId); uint64_t GetSessionCount() const; private: LoggerRef& Log() { return m_Log; } LoggerRef m_Log; mutable RwLock m_Lock; tsl::robin_map, Oid::Hasher> m_Sessions; std::unique_ptr m_SessionLogs; }; } // namespace zen