Files
MuditaOS/module-services/service-desktop/endpoints/developerMode/DeveloperModeEndpoint.cpp
Adam Dobrowolski 2a709ced4b [CP-325] Request reboot code adjusted to work with harness
We have no controll on UART over the device flushing, minimum code
added to assure that data could be flushed
We do not close services when these are closed with reason
2021-07-12 12:59:19 +02:00

45 lines
1.4 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "DeveloperModeEndpoint.hpp"
#include <log.hpp>
#include <endpoints/Context.hpp>
#include <service-desktop/parser/MessageHandler.hpp>
using namespace parserFSM;
auto DeveloperModeEndpoint::handle(Context &context) -> void
{
auto &p = helperSwitcher(context);
auto [sent, response] = p.process(context.getMethod(), context);
if (sent == sent::delayed) {
LOG_DEBUG("There is no proper delayed serving mechanism - depend on invisible context caching");
}
if (sent == sent::no) {
if (not response) {
LOG_ERROR("Response not sent & response not created : respond with error");
context.setResponseStatus(http::Code::NotAcceptable);
}
else {
context.setResponse(response.value());
}
MessageHandler::putToSendQueue(context.createSimpleResponse());
}
if (sent == sent::yes and response) {
LOG_ERROR("Response set when we already handled response in handler");
}
}
auto DeveloperModeEndpoint::helperSwitcher(parserFSM::Context &ctx) -> parserFSM::BaseHelper &
{
if (ctx.getBody()["ui"] == true) {
return *uiHelper;
}
if (ctx.getBody()["update"] == true) {
return *updateHelper;
}
return *helper;
}