Files
MuditaOS/module-sys/PhoneModes/Observer.hpp
Hubert Chrzaniuk 4490d0da7f [EGD-5714] Add phone mode handling for Audio Service
Added separate set of settings for all phone modes along
with basic support for phone mode change.
2021-02-24 13:00:43 +01:00

45 lines
1.3 KiB
C++

// 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 OnChangeCallback = std::function<void(PhoneMode, Tethering)>;
using OnCompleteCallback = std::function<void()>;
using OnErrorCallback = std::function<void(const std::exception &)>;
void connect(Service *owner);
void subscribe(OnChangeCallback &&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);
void onPhoneModeChanged();
OnChangeCallback onChangeCallback;
OnCompleteCallback onCompleteCallback;
OnErrorCallback onErrorCallback;
PhoneMode phoneMode = PhoneMode::Connected;
Tethering tetheringMode = Tethering::Off;
};
} // namespace sys::phone_modes