annotate Resources/CodeGeneration/testWasmIntegrated/main.cpp @ 507:ce49eae4c887 bgo-commands-codegen

Codegen + Warning fixes
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 01 Mar 2019 16:18:38 +0100
parents 329f229c2794
children 7105a0bad250
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>
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
4 #include "testWasmIntegratedCpp_generated.hpp"
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;
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
11 }
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
12
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
13 extern "C" void SendMessageFromCppJS(const char* message);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
14 extern "C" void SendFreeTextFromCppJS(const char* message);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
15
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
16 #define HANDLE_MESSAGE(Type,value) \
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
17 stringstream ss; \
500
329f229c2794 Improvements to the integrated demo for TS <--> C++
bgo-osimis
parents: 499
diff changeset
18 ss << "Received an instance of:\n" #Type "\n. Here's the dump:\n"; \
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
19 testWasmIntegratedCpp::StoneDumpValue(ss, value, 0); \
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
20 SendFreeTextFromCppJS(ss.str().c_str()); \
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
21 return true;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
22
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
23 class MyHandler : public testWasmIntegratedCpp::IHandler
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
24 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
25 public:
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
26 virtual bool Handle(const testWasmIntegratedCpp::A& value) override
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
27 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
28 HANDLE_MESSAGE(testWasmIntegratedCpp::A,value)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
29 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
30 virtual bool Handle(const testWasmIntegratedCpp::B& value) override
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
31 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
32 HANDLE_MESSAGE(testWasmIntegratedCpp::B,value)
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 virtual bool Handle(const testWasmIntegratedCpp::Message1& value) override
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
36 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
37 HANDLE_MESSAGE(testWasmIntegratedCpp::Message1,value)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
38 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
39
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
40 virtual bool Handle(const testWasmIntegratedCpp::Message2& value) override
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
41 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
42 HANDLE_MESSAGE(testWasmIntegratedCpp::Message2,value)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
43 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
44
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
45 virtual bool Handle(const testWasmIntegratedCpp::C& value) override
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
46 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
47 HANDLE_MESSAGE(testWasmIntegratedCpp::C,value)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
48 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
49 };
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
50
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
51 extern "C" void EMSCRIPTEN_KEEPALIVE SendMessageToCpp(const char* message)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
52 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
53 MyHandler handler;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
54 try
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
55 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
56 bool handled = testWasmIntegratedCpp::StoneDispatchToHandler(message,&handler);
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
57 if(!handled)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
58 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
59 SendFreeTextFromCppJS("This message is valid JSON, but was not recognized!");
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
60 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
61 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
62 catch(std::exception& e)
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
63 {
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
64 stringstream ss;
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
65 ss << "Error while parsing message: " << e.what() << "\n";
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
66 SendFreeTextFromCppJS(ss.str().c_str());
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
67 }
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 498
diff changeset
68 }
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
69
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
70 void EMSCRIPTEN_KEEPALIVE StartWasmApplication(const char* baseUri)
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
71 {
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
72 printf("Hello! (this is sent from C++)\n");
496
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
73
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
74 // // 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
75 // boost::program_options::variables_map parameters;
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
76 // boost::program_options::options_description options;
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
77 // application->DeclareStartupOptions(options);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
78 // startupParametersBuilder.GetStartupParameters(parameters, options);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
79
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
80 // context.reset(new OrthancStone::StoneApplicationContext(broker));
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
81 // context->SetOrthancBaseUrl(baseUri);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
82 // printf("Base URL to Orthanc API: [%s]\n", baseUri);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
83 // context->SetWebService(OrthancStone::WasmWebService::GetInstance());
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
84 // context->SetDelayedCallExecutor(OrthancStone::WasmDelayedCallExecutor::GetInstance());
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
85 // application->Initialize(context.get(), statusBar_, parameters);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
86 // application->InitializeWasm();
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
87
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
88 // // viewport->SetSize(width_, height_);
8b6ceae45ba0 Finished (untested) C++, html, typescript, tsc & browserify production.
bgo-osimis
parents: 495
diff changeset
89 // printf("StartWasmApplication - completed\n");
498
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
90 SendFreeTextFromCppJS("Hello world from C++!");
6d62fc8a6988 Web demonstrator for codegen ongoing work
bgo-osimis
parents: 496
diff changeset
91 }