~aleteoryx/muditaos

ref: 50f28e8f19b23384aac9efd5c22cc155d451cace muditaos/module-services/service-cellular/CallRequestFactory.cpp -rw-r--r-- 1.2 KiB
50f28e8f — Bartosz Cichocki [EGD-4270] updated test API, added sending message case in test harness (#1042) 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-cellular/CallRequestFactory.hpp"

#include <re2/re2.h>

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

namespace call_request
{
    constexpr inline auto IMEIRegex = "(\\*#06#)";
    constexpr inline auto USSDRegex = "^[\\*].*[\\#]$";

    Factory::Factory(const std::string &data) : request(data)
    {
        registerRequest(IMEIRegex, IMEIRequest::create);

        /*It have to be last check due to 3GPP TS 22.030*/
        registerRequest(USSDRegex, USSDRequest::create);
    }

    void Factory::registerRequest(std::string regex, CreateCallback callback)
    {
        requestMap.insert(std::make_pair(regex, callback));
    }

    std::unique_ptr<IRequest> Factory::create()
    {
        for (const auto &element : requestMap) {
            re2::StringPiece input(request);
            re2::RE2 reg(element.first);
            if (re2::RE2::FullMatch(input, reg)) {
                return element.second(request);
            }
        }
        return std::make_unique<CallRequest>(request);
    }

} // namespace call_request