2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-02-05 18:09:08 -05:00
# pragma once
# include "Interfaces/IBackgroundHttpManager.h"
# include "Interfaces/IBackgroundHttpResponse.h"
2020-09-01 14:07:48 -04:00
# include "BackgroundHttpFileHashHelper.h"
2019-02-05 18:09:08 -05:00
# include "Containers/Ticker.h"
DECLARE_LOG_CATEGORY_EXTERN ( LogBackgroundHttpManager , Log , All )
2020-09-01 14:07:48 -04:00
class FBackgroundHttpFileHashHelper ;
2019-02-05 18:09:08 -05:00
/**
* Contains implementation of some common functions that don ' t vary between implementation
*/
2021-06-22 00:27:54 -04:00
class BACKGROUNDHTTP_API FBackgroundHttpManagerImpl
2019-02-05 18:09:08 -05:00
: public IBackgroundHttpManager
2021-08-16 11:09:22 -04:00
, public FTSTickerObjectBase
2019-02-05 18:09:08 -05:00
{
public :
FBackgroundHttpManagerImpl ( ) ;
virtual ~ FBackgroundHttpManagerImpl ( ) ;
virtual void AddRequest ( const FBackgroundHttpRequestPtr Request ) override ;
virtual void RemoveRequest ( const FBackgroundHttpRequestPtr Request ) override ;
virtual void Initialize ( ) override ;
virtual void Shutdown ( ) override ;
2020-09-01 14:07:48 -04:00
virtual void DeleteAllTemporaryFiles ( ) override ;
2019-08-21 09:37:24 -04:00
virtual int GetMaxActiveDownloads ( ) const override ;
virtual void SetMaxActiveDownloads ( int MaxActiveDownloads ) override ;
2020-09-01 14:07:48 -04:00
virtual FString GetTempFileLocationForURL ( const FString & URL ) override ;
virtual void CleanUpDataAfterCompletingRequest ( const FBackgroundHttpRequestPtr Request ) override ;
2021-08-16 11:09:22 -04:00
//FTSTickerObjectBase implementation
2019-02-05 18:09:08 -05:00
virtual bool Tick ( float DeltaTime ) override ;
2020-09-01 14:07:48 -04:00
2019-02-05 18:09:08 -05:00
protected :
virtual bool AssociateWithAnyExistingRequest ( const FBackgroundHttpRequestPtr Request ) override ;
virtual bool CheckForExistingCompletedDownload ( const FBackgroundHttpRequestPtr Request , FString & ExistingFilePathOut , int64 & ExistingFileSizeOut ) ;
virtual void ActivatePendingRequests ( ) ;
2020-09-01 14:07:48 -04:00
2021-10-12 21:21:22 -04:00
//Different from DeleteAllTemporaryFiles as this doesn't delete all files but rather cleans up specific bad files that have gone stale
2020-09-01 14:07:48 -04:00
virtual void DeleteStaleTempFiles ( ) ;
//Gets a list of full filenames for all temp files.
virtual void GatherAllTempFilenames ( TArray < FString > & OutAllTempFilenames , bool bOutputAsFullPaths = false ) const ;
//Helper function that converts the supplied list of Temp folder filenames to a list that is always all full paths.
virtual void ConvertAllTempFilenamesToFullPaths ( TArray < FString > & OutFilenamesAsFullPaths , const TArray < FString > & FilenamesToConvertToFullPaths ) const ;
//Gather a list of any temp files that have timed out of our BackgroundHTTP settings.
//SecondsToConsiderOld should be a double representing how many seconds old a temp file needs to be to be returned by this function
//If OptionalFileListToCheck is empty will check all temp files in the backgroundhttp temp file folder. If supplied only the given file paths are checked
virtual void GatherTempFilesOlderThen ( TArray < FString > & OutTimedOutTempFilenames , double SecondsToConsiderOld , TArray < FString > * OptionalFileList = nullptr ) const ;
//Gather a list of any temp files that have no corresponding URL Mapping entry
//If OptionalFileListToCheck is empty will check all temp files in the backgroundhttp temp file folder. If supplied only the given file paths are checked
virtual void GatherTempFilesWithoutURLMappings ( TArray < FString > & OutTempFilesMissingURLMappings , TArray < FString > * OptionalFileList = nullptr ) const ;
//Gets our FileHashHelper to compute temp file mappings
virtual BackgroundHttpFileHashHelperRef GetFileHashHelper ( ) { return FileHashHelper ; }
virtual const BackgroundHttpFileHashHelperRef GetFileHashHelper ( ) const { return FileHashHelper ; }
2019-02-05 18:09:08 -05:00
protected :
/** List of Background Http requests that we have called AddRequest on, but have not yet started due to platform active download limits **/
TArray < FBackgroundHttpRequestPtr > PendingStartRequests ;
FRWLock PendingRequestLock ;
/** List of Background Http requests that are actively being processed **/
TArray < FBackgroundHttpRequestPtr > ActiveRequests ;
FRWLock ActiveRequestLock ;
/** Count of how many requests we have active **/
volatile int NumCurrentlyActiveRequests ;
2019-08-21 09:37:24 -04:00
TAtomic < int > MaxActiveDownloads ;
2020-09-01 14:07:48 -04:00
private :
BackgroundHttpFileHashHelperRef FileHashHelper ;
2019-02-05 18:09:08 -05:00
} ;