annotate Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts @ 703:d4d6c5b502b5

Merging refactor-viewport-controller
author Benjamin Golinvaux <bgo@osimis.io>
date Sun, 19 May 2019 16:31:56 +0200
parents 17106b29ed6d
children 342f3e04bfa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
1 var SendMessageToCpp: Function = null;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
2 export var TestWasmIntegratedModule : any;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
3
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
4 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
5 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
6 | install emscripten handlers |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
7 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
8 */
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
9
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
10 // (<any> window).Module = {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
11 // preRun: [
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
12 // function() {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
13 // console.log('Loading the Stone Framework using WebAssembly');
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
14 // }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
15 // ],
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
16 // postRun: [
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
17 // function() {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
18 // // This function is called by ".js" wrapper once the ".wasm"
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
19 // // WebAssembly module has been loaded and compiled by the
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
20 // // browser
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
21 // console.log('WebAssembly is ready');
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
22 // // window.SendMessageToCpp = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
23 // // window.SendFreeTextToCpp = (<any> window).Module.cwrap('SendFreeTextToCpp', 'string', ['string']);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
24 // }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
25 // ],
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
26 // print: function(text : string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
27 // console.log(text);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
28 // },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
29 // printErr: function(text : string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
30 // console.error(text);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
31 // },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
32 // totalDependencies: 0
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
33 // };
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
34
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
35 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
36 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
37 | install handlers |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
38 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
39 */
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
40 document.querySelectorAll(".TestWasm-button").forEach((e) => {
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
41 (e as HTMLButtonElement).addEventListener("click", () => {
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
42 ButtonClick(e.attributes["tool-selector"].value);
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
43 });
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
44 });
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
45
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
46 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
47 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
48 | define stock messages |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
49 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
50 */
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
51 let schemaText: string = `rootName: testWasmIntegratedCpp
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
52
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
53 struct B:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
54 someAs: vector<A>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
55 someInts: vector<int32>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
56
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
57 struct C:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
58 someBs: vector<B>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
59 ddd: vector<string>
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
60 definition: vector<json>
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
61
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
62 struct A:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
63 someStrings: vector<string>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
64 someInts2: vector<int32>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
65 movies: vector<MovieType>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
66
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
67 struct Message1:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
68 a: int32
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
69 b: string
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
70 c: EnumMonth0
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
71 d: bool
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
72
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
73 struct Message2:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
74 toto: string
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
75 tata: vector<Message1>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
76 tutu: vector<string>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
77 titi: map<string, string>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
78 lulu: map<string, Message1>
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
79 movieType: MovieType
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
80 definition: json
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
81
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
82 enum MovieType:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
83 - RomCom
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
84 - Horror
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
85 - ScienceFiction
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
86 - Vegetables
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
87
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
88 enum CrispType:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
89 - SaltAndPepper
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
90 - CreamAndChives
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
91 - Paprika
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
92 - Barbecue
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
93
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
94 enum EnumMonth0:
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
95 - January
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
96 - February
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
97 - March
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
98 `;
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
99
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
100 let stockSerializedMessages = new Map<string,string>();
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
101 stockSerializedMessages["Test 1"] = `{
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
102 "type" : "testWasmIntegratedCpp.Message2",
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
103 "value" :
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
104 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
105 "lulu" :
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
106 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
107 "54" :
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
108 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
109 "a" : 43,
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
110 "b" : "Sandrine",
519
17106b29ed6d Changed the metadata system for structs. A __handler entry is now required
Benjamin Golinvaux <bgo@osimis.io>
parents: 508
diff changeset
111 "c" : "March",
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
112 "d" : true
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
113 },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
114 "55" :
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
115 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
116 "a" : 42,
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
117 "b" : "Benjamin",
519
17106b29ed6d Changed the metadata system for structs. A __handler entry is now required
Benjamin Golinvaux <bgo@osimis.io>
parents: 508
diff changeset
118 "c" : "January",
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
119 "d" : false
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
120 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
121 },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
122 "tata" :
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
123 [
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
124 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
125 "a" : 42,
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
126 "b" : "Benjamin",
519
17106b29ed6d Changed the metadata system for structs. A __handler entry is now required
Benjamin Golinvaux <bgo@osimis.io>
parents: 508
diff changeset
127 "c" : "March",
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
128 "d" : false
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
129 },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
130 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
131 "a" : 43,
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
132 "b" : "Sandrine",
519
17106b29ed6d Changed the metadata system for structs. A __handler entry is now required
Benjamin Golinvaux <bgo@osimis.io>
parents: 508
diff changeset
133 "c" : "January",
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
134 "d" : false
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
135 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
136 ],
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
137 "titi" :
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
138 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
139 "44" : "key 44",
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
140 "45" : "key 45"
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
141 },
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
142 "toto" : "Prout zizi",
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
143 "tutu" :
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
144 [
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
145 "Mercadet",
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
146 "Poisson"
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
147 ],
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
148 "definition":
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
149 {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
150 "val" : [ "berk", 42 ],
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
151 "zozo" :
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
152 {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
153 "23": "zloutch",
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
154 "lalala": 42
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
155 }
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
156 }
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
157 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
158 }`;
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
159 stockSerializedMessages["Test 2"] = ` {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
160 "type" : "testWasmIntegratedCpp.Message1",
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
161 "value" : {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
162 "a" : -987,
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
163 "b" : "Salomé",
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
164 "c" : 2,
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
165 "d" : true
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
166 }
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
167 }`;
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
168 stockSerializedMessages["Test 3"] = "Test 3 stock message sdfsfsdfsdf";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
169 stockSerializedMessages["Test 4"] = "Test 4 stock message 355345345";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
170 stockSerializedMessages["Test 5"] = "Test 5 stock message 34535";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
171 stockSerializedMessages["Test 6"] = "Test 6 stock message xcvcxvx";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
172 stockSerializedMessages["Test 7"] = "Test 7 stock message fgwqewqdgg";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
173 stockSerializedMessages["Test 8"] = "Test 8 stock message fgfsdfsdgg";
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
174
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
175 /*
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
176 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
177 | define handler |
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
178 +--------------------------------------------------+
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
179 */
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
180
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
181 function setSerializedInputValue(text: string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
182 let e : HTMLTextAreaElement = document.getElementById('TestWasm-SerializedInput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
183 e.value = text;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
184 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
185
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
186 function getSerializedInputValue(): string {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
187 let e : HTMLTextAreaElement = document.getElementById('TestWasm-SerializedInput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
188 return e.value;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
189 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
190
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
191 function setCppOutputValue(text: string) {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
192 let e : HTMLTextAreaElement = document.getElementById('TestWasm-CppOutput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
193 e.value = text;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
194 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
195
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
196 function getCppOutputValue(): string {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
197 let e : HTMLTextAreaElement = document.getElementById('TestWasm-CppOutput') as HTMLTextAreaElement;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
198 return e.value;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
199 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
200
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
201 function SendFreeTextFromCpp(txt: string):string
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
202 {
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
203 setCppOutputValue(getCppOutputValue() + "\n" + txt);
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
204 return "";
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
205 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
206 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
207
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
208
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
209 function ButtonClick(buttonName: string) {
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
210 if (buttonName.startsWith('Test ')) {
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
211 setSerializedInputValue(stockSerializedMessages[buttonName]);
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
212 }
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
213 else if(buttonName == 'Trigger')
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
214 {
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
215 let serializedInputValue:string = getSerializedInputValue();
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
216
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
217 let SendMessageToCppLocal = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
218 SendMessageToCppLocal(serializedInputValue);
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
219 }
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
220 else if(buttonName == 'Clear')
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
221 {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
222 setCppOutputValue("");
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
223 }
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
224 else if(buttonName == 'ShowSchema')
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
225 {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
226 setCppOutputValue(schemaText);
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
227 }
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
228 else
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
229 {
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
230 throw new Error("Internal error!");
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
231 }
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
232 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
233
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
234
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
235
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
236 // this method is called "from the C++ code" when the StoneApplication is updated.
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
237 // it can be used to update the UI of the application
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
238 function UpdateWebApplicationWithString(statusUpdateMessageString: string) {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
239 console.log("updating web application (string): ", statusUpdateMessageString);
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
240 let statusUpdateMessage = JSON.parse(statusUpdateMessageString);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
241
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
242 if ("event" in statusUpdateMessage)
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
243 {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
244 let eventName = statusUpdateMessage["event"];
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
245 if (eventName == "appStatusUpdated")
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
246 {
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
247 //ui.onAppStatusUpdated(statusUpdateMessage["data"]);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
248 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
249 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff changeset
250 }
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
251
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
252
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
253 function UpdateWebApplicationWithSerializedMessage(statusUpdateMessageString: string) {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
254 console.log("updating web application (serialized message): ", statusUpdateMessageString);
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
255 console.log("<not supported!>");
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
256 }
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
257