{
return MODES_ERROR_NOT_SUPPORTED;
}
+ virtual int set(int val)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
};
MODES_NAMESPACE_END
#include "MediaFactory.h"
#include "plugin-log.h"
#include "MediaPlayer.h"
+#include "MediaVolume.h"
MODES_NAMESPACE_USE;
MediaFactory::MediaFactory()
{
actionMap[MediaPlayer::NAME] = PLAYER;
+ actionMap[MediaVolume::NAME] = VOLUME;
}
MediaAction* MediaFactory::createAction(const std::string &key)
case PLAYER:
action = new MediaPlayer();
break;
+ case VOLUME:
+ action = new MediaVolume();
+ break;
default:
action = nullptr;
break;
void destroyAction(MediaAction *action);
private:
enum actionKey{
- PLAYER
+ PLAYER,
+ VOLUME
};
std::map<std::string, enum actionKey> actionMap;
~MediaPlugin();
int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
+ int set(const std::string &key, int val, PluginAction **piAction) override;
PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+
+ void undo(PluginAction *piAction) override;
private:
MediaFactory mediaFactory;
};
MediaAction *action = mediaFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+ int ret = action->set(val);
+ if (ret != MODES_ERROR_NONE) {
+ ERR("Action(%s) set(%s) Fail(%d)", key.c_str(), val.c_str(), ret);
+ mediaFactory.destroyAction(action);
+ return ret;
+ }
DBG("Action(%s) set(%s)", key.c_str(), val.c_str());
+ if (piAction)
+ *piAction = action;
+ else
+ mediaFactory.destroyAction(action);
+ return ret;
+}
+
+int MediaPlugin::set(const std::string &key, int val, PluginAction **piAction)
+{
+ MediaAction *action = mediaFactory.createAction(key);
+ RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+
int ret = action->set(val);
- if ((ret == MODES_ERROR_NONE) && piAction)
+ if (ret != MODES_ERROR_NONE) {
+ ERR("Action(%s) set(%d) Fail(%d)", key.c_str(), val, ret);
+ mediaFactory.destroyAction(action);
+ return ret;
+ }
+ DBG("Action(%s) set(%d)", key.c_str(), val);
+
+ if (piAction)
*piAction = action;
else
mediaFactory.destroyAction(action);
return action;
}
+
+void MediaPlugin::undo(PluginAction *piAction)
+{
+ MediaAction *action = static_cast<MediaAction*>(piAction);
+ RET_IF(nullptr == piAction);
+
+ DBG("Action(%s) undo", action->getName().c_str());
+
+ action->undo();
+ mediaFactory.destroyAction(action);
+}
--- /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
<desc>Audio/Video player</desc>
<domain>Multimedia</domain>
</rule>
+ <rule name="media.volume" type="int" since="6.0" plugin="media">
+ <alias name="MEDIA_MUTE">0</alias>
+ <desc>Media volume</desc>
+ <domain>Multimedia</domain>
+ </rule>
</actionRule>
</tizenModes>
plugin = NULL;
}
- static gboolean mediaPluginSetUndoTimeout(gpointer data)
+ static gboolean mediaPlaySetUndoTimeout(gpointer data)
{
PluginAction *action = (PluginAction*)data;
plugin->undo(action);
return false;
}
- static gboolean mediaPluginSetUndoIdler(gpointer data)
+ static gboolean mediaPlaySetUndoIdler(gpointer data)
{
PluginAction *action;
result = plugin->set("player", std::string("/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"), &action);
EXPECT_EQ(MODES_ERROR_NONE, result);
if (MODES_ERROR_NONE == result)
- g_timeout_add(1000, mediaPluginSetUndoTimeout, action);
+ g_timeout_add(1000, mediaPlaySetUndoTimeout, action);
else
g_main_loop_quit(loop);
return G_SOURCE_REMOVE;
}
+ static gboolean mediaVolumeSetUndoIdler(gpointer data)
+ {
+ PluginAction *action;
+ result = plugin->set("volume", 5, &action);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+
+ plugin->undo(action);
+
+ g_main_loop_quit(loop);
+
+ return G_SOURCE_REMOVE;
+ }
+
static int result;
static GMainLoop *loop;
static Plugin *plugin;
Plugin *MediaPluginTest::plugin = NULL;
GMainLoop *MediaPluginTest::loop = NULL;
-TEST_F(MediaPluginTest, setUndoPluginmedia)
+TEST_F(MediaPluginTest, setUndoMediaPlay)
+{
+ g_idle_add(mediaPlaySetUndoIdler, plugin);
+ g_main_loop_run(loop);
+}
+
+TEST_F(MediaPluginTest, setUndoMediaVolume)
{
- g_idle_add(mediaPluginSetUndoIdler, plugin);
+ g_idle_add(mediaVolumeSetUndoIdler, plugin);
g_main_loop_run(loop);
}