2020-10-21 17:56:05 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# pragma once
2021-04-30 08:14:54 -04:00
# include "Compression/CompressedBuffer.h"
# include "HAL/CriticalSection.h"
2020-10-21 17:56:05 -04:00
# include "Logging/LogMacros.h"
2021-07-22 09:55:49 -04:00
# include "Templates/UniquePtr.h"
2021-04-30 08:14:54 -04:00
# include "Virtualization/PayloadId.h"
2020-10-21 17:56:05 -04:00
2021-10-25 20:05:28 -04:00
# include "Virtualization/VirtualizationSystem.h"
2021-04-30 08:14:54 -04:00
/**
* Configuring the backend hierarchy
*
* The [ Core . ContentVirtualization ] section can contain a string ' BackendGraph ' which will set with the name of
* the backend graph , if not set then the default ' ContentVirtualizationBackendGraph_None ' will be used instead .
* This value can also be overridden from the command line by using ' BackendGraph = FooBar ' where FooBar is the
* name of the graph .
*
* The first entry in the graph to be parsed will be the ' Hierarchy ' which describes which backends should be
* mounted and in which order . For example ' Hierarchy = ( Entry = Foo , Entry = Bar ) ' which should mount two backends
* ' Foo ' and ' Bar ' in that order .
*
* Each referenced backend in the hierarchy will then require it ' s own entry in the graph where the key will be
* it ' s name in the hierarchy and the value a string describing how to set it up .
* The value must contain ' Type = X ' where X is the name used to find the correct IVirtualizationBackendFactory
* to create the backend with .
* Once the backend is created then reset of the string will be passed to it , so that additional customization
* can be extracted . Depending on the backend implementation these values may or may not be required .
*
* Example graph :
* [ ContentVirtualizationBackendGraph_Example ]
* Hierarchy = ( Entry = MemoryCache , Entry = NetworkShare )
* MemoryCache = ( Type = InMemory )
* NetworkShare = ( Type = FileSystem , Path = " \\ path \t o \ somewhere " )
*
* The graph is named ' ContentVirtualizationBackendGraph_Example ' .
* The hierarchy contains two entries ' InMemory ' and ' NetworkShare ' to be mounted in that order
* MemoryCache creates a backend of type ' InMemory ' and has no additional customization
* NetworkShare creates a backend of type ' FileSystem ' and provides an additional path , the filesystem backend would
* fatal error without this value .
*/
2021-11-07 23:43:01 -05:00
/**
* Filtering
*
* When pushing a payload it can be filtered based on the path of the package it belongs to . The filtering options
* are set up via the config files .
* Note that this only affects pushing a payload , if the filtering for a project is changed to exclude a package that
* is already virtualized it will still be able to pull it ' s payloads as needed but will store them locally in the
* package the next time that it is saved .
* @ see ShouldVirtualizePackage for implementation details .
*
* Basic Setup :
*
* [ Core . ContentVirtualization ]
* FilterEngineContent = True / False When true any payload from a package under Engine / Content / . . will be excluded from virtualization
* FilterEnginePluginContent = True / False When true any payload from a package under Engine / Plugins / . . / Content / . . will be excluded from virtualization
*
* PackagePath Setup :
*
* The path given can either be to a directory or a specific package . It can be added to the config files for
* a GameFeature ( commonly used to exclude all content in that game feature from being virtualized ) in addition
* to the project ' s config files .
* Note that these paths will be stored in the ini files under the Saved directory . To remove a path make sure to
* use the - syntax to remove the entry from the array , rather than removing the line itself . Otherwise it will
* persist until the saved config file has been reset .
*
* [ / Script / Virtualization . VirtualizationFilterSettings ]
* + ExcludePackagePaths = " /MountPoint/PathToExclude/ " Excludes any package found under ' / MountPoint / PathToExclude / '
* + ExcludePackagePaths = " /MountPoint/PathTo/ThePackageToExclude " Excludes the specific package ' / MountPoint / PathTo / ThePackageToExclude '
*/
2021-04-30 08:14:54 -04:00
namespace UE : : Virtualization
{
class IVirtualizationBackend ;
class IVirtualizationBackendFactory ;
2020-10-21 17:56:05 -04:00
/** This is used as a wrapper around the various potential back end implementations.
The calling code shouldn ' t need to care about which back ends are actually in use . */
2021-12-02 04:41:46 -05:00
class FVirtualizationManager final : public IVirtualizationSystem
2020-10-21 17:56:05 -04:00
{
public :
2021-07-22 09:55:49 -04:00
using FRegistedFactories = TMap < FName , IVirtualizationBackendFactory * > ;
using FBackendArray = TArray < IVirtualizationBackend * > ;
2020-10-21 17:56:05 -04:00
FVirtualizationManager ( ) ;
2021-10-25 20:05:28 -04:00
virtual ~ FVirtualizationManager ( ) ;
2020-10-21 17:56:05 -04:00
2021-12-02 04:41:46 -05:00
private :
/* IVirtualizationSystem implementation */
2021-10-25 20:05:28 -04:00
virtual bool IsEnabled ( ) const override ;
2021-07-22 09:55:49 -04:00
2021-12-08 02:19:42 -05:00
virtual bool PushData ( const FPayloadId & Id , const FCompressedBuffer & Payload , EStorageType StorageType , const FString & Context ) override ;
virtual bool PushData ( TArrayView < FPushRequest > Requests , EStorageType StorageType ) override ;
2020-10-21 17:56:05 -04:00
2021-10-25 20:05:28 -04:00
virtual FCompressedBuffer PullData ( const FPayloadId & Id ) override ;
2020-10-21 17:56:05 -04:00
2021-12-01 11:13:31 -05:00
virtual bool DoPayloadsExist ( TArrayView < const FPayloadId > Ids , EStorageType StorageType , TArray < FPayloadStatus > & OutStatuses ) override ;
2021-11-18 14:37:34 -05:00
virtual FPayloadActivityInfo GetAccumualtedPayloadActivityInfo ( ) const override ;
2021-06-03 04:35:17 -04:00
2021-11-18 14:37:34 -05:00
virtual void GetPayloadActivityInfo ( GetPayloadActivityInfoFuncRef ) const override ;
2021-11-23 15:05:13 -05:00
virtual FOnNotification & GetNotificationEvent ( ) override
{
return NotificationEvent ;
}
2021-11-18 14:37:34 -05:00
2020-10-21 17:56:05 -04:00
private :
2021-12-02 04:41:46 -05:00
2021-04-30 08:14:54 -04:00
void ApplySettingsFromConfigFiles ( const FConfigFile & PlatformEngineIni ) ;
void ApplySettingsFromCmdline ( ) ;
2021-11-18 14:37:34 -05:00
2021-04-30 08:14:54 -04:00
void ApplyDebugSettingsFromConfigFiles ( const FConfigFile & PlatformEngineIni ) ;
2021-11-18 14:37:34 -05:00
void ApplyDebugSettingsFromFromCmdline ( ) ;
2021-04-30 08:14:54 -04:00
void MountBackends ( ) ;
2021-07-22 09:55:49 -04:00
void ParseHierarchy ( const TCHAR * GraphName , const TCHAR * HierarchyKey , const FRegistedFactories & FactoryLookupTable , FBackendArray & PushArray ) ;
bool CreateBackend ( const TCHAR * GraphName , const FString & ConfigEntryName , const FRegistedFactories & FactoryLookupTable , FBackendArray & PushArray ) ;
2021-04-30 08:14:54 -04:00
2021-07-22 09:55:49 -04:00
void AddBackend ( TUniquePtr < IVirtualizationBackend > Backend , FBackendArray & PushArray ) ;
2020-10-21 17:56:05 -04:00
2021-07-22 09:55:49 -04:00
void CachePayload ( const FPayloadId & Id , const FCompressedBuffer & Payload , const IVirtualizationBackend * BackendSource ) ;
2021-09-01 07:03:59 -04:00
bool TryCacheDataToBackend ( IVirtualizationBackend & Backend , const FPayloadId & Id , const FCompressedBuffer & Payload ) ;
2021-12-08 02:19:42 -05:00
bool TryPushDataToBackend ( IVirtualizationBackend & Backend , TArrayView < FPushRequest > Requests ) ;
2021-07-22 09:55:49 -04:00
FCompressedBuffer PullDataFromBackend ( IVirtualizationBackend & Backend , const FPayloadId & Id ) ;
2021-06-03 04:35:17 -04:00
2021-11-07 23:43:01 -05:00
/**
* Determines if a package should be virtualized or not based on it ' s package path and the current
* filtering set up for the project .
*
* @ param PackagePath The path of the package to check . This can be empty which would indicate that
* a payload is not owned by a specific package .
* @ return True if the package should be virtualized and false if the package path is
* excluded by the projects current filter set up .
*/
bool ShouldVirtualizePackage ( const FPackagePath & PackagePath ) const ;
2020-10-21 17:56:05 -04:00
/** Are payloads allowed to be virtualized. Defaults to true. */
bool bEnablePayloadPushing ;
2021-08-04 03:25:25 -04:00
/** Should payloads be cached locally after being pulled from persistent storage? Defaults to true. */
bool bEnableCacheAfterPull ;
2020-10-21 17:56:05 -04:00
/** The minimum length for a payload to be considered for virtualization. Defaults to 0 bytes. */
int64 MinPayloadLength ;
2021-04-30 08:14:54 -04:00
/** The name of the backend graph to load from the config ini file that will describe the backend hierarchy */
FString BackendGraphName ;
2021-11-07 23:43:01 -05:00
/** Should payloads in engine content packages before filtered out and never virtualized */
bool bFilterEngineContent ;
/** Should payloads in engine plugin content packages before filtered out and never virtualized */
bool bFilterEnginePluginContent ;
2021-04-30 08:14:54 -04:00
/** Debugging option: When enabled all public operations will be performed as single threaded. This is intended to aid debugging and not for production use.*/
bool bForceSingleThreaded ;
/**
* Debugging option : When enabled we will immediately ' pull ' each payload after it has been ' pushed ' and compare it to the original payload source to make
* sure that it can be pulled correctly .
* This is intended to aid debugging and not for production use .
*/
bool bValidateAfterPushOperation ;
2021-11-18 14:37:34 -05:00
/** Array of backend names that should have their pull operation disabled */
TArray < FString > BackendsToDisablePulls ;
2021-04-30 08:14:54 -04:00
/** The critical section used to force single threaded access if bForceSingleThreaded is true */
FCriticalSection ForceSingleThreadedCS ;
2021-07-22 09:55:49 -04:00
/** All of the backends that were mounted during graph creation */
TArray < TUniquePtr < IVirtualizationBackend > > AllBackends ;
2021-04-30 08:14:54 -04:00
2021-07-22 09:55:49 -04:00
/** Backends used for caching operations (must support push operations). */
FBackendArray LocalCachableBackends ;
2021-04-30 08:14:54 -04:00
2021-07-22 09:55:49 -04:00
/** Backends used for persistent storage operations (must support push operations). */
FBackendArray PersistentStorageBackends ;
/**
* The hierarchy of backends to pull from , this is assumed to be ordered from fastest to slowest
* and can contain a mixture of local cacheable and persistent backends
*/
FBackendArray PullEnabledBackends ;
2021-11-23 15:05:13 -05:00
/** Our notification Event */
FOnNotification NotificationEvent ;
2020-10-21 17:56:05 -04:00
} ;
2021-04-30 08:14:54 -04:00
} // namespace UE::Virtualization