Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
RemoteConfigIni.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Map.h"
7#include "Containers/UnrealString.h"
8#include "CoreTypes.h"
9#include "HAL/CriticalSection.h"
10#include "Misc/DateTime.h"
11#include "Stats/Stats.h"
12#include "Stats/Stats2.h"
13
14class FConfigFile;
15template<typename TTask> class FAsyncTask;
16
17/**
18 * Stores info relating to remote config files
19 */
21{
22 /** Constructors */
24 FRemoteConfigAsyncIOInfo(const TCHAR* InDefaultIniFile);
25
26 /** Assignment operator */
28
29 /** Stores the contents of the remote config file */
31
32 /** Time stamp of the remote config file */
34
35 /** Time at which the last read was initiated */
37
38 /** Time at which the last write was initiated */
40
41 /** If the last read operation failed, this flag will be set to true */
43
44 /** true if this file has been processed */
46
47 /** Name of the corresponding default config file */
48 TCHAR DefaultIniFile[1024];
49};
50
51
52/**
53 * Async task that handles the IO of a remote config file
54 */
56{
57public:
58
59 /** Constructor. */
60 FRemoteConfigAsyncWorker(const TCHAR* InFilename, FRemoteConfigAsyncIOInfo& InIOInfo, FString* InContents, bool bInIsRead);
61
62 /** Performs the actual IO operations. */
63 void DoWork();
64
65 /** Returns true if the read IO operation succeeded. */
66 bool IsReadSuccess() const;
67
68 /** Returns the local IO info object */
70
72 {
73 RETURN_QUICK_DECLARE_CYCLE_STAT(FRemoteConfigAsyncWorker, STATGROUP_ThreadPoolAsyncTasks);
74 }
75
76 /** Indicates to the thread pool that this task is abandonable. */
77 bool CanAbandon();
78
79 /** Abandon routine */
80 void Abandon();
81
82private:
83
84 /** Name of the remote config file. */
85 TCHAR Filename[1024];
86
87 /** Local copy of the IO info object, for thread safety. */
89
90 /** Contents to write out. */
92
93 /** true if read operation, false if write. */
94 bool bIsRead;
95};
96
97
98/**
99 * Info for cached write tasks
100 */
102{
103public:
104 FRemoteConfigAsyncCachedWriteTask(const TCHAR* InFileName, FString* InContents)
105 {
106 Filename = InFileName;
107 Contents = *InContents;
108 }
109
112};
113
114
115/**
116 * Manages async IO tasks for remote config files
117 */
119{
120public:
121
122 /** Returns a reference to the global FRemoteConfigAsyncTaskManager object. */
124
125 /** Handles cached write tasks. */
126 void Tick();
127
128 /** Add an async IO task to the queue and kick it off. */
129 bool StartTask(const TCHAR* InFilename, const TCHAR* RemotePath, FRemoteConfigAsyncIOInfo& InIOInfo, FString* InContents, bool bInIsRead);
130
131 /** Returns true if the task has completed */
132 bool IsFinished(const TCHAR* InFilename);
133
134 /** Returns true if the all tasks in the queue have completed (or, if the queue is empty). */
135 bool AreAllTasksFinished(bool bDoRemoval);
136
137 /** Safely retrieve the read data from the completed async task. */
138 bool GetReadData(const TCHAR* InFilename, FRemoteConfigAsyncIOInfo& OutIOInfo);
139
140private:
141
142 /** Returns true if file exists in the cached task list. */
143 bool FindCachedWriteTask(const TCHAR* InFilename, bool bCompareContents, const TCHAR* InContents);
144
145 /** List of pending async IO operations */
147
148 /** List of cached off write tasks waiting for currently pending tasks to complete. */
150
151 /** Object used for synchronization via a scoped lock. **/
153};
154
155
156/**
157 * Manages remote config files.
158 */
160{
161public:
162
163 /** Constructor */
165
166 /** Returns a reference to the global FRemoteConfig object. */
168
169 /** Returns true if the specified config file has been flagged as being remote. */
170 bool IsRemoteFile(const TCHAR* Filename);
171
172 /** Returns true if the specified file is remote and still needs to be read. */
173 bool ShouldReadRemoteFile(const TCHAR* Filename);
174
175 /** Simple accessor function. */
176 FRemoteConfigAsyncIOInfo* FindConfig(const TCHAR* Filename);
177
178 /** Returns true if the task has completed. */
179 bool IsFinished(const TCHAR* InFilename);
180
181 /** Queues up a new async task for reading a remote config file. */
182 bool Read(const TCHAR* GeneratedIniFile, const TCHAR* DefaultIniFile);
183
184 /** Queues up a new async task for writing a remote config file. */
185 bool Write(const TCHAR* Filename, FString& Contents);
186
187 /** Waits on the async read if it hasn't finished yet... times out if the operation has taken too long. */
188 void FinishRead(const TCHAR* Filename);
189
190 /** Finishes all pending async IO tasks. */
191 static void Flush();
192
193 /* Replaces chars used by the ini parser with "special chars". */
195
196 /* Replaces "special chars" that have been inserted to avoid problems with the ini parser with equivalent regular chars. */
198
199private:
200
201 /** Creates the remote path string for the specified file. */
202 FString GenerateRemotePath(const TCHAR* Filename);
203
204 /** List of remote config file info. */
206
207 /** Async IO operation timeout. */
208 float Timeout;
209
210 /** If true, remote ops are allowed. */
212
213 /** true if the list of desired remote files has been filled out. */
215
216 /** List of desired remote files. */
218};
219
220
221/** Returns true if no remote version of this config file exists and/or isn't being used. */
222bool IsUsingLocalIniFile(const TCHAR* FilenameToLoad, const TCHAR* IniFileName);
223
224/** Contains the logic for processing config files, local or remote. */
225void ProcessIniContents(const TCHAR* FilenameToLoad, const TCHAR* IniFileName, FConfigFile* Config, bool bDoEmptyConfig, bool bDoCombine);
226
227/** Returns the timestamp of the appropriate config file. */
228FDateTime GetIniTimeStamp(const TCHAR* FilenameToLoad, const TCHAR* IniFileName);
229
230/** Before overwriting the local file with the contents from the remote file, we save off a copy of the local file (if it exists). */
231void MakeLocalCopy(const TCHAR* Filename);
#define FORCEINLINE
Definition Platform.h:644
bool IsUsingLocalIniFile(const TCHAR *FilenameToLoad, const TCHAR *IniFileName)
FDateTime GetIniTimeStamp(const TCHAR *FilenameToLoad, const TCHAR *IniFileName)
void ProcessIniContents(const TCHAR *FilenameToLoad, const TCHAR *IniFileName, FConfigFile *Config, bool bDoEmptyConfig, bool bDoCombine)
void MakeLocalCopy(const TCHAR *Filename)
FWindowsCriticalSection FCriticalSection
FRemoteConfigAsyncCachedWriteTask(const TCHAR *InFileName, FString *InContents)
bool FindCachedWriteTask(const TCHAR *InFilename, bool bCompareContents, const TCHAR *InContents)
TArray< FRemoteConfigAsyncCachedWriteTask > CachedWriteTasks
FCriticalSection SynchronizationObject
bool AreAllTasksFinished(bool bDoRemoval)
bool GetReadData(const TCHAR *InFilename, FRemoteConfigAsyncIOInfo &OutIOInfo)
bool StartTask(const TCHAR *InFilename, const TCHAR *RemotePath, FRemoteConfigAsyncIOInfo &InIOInfo, FString *InContents, bool bInIsRead)
static FRemoteConfigAsyncTaskManager * Get()
bool IsFinished(const TCHAR *InFilename)
TMap< FString, FAsyncTask< FRemoteConfigAsyncWorker > * > PendingTasks
FRemoteConfigAsyncIOInfo IOInfo
FORCEINLINE TStatId GetStatId() const
FRemoteConfigAsyncIOInfo & GetIOInfo()
bool IsReadSuccess() const
FRemoteConfigAsyncWorker(const TCHAR *InFilename, FRemoteConfigAsyncIOInfo &InIOInfo, FString *InContents, bool bInIsRead)
static FString ReplaceIniSpecialCharWithChar(const FString &Str)
TMap< FString, FRemoteConfigAsyncIOInfo > ConfigBuffers
bool Read(const TCHAR *GeneratedIniFile, const TCHAR *DefaultIniFile)
bool IsFinished(const TCHAR *InFilename)
bool Write(const TCHAR *Filename, FString &Contents)
bool IsRemoteFile(const TCHAR *Filename)
FRemoteConfigAsyncIOInfo * FindConfig(const TCHAR *Filename)
static FString ReplaceIniCharWithSpecialChar(const FString &Str)
void FinishRead(const TCHAR *Filename)
TArray< FString > CachedFileNames
static void Flush()
bool ShouldReadRemoteFile(const TCHAR *Filename)
static FRemoteConfig * Get()
FString GenerateRemotePath(const TCHAR *Filename)
FRemoteConfigAsyncIOInfo(const TCHAR *InDefaultIniFile)
FRemoteConfigAsyncIOInfo & operator=(const FRemoteConfigAsyncIOInfo &Other)