Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/Defaults.cpp @ 287:2038d76bf13f am-2
interaction with HTML/JS
author | am@osimis.io |
---|---|
date | Thu, 30 Aug 2018 11:36:36 +0200 |
parents | 8a86695fcbc3 |
children | 8c8da145fefa |
comparison
equal
deleted
inserted
replaced
286:6b3d91857b96 | 287:2038d76bf13f |
---|---|
5 #include "Framework/Widgets/TestCairoWidget.h" | 5 #include "Framework/Widgets/TestCairoWidget.h" |
6 #include <Framework/Viewport/WidgetViewport.h> | 6 #include <Framework/Viewport/WidgetViewport.h> |
7 #include <Framework/Widgets/LayerWidget.h> | 7 #include <Framework/Widgets/LayerWidget.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include "Applications/Wasm/StartupParametersBuilder.h" | 9 #include "Applications/Wasm/StartupParametersBuilder.h" |
10 #include "Platforms/Wasm/IStoneApplicationToWebApplicationAdapter.h" | |
10 | 11 |
11 static unsigned int width_ = 0; | 12 static unsigned int width_ = 0; |
12 static unsigned int height_ = 0; | 13 static unsigned int height_ = 0; |
13 | 14 |
14 /**********************************/ | 15 /**********************************/ |
15 | 16 |
16 static std::unique_ptr<OrthancStone::IBasicApplication> application; | 17 static std::unique_ptr<OrthancStone::IBasicApplication> application; |
18 static OrthancStone::IStoneApplicationToWebApplicationAdapter* applicationWebAdapter = NULL; | |
17 static std::unique_ptr<OrthancStone::BasicApplicationContext> context; | 19 static std::unique_ptr<OrthancStone::BasicApplicationContext> context; |
18 static OrthancStone::StartupParametersBuilder startupParametersBuilder; | 20 static OrthancStone::StartupParametersBuilder startupParametersBuilder; |
19 static OrthancStone::MessageBroker broker; | 21 static OrthancStone::MessageBroker broker; |
20 | 22 |
21 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_; | 23 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_; |
41 | 43 |
42 // when WASM needs a C++ viewport | 44 // when WASM needs a C++ viewport |
43 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { | 45 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { |
44 | 46 |
45 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport); | 47 std::shared_ptr<OrthancStone::WidgetViewport> viewport(new OrthancStone::WidgetViewport); |
46 printf("viewport %x\n", viewport.get()); | 48 printf("viewport %x\n", (int)viewport.get()); |
47 | 49 |
48 viewports_.push_back(viewport); | 50 viewports_.push_back(viewport); |
49 | 51 |
50 printf("There are now %d viewports in C++\n", viewports_.size()); | 52 printf("There are now %d viewports in C++\n", viewports_.size()); |
51 | 53 |
65 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { | 67 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { |
66 | 68 |
67 printf("CreateWasmApplication\n"); | 69 printf("CreateWasmApplication\n"); |
68 | 70 |
69 application.reset(CreateUserApplication(broker)); | 71 application.reset(CreateUserApplication(broker)); |
72 applicationWebAdapter = dynamic_cast<OrthancStone::IStoneApplicationToWebApplicationAdapter*>(application.get()); | |
70 WasmWebService::SetBroker(broker); | 73 WasmWebService::SetBroker(broker); |
71 | 74 |
72 startupParametersBuilder.Clear(); | 75 startupParametersBuilder.Clear(); |
73 } | 76 } |
74 | 77 |
252 void EMSCRIPTEN_KEEPALIVE ViewportMouseLeave(ViewportHandle viewport) | 255 void EMSCRIPTEN_KEEPALIVE ViewportMouseLeave(ViewportHandle viewport) |
253 { | 256 { |
254 viewport->MouseLeave(); | 257 viewport->MouseLeave(); |
255 } | 258 } |
256 | 259 |
260 const char* EMSCRIPTEN_KEEPALIVE SendMessageToStoneApplication(const char* message) | |
261 { | |
262 static std::string output; // we don't want the string to be deallocated when we return to JS code so we always use the same string (this is fine since JS is single-thread) | |
263 | |
264 if (applicationWebAdapter != NULL) { | |
265 printf("sending message to C++"); | |
266 applicationWebAdapter->HandleMessageFromWeb(output, std::string(message)); | |
267 return output.c_str(); | |
268 } | |
269 return "This stone application does not have a Web Adapter"; | |
270 } | |
271 | |
257 | 272 |
258 #ifdef __cplusplus | 273 #ifdef __cplusplus |
259 } | 274 } |
260 #endif | 275 #endif |