From 4bdfb00de7c148ef00ecfed9748e449f57cc18a9 Mon Sep 17 00:00:00 2001 From: Radoslaw Wicik Date: Fri, 6 Nov 2020 17:00:25 +0100 Subject: [PATCH] [EGD-4214] Convert service audio to library --- module-apps/Application.cpp | 48 +++++++++++++++++++ module-apps/Application.hpp | 45 ++--------------- module-apps/CMakeLists.txt | 1 + .../application-call/ApplicationCall.cpp | 4 +- module-apps/application-call/CMakeLists.txt | 7 ++- .../application-call/windows/CallWindow.cpp | 4 +- .../application-meditation/CMakeLists.txt | 7 ++- .../widgets/MeditationTimer.cpp | 3 +- .../windows/MeditationTimerWindow.hpp | 4 +- .../ApplicationMusicPlayer.cpp | 5 +- .../ApplicationMusicPlayer.hpp | 3 +- .../application-music-player/CMakeLists.txt | 7 ++- .../models/SongsModel.cpp | 4 +- .../models/SongsModel.hpp | 3 +- .../windows/MusicPlayerAllSongsWindow.cpp | 4 +- .../windows/MusicPlayerEmptyWindow.cpp | 4 +- .../windows/QuotesMainWindow.hpp | 4 +- module-apps/windows/AppWindow.cpp | 4 +- module-apps/windows/AppWindow.hpp | 3 +- .../interface/profiles/A2DP/A2DP.cpp | 4 +- .../Bluetooth/interface/profiles/HSP/HSP.cpp | 4 +- .../Bluetooth/interface/profiles/HSP/SCO.cpp | 4 +- module-bluetooth/CMakeLists.txt | 3 +- .../service-antenna/CMakeLists.txt | 7 +-- module-services/service-appmgr/CMakeLists.txt | 5 +- .../{api => }/AudioServiceAPI.cpp | 18 +++---- module-services/service-audio/CMakeLists.txt | 35 +++++++------- .../service-audio/ServiceAudio.cpp | 12 ++--- .../AudioMessage.hpp | 11 +++-- .../AudioServiceAPI.hpp | 19 ++++---- .../{ => service-audio}/ServiceAudio.hpp | 21 ++++---- .../service-cellular/CMakeLists.txt | 1 + .../service-cellular/ServiceCellular.cpp | 2 +- module-services/service-evtmgr/CMakeLists.txt | 6 ++- .../service-evtmgr/EventManager.cpp | 6 +-- .../service-evtmgr/WorkerEvent.cpp | 2 +- 36 files changed, 184 insertions(+), 140 deletions(-) rename module-services/service-audio/{api => }/AudioServiceAPI.cpp (87%) rename module-services/service-audio/{messages => service-audio}/AudioMessage.hpp (96%) rename module-services/service-audio/{api => service-audio}/AudioServiceAPI.hpp (92%) rename module-services/service-audio/{ => service-audio}/ServiceAudio.hpp (97%) diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index 95ce17cb0..10e63da22 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -32,6 +32,8 @@ #include #include +#include // for GetOutputVolume + namespace gui { class DrawCommand; @@ -523,11 +525,57 @@ namespace app return ret == audio::RetCode::Success; } + auto Application::getVolume(audio::Volume &volume, + const audio::Profile::Type &profileType, + const audio::PlaybackType &playbackType) + { + return AudioServiceAPI::GetSetting(this, audio::Setting::Volume, volume, playbackType, profileType); + } + bool Application::adjustCurrentVolume(const int step) { return AudioServiceAPI::KeyPressed(this, step); } + audio::RetCode Application::getCurrentVolume(audio::Volume &volume) + { + return AudioServiceAPI::GetSetting(this, audio::Setting::Volume, volume); + } + + void Application::toggleTorchAndColourTemps() + { + using namespace bsp; + + auto retGetState = sys::Bus::SendUnicast(std::make_shared(torch::Action::getState), + service::name::evt_manager, + this, + pdMS_TO_TICKS(1500)); + if (retGetState.first == sys::ReturnCodes::Success) { + auto msgGetState = dynamic_cast(retGetState.second.get()); + if (msgGetState == nullptr) { + return; + } + auto msgSetState = std::make_shared(torch::Action::setState); + + switch (msgGetState->state) { + case torch::State::off: + msgSetState->state = torch::State::on; + msgSetState->colourTemp = torch::warmest; + break; + case torch::State::on: + if (msgGetState->colourTemp == torch::warmest) { // toggle colour temp + msgSetState->state = torch::State::on; + msgSetState->colourTemp = torch::coldest; + } + else { + msgSetState->state = torch::State::off; + } + break; + } + sys::Bus::SendUnicast(msgSetState, service::name::evt_manager, this); + } + } + void Application::requestAction(sys::Service *sender, const ApplicationName &applicationName, manager::actions::ActionId actionId, diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 8c95e4b73..19649515b 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -5,7 +5,6 @@ #include "Audio/AudioCommon.hpp" // for Volume, Play... #include "Audio/Profiles/Profile.hpp" // for Profile, Pro... -#include "AudioServiceAPI.hpp" // for GetOutputVolume #include "Interface/SettingsRecord.hpp" // for SettingsRecord #include "Service/Bus.hpp" // for Bus #include "Service/Common.hpp" // for ReturnCodes @@ -276,10 +275,7 @@ namespace app auto getVolume(audio::Volume &volume, const audio::Profile::Type &profileType, - const audio::PlaybackType &playbackType) - { - return AudioServiceAPI::GetSetting(this, audio::Setting::Volume, volume, playbackType, profileType); - } + const audio::PlaybackType &playbackType); bool adjustCurrentVolume(const int step); bool increaseCurrentVolume(const audio::Volume step = audio::defaultVolumeStep) @@ -290,44 +286,9 @@ namespace app { return adjustCurrentVolume(-step); } - auto getCurrentVolume(audio::Volume &volume) - { - return AudioServiceAPI::GetSetting(this, audio::Setting::Volume, volume); - } + audio::RetCode getCurrentVolume(audio::Volume &volume); - void toggleTorchAndColourTemps() - { - using namespace bsp; - - auto retGetState = sys::Bus::SendUnicast(std::make_shared(torch::Action::getState), - service::name::evt_manager, - this, - pdMS_TO_TICKS(1500)); - if (retGetState.first == sys::ReturnCodes::Success) { - auto msgGetState = dynamic_cast(retGetState.second.get()); - if (msgGetState == nullptr) { - return; - } - auto msgSetState = std::make_shared(torch::Action::setState); - - switch (msgGetState->state) { - case torch::State::off: - msgSetState->state = torch::State::on; - msgSetState->colourTemp = torch::warmest; - break; - case torch::State::on: - if (msgGetState->colourTemp == torch::warmest) { // toggle colour temp - msgSetState->state = torch::State::on; - msgSetState->colourTemp = torch::coldest; - } - else { - msgSetState->state = torch::State::off; - } - break; - } - sys::Bus::SendUnicast(msgSetState, service::name::evt_manager, this); - } - } + void toggleTorchAndColourTemps(); /// @defgroup Application Application static functions /// All this functions are meant to be used in ApplicationManager only diff --git a/module-apps/CMakeLists.txt b/module-apps/CMakeLists.txt index 4b133a1f6..f00019d06 100644 --- a/module-apps/CMakeLists.txt +++ b/module-apps/CMakeLists.txt @@ -91,6 +91,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE service-appmgr service-antenna + service-audio PUBLIC module-bsp module-os diff --git a/module-apps/application-call/ApplicationCall.cpp b/module-apps/application-call/ApplicationCall.cpp index 72130a355..9edbf6739 100644 --- a/module-apps/application-call/ApplicationCall.cpp +++ b/module-apps/application-call/ApplicationCall.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationCall.hpp" @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include