~aleteoryx/muditaos

ref: 2276ceed679b93a3a891e4f5739ade9e13991c5a muditaos/module-services/service-cellular/CellularCall.hpp -rw-r--r-- 3.9 KiB
2276ceed — Radoslaw Wicik [EGD-3743] Update copyrights in fies 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <PhoneNumber.hpp>
#include <Interface/CalllogRecord.hpp>
#include <time/time_conversion.hpp>

#include <functional>
#include <string>

namespace ModemCall
{
    enum class CallState : uint8_t
    {
        Active = 0, // 0 active: call in progress (setup was successful)
        Held,       // 1 held: call on hold
        Dialing,    // 2 dialing (MO call): number dialed
        Alerting,   // 3 alerting (MO call): number dialed and the called party is alerted
        Incoming,   // 4 incoming (MT call): incoming call, ringtone played (AT RING notification)
        Waiting // 5 waiting (MT call): call waiting notification while another call is active (if call waiting feature
                // enabled)
    };

    enum class CallDir : uint8_t
    {
        MO = 0, // Mobile originated (MO) call
        MT = 1, // Mobile terminated (MT) call
    };

    enum class CallMode : uint8_t
    {
        Voice = 0,
        Data  = 1,
        FAX   = 2,
    };

    // TODO: alek: check specification
    enum class CallType : uint8_t
    {
        UknownType      = 129,
        InternationType = 145, // contains the "+" character
        NationalType    = 161,
    };

    struct ModemCall
    {
        int8_t idx;
        CallDir dir;
        CallState state;
        CallMode mode;
        bool isConferenceCall;
        std::string phoneNumber;
        CallType type;
        std::string phoneBookName; // TODO: alek: This field is defined in the AT+CLCC command resposne but our modem is
                                   // not returning it. Need to verify in modem specification

        ModemCall()  = delete;
        ~ModemCall() = default;
        ModemCall(const std::string str);

        friend std::ostream &operator<<(std::ostream &out, const ModemCall &call);
    };
} // namespace ModemCall

namespace CellularCall
{
    enum class Forced : bool
    {
        False,
        True
    };

    class CellularCall
    {
        CalllogRecord call;
        bool isActiveCall = false;
        std::function<CalllogRecord(const CalllogRecord &rec)> startCallAction;
        std::function<bool(const CalllogRecord &rec)> endCallAction;
        utils::time::Timestamp startActiveTime = 0;

        void setType(const CallType type)
        {
            call.type = type;
        }

        void markUnread()
        {
            call.isRead = false;
        }

        void clear()
        {
            call              = CalllogRecord();
            isActiveCall      = false;
            startActiveTime   = 0;
        }

      public:
        CellularCall(utils::PhoneNumber::View number = utils::PhoneNumber::View(),
                     const CallType type             = CallType::CT_NONE,
                     const time_t date               = 0,
                     const time_t duration           = 0)
        {
            clear();
            this->call.phoneNumber = number;
            this->call.date        = date;
            this->call.duration    = duration;
            this->call.type        = type;
            this->call.name        = number.getEntered(); // temporary set number as name
            this->call.contactId   = 0;
        }

        ~CellularCall() = default;

        void setStartCallAction(const std::function<CalllogRecord(const CalllogRecord &rec)> callAction)
        {
            startCallAction = callAction;
        }

        void setEndCallAction(const std::function<bool(const CalllogRecord &rec)> callAction)
        {
            endCallAction = callAction;
        }

        bool startCall(const utils::PhoneNumber::View &number, const CallType type);

        bool setActive();

        bool endCall(Forced forced = Forced::False);

        bool isValid() const
        {
            return call.ID != 0;
        }
    };
} // namespace CellularCall