From 9fbdc1ab1153c19e672aa5df034060e82177d80b Mon Sep 17 00:00:00 2001 From: Ryszard Matuszyk Date: Thu, 5 Feb 2015 14:19:07 +0100 Subject: [PATCH] [Sound] getVolume [Verification] SoundManager_getVolume tct test should be pass Change-Id: Idad3d08915060cff025c5afe8f1633de271cb461 Signed-off-by: Ryszard Matuszyk --- src/sound/sound_instance.cc | 15 ++++++--------- src/sound/sound_manager.cc | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/sound/sound_instance.cc b/src/sound/sound_instance.cc index 712ab82f..eddd3663 100644 --- a/src/sound/sound_instance.cc +++ b/src/sound/sound_instance.cc @@ -70,17 +70,14 @@ void SoundInstance::SoundManagerSetVolume(const picojson::value& args, ReportSuccess(out); } -void SoundInstance::SoundManagerGetVolume(const picojson::value& args, picojson::object& out) { - - // implement it - - - // if success - // ReportSuccess(out); - // if error - // ReportError(out); +void SoundInstance::SoundManagerGetVolume(const picojson::value& args, + picojson::object& out) { + ReportSuccess(picojson::value(static_cast( + manager_->GetVolume(args.get()))), + out); } + void SoundInstance::SoundManagerSetSoundModeChangeListener(const picojson::value& args, picojson::object& out) { CHECK_EXIST(args, "callbackId", out) diff --git a/src/sound/sound_manager.cc b/src/sound/sound_manager.cc index aa10af1f..7cce879b 100644 --- a/src/sound/sound_manager.cc +++ b/src/sound/sound_manager.cc @@ -103,7 +103,30 @@ void SoundManager::SetVolume(const picojson::object& args) { } } -double SoundManager::GetVolume(const picojson::object& args) {} +double SoundManager::GetVolume(const picojson::object& args) { + const std::string& type = FromJson(args, "type"); + const sound_type_e type_enum = SoundManager::StrToPlatformEnum(type); + + auto it = max_volume_map_.find(type_enum); + if (it == max_volume_map_.end()) { + LoggerE("Failed to find maxVolume of type: %s", type.c_str()); + // TODO: throw UnknownException("Failed to find maxVolume"); + } + + int max_volume = it->second; + int value; + + int ret = sound_manager_get_volume(type_enum, &value); + if (ret != SOUND_MANAGER_ERROR_NONE) { + LoggerE("Failed to get volume: %d", ret); + // TODO: throw UnknownException("Failed to get volume"); + } + + double volume = static_cast(value) / max_volume; + LoggerD("volume: %lf, maxVolume: %d, value: %d", volume, max_volume, value); + + return volume; +} void SoundManager::SetSoundModeChangeListener(const picojson::object& args) {} -- 2.34.1