Files
UnrealEngineUWP/Engine/Source/Developer/DirectoryWatcher/Private/Mac/DirectoryWatcherMac.cpp
Steve Robb 0756ef15b9 Delegate comparisons deprecated, lots of other associated code deprecated, and lots of warning fixups:
* Multicast delegate Add* calls now return FDelegateHandles, and Remove* calls are now all deprecated, except for a new Remove function which takes a FDelegateHandle.
* New FConsoleManager::RegisterConsoleVariableSink_Handle and UnregisterConsoleVariableSink_Handle functions which work in terms of FConsoleVariableSinkHandle.
* Timer calls which don't take FTimerHandles are deprecated.
* FTicker::AddTicker now returns an FDelegateHandle and is removed by an overloaded Remove function.
* DEFINE_ONLINE_DELEGATE* macros now define _Handle variants of the Add/Remove functions which return/take handles.
* Various other handle-based registration changes.
* Some unity build fixes.
* Some simplification of delegate code.
* Fixes for lots of existing code to use handle-based registration and unregistration.

#codereview robert.manuszewski

[CL 2400883 by Steve Robb in Main branch]
2015-01-08 09:29:27 -05:00

187 lines
4.5 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "DirectoryWatcherPrivatePCH.h"
FDirectoryWatcherMac::FDirectoryWatcherMac()
{
NumRequests = 0;
}
FDirectoryWatcherMac::~FDirectoryWatcherMac()
{
if ( RequestMap.Num() != 0 )
{
// Delete any remaining requests here. These requests are likely from modules which are still loaded at the time that this module unloads.
for (TMap<FString, FDirectoryWatchRequestMac*>::TConstIterator RequestIt(RequestMap); RequestIt; ++RequestIt)
{
if ( ensure(RequestIt.Value()) )
{
delete RequestIt.Value();
NumRequests--;
}
}
RequestMap.Empty();
}
if ( RequestsPendingDelete.Num() != 0 )
{
for ( int32 RequestIdx = 0; RequestIdx < RequestsPendingDelete.Num(); ++RequestIdx )
{
delete RequestsPendingDelete[RequestIdx];
NumRequests--;
}
}
// Make sure every request that was created is destroyed
ensure(NumRequests == 0);
}
bool FDirectoryWatcherMac::RegisterDirectoryChangedCallback( const FString& Directory, const FDirectoryChanged& InDelegate )
{
FDirectoryWatchRequestMac** RequestPtr = RequestMap.Find(Directory);
FDirectoryWatchRequestMac* Request = NULL;
if ( RequestPtr )
{
// There should be no NULL entries in the map
check (*RequestPtr);
Request = *RequestPtr;
}
else
{
Request = new FDirectoryWatchRequestMac();
NumRequests++;
// Begin reading directory changes
if ( !Request->Init(Directory) )
{
UE_LOG(LogDirectoryWatcher, Warning, TEXT("Failed to begin reading directory changes for %s."), *Directory);
delete Request;
NumRequests--;
return false;
}
RequestMap.Add(Directory, Request);
}
Request->AddDelegate(InDelegate);
return true;
}
bool FDirectoryWatcherMac::UnregisterDirectoryChangedCallback( const FString& Directory, const FDirectoryChanged& InDelegate )
{
FDirectoryWatchRequestMac** RequestPtr = RequestMap.Find(Directory);
if ( RequestPtr )
{
// There should be no NULL entries in the map
check (*RequestPtr);
FDirectoryWatchRequestMac* Request = *RequestPtr;
if ( Request->DEPRECATED_RemoveDelegate(InDelegate) )
{
if ( !Request->HasDelegates() )
{
// Remove from the active map and add to the pending delete list
RequestMap.Remove(Directory);
RequestsPendingDelete.AddUnique(Request);
// Signal to end the watch which will mark this request for deletion
Request->EndWatchRequest();
}
return true;
}
}
return false;
}
bool FDirectoryWatcherMac::RegisterDirectoryChangedCallback_Handle( const FString& Directory, const FDirectoryChanged& InDelegate, FDelegateHandle& OutHandle )
{
FDirectoryWatchRequestMac** RequestPtr = RequestMap.Find(Directory);
FDirectoryWatchRequestMac* Request = NULL;
if ( RequestPtr )
{
// There should be no NULL entries in the map
check (*RequestPtr);
Request = *RequestPtr;
}
else
{
Request = new FDirectoryWatchRequestMac();
NumRequests++;
// Begin reading directory changes
if ( !Request->Init(Directory) )
{
UE_LOG(LogDirectoryWatcher, Warning, TEXT("Failed to begin reading directory changes for %s."), *Directory);
delete Request;
NumRequests--;
return false;
}
RequestMap.Add(Directory, Request);
}
OutHandle = Request->AddDelegate(InDelegate);
return true;
}
bool FDirectoryWatcherMac::UnregisterDirectoryChangedCallback_Handle( const FString& Directory, FDelegateHandle InHandle )
{
FDirectoryWatchRequestMac** RequestPtr = RequestMap.Find(Directory);
if ( RequestPtr )
{
// There should be no NULL entries in the map
check (*RequestPtr);
FDirectoryWatchRequestMac* Request = *RequestPtr;
if ( Request->RemoveDelegate(InHandle) )
{
if ( !Request->HasDelegates() )
{
// Remove from the active map and add to the pending delete list
RequestMap.Remove(Directory);
RequestsPendingDelete.AddUnique(Request);
// Signal to end the watch which will mark this request for deletion
Request->EndWatchRequest();
}
return true;
}
}
return false;
}
void FDirectoryWatcherMac::Tick( float DeltaSeconds )
{
// Delete unregistered requests
for ( int32 RequestIdx = RequestsPendingDelete.Num() - 1; RequestIdx >= 0; --RequestIdx )
{
FDirectoryWatchRequestMac* Request = RequestsPendingDelete[RequestIdx];
delete Request;
NumRequests--;
RequestsPendingDelete.RemoveAt(RequestIdx);
}
// Trigger any file change notification delegates
for (TMap<FString, FDirectoryWatchRequestMac*>::TConstIterator RequestIt(RequestMap); RequestIt; ++RequestIt)
{
RequestIt.Value()->ProcessPendingNotifications();
}
}