annotate Platforms/WebAssembly/stone-framework-loader.ts @ 231:5027cb2feb51 am

viewport is now part of the Application itself and not global anymore
author am@osimis.io
date Thu, 14 Jun 2018 18:49:19 +0200
parents d30a10d574ec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
1 module Stone {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
2 /**
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
3 * This file contains primitives to interface with WebAssembly and
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
4 * with the Stone framework.
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
5 **/
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
6
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
7 export declare type InitializationCallback = () => void;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
8
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
9 export declare var StoneFrameworkModule : any;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
10
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
11 //const ASSETS_FOLDER : string = "assets/lib";
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
12 //const WASM_FILENAME : string = "orthanc-framework";
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
13
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
14
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
15 export class Framework
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
16 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
17 private static singleton_ : Framework = null;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
18
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
19 private constructor(verbose : boolean)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
20 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
21 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
22 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
23
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
24
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
25 public ccall(name: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
26 returnType: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
27 argTypes: Array<string>,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
28 argValues: Array<any>) : any
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
29 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
30 return StoneFrameworkModule.ccall(name, returnType, argTypes, argValues);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
31 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
32
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
33
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
34 public cwrap(name: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
35 returnType: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
36 argTypes: Array<string>) : any
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
37 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
38 return StoneFrameworkModule.cwrap(name, returnType, argTypes);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
39 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
40
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
41
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
42 public static GetInstance() : Framework
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
43 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
44 if (Framework.singleton_ == null) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
45 throw new Error('The WebAssembly module is not loaded yet');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
46 } else {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
47 return Framework.singleton_;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
48 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
49 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
50
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
51
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
52 public static Initialize(verbose: boolean,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
53 callback: InitializationCallback)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
54 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
55 console.log('Initializing WebAssembly');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
56
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
57 (<any> window).StoneFrameworkModule = {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
58 preRun: [
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
59 function() {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
60 console.log('Loading the Stone Framework using WebAssembly');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
61 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
62 ],
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
63 postRun: [
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
64 function() {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
65 // This function is called by ".js" wrapper once the ".wasm"
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
66 // WebAssembly module has been loaded and compiled by the
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
67 // browser
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
68 console.log('WebAssembly is ready');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
69 Framework.singleton_ = new Framework(verbose);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
70 callback();
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
71 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
72 ],
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
73 print: function(text : string) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
74 console.log(text);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
75 },
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
76 printErr: function(text : string) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
77 console.error(text);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
78 },
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
79 totalDependencies: 0
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
80 };
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
81
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
82 // Dynamic loading of the JavaScript wrapper around WebAssembly
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
83 var script = document.createElement('script');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
84 script.type = 'application/javascript';
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
85 script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
86 script.async = true;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
87 document.head.appendChild(script);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
88 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
89 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
90 }