~aleteoryx/muditaos

ref: 0a322b878cb26c450064e5e3d9ec825415de241c muditaos/module-sys/PhoneModes/Observer.hpp -rw-r--r-- 1.9 KiB
0a322b87 — Przemyslaw Brudny [EGD-6770] ListView onPageElement rebuild page jump added 4 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <functional>
#include <stdexcept>

#include "Common.hpp"

namespace sys
{
    class Service; // Forward declaration
} // namespace sys

namespace sys::phone_modes
{
    class Observer
    {
      public:
        using OnPhoneModeChangedCallback = std::function<void(PhoneMode)>;
        using OnTetheringChangedCallback = std::function<void(Tethering)>;
        using OnCompleteCallback = std::function<void()>;
        using OnErrorCallback    = std::function<void(const std::exception &)>;
        struct OnFinishedCallbacks
        {
            OnCompleteCallback onComplete;
            OnErrorCallback onError;
        };

        void connect(Service *owner);
        void subscribe(OnPhoneModeChangedCallback &&onChange,
                       OnCompleteCallback &&onComplete = {},
                       OnErrorCallback &&onError       = {}) noexcept;
        void subscribe(OnTetheringChangedCallback &&onChange,
                       OnCompleteCallback &&onComplete = {},
                       OnErrorCallback &&onError       = {}) noexcept;

        bool isInMode(PhoneMode mode) const noexcept;
        PhoneMode getCurrentPhoneMode() const noexcept;
        bool isTetheringOn() const noexcept;

      private:
        sys::MessagePointer handlePhoneModeChange(PhoneModeChanged *message);
        sys::MessagePointer handleTetheringChange(TetheringChanged *message);

        OnPhoneModeChangedCallback onPhoneModeChangedCallback;
        OnTetheringChangedCallback onTetheringChangedCallback;
        OnFinishedCallbacks onPhoneModeChangeFinished;
        OnFinishedCallbacks onTetheringChangeFinished;
        PhoneMode phoneMode     = PhoneMode::Connected;
        Tethering tetheringMode = Tethering::Off;
    };
} // namespace sys::phone_modes