~aleteoryx/muditaos

muditaos/module-cellular/at/Urc.hpp -rw-r--r-- 2.3 KiB
a405cad6Aleteoryx trim readme 6 days 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
86
87
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <Utils.hpp>
#include "UrcHandler.hpp"

namespace at::urc

{
    class Urc
    {
      public:
        /**
         * Parses Urc body and constructs an instance.
         * @param urcBody - Urc message body without the header
         * @param urcHead - Urc message head
         * @param tokenDelimiter - sign that separates parameters in Urc message
         */
        Urc(const std::string &urcBody, const std::string &urcHead = std::string());

        virtual ~Urc() = default;

        /**
         * Checks weather Urc message is valid. Should be overridden in derived class of concrete Urc.
         * @return true if valid, false otherwise
         */
        virtual auto isValid() const noexcept -> bool
        {
            return !urcBody.empty() || !urcHead.empty();
        }

        /**
         * Gets vector of strings that represent Urc parameters.
         * @return vector or parameters in order of appearance in message
         */
        auto getTokens() const -> std::vector<std::string>;

        /**
         * Gets Urc body stripped of urc header.
         * @return Urc body string
         */
        auto getUrcBody() const -> std::string
        {
            return urcBody;
        }

        /**
         * Call for dispatching handling to UrcHandler
         * @param h - implementation of UrcHandler
         */
        virtual void Handle(UrcHandler &h)
        {}

        /**
         * Flag Urc handled/unhandled
         * @param state - true for handled, false for unhandled
         */
        void setHandled(bool state)
        {
            isUrcHandled = state;
        }

        /**
         * @return true if Urc has been flagged as handled, false otherwise
         */
        bool isHandled()
        {
            return isUrcHandled;
        }

      protected:
        std::vector<std::string> tokens;
        std::string urcBody;
        std::string urcHead;

        bool isUrcHandled = false;

        /**
         * Splits Urc into head and tokenized data, cleans tokens from whitespaces and quotes
         * @param str - string to be split
         */
        virtual void split(const std::string &str);
    };

} // namespace at::urc