~aleteoryx/muditaos

ref: 2de71a003692ec1207cd4f0258379f82500f378f muditaos/module-services/service-cellular/call/CellularCall.cpp -rw-r--r-- 3.9 KiB
2de71a00 — Maciej-Mudita [MOS-74] Fix wrong tethering popup order 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
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
139
140
141
142
143
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "call/CellularCall.hpp"
#include "service-cellular/ServiceCellular.hpp"

#include <log/log.hpp>

#include <memory>
#include <utility>
#include "CallMachine.hpp"

namespace call
{

    Call::Call()
    {}

    Call::Call(ServiceCellular *owner,
               CellularMux *cmux,
               sys::TimerHandle timer,
               sys::TimerHandle timerRing,
               std::shared_ptr<sys::CpuSentinel> sentinel)
    {
        machine = std::make_unique<StateMachine>(Dependencies{std::make_unique<Audio>(owner),
                                                              std::make_unique<CallMulticast>(owner),
                                                              std::make_unique<CallGUI>(owner),
                                                              std::make_unique<CallDB>(owner),
                                                              std::make_unique<CallTimer>(std::move(timer)),
                                                              std::make_unique<TimerRing>(std::move(timerRing)),
                                                              std::make_unique<cellular::Api>(owner, cmux),
                                                              std::move(sentinel)});
    }

    Call::~Call()
    {}

    Call &Call::operator=(Call &&other) noexcept
    {
        if (not other.machine) {
            LOG_ERROR("operator= on wrong call");
            return *this;
        }
        machine = std::make_unique<StateMachine>(std::move(other.machine->di));
        return *this;
    }

    bool Call::handle(const call::event::RING &ring)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(ring);
    }

    bool Call::handle(const call::event::CLIP &clip)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(clip);
    }

    bool Call::handle(const call::event::StartCall &call)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(call);
    }

    bool Call::handle(const call::event::Ended &ended)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(ended);
    }

    bool Call::handle(const call::event::Reject &reject)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(reject);
    }

    bool Call::handle(const call::event::AudioRequest &request)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(request);
    }

    bool Call::handle(const call::event::ModeChange &change)
    {
        if (machine == nullptr) {
            return false;
        };
        machine->call.mode = change.mode;
        return true;
    }

    bool Call::handle(const call::event::TetheringChange &change)
    {
        if (machine == nullptr) {
            return false;
        };
        machine->call.tethering = change.tethering;
        return true;
    }

    bool Call::handle(const call::event::Answer &answer)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(answer);
    }

    bool Call::handle(const call::event::OngoingTimer &tim)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(tim);
    }

    bool Call::handle(const call::event::RingTimeout &tim)
    {
        if (machine == nullptr) {
            return false;
        };
        return machine->machine.process_event(tim);
    }

    bool Call::active() const
    {
        return machine->active();
    }

} // namespace CellularCall