~aleteoryx/muditaos

ref: 26c032128a4727b701d2e11732cbbf51fe90cc1c muditaos/module-services/service-cellular/requests/CallWaitingRequest.cpp -rw-r--r-- 2.6 KiB
26c03212 — Hubert Chrzaniuk [EGD-4413] New MMI codes support (#1051) 5 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <string>

#include <at/Commands.hpp>
#include <Utils.hpp>

#include "service-cellular/requests/CallWaitingRequest.hpp"

namespace cellular
{

    std::unique_ptr<SupplementaryServicesRequest> CallWaitingRequest::create(const std::string &serviceCode,
                                                                             const std::string &data,
                                                                             GroupMatch matchGroups)
    {
        if (serviceCode == callWaitingServiceCode) {
            return std::make_unique<CallWaitingRequest>(data, matchGroups);
        }
        else {
            return nullptr;
        }
    }

    auto CallWaitingRequest::command() -> std::string
    {
        if (!isValid()) {
            return std::string();
        }

        std::array<std::function<std::string()>, 3> commandParts = {
            [this]() { return this->getCommandPresentation(); },
            [this]() { return this->getCommandMode(); },
            [this]() { return this->getCommandClass(); },
        };

        std::string cmd(at::factory(at::AT::CCWA));
        bool formatFirst = true;
        for (auto &cmdPart : commandParts) {
            auto partStr = cmdPart();
            if (partStr.empty()) {
                continue;
            }
            cmd.append(formatFirst ? partStr : "," + partStr);
            formatFirst = false;
        }

        return cmd;
    }

    auto CallWaitingRequest::getCommandPresentation() const noexcept -> std::string
    {
        // fixed, we always want full report
        return unsolicitedResultCodeEnable;
    }

    auto CallWaitingRequest::getCommandMode() const noexcept -> std::string
    {
        return utils::to_string(magic_enum::enum_integer(procedureType));
    }

    auto CallWaitingRequest::getCommandClass() const noexcept -> std::string
    {
        if (basicServiceGroup.empty()) {
            return std::string();
        }

        return getCommandInformationClass(basicServiceGroup).value_or(std::string());
    }

    void CallWaitingRequest::handle(RequestHandler &h, at::Result &result)
    {
        h.handle(*this, result);
    }

    auto CallWaitingRequest::isValid() const noexcept -> bool
    {
        if (!getCommandInformationClass(basicServiceGroup).has_value()) {
            return false;
        }
        return procedureType != ProcedureType::Registration && procedureType != ProcedureType::Erasure;
    }

} // namespace cellular