Files
UnrealEngineUWP/Engine/Source/Developer/TargetDeviceServices/Private/TargetDeviceProxyManager.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

142 lines
3.7 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "TargetDeviceServicesPrivatePCH.h"
/* FTargetDeviceProxyManager structors
*****************************************************************************/
FTargetDeviceProxyManager::FTargetDeviceProxyManager()
{
MessageEndpoint = FMessageEndpoint::Builder("FTargetDeviceProxyManager")
.Handling<FTargetDeviceServicePong>(this, &FTargetDeviceProxyManager::HandlePongMessage);
if (MessageEndpoint.IsValid())
{
TickDelegate = FTickerDelegate::CreateRaw(this, &FTargetDeviceProxyManager::HandleTicker);
TickDelegateHandle = FTicker::GetCoreTicker().AddTicker(TickDelegate, TARGET_DEVICE_SERVICES_PING_INTERVAL);
SendPing();
}
}
FTargetDeviceProxyManager::~FTargetDeviceProxyManager()
{
FTicker::GetCoreTicker().RemoveTicker(TickDelegateHandle);
}
/* ITargetDeviceProxyLocator interface
*****************************************************************************/
ITargetDeviceProxyPtr FTargetDeviceProxyManager::FindProxy(const FString& Name)
{
return Proxies.FindRef(Name);
}
ITargetDeviceProxyRef FTargetDeviceProxyManager::FindOrAddProxy(const FString& Name)
{
TSharedPtr<FTargetDeviceProxy>& Proxy = Proxies.FindOrAdd(Name);
if (!Proxy.IsValid())
{
Proxy = MakeShareable(new FTargetDeviceProxy(Name));
ProxyAddedDelegate.Broadcast(Proxy.ToSharedRef());
}
return Proxy.ToSharedRef();
}
ITargetDeviceProxyPtr FTargetDeviceProxyManager::FindProxyDeviceForTargetDevice(const FString& DeviceId)
{
for (TMap<FString, TSharedPtr<FTargetDeviceProxy> >::TConstIterator ItProxies(Proxies); ItProxies; ++ItProxies)
{
const TSharedPtr<FTargetDeviceProxy>& Proxy = ItProxies.Value();
if (Proxy->HasDeviceId(DeviceId))
{
return Proxy;
}
}
return ITargetDeviceProxyPtr();
}
void FTargetDeviceProxyManager::GetProxies(FName TargetPlatformName, bool IncludeUnshared, TArray<ITargetDeviceProxyPtr>& OutProxies)
{
OutProxies.Reset();
for (TMap<FString, TSharedPtr<FTargetDeviceProxy> >::TConstIterator It(Proxies); It; ++It)
{
const TSharedPtr<FTargetDeviceProxy>& Proxy = It.Value();
if ((IncludeUnshared || Proxy->IsShared()) || (Proxy->GetHostUser() == FPlatformProcess::UserName(true)))
{
if (TargetPlatformName == NAME_None || Proxy->HasTargetPlatform(TargetPlatformName))
{
OutProxies.Add(Proxy);
}
}
}
}
/* FTargetDeviceProxyManager implementation
*****************************************************************************/
void FTargetDeviceProxyManager::RemoveDeadProxies()
{
FDateTime CurrentTime = FDateTime::UtcNow();
for (auto ProxyIter = Proxies.CreateIterator(); ProxyIter; ++ProxyIter)
{
if (ProxyIter.Value()->GetLastUpdateTime() + FTimespan::FromSeconds(3.0 * TARGET_DEVICE_SERVICES_PING_INTERVAL) < CurrentTime)
{
ITargetDeviceProxyPtr RemovedProxy = ProxyIter.Value();
ProxyIter.RemoveCurrent();
ProxyRemovedDelegate.Broadcast(RemovedProxy.ToSharedRef());
}
}
}
void FTargetDeviceProxyManager::SendPing()
{
if (MessageEndpoint.IsValid())
{
MessageEndpoint->Publish(new FTargetDeviceServicePing(FPlatformProcess::UserName(true)), EMessageScope::Network);
}
}
/* FTargetDeviceProxyManager callbacks
*****************************************************************************/
void FTargetDeviceProxyManager::HandlePongMessage(const FTargetDeviceServicePong& Message, const IMessageContextRef& Context)
{
TSharedPtr<FTargetDeviceProxy>& Proxy = Proxies.FindOrAdd(Message.Name);
if (!Proxy.IsValid())
{
Proxy = MakeShareable(new FTargetDeviceProxy(Message.Name, Message, Context));
ProxyAddedDelegate.Broadcast(Proxy.ToSharedRef());
}
else
{
Proxy->UpdateFromMessage(Message, Context);
}
}
bool FTargetDeviceProxyManager::HandleTicker(float DeltaTime)
{
RemoveDeadProxies();
SendPing();
return true;
}