// 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); /// Begin new flow /// /// /// Fully cleans the device by deleting /// - Artifacts and other loose files associated with UE processes /// - Staged/Packaged builds /// void FullClean(); /// /// Deletes artifacts and other loose files associated with UE processes /// void CleanArtifacts(UnrealAppConfig AppConfiguration = null); /// /// Local cache path /// string LocalCachePath { get; } /// /// Installs a build to the device /// /// The configuration containing the build to install void InstallBuild(UnrealAppConfig AppConfiguration); /// /// Create an IAppInstall that is configured by the provided AppConfiguration /// /// The configuration used to create the IAppInstall /// An AppInstall handle which can be used to run the process IAppInstall CreateAppInstall(UnrealAppConfig AppConfiguration); /// /// Copies any additional files to the device /// /// The collection of files to copy void CopyAdditionalFiles(IEnumerable FilesToCopy); // End new flow // }; /// /// 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; } /// /// If platform supports host mounting of files or other platform specific /// functionality, this interface provides a way to provide that information /// without needing an instance of the device. /// public interface IPlatformTargetSupport { /// /// If host mounting is supported, return the equivalent /// host mounted path for given platform. /// /// Input path /// string GetHostMountedPath(string Path); /// /// Returns true if host mounting is supported on given /// platform. /// /// bool IsHostMountingSupported(); /// /// The target platform /// UnrealTargetPlatform? Platform { get; } } /// /// Default abstract implementation of IPlatformTargetSupport /// so that target platforms can override only parts they need /// public abstract class TargetPlatformSupportBase : IPlatformTargetSupport { public virtual string GetHostMountedPath(string Path) => Path; public virtual bool IsHostMountingSupported() => false; public virtual UnrealTargetPlatform? Platform => throw new NotImplementedException(); } }