Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/stone-framework-loader.ts @ 236:f73d722d98c8 am
renamed folder
author | am@osimis.io |
---|---|
date | Tue, 19 Jun 2018 16:06:32 +0200 |
parents | Platforms/WebAssembly/stone-framework-loader.ts@d30a10d574ec |
children | b4642964c355 |
comparison
equal
deleted
inserted
replaced
235:ce4405d98b92 | 236:f73d722d98c8 |
---|---|
1 module Stone { | |
2 /** | |
3 * This file contains primitives to interface with WebAssembly and | |
4 * with the Stone framework. | |
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 | |
19 private constructor(verbose : boolean) | |
20 { | |
21 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]); | |
22 } | |
23 | |
24 | |
25 public ccall(name: string, | |
26 returnType: string, | |
27 argTypes: Array<string>, | |
28 argValues: Array<any>) : any | |
29 { | |
30 return StoneFrameworkModule.ccall(name, returnType, argTypes, argValues); | |
31 } | |
32 | |
33 | |
34 public cwrap(name: string, | |
35 returnType: string, | |
36 argTypes: Array<string>) : any | |
37 { | |
38 return StoneFrameworkModule.cwrap(name, returnType, argTypes); | |
39 } | |
40 | |
41 | |
42 public static GetInstance() : Framework | |
43 { | |
44 if (Framework.singleton_ == null) { | |
45 throw new Error('The WebAssembly module is not loaded yet'); | |
46 } else { | |
47 return Framework.singleton_; | |
48 } | |
49 } | |
50 | |
51 | |
52 public static Initialize(verbose: boolean, | |
53 callback: InitializationCallback) | |
54 { | |
55 console.log('Initializing WebAssembly'); | |
56 | |
57 (<any> window).StoneFrameworkModule = { | |
58 preRun: [ | |
59 function() { | |
60 console.log('Loading the Stone Framework using WebAssembly'); | |
61 } | |
62 ], | |
63 postRun: [ | |
64 function() { | |
65 // This function is called by ".js" wrapper once the ".wasm" | |
66 // WebAssembly module has been loaded and compiled by the | |
67 // browser | |
68 console.log('WebAssembly is ready'); | |
69 Framework.singleton_ = new Framework(verbose); | |
70 callback(); | |
71 } | |
72 ], | |
73 print: function(text : string) { | |
74 console.log(text); | |
75 }, | |
76 printErr: function(text : string) { | |
77 console.error(text); | |
78 }, | |
79 totalDependencies: 0 | |
80 }; | |
81 | |
82 // Dynamic loading of the JavaScript wrapper around WebAssembly | |
83 var script = document.createElement('script'); | |
84 script.type = 'application/javascript'; | |
85 script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js'; | |
86 script.async = true; | |
87 document.head.appendChild(script); | |
88 } | |
89 } | |
90 } |