[Sound] getVolume
authorRyszard Matuszyk <r.matuszyk@samsung.com>
Thu, 5 Feb 2015 13:19:07 +0000 (14:19 +0100)
committerRyszard Matuszyk <r.matuszyk@samsung.com>
Fri, 6 Feb 2015 13:08:44 +0000 (14:08 +0100)
[Verification] SoundManager_getVolume tct test should be pass

Change-Id: Idad3d08915060cff025c5afe8f1633de271cb461
Signed-off-by: Ryszard Matuszyk <r.matuszyk@samsung.com>
src/sound/sound_instance.cc
src/sound/sound_manager.cc

index 712ab82..eddd366 100644 (file)
@@ -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<double>(
+                    manager_->GetVolume(args.get<picojson::object>()))),
+                out);
 }
+
 void SoundInstance::SoundManagerSetSoundModeChangeListener(const picojson::value& args, picojson::object& out) {
   CHECK_EXIST(args, "callbackId", out)
 
index aa10af1..7cce879 100644 (file)
@@ -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<std::string>(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<double>(value) / max_volume;
+  LoggerD("volume: %lf, maxVolume: %d, value: %d", volume, max_volume, value);
+
+  return volume;
+}
 
 void SoundManager::SetSoundModeChangeListener(const picojson::object& args) {}