Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/stone-framework-loader.ts @ 473:628941d63b8c bgo-commands-codegen
Ongoing work. Parsing tests work
author | bgo-osimis |
---|---|
date | Wed, 13 Feb 2019 12:07:00 +0100 |
parents | 5055031f4a06 |
children | 548eed46f535 |
rev | line source |
---|---|
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
1 /** |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
2 * This file contains primitives to interface with WebAssembly and |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
3 * with the Stone framework. |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
4 **/ |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
5 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
6 export declare type InitializationCallback = () => void; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
7 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
8 //export declare var StoneFrameworkModule : any; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
9 export var StoneFrameworkModule : any; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
10 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
11 //const ASSETS_FOLDER : string = "assets/lib"; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
12 //const WASM_FILENAME : string = "orthanc-framework"; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
13 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
14 export class Framework |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
15 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
16 private static singleton_ : Framework = null; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
17 private static wasmModuleName_ : string = null; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
18 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
19 public static Configure(wasmModuleName: string) { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
20 this.wasmModuleName_ = wasmModuleName; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
21 } |
238
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
22 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
23 private constructor(verbose : boolean) |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
24 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
25 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
26 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
27 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
28 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
29 public ccall( name: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
30 returnType: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
31 argTypes: Array<string>, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
32 argValues: Array<any>) : any |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
33 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
34 return (<any> window).StoneFrameworkModule.ccall(name, returnType, argTypes, argValues); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
35 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
36 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
37 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
38 public cwrap( name: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
39 returnType: string, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
40 argTypes: Array<string>) : any |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
41 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
42 return (<any> window).StoneFrameworkModule.cwrap(name, returnType, argTypes); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
43 } |
238
126c9c0c9333
SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents:
237
diff
changeset
|
44 |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
45 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
46 public static GetInstance() : Framework |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
47 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
48 if (Framework.singleton_ == null) { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
49 throw new Error('The WebAssembly module is not loaded yet'); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
50 } else { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
51 return Framework.singleton_; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
52 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
53 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
54 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
55 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
56 public static Initialize( verbose: boolean, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
57 callback: InitializationCallback) |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
58 { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
59 console.log('Initializing WebAssembly Module'); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
60 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
61 // (<any> window). |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
62 (<any> window).StoneFrameworkModule = { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
63 preRun: [ |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
64 function() { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
65 console.log('Loading the Stone Framework using WebAssembly'); |
223 | 66 } |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
67 ], |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
68 postRun: [ |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
69 function() { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
70 // This function is called by ".js" wrapper once the ".wasm" |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
71 // WebAssembly module has been loaded and compiled by the |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
72 // browser |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
73 console.log('WebAssembly is ready'); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
74 Framework.singleton_ = new Framework(verbose); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
75 callback(); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
76 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
77 ], |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
78 print: function(text : string) { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
79 console.log(text); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
80 }, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
81 printErr: function(text : string) { |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
82 console.error(text); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
83 }, |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
84 totalDependencies: 0 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
85 }; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
86 |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
87 // Dynamic loading of the JavaScript wrapper around WebAssembly |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
88 var script = document.createElement('script'); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
89 script.type = 'application/javascript'; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
90 //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
91 script.src = this.wasmModuleName_ + ".js";// "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
92 script.async = true; |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
93 document.head.appendChild(script); |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
94 } |
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
238
diff
changeset
|
95 } |