~aleteoryx/muditaos

ref: 95d96b82b63c85af4f655d10e52c5612121c23f6 muditaos/module-services/service-desktop/endpoints/factoryReset/FactoryResetEndpoint.cpp -rw-r--r-- 1.3 KiB
95d96b82 — Pawel.Paprocki [BH-370] Convert utils common_data into a libs 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "FactoryResetEndpoint.hpp"

#include <endpoints/Context.hpp>
#include <parser/MessageHandler.hpp>
#include <service-desktop/DesktopMessages.hpp>
#include <service-desktop/ServiceDesktop.hpp>

#include <json/json11.hpp>

#include <memory>

auto FactoryResetEndpoint::handle(parserFSM::Context &context) -> void
{
    if (context.getMethod() == parserFSM::http::Method::post) {

        if (context.getBody()[parserFSM::json::factoryRequest] == true) {
            auto msg = std::make_shared<sdesktop::FactoryMessage>();
            ownerServicePtr->bus.sendUnicast(msg, service::name::service_desktop);

            context.setResponseBody(json11::Json::object({{parserFSM::json::factoryRequest, true}}));
        }
        else {
            context.setResponseBody(json11::Json::object({{parserFSM::json::factoryRequest, false}}));
        }

        parserFSM::MessageHandler::putToSendQueue(context.createSimpleResponse());

        return;
    }
    else {
        context.setResponseBody(json11::Json::object({{parserFSM::json::factoryRequest, false}}));

        parserFSM::MessageHandler::putToSendQueue(context.createSimpleResponse());

        return;
    }
}