// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Diagnostics; using EpicGames.UBA.Impl; namespace EpicGames.UBA { /// /// Information needed to create a process /// public struct ProcessStartInfo { /// /// Common configs for processes to run /// public enum CommonProcessConfigs { /// /// MSVC based compiler /// CompileMsvc, /// /// Clang based compiler /// CompileClang, } /// /// The path to the application binary /// public string Application { get; set; } /// /// The working directory /// public string WorkingDirectory { get; set; } /// /// The command line arguments /// public string Arguments { get; set; } /// /// A text description of the process /// public string Description { get; set; } /// /// Which configuration to use /// public CommonProcessConfigs Configuration { get; set; } /// /// The process priority of the created process /// public ProcessPriorityClass Priority { get; set; } /// /// If input should be tracked /// public bool TrackInputs { get; set; } /// /// A path to a log file, or null for not log file /// public string? LogFile { get; set; } /// /// Arbitary user data to pass along with the process /// public object? UserData { get; set; } /// /// RootsHandle for process used to convert paths /// public ulong RootsHandle { get; set; } } /// /// Base interface for process start info /// internal interface IProcessStartInfo : IBaseInterface { /// /// Create a IProcessStartInfo object /// /// The start info for the process /// Set to true if exit callback is used /// The IProcessStartInfo public static IProcessStartInfo CreateProcessStartInfo(ProcessStartInfo info, bool useExitedCallback) { return new ProcessStartInfoImpl(info, useExitedCallback); } } /// /// Event args for exited event /// /// The process to pull data from public class ExitedEventArgs(IProcess process) : EventArgs { /// /// Process exit code /// public int ExitCode { get; } = process.ExitCode; /// /// The remote host that ran the process, if run remotely /// public string? ExecutingHost { get; } = process.ExecutingHost; /// /// Captured output lines /// public List LogLines { get; } = process.LogLines; /// /// Total time spent for the processor /// public TimeSpan TotalProcessorTime { get; } = process.TotalProcessorTime; /// /// Total wall time spent /// public TimeSpan TotalWallTime { get; } = process.TotalWallTime; /// /// Total wall time spent /// public object? UserData { get; } = process.UserData; } /// /// Interface for a process instance /// public interface IProcess : IBaseInterface { /// /// Delegate for Exited events /// /// The sender object /// The event args public delegate void ExitedEventHandler(object sender, ExitedEventArgs e); /// /// Exited event handler /// public abstract event ExitedEventHandler? Exited; /// /// Process exit code /// public abstract int ExitCode { get; } /// /// The remote host that ran the process, if run remotely /// public abstract string? ExecutingHost { get; } /// /// Captured output lines /// public abstract List LogLines { get; } /// /// Total time spent for the processor /// public abstract TimeSpan TotalProcessorTime { get; } /// /// Total wall time spent /// public abstract TimeSpan TotalWallTime { get; } /// /// Unique hash for this process (not stable between runs) /// public abstract ulong Hash { get; } /// /// Arbitary user data /// public abstract object? UserData { get; } /// /// Cancel the running process /// /// If the process should be force terminated public abstract void Cancel(bool terminate); /// /// Create a IProcess object /// /// unmanaged pointer to the process /// the processes start info /// Optional callback when the process exits /// Arbitary user data /// The IProcess internal static IProcess CreateProcess(IntPtr handle, IProcessStartInfo info, ExitedEventHandler? exitedEventHandler, object? userData) { return new ProcessImpl(handle, info, exitedEventHandler, userData); } } }