Mercurial > hg > orthanc-stone
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 |
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 | 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 | 4 #include "testWasmIntegratedCpp_generated.hpp" |
5 | |
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 | 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 | 13 extern "C" void SendMessageFromCppJS(const char* message); |
14 extern "C" void SendFreeTextFromCppJS(const char* message); | |
15 | |
16 #define HANDLE_MESSAGE(Type,value) \ | |
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 | 19 testWasmIntegratedCpp::StoneDumpValue(ss, value, 0); \ |
20 SendFreeTextFromCppJS(ss.str().c_str()); \ | |
21 return true; | |
22 | |
23 class MyHandler : public testWasmIntegratedCpp::IHandler | |
24 { | |
25 public: | |
26 virtual bool Handle(const testWasmIntegratedCpp::A& value) override | |
27 { | |
28 HANDLE_MESSAGE(testWasmIntegratedCpp::A,value) | |
29 } | |
30 virtual bool Handle(const testWasmIntegratedCpp::B& value) override | |
31 { | |
32 HANDLE_MESSAGE(testWasmIntegratedCpp::B,value) | |
33 } | |
34 | |
35 virtual bool Handle(const testWasmIntegratedCpp::Message1& value) override | |
36 { | |
37 HANDLE_MESSAGE(testWasmIntegratedCpp::Message1,value) | |
38 } | |
39 | |
40 virtual bool Handle(const testWasmIntegratedCpp::Message2& value) override | |
41 { | |
42 HANDLE_MESSAGE(testWasmIntegratedCpp::Message2,value) | |
43 } | |
44 | |
45 virtual bool Handle(const testWasmIntegratedCpp::C& value) override | |
46 { | |
47 HANDLE_MESSAGE(testWasmIntegratedCpp::C,value) | |
48 } | |
49 }; | |
50 | |
51 extern "C" void EMSCRIPTEN_KEEPALIVE SendMessageToCpp(const char* message) | |
52 { | |
53 MyHandler handler; | |
54 try | |
55 { | |
56 bool handled = testWasmIntegratedCpp::StoneDispatchToHandler(message,&handler); | |
57 if(!handled) | |
58 { | |
59 SendFreeTextFromCppJS("This message is valid JSON, but was not recognized!"); | |
60 } | |
61 } | |
62 catch(std::exception& e) | |
63 { | |
64 stringstream ss; | |
65 ss << "Error while parsing message: " << e.what() << "\n"; | |
66 SendFreeTextFromCppJS(ss.str().c_str()); | |
67 } | |
68 } | |
498 | 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 | 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 | 90 SendFreeTextFromCppJS("Hello world from C++!"); |
91 } |