Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 498:6d62fc8a6988 bgo-commands-codegen
Web demonstrator for codegen ongoing work
author | bgo-osimis |
---|---|
date | Sun, 24 Feb 2019 13:23:14 +0100 |
parents | 5055031f4a06 |
children | 7105a0bad250 |
rev | line source |
---|---|
307 | 1 #include "WasmPlatformApplicationAdapter.h" |
2 | |
3 #include "Framework/Toolbox/MessagingToolbox.h" | |
4 #include "Framework/StoneException.h" | |
5 #include <Applications/Commands/BaseCommandBuilder.h> | |
6 #include <stdio.h> | |
7 #include "Platforms/Wasm/Defaults.h" | |
8 | |
9 namespace OrthancStone | |
10 { | |
11 WasmPlatformApplicationAdapter::WasmPlatformApplicationAdapter(MessageBroker& broker, IStoneApplication& application) | |
12 : IObserver(broker), | |
13 application_(application) | |
14 { | |
15 } | |
16 | |
17 void WasmPlatformApplicationAdapter::HandleMessageFromWeb(std::string& output, const std::string& input) | |
18 { | |
19 try | |
20 { | |
21 Json::Value inputJson; | |
319
daa04d15192c
new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
307
diff
changeset
|
22 // if the message is a command, build it and execute it |
307 | 23 if (MessagingToolbox::ParseJson(inputJson, input.c_str(), input.size())) |
24 { | |
25 std::unique_ptr<ICommand> command(application_.GetCommandBuilder().CreateFromJson(inputJson)); | |
319
daa04d15192c
new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
307
diff
changeset
|
26 if (command.get() == NULL) |
daa04d15192c
new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
307
diff
changeset
|
27 printf("Could not parse command: '%s'\n", input.c_str()); |
daa04d15192c
new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
307
diff
changeset
|
28 else |
daa04d15192c
new SimpleViewer sample that has been split in multiple files to be able to scale it
am@osimis.io
parents:
307
diff
changeset
|
29 application_.ExecuteCommand(*command); |
466
5055031f4a06
- Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents:
322
diff
changeset
|
30 } |
307 | 31 } |
32 catch (StoneException& exc) | |
33 { | |
34 printf("Error while handling message from web (error code = %d):\n", exc.GetErrorCode()); | |
35 printf("While interpreting input: '%s'\n", input.c_str()); | |
36 } | |
37 } | |
38 | |
39 void WasmPlatformApplicationAdapter::NotifyStatusUpdateFromCppToWeb(const std::string& statusUpdateMessage) | |
40 { | |
322 | 41 try |
42 { | |
43 UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str()); | |
44 } | |
45 catch (...) | |
46 { | |
47 printf("Error while handling message to web\n"); | |
48 } | |
307 | 49 } |
50 | |
51 } |