2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-07-17 13:49:42 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/inotify.h>
|
|
|
|
|
|
|
|
|
|
#define EVENT_SIZE ( sizeof (struct inotify_event) )
|
2015-05-13 11:15:57 -04:00
|
|
|
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
|
2014-07-17 13:49:42 -04:00
|
|
|
|
|
|
|
|
class FDirectoryWatchRequestLinux
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-05-13 11:15:57 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 13:49:42 -04:00
|
|
|
FDirectoryWatchRequestLinux();
|
|
|
|
|
virtual ~FDirectoryWatchRequestLinux();
|
|
|
|
|
|
|
|
|
|
/** Sets up the directory handle and request information */
|
2015-06-25 20:17:42 -04:00
|
|
|
bool Init(const FString& InDirectory, uint32 Flags);
|
2014-07-17 13:49:42 -04:00
|
|
|
|
|
|
|
|
/** Adds a delegate to get fired when the directory changes */
|
2015-01-08 09:29:27 -05:00
|
|
|
FDelegateHandle AddDelegate( const IDirectoryWatcher::FDirectoryChanged& InDelegate );
|
2014-07-17 13:49:42 -04:00
|
|
|
/** Removes a delegate to get fired when the directory changes */
|
2015-01-08 09:29:27 -05:00
|
|
|
bool RemoveDelegate( FDelegateHandle InHandle );
|
2014-07-17 13:49:42 -04:00
|
|
|
/** 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:
|
|
|
|
|
|
2015-05-13 11:15:57 -04:00
|
|
|
/** 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);
|
|
|
|
|
|
2014-08-05 19:12:20 -04:00
|
|
|
FString Directory;
|
|
|
|
|
|
|
|
|
|
bool bRunning;
|
2014-07-17 13:49:42 -04:00
|
|
|
bool bEndWatchRequestInvoked;
|
|
|
|
|
|
2015-05-13 11:15:57 -04:00
|
|
|
/** Whether to report directory creation/deletion changes. */
|
|
|
|
|
bool bIncludeDirectoryChanges;
|
|
|
|
|
|
2015-06-25 20:17:42 -04:00
|
|
|
/** Whether or not watch subtree. */
|
|
|
|
|
bool bWatchSubtree;
|
|
|
|
|
|
2014-08-05 19:12:20 -04:00
|
|
|
int FileDescriptor;
|
2015-05-13 11:15:57 -04:00
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
|
|
2014-08-05 19:12:20 -04:00
|
|
|
int NotifyFilter;
|
2014-07-17 13:49:42 -04:00
|
|
|
|
|
|
|
|
TArray<IDirectoryWatcher::FDirectoryChanged> Delegates;
|
|
|
|
|
TArray<FFileChangeData> FileChanges;
|
|
|
|
|
|
2014-08-05 19:12:20 -04:00
|
|
|
void Shutdown();
|
|
|
|
|
void ProcessChanges();
|
2014-07-17 13:49:42 -04:00
|
|
|
};
|