mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-06-12 10:35:15 -04:00
1. Prepare Pure and Bell specific `Application` classes and add them to `app` target: - `products/BellHybrid/apps/Application.cpp` - `products/PurePhone/apps/Application.cpp` 2. Update `CMakeLists.txt` files. 3. Move `ApplicationBell` implementation to Bell-specific `Application` class and remove `ApplicationBell` files. 4. Change Bell apps parent classes from `ApplicationBell` to Bell-specific `Application` class. 5. Rename `Application` to `ApplicationCommon` in the rest of the files.
92 lines
3.3 KiB
C++
92 lines
3.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
|
|
|
|
#include "AudioOperations.hpp"
|
|
|
|
#include <log.hpp>
|
|
#include <service-audio/AudioServiceAPI.hpp>
|
|
#include <service-audio/AudioServiceName.hpp>
|
|
#include <time/ScopedTime.hpp>
|
|
#include <purefs/filesystem_paths.hpp>
|
|
#include <service-audio/AudioMessage.hpp>
|
|
|
|
#include <filesystem>
|
|
|
|
namespace app
|
|
{
|
|
AsyncAudioOperations::AsyncAudioOperations(ApplicationCommon *application)
|
|
: app::AsyncCallbackReceiver{application}, application(application)
|
|
{}
|
|
|
|
bool AsyncAudioOperations::play(const std::string &filePath, const OnPlayCallback &callback)
|
|
{
|
|
auto msg = std::make_unique<AudioStartPlaybackRequest>(filePath, audio::PlaybackType::Multimedia);
|
|
auto task = app::AsyncRequest::createFromMessage(std::move(msg), service::name::audio);
|
|
auto cb = [callback](auto response) {
|
|
auto result = dynamic_cast<AudioStartPlaybackResponse *>(response);
|
|
if (result == nullptr) {
|
|
return false;
|
|
}
|
|
if (callback) {
|
|
callback(result->retCode, result->token);
|
|
}
|
|
return true;
|
|
};
|
|
task->execute(application, this, cb);
|
|
return true;
|
|
}
|
|
|
|
bool AsyncAudioOperations::pause(const audio::Token &token, const OnPauseCallback &callback)
|
|
{
|
|
auto msg = std::make_unique<AudioPauseRequest>(token);
|
|
auto task = app::AsyncRequest::createFromMessage(std::move(msg), service::name::audio);
|
|
auto cb = [callback](auto response) {
|
|
auto result = dynamic_cast<AudioPauseResponse *>(response);
|
|
if (result == nullptr) {
|
|
return false;
|
|
}
|
|
if (callback) {
|
|
callback(result->retCode, result->token);
|
|
}
|
|
return true;
|
|
};
|
|
task->execute(application, this, cb);
|
|
return true;
|
|
}
|
|
bool AsyncAudioOperations::resume(const audio::Token &token, const OnResumeCallback &callback)
|
|
{
|
|
auto msg = std::make_unique<AudioResumeRequest>(token);
|
|
auto task = app::AsyncRequest::createFromMessage(std::move(msg), service::name::audio);
|
|
auto cb = [callback](auto response) {
|
|
auto result = dynamic_cast<AudioResumeResponse *>(response);
|
|
if (result == nullptr) {
|
|
return false;
|
|
}
|
|
if (callback) {
|
|
callback(result->retCode, result->token);
|
|
}
|
|
return true;
|
|
};
|
|
task->execute(application, this, cb);
|
|
return true;
|
|
}
|
|
bool AsyncAudioOperations::stop(const audio::Token &token, const OnStopCallback &callback)
|
|
{
|
|
auto msg = std::make_unique<AudioStopRequest>(token);
|
|
auto task = app::AsyncRequest::createFromMessage(std::move(msg), service::name::audio);
|
|
auto cb = [callback](auto response) {
|
|
auto result = dynamic_cast<AudioStopResponse *>(response);
|
|
if (result == nullptr) {
|
|
return false;
|
|
}
|
|
if (callback) {
|
|
callback(result->retCode, result->token);
|
|
}
|
|
return true;
|
|
};
|
|
task->execute(application, this, cb);
|
|
return true;
|
|
}
|
|
|
|
} // namespace app
|