Files
UnrealEngineUWP/Engine/Source/Developer/DirectoryWatcher/Private/Linux/DirectoryWatchRequestLinux.h
ryan durand 471d972e62 Updating copyright for Engine Developer.
#rnx
#rb none


#ROBOMERGE-SOURCE: CL 10869240 via CL 10869516 via CL 10869902
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870584 by ryan durand in Main branch]
2019-12-26 15:32:37 -05:00

89 lines
2.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "IDirectoryWatcher.h"
#include <sys/inotify.h>
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
class FDirectoryWatchRequestLinux
{
public:
/**
* Template class to support FString to TValueType maps with a case sensitive key
*/
template<typename TValueType>
struct FCaseSensitiveLookupKeyFuncs : BaseKeyFuncs<TValueType, FString>
{
static FORCEINLINE const FString& GetSetKey(const TPair<FString, TValueType>& Element)
{
return Element.Key;
}
static FORCEINLINE bool Matches(const FString& A, const FString& B)
{
return A.Equals(B, ESearchCase::CaseSensitive);
}
static FORCEINLINE uint32 GetKeyHash(const FString& Key)
{
return FCrc::StrCrc32<TCHAR>(*Key);
}
};
FDirectoryWatchRequestLinux();
virtual ~FDirectoryWatchRequestLinux();
/** Sets up the directory handle and request information */
bool Init(const FString& InDirectory, uint32 Flags);
/** Adds a delegate to get fired when the directory changes */
FDelegateHandle AddDelegate( const IDirectoryWatcher::FDirectoryChanged& InDelegate, uint32 Flags );
/** Removes a delegate to get fired when the directory changes */
bool RemoveDelegate( FDelegateHandle InHandle );
/** Returns true if this request has any delegates listening to directory changes */
bool HasDelegates() const;
/** Prepares the request for deletion */
void EndWatchRequest();
/** Triggers all pending file change notifications */
void ProcessPendingNotifications();
private:
/** Adds watches for all files (and subdirectories) in a directory. */
void WatchDirectoryTree(const FString & RootAbsolutePath);
/** Removes all watches from a */
void UnwatchDirectoryTree(const FString & RootAbsolutePath);
FString Directory;
bool bRunning;
bool bEndWatchRequestInvoked;
/** Whether or not watch subtree. */
bool bWatchSubtree;
int FileDescriptor;
/** Mapping from watch descriptors to their path names */
TMap<int32, FString> WatchDescriptorsToPaths;
/** Mapping from paths to watch descriptors */
TMap<FString, int32, FDefaultSetAllocator, FCaseSensitiveLookupKeyFuncs<int32>> PathsToWatchDescriptors;
int NotifyFilter;
/** A delegate with its corresponding IDirectoryWatcher::WatchOptions flags */
typedef TPair<IDirectoryWatcher::FDirectoryChanged, uint32> FWatchDelegate;
TArray<FWatchDelegate> Delegates;
/** Each FFileChangeData tracks whether it is a directory or not */
TArray<TPair<FFileChangeData, bool>> FileChanges;
void Shutdown();
void ProcessChanges();
};