~aleteoryx/muditaos

ref: 6e76dc3e5f1381725ee1de3c11c35d74fd9242d2 muditaos/module-services/service-desktop/endpoints/factoryReset/FactoryResetEndpoint.cpp -rw-r--r-- 1.4 KiB
6e76dc3e — Mateusz Szczesny [BH-1787] Reboot to MSC endpoint 2 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
41
42
43
44
45
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <endpoints/factoryReset/FactoryResetEndpoint.hpp>

#include <endpoints/JsonKeyNames.hpp>
#include <endpoints/message/Sender.hpp>
#include <service-desktop/DesktopMessages.hpp>
#include <service-desktop/ServiceDesktop.hpp>

#include <json11.hpp>

#include <memory>

namespace sdesktop::endpoints
{

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

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

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

            sender::putToSendQueue(context.createSimpleResponse());

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

            sender::putToSendQueue(context.createSimpleResponse());

            return;
        }
    }

} // namespace sdesktop::endpoints