annotate Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 466:5055031f4a06 bgo-commands-codegen

- Added browserify to build. This allows using require calls for modules that work with tsc compiler. - removed older stuff related to Protocol Buffers and Flatbuffers - changed triple-slash references to import statements - module prefixes are now added at call sites - added cmake module for filename handling - switched to Ninja for sample build - Added virtual dtor in ICommand
author bgo-osimis
date Mon, 11 Feb 2019 16:00:04 +0100
parents a902a07769d4
children 7105a0bad250
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
1 #include "WasmPlatformApplicationAdapter.h"
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
2
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
3 #include "Framework/Toolbox/MessagingToolbox.h"
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
4 #include "Framework/StoneException.h"
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
5 #include <Applications/Commands/BaseCommandBuilder.h>
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
6 #include <stdio.h>
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
7 #include "Platforms/Wasm/Defaults.h"
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
8
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
9 namespace OrthancStone
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
10 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
11 WasmPlatformApplicationAdapter::WasmPlatformApplicationAdapter(MessageBroker& broker, IStoneApplication& application)
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
12 : IObserver(broker),
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
13 application_(application)
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
14 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
15 }
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
16
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
17 void WasmPlatformApplicationAdapter::HandleMessageFromWeb(std::string& output, const std::string& input)
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
18 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
19 try
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
20 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
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
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
23 if (MessagingToolbox::ParseJson(inputJson, input.c_str(), input.size()))
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
24 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
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
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
31 }
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
32 catch (StoneException& exc)
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
33 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
34 printf("Error while handling message from web (error code = %d):\n", exc.GetErrorCode());
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
35 printf("While interpreting input: '%s'\n", input.c_str());
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
36 }
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
37 }
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
38
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
39 void WasmPlatformApplicationAdapter::NotifyStatusUpdateFromCppToWeb(const std::string& statusUpdateMessage)
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
40 {
322
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
41 try
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
42 {
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
43 UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str());
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
44 }
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
45 catch (...)
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
46 {
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
47 printf("Error while handling message to web\n");
a902a07769d4 wip: preload slice
am@osimis.io
parents: 319
diff changeset
48 }
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
49 }
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
50
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
51 }