~aleteoryx/muditaos

ref: 5447774803ddda4df9e2e54ee7778c80a317ca92 muditaos/module-apps/application-call/model/CallModel.hpp -rw-r--r-- 3.8 KiB
54477748 — Mateusz Piesta [BH-1449] Fix crash during startup 3 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
// Copyright (c) 2017-2022, 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
    };

    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 "Ended";
        }
        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 void transmitDtmfTone(const uint32_t &digit) = 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;
        void transmitDtmfTone(const uint32_t &digit) 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