comparison Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 508:7105a0bad250 bgo-commands-codegen

- Added HandleSerializedMessage to IStoneApplication (empty impl) - Split UpdateWebApplication with "WithString" and "WithSerializedMessage" variants - Due to the modules in TS, globals are now unallowed and the callbacks from C++ to JS are stored in the "window" instance - Split UpdateStoneApplicationStatusFromCpp with "WithString" and "WithSerializedMessage" variants - Split NotifyStatusUpdateFromCppToWeb with "WithString" and "WithSerializedMessage" variants - SendMessageToStoneApplication (C++ global) has been split into SendSerializedMessageToStoneApplication and SendCommandToStoneApplication - In WasmPlatformApplicationAdapter: HandleMessageFromWeb becomes HandleCommandFromWeb - In WasmPlatformApplicationAdapter: added HandleSerializedMessageFromWeb - stonegentool now handles the "json" primitive type (used, a.o., in the VSOL "EditInstance" message) - Fixed indentation and added json serialization overloads in the stonegentool templates - Added test of the json primitive type to testWasmIntegrated (in Resources/CodeGeneration) - Adapted testWasmIntegrated (in Resources/CodeGeneration) to the changes above
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 06 Mar 2019 10:14:59 +0100
parents 5055031f4a06
children 79bb0a02d1cc
comparison
equal deleted inserted replaced
507:ce49eae4c887 508:7105a0bad250
6 #include <stdio.h> 6 #include <stdio.h>
7 #include "Platforms/Wasm/Defaults.h" 7 #include "Platforms/Wasm/Defaults.h"
8 8
9 namespace OrthancStone 9 namespace OrthancStone
10 { 10 {
11 WasmPlatformApplicationAdapter::WasmPlatformApplicationAdapter(MessageBroker& broker, IStoneApplication& application) 11 WasmPlatformApplicationAdapter::WasmPlatformApplicationAdapter(MessageBroker& broker, IStoneApplication& application)
12 : IObserver(broker), 12 : IObserver(broker),
13 application_(application) 13 application_(application)
14 {
15 }
16
17 void WasmPlatformApplicationAdapter::HandleCommandFromWeb(std::string& output, const std::string& input)
18 {
19 try
14 { 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 }
15 } 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 }
16 45
17 void WasmPlatformApplicationAdapter::HandleMessageFromWeb(std::string& output, const std::string& input) 46 void WasmPlatformApplicationAdapter::HandleSerializedMessageFromWeb(std::string& output, const std::string& input)
47 {
48 try
18 { 49 {
19 try 50 application_.HandleSerializedMessage(input.c_str());
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 message from web (error code = %d):\n", exc.GetErrorCode());
35 printf("While interpreting input: '%s'\n", input.c_str());
36 }
37 } 51 }
52 catch (StoneException& exc)
53 {
54 printf("Error while handling message from web (error code = %d):\n", exc.GetErrorCode());
55 printf("While interpreting input: '%s'\n", input.c_str());
56 output = std::string("ERROR : ");
57 }
58 catch (std::exception& exc)
59 {
60 printf("Error while handling message from web (error text = %s):\n", exc.what());
61 printf("While interpreting input: '%s'\n", input.c_str());
62 output = std::string("ERROR : ");
63 }
64 }
38 65
39 void WasmPlatformApplicationAdapter::NotifyStatusUpdateFromCppToWeb(const std::string& statusUpdateMessage) 66 void WasmPlatformApplicationAdapter::NotifyStatusUpdateFromCppToWebWithString(const std::string& statusUpdateMessage)
67 {
68 try
40 { 69 {
41 try 70 UpdateStoneApplicationStatusFromCppWithString(statusUpdateMessage.c_str());
42 {
43 UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str());
44 }
45 catch (...)
46 {
47 printf("Error while handling message to web\n");
48 }
49 } 71 }
72 catch (...)
73 {
74 printf("Error while handling string message to web\n");
75 }
76 }
77
78 void WasmPlatformApplicationAdapter::NotifyStatusUpdateFromCppToWebWithSerializedMessage(const std::string& statusUpdateMessage)
79 {
80 try
81 {
82 UpdateStoneApplicationStatusFromCppWithSerializedMessage(statusUpdateMessage.c_str());
83 }
84 catch (...)
85 {
86 printf("Error while handling serialized message to web\n");
87 }
88 }
50 89
51 } 90 }