/*
* 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 .
*/
namespace ThreadPilot.Services
{
using System;
using System.Threading.Tasks;
using ThreadPilot.Models;
///
/// Interface for process monitoring service that uses WMI events with fallback polling.
///
public interface IProcessMonitorService : IDisposable
{
///
/// Event fired when a process starts
///
event EventHandler? ProcessStarted;
///
/// Event fired when a process stops
///
event EventHandler? ProcessStopped;
///
/// Event fired when monitoring status changes
///
event EventHandler? MonitoringStatusChanged;
///
/// Gets a value indicating whether gets whether the service is currently monitoring.
///
bool IsMonitoring { get; }
///
/// Gets a value indicating whether gets whether WMI monitoring is available and working.
///
bool IsWmiAvailable { get; }
///
/// Gets a value indicating whether gets whether fallback polling is currently active.
///
bool IsFallbackPollingActive { get; }
///
/// Starts monitoring processes.
///
Task StartMonitoringAsync();
///
/// Stops monitoring processes.
///
Task StopMonitoringAsync();
///
/// Gets all currently running processes.
///
Task> GetRunningProcessesAsync();
///
/// Checks if a specific process is currently running.
///
Task IsProcessRunningAsync(string executableName);
///
/// Updates the service settings (polling intervals, etc.)
///
void UpdateSettings();
}
///
/// Event arguments for process events.
///
public class ProcessEventArgs : EventArgs
{
public ProcessModel Process { get; }
public DateTime Timestamp { get; }
public ProcessEventArgs(ProcessModel process)
{
this.Process = process;
this.Timestamp = DateTime.Now;
}
}
///
/// Event arguments for monitoring status changes.
///
public class MonitoringStatusEventArgs : EventArgs
{
public bool IsMonitoring { get; }
public bool IsWmiAvailable { get; }
public bool IsFallbackPollingActive { get; }
public string? StatusMessage { get; }
public Exception? Error { get; }
public MonitoringStatusEventArgs(bool isMonitoring, bool isWmiAvailable, bool isFallbackPollingActive, string? statusMessage = null, Exception? error = null)
{
this.IsMonitoring = isMonitoring;
this.IsWmiAvailable = isWmiAvailable;
this.IsFallbackPollingActive = isFallbackPollingActive;
this.StatusMessage = statusMessage;
this.Error = error;
}
}
}