view Platforms/Wasm/WasmPlatformApplicationAdapter.cpp @ 457:3b4df9925db6 am-touch-events

added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
author Alain Mazy <alain@mazy.be>
date Thu, 24 Jan 2019 16:42:27 +0100
parents a902a07769d4
children 5055031f4a06
line wrap: on
line source

#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 the message is a command, build it and execute it
        if (MessagingToolbox::ParseJson(inputJson, input.c_str(), input.size()))
        {
            std::unique_ptr<ICommand> command(application_.GetCommandBuilder().CreateFromJson(inputJson));
            if (command.get() == NULL) 
              printf("Could not parse command: '%s'\n", input.c_str());
            else
              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)
    {
      try
      {
        UpdateStoneApplicationStatusFromCpp(statusUpdateMessage.c_str());
      }
      catch (...)
      {
        printf("Error while handling message to web\n");
      }
    }

}