wasm.timer.api.pas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. {
  2. This file is part of the Free Component Library
  3. Webassembly Timer API - imported functions and structures.
  4. Copyright (c) 2024 by Michael Van Canneyt [email protected]
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit wasm.timer.api;
  12. {$mode ObjFPC}{$H+}
  13. interface
  14. uses
  15. {$IFDEF FPC_DOTTEDUNITS}
  16. System.SysUtils,
  17. {$ELSE}
  18. SysUtils,
  19. {$ENDIF}
  20. wasm.logger.api, wasm.timer.shared;
  21. Type
  22. TWasmTimerTickEvent = Procedure (aTimerID : TWasmTimerID; userdata : pointer; var aContinue : Boolean);
  23. function __wasm_timer_allocate(ainterval : longint; userdata: pointer) : TWasmTimerID; external TimerExportName name TimerFN_allocate;
  24. procedure __wasm_timer_deallocate(timerid: TWasmTimerID); external TimerExportName name TimerFN_Deallocate;
  25. function __wasm_timer_tick(timerid: TWasmTimerID; userdata : pointer) : boolean;
  26. procedure __wasmtimer_log(level : TWasmLogLevel; const Msg : String);
  27. procedure __wasmtimer_log(level : TWasmLogLevel; const Fmt : String; Args : Array of const);
  28. var
  29. OnWasmTimerTick : TWasmTimerTickEvent;
  30. WasmTimerLogEnabled : Boolean;
  31. implementation
  32. function __wasm_timer_tick(timerid: TWasmTimerID; userdata : pointer) : boolean;
  33. begin
  34. Result:=True;
  35. if assigned(OnWasmTimerTick) then
  36. OnWasmTimerTick(timerid,userdata,Result)
  37. else
  38. Result:=False;
  39. end;
  40. procedure __wasmtimer_log(level : TWasmLogLevel; const Msg : String);
  41. begin
  42. if not WasmTimerLogEnabled then
  43. exit;
  44. __wasm_log(level,'timer',msg);
  45. end;
  46. procedure __wasmtimer_log(level : TWasmLogLevel; const Fmt : String; Args : Array of const);
  47. begin
  48. if not WasmTimerLogEnabled then
  49. exit;
  50. __wasm_log(level,'timer',fmt,args);
  51. end;
  52. exports __wasm_timer_tick;
  53. end.