Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 427:3f9017db1738 am-vsol-upgrade-radiography-export
wip
author | am@osimis.io |
---|---|
date | Fri, 23 Nov 2018 16:06:23 +0100 |
parents | a902a07769d4 |
children | 5055031f4a06 |
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); |
307 | 30 } |
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 } |