~aleteoryx/muditaos

ref: 6e76dc3e5f1381725ee1de3c11c35d74fd9242d2 muditaos/module-services/service-desktop/endpoints/reboot/RebootHelper.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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

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

#include <json11.hpp>

namespace sdesktop::endpoints
{
    using sender::putToSendQueue;
    auto RebootHelper::processPost(Context &context) -> ProcessResult
    {
        const auto rebootType = context.getBody()[json::reboot::rebootType].string_value();

        if (rebootType == json::reboot::msc) {
            sys::SystemManagerCommon::RebootMSC(owner);
            return {sent::no, ResponseContext{.status = http::Code::Accepted}};
        }
        else if (rebootType == json::reboot::reboot) {
            sys::SystemManagerCommon::Reboot(owner);
            return {sent::no, ResponseContext{.status = http::Code::Accepted}};
        }
        else if (rebootType == json::reboot::shutdown) {
            sys::SystemManagerCommon::RegularPowerDown(owner);
            return {sent::no, ResponseContext{.status = http::Code::Accepted}};
        }
        LOG_ERROR("Invalid request: %s", rebootType.c_str());
        return {sent::no, ResponseContext{.status = http::Code::BadRequest}};
    }

} // namespace sdesktop::endpoints