Mercurial > hg > orthanc-stone
comparison Deprecated/Platforms/Wasm/stone-framework-loader.ts @ 1400:419d0320c344
moved Platforms into Deprecated
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 29 Apr 2020 20:45:14 +0200 |
parents | Platforms/Wasm/stone-framework-loader.ts@daf43666bbc2 |
children |
comparison
equal
deleted
inserted
replaced
1399:ff8d2e46ac63 | 1400:419d0320c344 |
---|---|
1 /** | |
2 * This file contains primitives to interface with WebAssembly and | |
3 * with the Stone framework. | |
4 **/ | |
5 import * as Logger from './logger' | |
6 | |
7 export declare type InitializationCallback = () => void; | |
8 | |
9 //export declare var StoneFrameworkModule : any; | |
10 export var StoneFrameworkModule : any; | |
11 | |
12 //const ASSETS_FOLDER : string = "assets/lib"; | |
13 //const WASM_FILENAME : string = "orthanc-framework"; | |
14 | |
15 export class Framework | |
16 { | |
17 private static singleton_ : Framework = null; | |
18 private static wasmModuleName_ : string = null; | |
19 | |
20 public static Configure(wasmModuleName: string) { | |
21 this.wasmModuleName_ = wasmModuleName; | |
22 } | |
23 | |
24 private constructor(verbose : boolean) | |
25 { | |
26 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]); | |
27 } | |
28 | |
29 | |
30 public ccall( name: string, | |
31 returnType: string, | |
32 argTypes: Array<string>, | |
33 argValues: Array<any>) : any | |
34 { | |
35 return (<any> window).StoneFrameworkModule.ccall(name, returnType, argTypes, argValues); | |
36 } | |
37 | |
38 | |
39 public cwrap( name: string, | |
40 returnType: string, | |
41 argTypes: Array<string>) : any | |
42 { | |
43 return (<any> window).StoneFrameworkModule.cwrap(name, returnType, argTypes); | |
44 } | |
45 | |
46 | |
47 public static GetInstance() : Framework | |
48 { | |
49 if (Framework.singleton_ == null) { | |
50 throw new Error('The WebAssembly module is not loaded yet'); | |
51 } else { | |
52 return Framework.singleton_; | |
53 } | |
54 } | |
55 | |
56 | |
57 public static Initialize( verbose: boolean, | |
58 callback: InitializationCallback) | |
59 { | |
60 Logger.defaultLogger.debug('Initializing WebAssembly Module'); | |
61 | |
62 (<any> window).errorFromCpp = function(text:any) { Logger.defaultLogger.errorFromCpp(text); }; | |
63 (<any> window).warningFromCpp = function(text:any) { Logger.defaultLogger.warningFromCpp(text); }; | |
64 (<any> window).infoFromCpp = function(text:any) { Logger.defaultLogger.infoFromCpp(text); }; | |
65 (<any> window).debugFromCpp = function(text:any) { Logger.defaultLogger.debugFromCpp(text); }; | |
66 | |
67 // (<any> window). | |
68 (<any> window).StoneFrameworkModule = { | |
69 preRun: [ | |
70 function() { | |
71 Logger.defaultLogger.debug('Loading the Stone Framework using WebAssembly'); | |
72 } | |
73 ], | |
74 postRun: [ | |
75 function() { | |
76 // This function is called by ".js" wrapper once the ".wasm" | |
77 // WebAssembly module has been loaded and compiled by the | |
78 // browser | |
79 Logger.defaultLogger.debug('WebAssembly is ready'); | |
80 Framework.singleton_ = new Framework(verbose); | |
81 callback(); | |
82 } | |
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 } |