httphost.lpr 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {
  2. This file is part of the Free Component Library
  3. Webassembly HTTP API - demo host program
  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. program httphost;
  12. {$mode objfpc}
  13. {$modeswitch externalclass}
  14. uses
  15. BrowserConsole, JS, Classes, SysUtils, Web, WasiEnv, WasiHostApp,
  16. wasm.pas2js.httpapi;
  17. Type
  18. THostConfig = class external name 'Object' (TJSObject)
  19. wasmFilename : String;
  20. logHTTPAPI : Boolean;
  21. logWasiAPI : Boolean;
  22. end;
  23. var
  24. HostConfig : THostConfig; external name 'hostConfig';
  25. Type
  26. { THTTPHostApplication }
  27. THTTPHostApplication = class(TBrowserWASIHostApplication)
  28. Private
  29. FHTTPAPI : TWasmHTTPAPI;
  30. Public
  31. constructor Create(aOwner : TComponent); override;
  32. procedure DoRun; override;
  33. end;
  34. constructor THTTPHostApplication.Create(aOwner: TComponent);
  35. begin
  36. inherited Create(aOwner);
  37. FHTTPAPI:=TWasmHTTPAPI.Create(WasiEnvironment);
  38. RunEntryFunction:='_initialize';
  39. if isDefined(hostConfig) and Assigned(hostConfig) then
  40. begin
  41. WasiEnvironment.LogAPI:=HostConfig.logWasiAPi;
  42. FHTTPAPI.LogAPICalls:=HostConfig.logHTTPAPI;
  43. end;
  44. end;
  45. procedure THTTPHostApplication.DoRun;
  46. var
  47. wasm : String;
  48. begin
  49. Terminate;
  50. if Assigned(HostConfig) and isString(HostConfig.wasmFilename) then
  51. Wasm:=HostConfig.wasmFilename
  52. else
  53. begin
  54. Wasm:=ParamStr(1);
  55. if Wasm='' then
  56. Wasm:='wasmhttpdemo.wasm';
  57. end;
  58. StartWebAssembly(Wasm, true);
  59. end;
  60. var
  61. Application : THTTPHostApplication;
  62. begin
  63. Application:=THTTPHostApplication.Create(nil);
  64. Application.Initialize;
  65. Application.Run;
  66. end.