comparison Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 535:79bb0a02d1cc bgo-commands-codegen

- Added ORTHANC_OVERRIDE to several methods (translates to "override" in C++ 11 compilers) - Last fixes to new style command handling (removed useless commands and switch command handling in simple samples to use XxxxSerializedMessageXxxx instead of XxxxCommandXxxx - Fixed hardcoded input instance in SingleFrameEditorApplication
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 19 Mar 2019 09:13:57 +0100
parents 7105a0bad250
children 4fe4b221a31f
comparison
equal deleted inserted replaced
534:7016c35d163c 535:79bb0a02d1cc
1 #include "WasmPlatformApplicationAdapter.h" 1 #include "WasmPlatformApplicationAdapter.h"
2 2
3 #include "Framework/Toolbox/MessagingToolbox.h" 3 #include "Framework/Toolbox/MessagingToolbox.h"
4 #include "Framework/StoneException.h" 4 #include "Framework/StoneException.h"
5 #include <Applications/Commands/BaseCommandBuilder.h>
6 #include <stdio.h> 5 #include <stdio.h>
7 #include "Platforms/Wasm/Defaults.h" 6 #include "Platforms/Wasm/Defaults.h"
8 7
9 namespace OrthancStone 8 namespace OrthancStone
10 { 9 {
11 WasmPlatformApplicationAdapter::WasmPlatformApplicationAdapter(MessageBroker& broker, IStoneApplication& application) 10 WasmPlatformApplicationAdapter::WasmPlatformApplicationAdapter(MessageBroker& broker, IStoneApplication& application)
12 : IObserver(broker), 11 : IObserver(broker),
13 application_(application) 12 application_(application)
14 { 13 {
15 }
16
17 void WasmPlatformApplicationAdapter::HandleCommandFromWeb(std::string& output, const std::string& input)
18 {
19 try
20 {
21 Json::Value inputJson;
22 // if the message is a command, build it and execute it
23 if (MessagingToolbox::ParseJson(inputJson, input.c_str(), input.size()))
24 {
25 std::unique_ptr<ICommand> command(application_.GetCommandBuilder().CreateFromJson(inputJson));
26 if (command.get() == NULL)
27 printf("Could not parse command: '%s'\n", input.c_str());
28 else
29 application_.ExecuteCommand(*command);
30 }
31 }
32 catch (StoneException& exc)
33 {
34 printf("Error while handling command from web (error code = %d):\n", exc.GetErrorCode());
35 printf("While interpreting input: '%s'\n", input.c_str());
36 output = std::string("ERROR : ");
37 }
38 catch (std::exception& exc)
39 {
40 printf("Error while handling message from web (error text = %s):\n", exc.what());
41 printf("While interpreting input: '%s'\n", input.c_str());
42 output = std::string("ERROR : ");
43 }
44 } 14 }
45 15
46 void WasmPlatformApplicationAdapter::HandleSerializedMessageFromWeb(std::string& output, const std::string& input) 16 void WasmPlatformApplicationAdapter::HandleSerializedMessageFromWeb(std::string& output, const std::string& input)
47 { 17 {
48 try 18 try