~aleteoryx/muditaos

ref: f4bcc5ce6f0d66f6ee55949f9978ad0c0399fddb muditaos/module-apps/application-call/model/CallModel.hpp -rw-r--r-- 4.1 KiB
f4bcc5ce — Dawid Wojtas [BH-1758] Fix information about next alarm ring 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
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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <module-utils/time/time/time_conversion.hpp>
#include <module-utils/phonenumber/PhoneNumber.hpp>

#include <products/PurePhone/apps/include/Application.hpp>

#include <cstdint>

namespace app::call
{
    enum class CallState
    {
        None,
        Incoming,
        Outgoing,
        Active,
        Ended,
        Rejected,
        Missed,
        Disconnecting
    };

    inline auto c_str(app::call::CallState state) -> const char *
    {
        switch (state) {
        case CallState::None:
            return "None";
        case CallState::Incoming:
            return "Incoming";
        case CallState::Outgoing:
            return "Outgoing";
        case CallState::Active:
            return "Active";
        case CallState::Ended:
            return "Ended";
        case CallState::Rejected:
            return "Rejected";
        case CallState::Missed:
            return "Missed";
        case CallState::Disconnecting:
            return "Disconnecting";
        }
        return "";
    }

    class AbstractCallModel
    {
      public:
        virtual ~AbstractCallModel() noexcept                        = default;
        virtual time_t getTime()                                     = 0;
        virtual void setTime(time_t newTime)                         = 0;
        virtual CallState getState()                                 = 0;
        virtual void setState(CallState newState)                    = 0;
        virtual void setPhoneNumber(const utils::PhoneNumber number) = 0;
        virtual utils::PhoneNumber getPhoneNumber()                  = 0;
        virtual UTF8 getCallerId()                                   = 0;

        virtual void hangUpCall()                               = 0;
        virtual void answerCall()                               = 0;
        virtual bool sendSms(const UTF8 &smsBody)               = 0;
        virtual void transmitDtmfTone(const uint8_t &digitCode) = 0;
        virtual void muteCall()                                 = 0;
        virtual void unmuteCall()                               = 0;
        virtual void turnLoudspeakerOn()                        = 0;
        virtual void turnLoudspeakerOff()                       = 0;

        virtual void turnOnKeypadBacklight()  = 0;
        virtual void turnOffKeypadBacklight() = 0;

        virtual void clear()                                                       = 0;
        virtual void attachDurationChangeCallback(std::function<void()> callback)  = 0;
        virtual void attachCallStateChangeCallback(std::function<void()> callback) = 0;
    };

    class CallModel : public AbstractCallModel
    {
      public:
        CallModel() = delete;
        explicit CallModel(app::Application *app) : application(app){};
        time_t getTime() final;
        void setTime(time_t newTime) final;
        CallState getState() final;
        void setState(CallState newState) final;
        void setPhoneNumber(const utils::PhoneNumber number) final;
        utils::PhoneNumber getPhoneNumber() final;
        UTF8 getCallerId() final;

        void hangUpCall() final;
        void answerCall() final;
        bool sendSms(const UTF8 &smsBody) final;
        void transmitDtmfTone(const uint8_t &digitCode) final;
        void muteCall();
        void unmuteCall();
        void turnLoudspeakerOn();
        void turnLoudspeakerOff();

        void turnOnKeypadBacklight() final;
        void turnOffKeypadBacklight() final;

        void clear() final;
        void attachDurationChangeCallback(std::function<void()> callback) final;
        void attachCallStateChangeCallback(std::function<void()> callback) final;

      private:
        Application *application;
        CallState callState = CallState::None;
        time_t callTime     = 0;

        std::function<void()> notifyPresenterOnDurationChange;
        std::function<void()> notifyPresenterOnCallStateChange;

        utils::PhoneNumber phoneNumber;
        UTF8 callerId;

        bool callWasRejected = false;
    };
} // namespace app::call