~aleteoryx/muditaos

ref: bba04acbe0ac6234cb207704fcfb58259196a9af muditaos/module-services/service-desktop/endpoints/reboot/RebootHelper.cpp -rw-r--r-- 1.3 KiB
bba04acb — Lefucjusz [BH-2075] Add GET method to time sync endpoint 1 year, 2 months 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

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

#include <json11.hpp>

namespace sdesktop::endpoints
{
    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