Files
UnrealEngineUWP/Engine/Source/Developer/TargetDeviceServices/Private/TargetDeviceProxyManager.cpp
Max Preussner 3aece47882 Docs: Removed file comments and added missing code documentation
Please note that file comments had no purpose in nearly all cases and just added visual clutter. The two files that had meaningful file comments had their comments moved into the corresponding classes. There are still hundreds of file comments left in other files that will be removed over time.

Also cleaned up some random stuff along the way:
- relative paths to public headers within the same module are no longer necessary (automatically discovered by UBT now)
- header guards are deprecated, use #pragma once instead (all compilers support it now)
- space between multiple template brackets is no longer required (all compilers support >> now)
- NULL to nullptr, OVERRIDE to override
- spelling errors, whitespace, line breaks

[CL 2104067 by Max Preussner in Main branch]
2014-06-12 23:22:18 -04:00

127 lines
3.4 KiB
C++

// Copyright 1998-2014 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);
FTicker::GetCoreTicker().AddTicker(TickDelegate, TARGET_DEVICE_SERVICES_PING_INTERVAL);
SendPing();
}
}
FTargetDeviceProxyManager::~FTargetDeviceProxyManager( )
{
FTicker::GetCoreTicker().RemoveTicker(TickDelegate);
}
/* ITargetDeviceProxyLocator interface
*****************************************************************************/
ITargetDeviceProxyPtr FTargetDeviceProxyManager::FindProxy( const FString& DeviceId )
{
return Proxies.FindRef(DeviceId);
}
ITargetDeviceProxyRef FTargetDeviceProxyManager::FindOrAddProxy( const FString& DeviceId )
{
TSharedPtr<FTargetDeviceProxy>& Proxy = Proxies.FindOrAdd(DeviceId);
if (!Proxy.IsValid())
{
Proxy = MakeShareable(new FTargetDeviceProxy(DeviceId));
ProxyAddedDelegate.Broadcast(Proxy.ToSharedRef());
}
return Proxy.ToSharedRef();
}
void FTargetDeviceProxyManager::GetProxies( const FString& PlatformName, 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(false)))
{
if (PlatformName.IsEmpty() || (Proxy->GetPlatformName() == PlatformName))
{
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(false)), EMessageScope::Network);
}
}
/* FTargetDeviceProxyManager event handlers
*****************************************************************************/
void FTargetDeviceProxyManager::HandlePongMessage( const FTargetDeviceServicePong& Message, const IMessageContextRef& Context )
{
TSharedPtr<FTargetDeviceProxy>& Proxy = Proxies.FindOrAdd(Message.DeviceID);
if (!Proxy.IsValid())
{
Proxy = MakeShareable(new FTargetDeviceProxy(Message.DeviceID, Message, Context));
ProxyAddedDelegate.Broadcast(Proxy.ToSharedRef());
}
else
{
Proxy->UpdateFromMessage(Message, Context);
}
}
bool FTargetDeviceProxyManager::HandleTicker( float DeltaTime )
{
RemoveDeadProxies();
SendPing();
return true;
}