#include "MediaFactory.h"
#include "plugin-log.h"
#include "MediaPlayer.h"
-#include "MediaVolume.h"
+#include "SoundVolume.h"
MODES_NAMESPACE_USE;
MediaFactory::MediaFactory()
{
actionMap[MediaPlayer::NAME] = PLAYER;
- actionMap[MediaVolume::NAME] = VOLUME;
+ actionMap[SoundVolume::NAME[MEDIA_VOLUME]] = MEDIA_VOLUME;
+ actionMap[SoundVolume::NAME[SYSTEM_VOLUME]] = SYSTEM_VOLUME;
+ actionMap[SoundVolume::NAME[RINGTONE_VOLUME]] = RINGTONE_VOLUME;
+ actionMap[SoundVolume::NAME[NOTIFICATION_VOLUME]] = NOTIFICATION_VOLUME;
}
MediaAction* MediaFactory::createAction(const std::string &key)
case PLAYER:
action = new MediaPlayer();
break;
- case VOLUME:
- action = new MediaVolume();
+ case MEDIA_VOLUME:
+ action = new SoundVolume(MEDIA_VOLUME, SOUND_TYPE_MEDIA);
+ break;
+ case SYSTEM_VOLUME:
+ action = new SoundVolume(SYSTEM_VOLUME, SOUND_TYPE_SYSTEM);
+ break;
+ case RINGTONE_VOLUME:
+ action = new SoundVolume(RINGTONE_VOLUME, SOUND_TYPE_RINGTONE);
+ break;
+ case NOTIFICATION_VOLUME:
+ action = new SoundVolume(NOTIFICATION_VOLUME, SOUND_TYPE_NOTIFICATION);
break;
default:
action = nullptr;
void destroyAction(MediaAction *action);
private:
enum actionKey{
- PLAYER,
- VOLUME
+ MEDIA_VOLUME,
+ SYSTEM_VOLUME,
+ RINGTONE_VOLUME,
+ NOTIFICATION_VOLUME,
+ PLAYER
};
std::map<std::string, enum actionKey> actionMap;
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "MediaVolume.h"
-#include <string>
-#include <sstream>
-#include <modes_errors.h>
-#include <player.h>
-#include "plugin-log.h"
-
-MODES_NAMESPACE_USE;
-
-const std::string MediaVolume::NAME = "volume";
-
-MediaVolume::MediaVolume()
- : MediaAction(NAME), oldVal(-1), volumeCallbackID(0), cb(NULL), cbData(NULL), requestVal(-1)
-{
-}
-
-void MediaVolume::volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data)
-{
- MediaVolume *action = (MediaVolume*)user_data;
- RET_IF(NULL == user_data);
-
- if (action->requestVal != (int)volume)
- action->cb(action->cbData);
-}
-
-int MediaVolume::set(int val)
-{
- requestVal = val;
- int ret = sound_manager_get_volume(SOUND_TYPE_MEDIA, &oldVal);
- if (SOUND_MANAGER_ERROR_NONE != ret) {
- ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_SYSTEM;
- }
-
- if (val == oldVal) {
- INFO("Already media volume is [%d]", val);
- return MODES_ERROR_NONE;
- }
-
- ret = sound_manager_set_volume(SOUND_TYPE_MEDIA, val);
- if (SOUND_MANAGER_ERROR_NONE != ret) {
- ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_SYSTEM;
- }
-
- return MODES_ERROR_NONE;
-}
-
-void MediaVolume::undo()
-{
- int ret = sound_manager_set_volume(SOUND_TYPE_MEDIA, oldVal);
- if (SOUND_MANAGER_ERROR_NONE != ret) {
- ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret));
- }
-}
-
-std::string MediaVolume::serialize()
-{
- std::ostringstream ostr;
-
- ostr << oldVal;
- return ostr.str();
-}
-
-int MediaVolume::parse(const std::string &archive)
-{
- std::istringstream iss(archive);
- iss >> oldVal;
-
- return MODES_ERROR_NONE;
-}
-
-int MediaVolume::setChangedCallback(valueChangedCB callback, void *userData)
-{
- int ret = sound_manager_add_volume_changed_cb(volumeChangedCB, this, &volumeCallbackID);
- if (SOUND_MANAGER_ERROR_NONE != ret) {
- ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_SYSTEM;
- }
- cb = callback;
- cbData = userData;
- return MODES_ERROR_NONE;
-}
-
-void MediaVolume::unSetChangedCallback(valueChangedCB callback, void *userData)
-{
- int ret = sound_manager_remove_volume_changed_cb(volumeCallbackID);
- if (SOUND_MANAGER_ERROR_NONE != ret) {
- ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret));
- }
- cb = NULL;
- cbData = NULL;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <string>
-#include <sound_manager.h>
-#include "plugin-def.h"
-#include "MediaAction.h"
-
-MODES_NAMESPACE_BEGIN
-
-class MediaVolume : public MediaAction {
-public:
- static const std::string NAME;
- MediaVolume();
- ~MediaVolume() = default;
-
- int set(int val) override;
- void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
- int setChangedCallback(valueChangedCB callback, void *userData) override;
- void unSetChangedCallback(valueChangedCB callback, void *userData) override;
-
-private:
- static void volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data);
- int oldVal;
- int volumeCallbackID;
- valueChangedCB cb;
- void *cbData;
- int requestVal;
-};
-
-MODES_NAMESPACE_END
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "SoundVolume.h"
+#include <string>
+#include <sstream>
+#include <modes_errors.h>
+#include <player.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+// It should align with actionKey in MediaFactory
+const std::string SoundVolume::NAME[4] = {
+ "mediaVolume",
+ "systemVolume",
+ "ringtoneVolume",
+ "notificationVolume"
+};
+
+SoundVolume::SoundVolume(int key, sound_type_e soundType)
+ : MediaAction(NAME[key]), oldVal(-1), volumeCallbackID(0), cb(NULL), cbData(NULL), requestVal(-1), type(soundType)
+{
+}
+
+void SoundVolume::volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data)
+{
+ SoundVolume *action = (SoundVolume*)user_data;
+ RET_IF(NULL == user_data);
+
+ if (action->requestVal != (int)volume)
+ action->cb(action->cbData);
+}
+
+int SoundVolume::set(int val)
+{
+ requestVal = val;
+ int ret = sound_manager_get_volume(type, &oldVal);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret));
+ return MODES_ERROR_SYSTEM;
+ }
+
+ if (val == oldVal) {
+ INFO("Already media volume is [%d]", val);
+ return MODES_ERROR_NONE;
+ }
+
+ ret = sound_manager_set_volume(type, val);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret));
+ return MODES_ERROR_SYSTEM;
+ }
+
+ return MODES_ERROR_NONE;
+}
+
+void SoundVolume::undo()
+{
+ int ret = sound_manager_set_volume(type, oldVal);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret));
+ }
+}
+
+std::string SoundVolume::serialize()
+{
+ std::ostringstream ostr;
+
+ ostr << oldVal;
+ return ostr.str();
+}
+
+int SoundVolume::parse(const std::string &archive)
+{
+ std::istringstream iss(archive);
+ iss >> oldVal;
+
+ return MODES_ERROR_NONE;
+}
+
+int SoundVolume::setChangedCallback(valueChangedCB callback, void *userData)
+{
+ int ret = sound_manager_add_volume_changed_cb(volumeChangedCB, this, &volumeCallbackID);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret));
+ return MODES_ERROR_SYSTEM;
+ }
+ cb = callback;
+ cbData = userData;
+ return MODES_ERROR_NONE;
+}
+
+void SoundVolume::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+ int ret = sound_manager_remove_volume_changed_cb(volumeCallbackID);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret));
+ }
+ cb = NULL;
+ cbData = NULL;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <string>
+#include <sound_manager.h>
+#include "plugin-def.h"
+#include "MediaAction.h"
+
+MODES_NAMESPACE_BEGIN
+
+class SoundVolume : public MediaAction {
+public:
+ static const std::string NAME[4];
+ SoundVolume(int key, sound_type_e soundType);
+ ~SoundVolume() = default;
+
+ int set(int val) override;
+ void undo() override;
+ std::string serialize() override;
+ int parse(const std::string &archive) override;
+ int setChangedCallback(valueChangedCB callback, void *userData) override;
+ void unSetChangedCallback(valueChangedCB callback, void *userData) override;
+
+private:
+ static void volumeChangedCB(sound_type_e type, unsigned int volume, void *user_data);
+ int oldVal;
+ int volumeCallbackID;
+ valueChangedCB cb;
+ void *cbData;
+ int requestVal;
+ sound_type_e type;
+};
+
+MODES_NAMESPACE_END
<desc>Audio/Video player</desc>
<domain>Multimedia</domain>
</rule>
- <rule name="media.volume" type="int" since="6.0" plugin="media">
+ <rule name="media.mediaVolume" type="int" since="6.0" plugin="media">
<alias name="MEDIA_MUTE">0</alias>
<desc>Media volume</desc>
<domain>Multimedia</domain>
</rule>
+ <rule name="media.systemVolume" type="int" since="6.0" plugin="media">
+ <alias name="SYSTEM_MUTE">0</alias>
+ <desc>System volume</desc>
+ <domain>Multimedia</domain>
+ </rule>
+ <rule name="media.ringtoneVolume" type="int" since="6.0" plugin="media">
+ <alias name="RINGTONE_MUTE">0</alias>
+ <desc>Ringtone volume</desc>
+ <domain>Multimedia</domain>
+ </rule>
+ <rule name="media.notificationVolume" type="int" since="6.0" plugin="media">
+ <alias name="NOTIFICATION_MUTE">0</alias>
+ <desc>Notification volume</desc>
+ <domain>Multimedia</domain>
+ </rule>
</actionRule>
</tizenModes>
return G_SOURCE_REMOVE;
}
- static gboolean mediaVolumeSetUndoIdler(gpointer data)
+ static gboolean VolumeSetUndoIdler(gpointer data)
{
PluginAction *action;
- result = plugin->set("volume", 5, &action);
+ result = plugin->set("mediaVolume", 5, &action);
EXPECT_EQ(MODES_ERROR_NONE, result);
+ plugin->undo(action);
+
+ result = plugin->set("systemVolume", 2, &action);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+ plugin->undo(action);
+ result = plugin->set("ringtoneVolume", 9, &action);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+ plugin->undo(action);
+
+ result = plugin->set("notificationVolume", 1, &action);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
plugin->undo(action);
g_main_loop_quit(loop);
TEST_F(MediaPluginTest, setUndoMediaVolume)
{
- g_idle_add(mediaVolumeSetUndoIdler, plugin);
+ g_idle_add(VolumeSetUndoIdler, plugin);
g_main_loop_run(loop);
}