Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/wasm-application-runner.ts @ 877:f7e5ee59ba17 am-dev
debug code to monitor large malloc/free (currently disabled)
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 03 Jul 2019 10:16:22 +0200 |
parents | 847fd11384bc |
children | 861c080ef47b |
rev | line source |
---|---|
785
67d0a8da4afe
made typescript more future-proof (not completed, I finally disabled a few warnings in my tsconfig.json)
Alain Mazy <alain@mazy.be>
parents:
722
diff
changeset
|
1 import * as Stone from './stone-framework-loader' |
67d0a8da4afe
made typescript more future-proof (not completed, I finally disabled a few warnings in my tsconfig.json)
Alain Mazy <alain@mazy.be>
parents:
722
diff
changeset
|
2 import * as StoneViewport from './wasm-viewport' |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
508
diff
changeset
|
3 import * as Logger from './logger' |
287 | 4 |
5 if (!('WebAssembly' in window)) { | |
6 alert('Sorry, your browser does not support WebAssembly :('); | |
7 } | |
8 | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
9 //var StoneFrameworkModule : Stone.Framework = (<any>window).StoneFrameworkModule; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
10 //export declare var StoneFrameworkModule : Stone.Framework; |
287 | 11 |
12 // global functions | |
13 var WasmWebService_NotifyError: Function = null; | |
14 var WasmWebService_NotifySuccess: Function = null; | |
435
e641d3978856
WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents:
431
diff
changeset
|
15 var WasmWebService_NotifyCachedSuccess: Function = null; |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
16 var WasmDelayedCallExecutor_ExecuteCallback: Function = null; |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
17 var WasmDoAnimation: Function = null; |
287 | 18 var SetStartupParameter: Function = null; |
19 var CreateWasmApplication: Function = null; | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
20 export var CreateCppViewport: Function = null; |
287 | 21 var ReleaseCppViewport: Function = null; |
22 var StartWasmApplication: Function = null; | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
466
diff
changeset
|
23 export var SendSerializedMessageToStoneApplication: Function = null; |
287 | 24 |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
25 var auxiliaryParameters : Map<string,string> = null; |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
26 |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
27 export function SetApplicationParameters(params : Map<string,string>) { |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
28 if (auxiliaryParameters != null) { |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
29 console.warn("wasm-application-runner.SetApplicationParameters: about to overwrite the existing application parameters!") |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
30 } |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
31 auxiliaryParameters = params; |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
32 } |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
33 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
34 function DoAnimationThread() { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
35 if (WasmDoAnimation != null) { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
36 WasmDoAnimation(); |
287 | 37 } |
38 | |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
39 // Update the viewport content every 100ms if need be |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
40 setTimeout(DoAnimationThread, 100); |
287 | 41 } |
42 | |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
43 |
313 | 44 function GetUriParameters(): Map<string, string> { |
287 | 45 var parameters = window.location.search.substr(1); |
46 | |
47 if (parameters != null && | |
48 parameters != '') { | |
313 | 49 var result = new Map<string, string>(); |
287 | 50 var tokens = parameters.split('&'); |
51 | |
52 for (var i = 0; i < tokens.length; i++) { | |
53 var tmp = tokens[i].split('='); | |
54 if (tmp.length == 2) { | |
55 result[tmp[0]] = decodeURIComponent(tmp[1]); | |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
56 } else if(tmp.length == 1) { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
57 // if there is no '=', we treat ot afterwards as a flag-style param |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
58 result[tmp[0]] = ""; |
287 | 59 } |
60 } | |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
61 return result; |
287 | 62 } |
63 else { | |
313 | 64 return new Map<string, string>(); |
287 | 65 } |
66 } | |
67 | |
68 // function UpdateWebApplication(statusUpdateMessage: string) { | |
69 // console.log(statusUpdateMessage); | |
70 // } | |
71 | |
314 | 72 function _InitializeWasmApplication(orthancBaseUrl: string): void { |
287 | 73 |
74 CreateWasmApplication(); | |
75 | |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
76 // transmit the API-specified parameters to the app before initializing it |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
77 for (let key in auxiliaryParameters) { |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
78 if (auxiliaryParameters.hasOwnProperty(key)) { |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
79 Logger.defaultLogger.debug( |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
80 `About to call SetStartupParameter("${key}","${auxiliaryParameters[key]}")`); |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
81 SetStartupParameter(key, auxiliaryParameters[key]); |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
82 } |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
83 } |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
84 |
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
85 // parse uri and transmit the URI parameters to the app before initializing it |
313 | 86 let parameters = GetUriParameters(); |
287 | 87 |
313 | 88 for (let key in parameters) { |
287 | 89 if (parameters.hasOwnProperty(key)) { |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
90 Logger.defaultLogger.debug( |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
91 `About to call SetStartupParameter("${key}","${parameters[key]}")`); |
287 | 92 SetStartupParameter(key, parameters[key]); |
93 } | |
94 } | |
95 | |
418 | 96 StartWasmApplication(orthancBaseUrl); |
313 | 97 |
418 | 98 // trigger a first resize of the canvas that has just been initialized |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
99 StoneViewport.WasmViewport.ResizeAll(); |
287 | 100 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
101 DoAnimationThread(); |
287 | 102 } |
103 | |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
104 export function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { |
287 | 105 |
106 Stone.Framework.Configure(wasmModuleName); | |
107 | |
108 // Wait for the Orthanc Framework to be initialized (this initializes | |
109 // the WebAssembly environment) and then, create and initialize the Wasm application | |
110 Stone.Framework.Initialize(true, function () { | |
111 | |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
508
diff
changeset
|
112 Logger.defaultLogger.debug("Connecting C++ methods to JS methods"); |
287 | 113 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
114 SetStartupParameter = (<any> window).StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
115 CreateWasmApplication = (<any> window).StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
116 CreateCppViewport = (<any> window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
117 ReleaseCppViewport = (<any> window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
118 StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
119 (<any> window).IsTraceLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsTraceLevelEnabled', 'boolean', null); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
545
diff
changeset
|
120 (<any> window).IsInfoLevelEnabled = (<any> window).StoneFrameworkModule.cwrap('WasmIsInfoLevelEnabled', 'boolean', null); |
287 | 121 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
122 (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
123 (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
124 (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
125 (<any> window).WasmDelayedCallExecutor_ExecuteCallback = (<any> window).StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
126 // no need to put this into the globals for it's only used in this very module |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
127 WasmDoAnimation = (<any> window).StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); |
287 | 128 |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
466
diff
changeset
|
129 SendSerializedMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendSerializedMessageToStoneApplication', 'string', ['string']); |
287 | 130 |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
508
diff
changeset
|
131 Logger.defaultLogger.debug("Connecting C++ methods to JS methods - done"); |
287 | 132 |
314 | 133 _InitializeWasmApplication(orthancBaseUrl); |
287 | 134 }); |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
135 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
136 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
137 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
138 // exports.InitializeWasmApplication = InitializeWasmApplication; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
139 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
140 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
435
diff
changeset
|
141 |