~aleteoryx/muditaos

ref: 44d3306f280cc7d6daa718d2a9f6323e48f54616 muditaos/module-cellular/at/src/UrcFactory.cpp -rw-r--r-- 2.0 KiB
44d3306f — rrandomsky [CP-1059] Fix for erase only sensitive data from logs 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <UrcFactory.hpp>

#include <UrcCreg.hpp>
#include <UrcCtze.hpp>
#include <UrcCusd.hpp>
#include <UrcQind.hpp>
#include <UrcCmti.hpp>
#include <UrcClip.hpp>
#include <UrcPoweredDown.hpp>
#include <UrcResponse.hpp>
#include <UrcCpin.hpp>
#include <UrcQiurc.hpp>
#include <UrcRing.hpp>
#include <UrcQSimstat.hpp>

using namespace at::urc;

std::unique_ptr<Urc> UrcFactory::Create(const std::string &urcMessage)
{
    if (urcMessage.empty()) {
        return std::make_unique<Urc>(std::string());
    }
    const auto headDelimiter = ':';
    const auto it            = std::find(urcMessage.begin(), urcMessage.end(), headDelimiter);
    const auto &head         = utils::trim(std::string(urcMessage.begin(), it));
    const auto &body         = std::string(it == urcMessage.end() ? urcMessage.begin() : it + 1, urcMessage.end());

    if (Ctze::isURC(head)) {
        return std::make_unique<Ctze>(body);
    }
    else if (Creg::isURC(head)) {
        return std::make_unique<Creg>(body);
    }
    else if (Qind::isURC(head)) {
        return std::make_unique<Qind>(body);
    }
    else if (Cusd::isURC(head)) {
        return std::make_unique<Cusd>(body);
    }
    else if (Cmti::isURC(head)) {
        return std::make_unique<Cmti>(body);
    }
    else if (Clip::isURC(head)) {
        return std::make_unique<Clip>(body);
    }
    else if (Cpin::isURC(head)) {
        return std::make_unique<Cpin>(body);
    }
    else if (PoweredDown::isURC(head)) {
        return std::make_unique<PoweredDown>(body);
    }
    else if (Ring::isURC(head)) {
        return std::make_unique<Ring>(body);
    }
    else if (auto type = UrcResponse::isURC(head)) {
        return std::make_unique<UrcResponse>(type.value());
    }
    else if (Qiurc::isURC(head)) {
        return std::make_unique<Qiurc>(body);
    }
    else if (QSimstat::isURC(head)) {
        return std::make_unique<QSimstat>(body);
    }

    return std::make_unique<Urc>(body, head);
}