SimulatorFans/Client/source/Simulator.Registry.pas

97 lines
2.1 KiB
ObjectPascal

unit Simulator.Registry;
interface
uses
Vcl.Controls,
System.Generics.Collections;
type
ISimulator = interface
['{732D49D6-2E54-4257-887A-B09D8F2771B1}']
procedure Start;
procedure Stop;
procedure SetUIParent(AParent: TWinControl);
end;
ISimulatorFans = interface
['{23A005ED-907A-4776-A9FB-70D213C7381C}']
function GetFanCount: Integer;
function GetReady: Boolean;
function GetIsRunning: Boolean;
function GetValue(const AFan: Byte): Byte;
function GetMaxValue: Byte;
procedure SetValue(const AFan, AValue: Byte);
procedure SetAll(const AValue: Byte);
procedure SetFull;
property Ready: Boolean read GetReady;
property IsRunning: Boolean read GetIsRunning;
property FanCount: Integer read GetFanCount;
end;
TSimulatorConstructor = reference to function(AFans: ISimulatorFans): ISimulator;
TRegisteredSimulator = class(TObject)
private
FKey: string;
FName: string;
FConstructorFunc: TSimulatorConstructor;
public
constructor Create(const AKey, AName: string; AConstructor: TSimulatorConstructor);
property Key: string read FKey;
property Name: string read FName;
property ConstructorFunc: TSimulatorConstructor read FConstructorFunc;
end;
procedure RegisterSimulator(const AKey, AName: string; AConstructor: TSimulatorConstructor);
function GetRegisteredSimulators: TEnumerable<TRegisteredSimulator>;
implementation
uses
System.SysUtils;
var
SimulatorsList: TObjectList<TRegisteredSimulator>;
procedure RegisterSimulator(const AKey, AName: string; AConstructor: TSimulatorConstructor);
begin
SimulatorsList.Add(TRegisteredSimulator.Create(AKey, AName, AConstructor));
end;
function GetRegisteredSimulators: TEnumerable<TRegisteredSimulator>;
begin
Result := SimulatorsList;
end;
{ TRegisteredSimulator }
constructor TRegisteredSimulator.Create(const AKey, AName: string; AConstructor: TSimulatorConstructor);
begin
inherited Create;
FKey := AKey;
FName := AName;
FConstructorFunc := AConstructor;
end;
initialization
SimulatorsList := TObjectList<TRegisteredSimulator>.Create;
finalization
FreeAndNil(SimulatorsList);
end.