~aleteoryx/muditaos

ref: fe8671698432b6877da6b8e911b8df77fc439922 muditaos/module-apps/application-call/ApplicationCall.hpp -rw-r--r-- 2.8 KiB
fe867169 — Piotr Tanski [EGD-4153] Use actions instead explicit applications switch. (#1032) 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
// 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 "Application.hpp"
#include "Service/Message.hpp"
#include "Service/Timer.hpp"
#include "SystemManager/SystemManager.hpp"
#include <service-cellular/CellularMessage.hpp>
#include <time/time_conversion.hpp>

namespace app
{
    inline constexpr auto name_call       = "ApplicationCall";
    inline constexpr auto call_stack_size = 8192U;

    namespace window
    {
        inline constexpr auto name_call              = "CallWindow";
        inline constexpr auto name_enterNumber       = "EnterNumberWindow";
        inline constexpr auto name_emergencyCall     = "EmergencyCallWindow";
        inline constexpr auto name_duplicatedContact = "DuplicatedContactWindow";
        inline constexpr auto name_dialogConfirm     = "DialogConfirm";
    } // namespace window

    inline constexpr auto ringtone_path = "assets/audio/Ringtone-drum2.mp3"; // Should bo moved to database

    class ApplicationCall : public Application
    {
      private:
        void CallAbortHandler();
        void CallActiveHandler();
        void IncomingCallHandler(const CellularCallMessage *const msg);
        void RingingHandler(const CellularCallMessage *const msg);

      protected:
        sys::ms callDelayedStopTime = 3000;

      public:
        ApplicationCall(std::string name                    = name_call,
                        std::string parent                  = {},
                        StartInBackground startInBackground = {false});
        sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override;
        sys::ReturnCodes InitHandler() override;
        sys::ReturnCodes DeinitHandler() override;

        sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final
        {
            return sys::ReturnCodes::Success;
        }

        void createUserInterface() override;
        void destroyUserInterface() override;
        void setDisplayedNumber(std::string num);
        const std::string &getDisplayedNumber();

        void handleCallEvent(const std::string &number);
        void handleAddContactEvent(const std::string &number);

        bool showNotification(std::function<bool()> action);
        void transmitDtmfTone(uint32_t digit);
        auto getDelayedStopTime() const
        {
            return callDelayedStopTime;
        }

        void stopAudio();
        void startRinging();
        void startRouting();
    };

    template <> struct ManifestTraits<ApplicationCall>
    {
        static auto GetManifest() -> manager::ApplicationManifest
        {
            return {{manager::actions::Launch, manager::actions::Call, manager::actions::Dial}};
        }
    };
} /* namespace app */