annotate Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 319:daa04d15192c am-2

new SimpleViewer sample that has been split in multiple files to be able to scale it
author am@osimis.io
date Thu, 11 Oct 2018 13:16:54 +0200
parents be2660b6e40a
children a902a07769d4
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);
307
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
30 }
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 {
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
41 printf("NotifyStatusUpdateFromCppToWeb (TODO)\n");
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
42 UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str());
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
43 printf("NotifyStatusUpdateFromCppToWeb (DONE)\n");
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
44 }
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
45
be2660b6e40a wip: commands + status update
am@osimis.io
parents:
diff changeset
46 }