annotate Deprecated/Resources/CodeGeneration/testWasmIntegrated/main.cpp @ 1401:f6a2d46d2b76

moved CodeGeneration into Deprecated
author Alain Mazy <alain@mazy.be>
date Wed, 29 Apr 2020 20:48:18 +0200
parents Resources/CodeGeneration/testWasmIntegrated/main.cpp@f185cfcb72a0
children 828a9b4ee1b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
diff changeset
1 #include <iostream>
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
2 #include <sstream>
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
3 #include <emscripten/emscripten.h>
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
4 #include "TestStoneCodeGen_generated.hpp"
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
5
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
6 using std::stringstream;
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
diff changeset
7
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
diff changeset
8 int main()
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
diff changeset
9 {
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
10 std::cout << "Hello world from testWasmIntegrated! (this is sent from C++)" << std::endl;
508
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
11 try
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
12 {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
13 const char* jsonData = R"bgo({"definition":
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
14 {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
15 "val" : [ "berk", 42 ],
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
16 "zozo" : { "23": "zloutch", "lalala": 42}
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
17 }
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
18 })bgo";
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
19 std::string strValue(jsonData);
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
20
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
21 Json::Value readValue;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
22
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
23 Json::CharReaderBuilder builder;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
24 Json::CharReader* reader = builder.newCharReader();
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
25
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
26 StoneSmartPtr<Json::CharReader> ptr(reader);
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
27
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
28 std::string errors;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
29
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
30 bool ok = reader->parse(
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
31 strValue.c_str(),
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
32 strValue.c_str() + strValue.size(),
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
33 &readValue,
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
34 &errors
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
35 );
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
36 if (!ok)
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
37 {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
38 std::stringstream ss;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
39 ss << "Jsoncpp parsing error: " << errors;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
40 throw std::runtime_error(ss.str());
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
41 }
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
42 std::cout << "Json parsing OK" << std::endl;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
43 std::cout << readValue << std::endl;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
44 }
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
45 catch(std::exception& e)
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
46 {
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
47 std::cout << "Json parsing THROW" << std::endl;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
48 std::cout << "e.what() = " << e.what() << std::endl;
7105a0bad250 - Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents: 500
diff changeset
49 }
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
50 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
51
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
52 extern "C" void SendMessageFromCppJS(const char* message);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
53 extern "C" void SendFreeTextFromCppJS(const char* message);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
54
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
55 #define HANDLE_MESSAGE(Type,value) \
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
56 stringstream ss; \
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
57 ss << "Received an instance of:\n" #Type "\n. Here's the dump:\n"; \
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
58 TestStoneCodeGen::StoneDumpValue(ss, value, 0); \
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
59 SendFreeTextFromCppJS(ss.str().c_str()); \
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
60 return true;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
61
690
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
62 #define ECHO_MESSAGE(Type,value) \
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
63 stringstream ss; \
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
64 ss << "Received an instance of:\n" #Type "\n. Here's the dump:\n"; \
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
65 TestStoneCodeGen::StoneDumpValue(ss, value, 0); \
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
66 SendFreeTextFromCppJS(ss.str().c_str()); \
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
67 std::string serializedInCpp = StoneSerialize(value); \
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
68 SendMessageFromCppJS(serializedInCpp.c_str()); \
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
69 return true;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
70
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
71 class MyHandler : public TestStoneCodeGen::IHandler
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
72 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
73 public:
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
74 virtual bool Handle(const TestStoneCodeGen::A& value) override
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
75 {
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
76 HANDLE_MESSAGE(TestStoneCodeGen::A,value)
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
77 }
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
78 virtual bool Handle(const TestStoneCodeGen::B& value) override
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
79 {
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
80 HANDLE_MESSAGE(TestStoneCodeGen::B,value)
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
81 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
82
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
83 virtual bool Handle(const TestStoneCodeGen::Message1& value) override
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
84 {
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
85 HANDLE_MESSAGE(TestStoneCodeGen::Message1,value)
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
86 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
87
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
88 virtual bool Handle(const TestStoneCodeGen::Message2& value) override
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
89 {
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
90 HANDLE_MESSAGE(TestStoneCodeGen::Message2,value)
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
91 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
92
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
93 virtual bool Handle(const TestStoneCodeGen::C& value) override
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
94 {
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
95 HANDLE_MESSAGE(TestStoneCodeGen::C,value)
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
96 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
97 };
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
98
690
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
99 class MyEchoHandler : public TestStoneCodeGen::IHandler
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
100 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
101 public:
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
102 virtual bool Handle(const TestStoneCodeGen::A& value) override
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
103 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
104 ECHO_MESSAGE(TestStoneCodeGen::A,value)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
105 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
106 virtual bool Handle(const TestStoneCodeGen::B& value) override
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
107 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
108 ECHO_MESSAGE(TestStoneCodeGen::B,value)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
109 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
110
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
111 virtual bool Handle(const TestStoneCodeGen::Message1& value) override
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
112 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
113 ECHO_MESSAGE(TestStoneCodeGen::Message1,value)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
114 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
115
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
116 virtual bool Handle(const TestStoneCodeGen::Message2& value) override
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
117 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
118 ECHO_MESSAGE(TestStoneCodeGen::Message2,value)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
119 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
120
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
121 virtual bool Handle(const TestStoneCodeGen::C& value) override
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
122 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
123 ECHO_MESSAGE(TestStoneCodeGen::C,value)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
124 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
125 };
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
126
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
127 extern "C" void EMSCRIPTEN_KEEPALIVE SendMessageToCpp(const char* message)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
128 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
129 MyHandler handler;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
130 try
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
131 {
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
132 bool handled = TestStoneCodeGen::StoneDispatchToHandler(message,&handler);
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
133 if(!handled)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
134 {
688
8c0b073efda8 Codegen: fix
Alain Mazy <alain@mazy.be>
parents: 508
diff changeset
135 SendFreeTextFromCppJS("This message is valid JSON, but was not handled!");
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
136 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
137 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
138 catch(std::exception& e)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
139 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
140 stringstream ss;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
141 ss << "Error while parsing message: " << e.what() << "\n";
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
142 SendFreeTextFromCppJS(ss.str().c_str());
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
143 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
144 }
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
145
690
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
146 extern "C" void EMSCRIPTEN_KEEPALIVE SendMessageToCppForEcho(const char* message)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
147 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
148 MyEchoHandler echoHandler;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
149 try
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
150 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
151 bool handled = TestStoneCodeGen::StoneDispatchToHandler(message,&echoHandler);
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
152 if(!handled)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
153 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
154 SendFreeTextFromCppJS("This message is valid JSON, but was not handled by the echo handler!");
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
155 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
156 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
157 catch(std::exception& e)
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
158 {
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
159 stringstream ss;
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
160 ss << "Error while parsing message: " << e.what() << "\n";
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
161 SendFreeTextFromCppJS(ss.str().c_str());
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
162 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
163 }
f185cfcb72a0 CodeGen: tests improvements
Alain Mazy <alain@mazy.be>
parents: 688
diff changeset
164
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
165 void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri)
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
166 {
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
167 printf("Hello! (this is sent from C++)\n");
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
168
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
169 // // recreate a command line from uri arguments and parse it
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
170 // boost::program_options::variables_map parameters;
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
171 // boost::program_options::options_description options;
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
172 // application->DeclareStartupOptions(options);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
173 // startupParametersBuilder.GetStartupParameters(parameters, options);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
174
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
175 // context.reset(new OrthancStone::StoneApplicationContext(broker));
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
176 // context->SetOrthancBaseUrl(baseUri);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
177 // printf("Base URL to Orthanc API: [%s]\n", baseUri);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
178 // context->SetWebService(OrthancStone::WasmWebService::GetInstance());
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
179 // context->SetDelayedCallExecutor(OrthancStone::WasmDelayedCallExecutor::GetInstance());
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
180 // application->Initialize(context.get(), statusBar_, parameters);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
181 // application->InitializeWasm();
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
182
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
183 // // viewport->SetSize(width_, height_);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
184 // printf("StartWasmApplication - completed\n");
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
185 SendFreeTextFromCppJS("Hello world from C++!");
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
186 }