Plasma Engine  2.0
Loading...
Searching...
No Matches
FileserveClient.h
1#pragma once
2
3#include <FileservePlugin/FileservePluginDLL.h>
4
5#include <Core/Interfaces/RemoteToolingInterface.h>
6#include <Foundation/Communication/RemoteInterface.h>
7#include <Foundation/Configuration/Singleton.h>
8#include <Foundation/Types/UniquePtr.h>
9#include <Foundation/Types/Uuid.h>
10
11namespace plDataDirectory
12{
13 class FileserveType;
14}
15
28class PL_FILESERVEPLUGIN_DLL plFileserveClient : public plRemoteToolingInterface
29{
30 PL_DECLARE_SINGLETON_OF_INTERFACE(plFileserveClient, plRemoteToolingInterface);
31
32public:
35
37
39 plRemoteInterface* GetRemoteInterface() override { return m_pNetwork.Borrow(); }
40
49 plResult SearchForServerAddress(plTime timeout = plTime::MakeFromSeconds(5));
50
59 plResult WaitForServerInfo(plTime timeout = plTime::MakeFromSeconds(60.0 * 5));
60
62 plResult SaveCurrentConnectionInfoToDisk() const;
63
67 static void DisabledFileserveClient() { s_bEnableFileserve = false; }
68
70 const char* GetServerConnectionAddress() { return m_sServerConnectionAddress; }
71
79 plResult EnsureConnected(plTime timeout = plTime::MakeFromSeconds(-5));
80
83 void UpdateClient();
84
86 void AddServerAddressToTry(plStringView sAddress);
87
88private:
90
92 static bool s_bEnableFileserve;
93
94 struct FileCacheStatus
95 {
96 plInt64 m_TimeStamp = 0;
97 plUInt64 m_FileHash = 0;
98 plTime m_LastCheck;
99 };
100
101 struct DataDir
102 {
103 // plString m_sRootName;
104 // plString m_sPathOnClient;
105 plString m_sMountPoint;
106 bool m_bMounted = false;
107
109 };
110
111 void DeleteFile(plUInt16 uiDataDir, plStringView sFile);
112 plUInt16 MountDataDirectory(plStringView sDataDir, plStringView sRootName);
113 void UnmountDataDirectory(plUInt16 uiDataDir);
114 static void ComputeDataDirMountPoint(plStringView sDataDir, plStringBuilder& out_sMountPoint);
115 void BuildPathInCache(const char* szFile, const char* szMountPoint, plStringBuilder* out_pAbsPath, plStringBuilder* out_pFullPathMeta) const;
116 void GetFullDataDirCachePath(const char* szDataDir, plStringBuilder& out_sFullPath, plStringBuilder& out_sFullPathMeta) const;
117 void NetworkMsgHandler(plRemoteMessage& msg);
118 void HandleFileTransferMsg(plRemoteMessage& msg);
119 void HandleFileTransferFinishedMsg(plRemoteMessage& msg);
120 static void WriteMetaFile(plStringBuilder sCachedMetaFile, plInt64 iFileTimeStamp, plUInt64 uiFileHash);
121 void WriteDownloadToDisk(plStringBuilder sCachedFile);
122 plResult DownloadFile(plUInt16 uiDataDirID, const char* szFile, bool bForceThisDataDir, plStringBuilder* out_pFullPath);
123 void DetermineCacheStatus(plUInt16 uiDataDirID, const char* szFile, FileCacheStatus& out_Status) const;
124 void UploadFile(plUInt16 uiDataDirID, const char* szFile, const plDynamicArray<plUInt8>& fileContent);
125 void InvalidateFileCache(plUInt16 uiDataDirID, plStringView sFile, plUInt64 uiHash);
126 static plResult TryReadFileserveConfig(const char* szFile, plStringBuilder& out_Result);
127 plResult TryConnectWithFileserver(const char* szAddress, plTime timeout) const;
128 void FillFileStatusCache(const char* szFile);
129 void ShutdownConnection();
130 void ClearState();
131
132 mutable plMutex m_Mutex;
133 mutable plString m_sServerConnectionAddress;
134 plString m_sFileserveCacheFolder;
135 plString m_sFileserveCacheMetaFolder;
136 bool m_bDownloading = false;
137 bool m_bFailedToConnect = false;
138 bool m_bWaitingForUploadFinished = false;
139 plUuid m_CurFileRequestGuid;
140 plStringBuilder m_sCurFileRequest;
142 plDynamicArray<plUInt8> m_Download;
143 plTime m_CurrentTime;
144 plHybridArray<plString, 4> m_TryServerAddresses;
145
146 plMap<plString, plUInt16> m_FileDataDir;
147 plHybridArray<DataDir, 8> m_MountedDataDirs;
148};
A data directory type to handle access to files that are served from a network host.
Definition FileserveDataDir.h:31
Definition DynamicArray.h:81
Singleton that represents the client side part of a fileserve connection.
Definition FileserveClient.h:29
static void DisabledFileserveClient()
Allows to disable the file serving functionality. Should be called before mounting data directories.
Definition FileserveClient.h:67
const char * GetServerConnectionAddress()
Returns the address through which the Fileserve client tried to connect with the server last.
Definition FileserveClient.h:70
plRemoteInterface * GetRemoteInterface() override
plRemoteToolingInterface
Definition FileserveClient.h:39
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Map.h:408
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Definition RemoteInterface.h:60
Encapsulates all the data that is transmitted when sending or receiving a message with plRemoteInterf...
Definition RemoteMessage.h:11
Interface to give access to the FileServe client for additional tooling needs.
Definition RemoteToolingInterface.h:10
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE static constexpr plTime MakeFromSeconds(double fSeconds)
Creates an instance of plTime that was initialized from seconds.
Definition Time.h:30