Mercurial > hg > orthanc-stone
annotate Resources/CodeGeneration/testWasmIntegrated/testWasmIntegrated.ts @ 687:342f3e04bfa9 am-dev
CodeGen: test cleanup + all working again + using same yaml and stimuli files
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 16 May 2019 17:51:17 +0200 |
parents | 17106b29ed6d |
children | f185cfcb72a0 |
rev | line source |
---|---|
499 | 1 var SendMessageToCpp: Function = null; |
2 export var TestWasmIntegratedModule : any; | |
3 | |
4 /* | |
5 +--------------------------------------------------+ | |
6 | install emscripten handlers | | |
7 +--------------------------------------------------+ | |
8 */ | |
496
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
9 |
499 | 10 // (<any> window).Module = { |
11 // preRun: [ | |
12 // function() { | |
13 // console.log('Loading the Stone Framework using WebAssembly'); | |
14 // } | |
15 // ], | |
16 // postRun: [ | |
17 // function() { | |
18 // // This function is called by ".js" wrapper once the ".wasm" | |
19 // // WebAssembly module has been loaded and compiled by the | |
20 // // browser | |
21 // console.log('WebAssembly is ready'); | |
22 // // window.SendMessageToCpp = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']); | |
23 // // window.SendFreeTextToCpp = (<any> window).Module.cwrap('SendFreeTextToCpp', 'string', ['string']); | |
24 // } | |
25 // ], | |
26 // print: function(text : string) { | |
27 // console.log(text); | |
28 // }, | |
29 // printErr: function(text : string) { | |
30 // console.error(text); | |
31 // }, | |
32 // totalDependencies: 0 | |
33 // }; | |
34 | |
35 /* | |
36 +--------------------------------------------------+ | |
37 | install handlers | | |
38 +--------------------------------------------------+ | |
39 */ | |
498 | 40 document.querySelectorAll(".TestWasm-button").forEach((e) => { |
41 (e as HTMLButtonElement).addEventListener("click", () => { | |
42 ButtonClick(e.attributes["tool-selector"].value); | |
43 }); | |
44 }); | |
45 | |
499 | 46 /* |
47 +--------------------------------------------------+ | |
48 | define stock messages | | |
49 +--------------------------------------------------+ | |
50 */ | |
687
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
51 let schemaText: string = null; |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
52 fetch("testTestStoneCodeGen.yaml").then(function(res) {return res.text();}).then(function(text) {schemaText = text;}); |
500
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
53 |
498 | 54 let stockSerializedMessages = new Map<string,string>(); |
687
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
55 stockSerializedMessages["Test CppHandler message2"] = null; |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
56 fetch("cppHandler_test_Message2.json").then(function(res) {return res.text();}).then(function(text) {stockSerializedMessages["Test CppHandler message2"] = text;}); |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
57 |
500
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
58 stockSerializedMessages["Test 2"] = ` { |
687
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
59 "type" : "TestStoneCodeGen.Message1", |
500
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
60 "value" : { |
687
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
61 "memberInt32" : -987, |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
62 "memberString" : "Salomé", |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
63 "memberEnumMonth" : "March", |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
64 "memberBool" : true, |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
65 "memberFloat32" : 0.1, |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
66 "memberFloat64" : -0.2, |
342f3e04bfa9
CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents:
519
diff
changeset
|
67 "extraMember" : "don't care" |
500
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
68 } |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
69 }`; |
498 | 70 stockSerializedMessages["Test 3"] = "Test 3 stock message sdfsfsdfsdf"; |
71 stockSerializedMessages["Test 4"] = "Test 4 stock message 355345345"; | |
72 stockSerializedMessages["Test 5"] = "Test 5 stock message 34535"; | |
73 stockSerializedMessages["Test 6"] = "Test 6 stock message xcvcxvx"; | |
74 stockSerializedMessages["Test 7"] = "Test 7 stock message fgwqewqdgg"; | |
75 stockSerializedMessages["Test 8"] = "Test 8 stock message fgfsdfsdgg"; | |
76 | |
499 | 77 /* |
78 +--------------------------------------------------+ | |
79 | define handler | | |
80 +--------------------------------------------------+ | |
81 */ | |
82 | |
83 function setSerializedInputValue(text: string) { | |
84 let e : HTMLTextAreaElement = document.getElementById('TestWasm-SerializedInput') as HTMLTextAreaElement; | |
85 e.value = text; | |
86 } | |
87 | |
88 function getSerializedInputValue(): string { | |
89 let e : HTMLTextAreaElement = document.getElementById('TestWasm-SerializedInput') as HTMLTextAreaElement; | |
90 return e.value; | |
91 } | |
92 | |
93 function setCppOutputValue(text: string) { | |
94 let e : HTMLTextAreaElement = document.getElementById('TestWasm-CppOutput') as HTMLTextAreaElement; | |
95 e.value = text; | |
96 } | |
97 | |
98 function getCppOutputValue(): string { | |
99 let e : HTMLTextAreaElement = document.getElementById('TestWasm-CppOutput') as HTMLTextAreaElement; | |
100 return e.value; | |
101 } | |
102 | |
103 function SendFreeTextFromCpp(txt: string):string | |
104 { | |
500
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
105 setCppOutputValue(getCppOutputValue() + "\n" + txt); |
499 | 106 return ""; |
107 } | |
108 (<any> window).SendFreeTextFromCpp = SendFreeTextFromCpp; | |
109 | |
110 | |
498 | 111 function ButtonClick(buttonName: string) { |
112 if (buttonName.startsWith('Test ')) { | |
499 | 113 setSerializedInputValue(stockSerializedMessages[buttonName]); |
498 | 114 } |
115 else if(buttonName == 'Trigger') | |
116 { | |
499 | 117 let serializedInputValue:string = getSerializedInputValue(); |
118 | |
119 let SendMessageToCppLocal = (<any> window).Module.cwrap('SendMessageToCpp', 'string', ['string']); | |
120 SendMessageToCppLocal(serializedInputValue); | |
498 | 121 } |
500
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
122 else if(buttonName == 'Clear') |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
123 { |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
124 setCppOutputValue(""); |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
125 } |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
126 else if(buttonName == 'ShowSchema') |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
127 { |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
128 setCppOutputValue(schemaText); |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
129 } |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
130 else |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
131 { |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
132 throw new Error("Internal error!"); |
329f229c2794
Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents:
499
diff
changeset
|
133 } |
496
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
134 } |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
135 |
498 | 136 |
496
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
137 |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
138 // 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
|
139 // 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
|
140 function UpdateWebApplicationWithString(statusUpdateMessageString: string) { |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
141 console.log("updating web application (string): ", statusUpdateMessageString); |
496
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
142 let statusUpdateMessage = JSON.parse(statusUpdateMessageString); |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
143 |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
144 if ("event" in statusUpdateMessage) |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
145 { |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
146 let eventName = statusUpdateMessage["event"]; |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
147 if (eventName == "appStatusUpdated") |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
148 { |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
149 //ui.onAppStatusUpdated(statusUpdateMessage["data"]); |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
150 } |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
151 } |
8b6ceae45ba0
Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents:
diff
changeset
|
152 } |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
153 |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
154 |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
155 function UpdateWebApplicationWithSerializedMessage(statusUpdateMessageString: string) { |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
156 console.log("updating web application (serialized message): ", statusUpdateMessageString); |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
157 console.log("<not supported!>"); |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
158 } |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
500
diff
changeset
|
159 |