Mercurial > hg > orthanc-stone
diff Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 307:be2660b6e40a am-callable-and-promise
wip: commands + status update
author | am@osimis.io |
---|---|
date | Tue, 25 Sep 2018 15:14:53 +0200 |
parents | |
children | daa04d15192c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Platforms/Wasm/WasmPlatformApplicationAdapter.cpp Tue Sep 25 15:14:53 2018 +0200 @@ -0,0 +1,42 @@ +#include "WasmPlatformApplicationAdapter.h" + +#include "Framework/Toolbox/MessagingToolbox.h" +#include "Framework/StoneException.h" +#include <Applications/Commands/BaseCommandBuilder.h> +#include <stdio.h> +#include "Platforms/Wasm/Defaults.h" + +namespace OrthancStone +{ + WasmPlatformApplicationAdapter::WasmPlatformApplicationAdapter(MessageBroker& broker, IStoneApplication& application) + : IObserver(broker), + application_(application) + { + } + + void WasmPlatformApplicationAdapter::HandleMessageFromWeb(std::string& output, const std::string& input) + { + try + { + Json::Value inputJson; + if (MessagingToolbox::ParseJson(inputJson, input.c_str(), input.size())) + { + std::unique_ptr<ICommand> command(application_.GetCommandBuilder().CreateFromJson(inputJson)); + application_.ExecuteCommand(*command); + } + } + catch (StoneException& exc) + { + printf("Error while handling message from web (error code = %d):\n", exc.GetErrorCode()); + printf("While interpreting input: '%s'\n", input.c_str()); + } + } + + void WasmPlatformApplicationAdapter::NotifyStatusUpdateFromCppToWeb(const std::string& statusUpdateMessage) + { + printf("NotifyStatusUpdateFromCppToWeb (TODO)\n"); + UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str()); + printf("NotifyStatusUpdateFromCppToWeb (DONE)\n"); + } + +} \ No newline at end of file