124 lines
3.8 KiB
C#
124 lines
3.8 KiB
C#
/*
|
|
* ThreadPilot - Advanced Windows Process and Power Plan Manager
|
|
* Copyright (C) 2025 Prime Build
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, version 3 only.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
namespace ThreadPilot.Services.ProcessManagement
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using ThreadPilot.Models;
|
|
|
|
/// <summary>
|
|
/// Unified interface for process management operations.
|
|
/// </summary>
|
|
public interface IProcessManagementService
|
|
{
|
|
/// <summary>
|
|
/// Event fired when a process starts
|
|
/// </summary>
|
|
event EventHandler<ProcessEventArgs>? ProcessStarted;
|
|
|
|
/// <summary>
|
|
/// Event fired when a process stops
|
|
/// </summary>
|
|
event EventHandler<ProcessEventArgs>? ProcessStopped;
|
|
|
|
/// <summary>
|
|
/// Event fired when process monitoring status changes
|
|
/// </summary>
|
|
event EventHandler<MonitoringStatusChangedEventArgs>? MonitoringStatusChanged;
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether gets whether process monitoring is currently active.
|
|
/// </summary>
|
|
bool IsMonitoringActive { get; }
|
|
|
|
/// <summary>
|
|
/// Gets all currently running processes.
|
|
/// </summary>
|
|
Task<IEnumerable<ProcessModel>> GetRunningProcessesAsync();
|
|
|
|
/// <summary>
|
|
/// Gets a specific process by ID.
|
|
/// </summary>
|
|
Task<ProcessModel?> GetProcessByIdAsync(int processId);
|
|
|
|
/// <summary>
|
|
/// Gets processes by executable name.
|
|
/// </summary>
|
|
Task<IEnumerable<ProcessModel>> GetProcessesByNameAsync(string executableName);
|
|
|
|
/// <summary>
|
|
/// Start monitoring for process events.
|
|
/// </summary>
|
|
Task StartMonitoringAsync();
|
|
|
|
/// <summary>
|
|
/// Stop monitoring for process events.
|
|
/// </summary>
|
|
Task StopMonitoringAsync();
|
|
|
|
/// <summary>
|
|
/// Set processor affinity for a process.
|
|
/// </summary>
|
|
Task SetProcessorAffinityAsync(ProcessModel process, long affinityMask);
|
|
|
|
/// <summary>
|
|
/// Set priority for a process.
|
|
/// </summary>
|
|
Task SetProcessPriorityAsync(ProcessModel process, ProcessPriorityClass priority);
|
|
|
|
/// <summary>
|
|
/// Refresh process information.
|
|
/// </summary>
|
|
Task RefreshProcessInfoAsync(ProcessModel process);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event args for process events.
|
|
/// </summary>
|
|
public class ProcessEventArgs : EventArgs
|
|
{
|
|
public ProcessModel Process { get; }
|
|
|
|
public DateTime Timestamp { get; }
|
|
|
|
public ProcessEventArgs(ProcessModel process)
|
|
{
|
|
this.Process = process ?? throw new ArgumentNullException(nameof(process));
|
|
this.Timestamp = DateTime.Now;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event args for monitoring status changes.
|
|
/// </summary>
|
|
public class MonitoringStatusChangedEventArgs : EventArgs
|
|
{
|
|
public bool IsActive { get; }
|
|
|
|
public string? Reason { get; }
|
|
|
|
public MonitoringStatusChangedEventArgs(bool isActive, string? reason = null)
|
|
{
|
|
this.IsActive = isActive;
|
|
this.Reason = reason;
|
|
}
|
|
}
|
|
}
|
|
|