// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using AutomationTool;
using UnrealBuildTool;
using System.Threading;
using System.Text.RegularExpressions;
namespace Gauntlet
{
///
/// Base class for a device that is able to run applications
///
public interface ITargetDevice : IDisposable
{
///
/// Name of this device
///
string Name { get; }
///
/// Platform of this device
///
UnrealTargetPlatform? Platform { get; }
///
/// Options used when running processes
///
CommandUtils.ERunOptions RunOptions { get; set; }
///
/// Is the device available for use?
/// Note: If we are the process holding a connection then this should still return true
///
bool IsAvailable { get; }
///
/// Are we connected to this device?
///
bool IsConnected { get; }
///
/// Connect and reserve the device
///
///
bool Connect();
///
/// Disconnect the device.
///
/// If supported force the device into a disconnected state (e.g. kick other users)
///
bool Disconnect(bool bForce=false);
///
/// Is the device powered on?
/// TODO - Do we need to have a way of expressing whether power changes are supported
///
bool IsOn { get; }
///
/// Request the device power on. Should block until the change succeeds (or fails)
///
///
bool PowerOn();
///
/// Request the device power on. Should block until the change succeeds (or fails)
///
///
bool PowerOff();
///
/// Request the device power on. Should block until the change succeeds (or fails)
///
///
bool Reboot();
///
/// Returns a Dictionary of EIntendedBaseCopyDirectory keys and their corresponding file path string values.
/// If a platform has not set up these mappings, returns an empty Dictionary and warns.
///
///
Dictionary GetPlatformDirectoryMappings();
IAppInstall InstallApplication(UnrealAppConfig AppConfiguration);
IAppInstance Run(IAppInstall App);
string GetPackagedExecutableLocation() { return null; }
};
///
/// Interface used by TargetDevice* classes to track spawned application running state.
///
public interface IRunningStateOptions
{
///
/// Whether or not to sleep after launching an app before querying for its running state.
///
bool WaitForRunningState { get; set; }
///
/// The number of seconds to sleep after launching an app before querying for its running state.
///
int SecondsToRunningState { get; set; }
///
/// Interval of time between app running state queries, in seconds.
///
int CachedStateRefresh { get; set; }
}
///
/// Represents a class able to provide devices
///
public interface IDeviceSource
{
bool CanSupportPlatform(UnrealTargetPlatform? Platform);
}
///
/// Represents a class that provides locally available devices
///
public interface IDefaultDeviceSource : IDeviceSource
{
ITargetDevice[] GetDefaultDevices();
}
///
/// Represents a class capable of creating devices of a specific type
///
public interface IDeviceFactory : IDeviceSource
{
ITargetDevice CreateDevice(string InRef, string InLocalCache, string InParam=null);
}
///
/// Represents a class that provides services for available devices
///
public interface IDeviceService : IDeviceSource
{
void CleanupDevices();
}
///
/// Represents a class that can provides virtual local devices
///
public interface IVirtualLocalDevice : IDeviceSource
{
bool CanRunVirtualFromPlatform(UnrealTargetPlatform? Platfrom);
UnrealTargetPlatform? GetPlatform();
}
///
/// Represents a class that tell what build the device support
///
public interface IDeviceBuildSupport : IDeviceSource
{
bool CanSupportBuildType(BuildFlags Flag);
UnrealTargetPlatform? GetPlatform();
bool NeedBuildDeployed();
}
public abstract class BaseBuildSupport : IDeviceBuildSupport
{
protected virtual BuildFlags SupportedBuildTypes => BuildFlags.None;
protected virtual UnrealTargetPlatform? Platform => null;
public bool CanSupportBuildType(BuildFlags Flag)
{
return (SupportedBuildTypes & Flag) == Flag;
}
public bool CanSupportPlatform(UnrealTargetPlatform? InPlatform)
{
return Platform == InPlatform;
}
public UnrealTargetPlatform? GetPlatform()
{
return Platform;
}
public virtual bool NeedBuildDeployed() => true;
}
}