Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/stone-framework-loader.ts @ 466:5055031f4a06 bgo-commands-codegen
- Added browserify to build. This allows using require calls for modules that
work with tsc compiler.
- removed older stuff related to Protocol Buffers and Flatbuffers
- changed triple-slash references to import statements
- module prefixes are now added at call sites
- added cmake module for filename handling
- switched to Ninja for sample build
- Added virtual dtor in ICommand
author | bgo-osimis |
---|---|
date | Mon, 11 Feb 2019 16:00:04 +0100 |
parents | 126c9c0c9333 |
children | 548eed46f535 |
comparison
equal
deleted
inserted
replaced
448:cc47e6eaefb0 | 466:5055031f4a06 |
---|---|
1 module Stone { | 1 /** |
2 /** | 2 * This file contains primitives to interface with WebAssembly and |
3 * This file contains primitives to interface with WebAssembly and | 3 * with the Stone framework. |
4 * with the Stone framework. | 4 **/ |
5 **/ | |
6 | |
7 export declare type InitializationCallback = () => void; | |
8 | |
9 export declare var StoneFrameworkModule : any; | |
10 | |
11 //const ASSETS_FOLDER : string = "assets/lib"; | |
12 //const WASM_FILENAME : string = "orthanc-framework"; | |
13 | |
14 | |
15 export class Framework | |
16 { | |
17 private static singleton_ : Framework = null; | |
18 private static wasmModuleName_ : string = null; | |
19 | 5 |
20 public static Configure(wasmModuleName: string) { | 6 export declare type InitializationCallback = () => void; |
21 this.wasmModuleName_ = wasmModuleName; | |
22 } | |
23 | 7 |
24 private constructor(verbose : boolean) | 8 //export declare var StoneFrameworkModule : any; |
25 { | 9 export var StoneFrameworkModule : any; |
26 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]); | 10 |
27 } | 11 //const ASSETS_FOLDER : string = "assets/lib"; |
28 | 12 //const WASM_FILENAME : string = "orthanc-framework"; |
29 | 13 |
30 public ccall(name: string, | 14 export class Framework |
31 returnType: string, | 15 { |
32 argTypes: Array<string>, | 16 private static singleton_ : Framework = null; |
33 argValues: Array<any>) : any | 17 private static wasmModuleName_ : string = null; |
34 { | 18 |
35 return StoneFrameworkModule.ccall(name, returnType, argTypes, argValues); | 19 public static Configure(wasmModuleName: string) { |
36 } | 20 this.wasmModuleName_ = wasmModuleName; |
37 | 21 } |
38 | 22 |
39 public cwrap(name: string, | 23 private constructor(verbose : boolean) |
40 returnType: string, | 24 { |
41 argTypes: Array<string>) : any | 25 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]); |
42 { | 26 } |
43 return StoneFrameworkModule.cwrap(name, returnType, argTypes); | 27 |
44 } | 28 |
45 | 29 public ccall( name: string, |
46 | 30 returnType: string, |
47 public static GetInstance() : Framework | 31 argTypes: Array<string>, |
48 { | 32 argValues: Array<any>) : any |
49 if (Framework.singleton_ == null) { | 33 { |
50 throw new Error('The WebAssembly module is not loaded yet'); | 34 return (<any> window).StoneFrameworkModule.ccall(name, returnType, argTypes, argValues); |
51 } else { | 35 } |
52 return Framework.singleton_; | 36 |
37 | |
38 public cwrap( name: string, | |
39 returnType: string, | |
40 argTypes: Array<string>) : any | |
41 { | |
42 return (<any> window).StoneFrameworkModule.cwrap(name, returnType, argTypes); | |
43 } | |
44 | |
45 | |
46 public static GetInstance() : Framework | |
47 { | |
48 if (Framework.singleton_ == null) { | |
49 throw new Error('The WebAssembly module is not loaded yet'); | |
50 } else { | |
51 return Framework.singleton_; | |
52 } | |
53 } | |
54 | |
55 | |
56 public static Initialize( verbose: boolean, | |
57 callback: InitializationCallback) | |
58 { | |
59 console.log('Initializing WebAssembly Module'); | |
60 | |
61 // (<any> window). | |
62 (<any> window).StoneFrameworkModule = { | |
63 preRun: [ | |
64 function() { | |
65 console.log('Loading the Stone Framework using WebAssembly'); | |
53 } | 66 } |
54 } | 67 ], |
55 | 68 postRun: [ |
56 | 69 function() { |
57 public static Initialize(verbose: boolean, | 70 // This function is called by ".js" wrapper once the ".wasm" |
58 callback: InitializationCallback) | 71 // WebAssembly module has been loaded and compiled by the |
59 { | 72 // browser |
60 console.log('Initializing WebAssembly Module'); | 73 console.log('WebAssembly is ready'); |
61 | 74 Framework.singleton_ = new Framework(verbose); |
62 (<any> window).StoneFrameworkModule = { | 75 callback(); |
63 preRun: [ | 76 } |
64 function() { | 77 ], |
65 console.log('Loading the Stone Framework using WebAssembly'); | 78 print: function(text : string) { |
66 } | 79 console.log(text); |
67 ], | 80 }, |
68 postRun: [ | 81 printErr: function(text : string) { |
69 function() { | 82 console.error(text); |
70 // This function is called by ".js" wrapper once the ".wasm" | 83 }, |
71 // WebAssembly module has been loaded and compiled by the | 84 totalDependencies: 0 |
72 // browser | 85 }; |
73 console.log('WebAssembly is ready'); | 86 |
74 Framework.singleton_ = new Framework(verbose); | 87 // Dynamic loading of the JavaScript wrapper around WebAssembly |
75 callback(); | 88 var script = document.createElement('script'); |
76 } | 89 script.type = 'application/javascript'; |
77 ], | 90 //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
78 print: function(text : string) { | 91 script.src = this.wasmModuleName_ + ".js";// "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; |
79 console.log(text); | 92 script.async = true; |
80 }, | 93 document.head.appendChild(script); |
81 printErr: function(text : string) { | 94 } |
82 console.error(text); | |
83 }, | |
84 totalDependencies: 0 | |
85 }; | |
86 | |
87 // Dynamic loading of the JavaScript wrapper around WebAssembly | |
88 var script = document.createElement('script'); | |
89 script.type = 'application/javascript'; | |
90 //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; | |
91 script.src = this.wasmModuleName_ + ".js";// "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; | |
92 script.async = true; | |
93 document.head.appendChild(script); | |
94 } | |
95 } | |
96 } | 95 } |