* Conditional logging

This commit is contained in:
Michael Van Canneyt 2025-01-30 14:56:26 +01:00
parent 22746ebdc3
commit 755e5ffc1e

View File

@ -4,6 +4,7 @@ unit wasiworkerthreadhost;
{$mode ObjFPC} {$mode ObjFPC}
{$modeswitch externalclass} {$modeswitch externalclass}
{ $define NOLOGAPICALLS}
interface interface
@ -453,12 +454,16 @@ procedure TWorkerThreadSupport.RunWasmModule(aCommand : TWorkerRunCommand);
begin begin
if (FState=wsNeutral) then if (FState=wsNeutral) then
begin begin
Writeln('No webassembly loaded'); {$IFNDEF NOLOGAPICALLS}
DoLog('No webassembly loaded');
{$ENDIF}
exit; // Todo: send error back exit; // Todo: send error back
end; end;
if (FState in [wsRunning,wsRunWaiting]) then if (FState in [wsRunning,wsRunWaiting]) then
begin begin
Writeln('Webassembly already running'); {$IFNDEF NOLOGAPICALLS}
DoLog('Webassembly already running');
{$ENDIF}
exit; // Todo: send error back exit; // Todo: send error back
end; end;
// Writeln('Entering TWorkerThreadSupport.RunWasmModule '+TJSJSON.Stringify(aCommand)); // Writeln('Entering TWorkerThreadSupport.RunWasmModule '+TJSJSON.Stringify(aCommand));
@ -763,9 +768,15 @@ Var
aData : TWorkerCommand; aData : TWorkerCommand;
begin begin
{$IFNDEF NOLOGAPICALLS}
DoLog(etDebug,'Message received in worker');
{$ENDIF}
if IsObject(aMessageEvent.Data) and TJSObject(aMessageEvent.Data).hasOwnProperty('Command') then if IsObject(aMessageEvent.Data) and TJSObject(aMessageEvent.Data).hasOwnProperty('Command') then
begin begin
aData:=TWorkerCommand(aMessageEvent.Data); aData:=TWorkerCommand(aMessageEvent.Data);
{$IFNDEF NOLOGAPICALLS}
DoLog(etDebug,'Command Message received in worker: '+TJSJSON.Stringify(aData));
{$ENDIF}
if not HandleCustomCommand(aData) then if not HandleCustomCommand(aData) then
FThreadSupport.HandleCommand(aData); FThreadSupport.HandleCommand(aData);
end end
@ -899,9 +910,11 @@ var
aData: TWorkerCommand; aData: TWorkerCommand;
begin begin
Writeln('Thread Message received');
if IsObject(aMessageEvent.Data) and TJSObject(aMessageEvent.Data).hasOwnProperty('Command') then if IsObject(aMessageEvent.Data) and TJSObject(aMessageEvent.Data).hasOwnProperty('Command') then
begin begin
aData:=TWorkerCommand(aMessageEvent.Data); aData:=TWorkerCommand(aMessageEvent.Data);
Writeln('Command message received: '+TJSJSON.Stringify(aData));
case aData.Command of case aData.Command of
cmdExecute : HandleExecuteCommand(TWorkerExecuteCommand(aData)); cmdExecute : HandleExecuteCommand(TWorkerExecuteCommand(aData));
cmdRpc : HandleRPCCommand(TWorkerRpcCommand(aData)); cmdRpc : HandleRPCCommand(TWorkerRpcCommand(aData));