Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/Defaults.cpp @ 307:be2660b6e40a am-callable-and-promise
wip: commands + status update
author | am@osimis.io |
---|---|
date | Tue, 25 Sep 2018 15:14:53 +0200 |
parents | 8c8da145fefa |
children | 14ef1227120f |
comparison
equal
deleted
inserted
replaced
304:6c22e0506587 | 307:be2660b6e40a |
---|---|
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 #include "Platforms/Wasm/WasmPlatformApplicationAdapter.h" |
11 | 11 |
12 static unsigned int width_ = 0; | 12 static unsigned int width_ = 0; |
13 static unsigned int height_ = 0; | 13 static unsigned int height_ = 0; |
14 | 14 |
15 /**********************************/ | 15 /**********************************/ |
16 | 16 |
17 static std::unique_ptr<OrthancStone::IStoneApplication> application; | 17 static std::unique_ptr<OrthancStone::IStoneApplication> application; |
18 static OrthancStone::IStoneApplicationToWebApplicationAdapter* applicationWebAdapter = NULL; | 18 static std::unique_ptr<OrthancStone::WasmPlatformApplicationAdapter> applicationWasmAdapter = NULL; |
19 static std::unique_ptr<OrthancStone::StoneApplicationContext> context; | 19 static std::unique_ptr<OrthancStone::StoneApplicationContext> context; |
20 static OrthancStone::StartupParametersBuilder startupParametersBuilder; | 20 static OrthancStone::StartupParametersBuilder startupParametersBuilder; |
21 static OrthancStone::MessageBroker broker; | 21 static OrthancStone::MessageBroker broker; |
22 | 22 |
23 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_; | 23 static OrthancStone::ViewportContentChangedObserver viewportContentChangedObserver_; |
67 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { | 67 void EMSCRIPTEN_KEEPALIVE CreateWasmApplication(ViewportHandle viewport) { |
68 | 68 |
69 printf("CreateWasmApplication\n"); | 69 printf("CreateWasmApplication\n"); |
70 | 70 |
71 application.reset(CreateUserApplication(broker)); | 71 application.reset(CreateUserApplication(broker)); |
72 applicationWebAdapter = dynamic_cast<OrthancStone::IStoneApplicationToWebApplicationAdapter*>(application.get()); | 72 applicationWasmAdapter.reset(CreateWasmApplicationAdapter(broker, application.get())); |
73 WasmWebService::SetBroker(broker); | 73 WasmWebService::SetBroker(broker); |
74 | 74 |
75 startupParametersBuilder.Clear(); | 75 startupParametersBuilder.Clear(); |
76 } | 76 } |
77 | 77 |
259 | 259 |
260 const char* EMSCRIPTEN_KEEPALIVE SendMessageToStoneApplication(const char* message) | 260 const char* EMSCRIPTEN_KEEPALIVE SendMessageToStoneApplication(const char* message) |
261 { | 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) | 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 | 263 |
264 if (applicationWebAdapter != NULL) { | 264 printf("SendMessageToStoneApplication\n"); |
265 printf("sending message to C++"); | 265 printf(message); |
266 applicationWebAdapter->HandleMessageFromWeb(output, std::string(message)); | 266 |
267 if (applicationWasmAdapter.get() != NULL) { | |
268 printf("sending message to C++\n"); | |
269 applicationWasmAdapter->HandleMessageFromWeb(output, std::string(message)); | |
267 return output.c_str(); | 270 return output.c_str(); |
268 } | 271 } |
269 return "This stone application does not have a Web Adapter"; | 272 printf("This stone application does not have a Web Adapter"); |
273 return NULL; | |
270 } | 274 } |
271 | 275 |
272 | 276 |
273 #ifdef __cplusplus | 277 #ifdef __cplusplus |
274 } | 278 } |