1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
unit DebugScriptServer;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
debugthread,
DebugInOutputProcessor;
type
{ TFpDebugScriptServer }
TFpDebugScriptServer = class(TThread, IFpDebugListener)
private
FDebugThread: TFpDebugThread;
FConnectionIdentifier: integer;
FFileContents: TStringList;
FInOutputProcessor: TJSonInOutputProcessor;
protected
procedure Execute; override;
public
constructor create(ADebugThread: TFpDebugThread; AFileName: string);
function GetOrigin: string;
procedure SendEvent(AnEvent: TFpDebugEvent);
destructor Destroy; override;
end;
implementation
{ TFpDebugScriptServer }
procedure TFpDebugScriptServer.Execute;
var
ACommand: TFpDebugThreadCommand;
i: Integer;
begin
FInOutputProcessor := TJSonInOutputProcessor.create(FConnectionIdentifier, @FDebugThread.SendLogMessage);
try
for i := 0 to FFileContents.Count-1 do
begin
ACommand := FInOutputProcessor.TextToCommand(FFileContents.Strings[i]);
if assigned(ACommand) then
FDebugThread.QueueCommand(ACommand);
if Terminated then
Break;
end;
finally
FInOutputProcessor.Free;
end;
Terminate;
end;
constructor TFpDebugScriptServer.create(ADebugThread: TFpDebugThread; AFileName: string);
begin
inherited Create(false);
FDebugThread:=ADebugThread;
FConnectionIdentifier := FDebugThread.AddListener(self);
FFileContents := TStringList.Create;
FFileContents.LoadFromFile(AFileName);
end;
function TFpDebugScriptServer.GetOrigin: string;
begin
result := 'File input';
end;
procedure TFpDebugScriptServer.SendEvent(AnEvent: TFpDebugEvent);
begin
// Ignore
end;
destructor TFpDebugScriptServer.Destroy;
begin
FFileContents.Free;
inherited Destroy;
end;
end.
|