#pragma once
#include <string>
+#include <PluginAction.h>
#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
-class AppAction {
+class AppAction : public PluginAction {
public:
- AppAction();
- virtual ~AppAction();
-
- std::string getName();
- virtual int set(const std::string &val);
- virtual int get(std::string *val);
- virtual int undo(const std::string &val);
-
-protected:
- void setName(std::string name);
-
-private:
- std::string name;
+ AppAction() = default;
+ virtual ~AppAction() = default;
+
+ virtual int set(const std::string &val)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ virtual int get(std::string *val)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
};
MODES_NAMESPACE_END
int ret = app_control_send_launch_request(service, NULL, NULL);
if (APP_CONTROL_ERROR_NONE != ret) {
ERR("app_control_send_launch_request() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_IO_ERROR;
+ return MODES_ERROR_SYSTEM;
}
app_control_destroy(service);
DBG("APP_CONTEXT_EVENT_LAUNCHED(appid : %s) added list\n", val.c_str());
- ret = app_manager_set_app_context_status_cb(AppActionLaunch::appContextStatusCallback, val.c_str(), NULL);
- if (APP_MANAGER_ERROR_NONE != ret) {
- ERR("app_manager_set_app_context_status_cb() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_IO_ERROR;
+ int err = app_manager_set_app_context_status_cb(AppActionLaunch::appContextStatusCallback, val.c_str(), NULL);
+ if (APP_MANAGER_ERROR_NONE != err) {
+ ERR("app_manager_set_app_context_status_cb() Fail(%s)", get_error_message(err));
+ return MODES_ERROR_SYSTEM;
}
appID = val;
return MODES_ERROR_NONE;
}
-int AppActionLaunch::undo(const std::string &val)
+int AppActionLaunch::undo()
{
bool running;
app_context_h runAppContext;
- app_manager_is_running(val.c_str(), &running);
+ app_manager_is_running(appID.c_str(), &running);
if (!running) {
DBG("It's NOT running");
return MODES_ERROR_NONE;
}
- int ret = app_manager_unset_app_context_status_cb(AppActionLaunch::appContextStatusCallback, val.c_str());
+ int ret = app_manager_unset_app_context_status_cb(AppActionLaunch::appContextStatusCallback, appID.c_str());
if (APP_MANAGER_ERROR_NONE != ret) {
ERR("app_manager_unset_app_context_status_cb() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_IO_ERROR;
+ return MODES_ERROR_SYSTEM;
}
- appidList.remove(val);
+ appidList.remove(appID);
- ret = app_manager_get_app_context(val.c_str(), &runAppContext);
+ ret = app_manager_get_app_context(appID.c_str(), &runAppContext);
if (APP_MANAGER_ERROR_NONE != ret) {
- ERR("app_manager_get_app_context(%s) Fail(%s)", val.c_str(), get_error_message(ret));
- return MODES_ERROR_IO_ERROR;
+ ERR("app_manager_get_app_context(%s) Fail(%s)", appID.c_str(), get_error_message(ret));
+ return MODES_ERROR_SYSTEM;
}
ret = app_manager_terminate_app(runAppContext);
if (APP_MANAGER_ERROR_NONE != ret) {
ERR("app_manager_terminate_app() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_IO_ERROR;
+ return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
}
virtual int set(const std::string &val) override;
virtual int get(std::string *val) override;
- virtual int undo(const std::string &val) override;
+ virtual int undo() override;
static const std::string NAME;
static void appContextStatusCallback(app_context_h app_context, app_context_status_e status, void *user_data);
AppPlugin();
~AppPlugin();
- int set(const std::string &key, const std::string &val, std::string *oldVal) override;
- int undo(const std::string &key, const std::string &val) override;
+ int set(const std::string &key, const std::string &val, PluginAction **pluginAction) override;
+ int undo(PluginAction *pluginAction) override;
private:
AppFactory appFactory;
{
}
-int AppPlugin::set(const std::string &key, const std::string &val, std::string *oldVal)
+int AppPlugin::set(const std::string &key, const std::string &val, PluginAction **pluginAction)
{
AppAction *action = appFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %s]", key.c_str(), val.c_str());
- int appRet = action->set(val);
+ int ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ appFactory.destroyAction(action);
- if (oldVal)
- action->get(oldVal);
-
- appFactory.destroyAction(action);
- return appRet;
+ return ret;
}
-int AppPlugin::undo(const std::string &key, const std::string &val)
+int AppPlugin::undo(PluginAction *pluginAction)
{
- AppAction *action = appFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+ AppAction *action = static_cast<AppAction*>(pluginAction);
+ RETV_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER);
- DBG("set [%s, %s]", key.c_str(), val.c_str());
+ DBG("Action(%s) undo", action->getName().c_str());
- int appRet = action->undo(val);
+ int ret = action->undo();
appFactory.destroyAction(action);
- return appRet;
+
+ return ret;
}
if (BT_ERROR_NONE != btRet) {
ERR("bt_initialize() Fail(%d)", btRet);
}
-
- btAdapterStatus = getAdapterStatus();
}
BtAction::~BtAction()
return state;
}
-int BtAction::set(bool val, int *oldVal)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
-
-int BtAction::set(bool val, double *oldVal)
+int BtAction::set(bool val)
{
return MODES_ERROR_NOT_SUPPORTED;
}
-int BtAction::set(bool val, bool *oldVal)
+int BtAction::set(const std::string &val)
{
return MODES_ERROR_NOT_SUPPORTED;
}
-
-int BtAction::set(const std::string &val, std::string *oldVal)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
-
-int BtAction::undo(bool val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
-
-void BtAction::setName(std::string name)
-{
- this->name = name;
-}
-
-std::string BtAction::getName()
-{
- return name;
-}
#include <string>
#include <bluetooth.h>
+#include <PluginAction.h>
#include "plugin-log.h"
#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
-class BtAction {
+class BtAction : public PluginAction {
public:
BtAction();
virtual ~BtAction();
+ virtual int set(bool val);
+ virtual int set(const std::string &val);
bt_adapter_state_e getAdapterStatus();
- std::string getName();
-
- virtual int set(bool val, int *oldVal);
- virtual int set(bool val, double *oldVal);
- virtual int set(bool val, bool *oldVal);
- virtual int set(const std::string &val, std::string *oldVal);
- virtual int undo(bool val);
-
-protected:
- void setName(std::string name);
- bt_adapter_state_e btAdapterStatus;
-private:
- std::string name;
};
MODES_NAMESPACE_END
DBG("BtActionAudioConnect Success! [%s][%s]", device_info->remote_name, device_info->remote_address);
}
-int BtActionAudioConnect::set(const std::string &val, std::string *oldVal)
+int BtActionAudioConnect::set(const std::string &val)
{
if (!isBtAdapterEnabled()) {
ERR("BT is disabled");
}
#endif
- *oldVal = std::string();
int btRet;
btRet = bt_device_set_bond_created_cb(btDeviceBondCreatedCb, NULL);
class BtActionAudioConnect : public BtAction {
public:
BtActionAudioConnect();
- int set(const std::string &val, std::string *oldVal) override;
+ int set(const std::string &val) override;
private:
bool isBtAdapterEnabled();
#define SAFE_POINTER_ASSIGN( arg1, arg2) if ( arg1 != NULL ) { *arg1 = arg2; }
BtActionPower::BtActionPower()
+ :undoVal(false)
{
setName("power");
}
-int BtActionPower::set(bool val, bool *oldVal)
+int BtActionPower::set(bool val)
{
if (val) {
- SAFE_POINTER_ASSIGN(oldVal, false);
+ undoVal = false;
int btRet = bt_adapter_enable();
if (BT_ERROR_NONE != btRet) {
if (BT_ERROR_ALREADY_DONE == btRet) {
- SAFE_POINTER_ASSIGN(oldVal, true);
+ undoVal = true;
} else {
ERR("bt_adapter_enable() Fail(%d)", btRet);
return MODES_ERROR_SYSTEM;
}
}
} else {
- SAFE_POINTER_ASSIGN(oldVal, true);
+ undoVal = true;
int btRet = bt_adapter_disable();
if (BT_ERROR_NONE != btRet) {
if (BT_ERROR_NOT_ENABLED == btRet) {
- SAFE_POINTER_ASSIGN(oldVal, false);
+ undoVal = false;
} else {
ERR("bt_adapter_disable() Fail(%d)", btRet);
return MODES_ERROR_SYSTEM;
}
}
- INFO("Bluetooth power [%s]", val ? "On" : "Off");
+ INFO("BT power changed to (%s) from (%s)", val ? "On" : "Off", undoVal ? "On" : "Off");
return MODES_ERROR_NONE;
}
-int BtActionPower::undo(bool val)
+int BtActionPower::undo()
{
- return set(val, nullptr);
+ return set(undoVal);
}
public:
BtActionPower();
- int set(bool val, bool *oldVal) override;
- int undo(bool val) override;
+ int set(bool val) override;
+ int undo() override;
private:
+ bool undoVal;
};
MODES_NAMESPACE_END
BtPlugin();
~BtPlugin();
- int set(const std::string &key, int val, int *oldVal) override;
- int set(const std::string &key, double val, double *oldVal) override;
- int set(const std::string &key, bool val, bool *oldVal) override;
- int set(const std::string &key, const std::string &val, std::string *oldVal) override;
- int undo(const std::string &key, bool val) override;
-
+ int set(const std::string &key, int val, PluginAction **pluginAction) override;
+ int set(const std::string &key, double val, PluginAction **pluginAction) override;
+ int set(const std::string &key, bool val, PluginAction **pluginAction) override;
+ int set(const std::string &key, const std::string &val, PluginAction **pluginAction) override;
+ int undo(PluginAction *pluginAction) override;
private:
BtFactory btFactory;
};
{
}
-int BtPlugin::set(const std::string &key, int val, int *oldVal)
+int BtPlugin::set(const std::string &key, int val, PluginAction **pluginAction)
{
BtAction *action = btFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %d]", key.c_str(), val);
- int btRet = action->set(val, oldVal);
- btFactory.destroyAction(action);
- return btRet;
+ int ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ btFactory.destroyAction(action);
+
+ return ret;
}
-int BtPlugin::set(const std::string &key, double val, double *oldVal)
+int BtPlugin::set(const std::string &key, double val, PluginAction **pluginAction)
{
BtAction *action = btFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %f]", key.c_str(), val);
- int btRet = action->set(val, oldVal);
- btFactory.destroyAction(action);
- return btRet;
+ int ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ btFactory.destroyAction(action);
+
+ return ret;
}
-int BtPlugin::set(const std::string &key, bool val, bool *oldVal)
+int BtPlugin::set(const std::string &key, bool val, PluginAction **pluginAction)
{
BtAction *action = btFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %s]", key.c_str(), (val ? "on" : "off"));
- int btRet = action->set(val, oldVal);
- btFactory.destroyAction(action);
- return btRet;
+ int ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ btFactory.destroyAction(action);
+
+ return ret;
}
-int BtPlugin::set(const std::string &key, const std::string &val, std::string *oldVal)
+int BtPlugin::set(const std::string &key, const std::string &val, PluginAction **pluginAction)
{
BtAction *action = btFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %s]", key.c_str(), val.c_str());
- int btRet = action->set(val, oldVal);
- btFactory.destroyAction(action);
- return btRet;
+ int ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ btFactory.destroyAction(action);
+
+ return ret;
}
-int BtPlugin::undo(const std::string &key, bool val)
+int BtPlugin::undo(PluginAction *pluginAction)
{
- BtAction *action = btFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+ BtAction *action = static_cast<BtAction*>(pluginAction);
+ RETV_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER);
- DBG("set [%s, %s]", key.c_str(), (val ? "on" : "off"));
+ DBG("Action(%s) undo", action->getName().c_str());
- int appRet = action->undo(val);
+ int ret = action->undo();
btFactory.destroyAction(action);
- return appRet;
+
+ return ret;
}
#pragma once
#include <string>
+#include <PluginAction.h>
#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
-class PkgAction {
+class PkgAction : public PluginAction {
public:
- PkgAction();
- virtual ~PkgAction();
-
- std::string getName();
- virtual int set(int val);
- virtual int get(int *val);
- virtual int undo(int val);
-
-protected:
- void setName(std::string name);
-
-private:
- std::string name;
+ PkgAction() = default;
+ virtual ~PkgAction() = default;
+
+ virtual int set(int val)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ virtual int get(int *val)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
};
MODES_NAMESPACE_END
}
-int PkgStartSupportMode::undo(int val)
+int PkgStartSupportMode::undo()
{
//If the appList is empty, it will be ignored at subroutines.
#include <list>
#include <string>
#include <pkgmgr-info.h>
+#include "plugin-def.h"
#include "PkgAction.h"
MODES_NAMESPACE_BEGIN
public:
PkgStartSupportMode();
- virtual int set(int val) override;
- virtual int get(int *val) override;
- virtual int undo(int val) override;
+ virtual int set(int val);
+ virtual int get(int *val);
+ virtual int undo() override;
static const std::string NAME;
private:
MODES_NAMESPACE_USE;
-std::map<std::string, PkgAction*> PkgFactory::savedActionMap;
-
PkgFactory::PkgFactory()
{
actionMap[PkgStartSupportMode::NAME] = PKG_ACT_STARTSUPPORTMODE;
}
-PkgAction* PkgFactory::newStartSupportMode(const std::string &key, bool isUndo)
-{
- auto it = savedActionMap.find(key);
- if (it != savedActionMap.end()) {
- if (isUndo) {
- DBG("savedAction(%s) exist", key.c_str());
- PkgAction *action = it->second;
- savedActionMap.erase(it);
- return action;
- } else {
- ERR("savedAction(%s) exist", key.c_str());
- return nullptr;
- }
- } else {
- if (isUndo) {
- ERR("No savedAction(%s)", key.c_str());
- return nullptr;
- } else {
- PkgAction *action = new PkgStartSupportMode();
- savedActionMap[key] = action;
- return action;
- }
- }
-}
-
-PkgAction* PkgFactory::createAction(const std::string &key, bool isUndo)
+PkgAction* PkgFactory::createAction(const std::string &key)
{
auto search = actionMap.find(key);
if (search == actionMap.end()) {
PkgAction *action;
switch (search->second) {
case PKG_ACT_STARTSUPPORTMODE:
- action = newStartSupportMode(key, isUndo);
+ action = new PkgStartSupportMode();
break;
default:
action = nullptr;
void PkgFactory::destroyAction(PkgAction *action)
{
- auto it = savedActionMap.find(action->getName());
- if (it != savedActionMap.end()) {
- if (action == it->second)
- DBG("savedAction(%s) exist", action->getName().c_str());
- else
- ERR("Should not reach");
- } else {
- delete action;
- }
+ delete action;
}
PkgFactory();
~PkgFactory() = default;
- PkgAction* createAction(const std::string &key, bool isUndo);
+ PkgAction* createAction(const std::string &key);
void destroyAction(PkgAction *action);
private:
enum actionKey{
PKG_ACT_STARTSUPPORTMODE
};
- PkgAction* newStartSupportMode(const std::string &key, bool isUndo);
-
std::map<std::string, enum actionKey> actionMap;
- static std::map<std::string, PkgAction*> savedActionMap;
};
MODES_NAMESPACE_END
#include <modes_errors.h>
#include <Plugin.h>
#include "plugin-log.h"
+#include "plugin-def.h"
#include "PkgFactory.h"
+#include "PkgAction.h"
MODES_NAMESPACE_USE;
PkgPlugin();
~PkgPlugin();
- int set(const std::string &key, int val, int *oldVal) override;
- int undo(const std::string &key, int val) override;
+ int set(const std::string &key, int val, PluginAction **pluginAction) override;
+ int undo(PluginAction *pluginAction) override;
private:
PkgFactory pkgFactory;
{
}
-int PkgPlugin::set(const std::string &key, int val, int *oldVal)
+int PkgPlugin::set(const std::string &key, int val, PluginAction **pluginAction)
{
- PkgAction *action = pkgFactory.createAction(key, false);
+ PkgAction *action = pkgFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
- DBG("set [%s, %d]", key.c_str(), val);
+ DBG("Action(%s) set(%d)", key.c_str(), val);
int ret = action->set(val);
- if (oldVal)
- action->get(oldVal);
-
- pkgFactory.destroyAction(action);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ pkgFactory.destroyAction(action);
return ret;
}
-int PkgPlugin::undo(const std::string &key, int val)
+int PkgPlugin::undo(PluginAction *pluginAction)
{
- PkgAction *action = pkgFactory.createAction(key, true);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+ PkgAction *action = static_cast<PkgAction*>(pluginAction);
+ RETV_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER);
- DBG("set [%s, %d]", key.c_str(), val);
+ DBG("Action(%s) undo", action->getName().c_str());
- int ret = action->undo(val);
+ int ret = action->undo();
pkgFactory.destroyAction(action);
return ret;
void SetUp() override
{
loop = g_main_loop_new(NULL, FALSE);
+ plugin = objectCreate();
}
void TearDown() override
{
g_main_loop_unref(loop);
loop = NULL;
+ objectDelete(plugin);
+ plugin = NULL;
}
static gboolean appPluginUndoConflictIdler(gpointer data)
{
- app_context_h runAppContext;
- Plugin *plugin = objectCreate();
- result = plugin->set("launch", std::string("org.tizen.w-stopwatch"), nullptr);
+ PluginAction *action;
+ result = plugin->set("launch", std::string("org.tizen.w-stopwatch"), &action);
EXPECT_EQ(MODES_ERROR_NONE, result);
+
+ app_context_h runAppContext;
app_manager_get_app_context("org.tizen.w-stopwatch", &runAppContext);
app_manager_terminate_app(runAppContext);
- result = plugin->undo("launch", std::string("org.tizen.w-stopwatch"));
+ result = plugin->undo(action);
EXPECT_EQ(MODES_ERROR_NONE, result);
- objectDelete(plugin);
g_main_loop_quit(loop);
return G_SOURCE_REMOVE;
static gboolean appPluginSetUndoTimeout(gpointer data)
{
- Plugin *plugin = (Plugin *)data;
- result = plugin->undo("launch", std::string("org.tizen.w-stopwatch"));
+ PluginAction *action = (PluginAction*)data;
+ result = plugin->undo(action);
EXPECT_EQ(MODES_ERROR_NONE, result);
g_main_loop_quit(loop);
return false;
static gboolean appPluginSetUndoIdler(gpointer data)
{
- Plugin *plugin = (Plugin *)data;
- result = plugin->set("launch", std::string("org.tizen.w-stopwatch"), nullptr);
+ PluginAction *action;
+ result = plugin->set("launch", std::string("org.tizen.w-stopwatch"), &action);
EXPECT_EQ(MODES_ERROR_NONE, result);
- g_timeout_add(1000, appPluginSetUndoTimeout, plugin);
+ g_timeout_add(1000, appPluginSetUndoTimeout, action);
return G_SOURCE_REMOVE;
}
static int result;
static GMainLoop *loop;
static GThread *my_thread;
+ static Plugin *plugin;
};
int PluginTest::result = 0;
+Plugin *PluginTest::plugin = NULL;
GMainLoop *PluginTest::loop = NULL;
TEST_F(PluginTest, setUndoPluginApp)
{
- Plugin *plugin = objectCreate();
g_idle_add(appPluginSetUndoIdler, plugin);
g_main_loop_run(loop);
- objectDelete(plugin);
}
TEST_F(PluginTest, undoConflictPluginApp)
g_main_loop_run(loop);
}
-
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
plugin = NULL;
}
- static gboolean pkgPluginTimeout(gpointer data)
- {
- Plugin *plugin = (Plugin *)data;
- result = plugin->undo("startSupportMode", 1);
- EXPECT_EQ(MODES_ERROR_NONE, result);
- g_main_loop_quit(loop);
-
- return G_SOURCE_REMOVE;
- }
-
static gboolean pkgPluginIdler(gpointer data)
{
- Plugin *plugin = (Plugin *)data;
- result = plugin->set("startSupportMode", 1, nullptr);
- EXPECT_EQ(MODES_ERROR_NONE, result);
-
- g_timeout_add_seconds(5, pkgPluginTimeout, plugin);
+ g_main_loop_quit(loop);
return G_SOURCE_REMOVE;
}
Plugin *plugin;
};
-int PkgPluginTest::result = 0;
GMainLoop *PkgPluginTest::loop = NULL;
TEST_F(PkgPluginTest, setUndoTest)
{
+ PluginAction *action;
+ int ret = plugin->set("startSupportMode", 1, &action);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+ g_idle_add(pkgPluginIdler, plugin);
+ g_main_loop_run(loop);
+
+ ret = plugin->undo(action);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
+
g_idle_add(pkgPluginIdler, plugin);
g_main_loop_run(loop);
}
objectDelete(plugin);
g_main_loop_unref(loop);
loop = NULL;
- result = -1;
+ cb1Called = false;
+ cb2Called = false;
+ }
+
+ static void shoudNotBeCalled(const std::string &key, void *userData)
+ {
+ ERR("This Callback(%s) should not be called", key.c_str());
+ g_main_loop_quit(loop);
+ GTEST_FAIL();
}
static void valChangedCb(const std::string &key, void *userData)
g_main_loop_quit(loop);
}
- static void valChangedResetStoredCb(const std::string &key, void *userData)
+ static void callback1(const std::string &key, void *userData)
{
DBG("%s changed callback called!", key.c_str());
- result = MODES_ERROR_NONE;
+ cb1Called = true;
}
- static void valChangedResetCb(const std::string &key, void *userData)
+ static void callback2(const std::string &key, void *userData)
{
DBG("%s changed callback called!", key.c_str());
+ cb2Called = true;
g_main_loop_quit(loop);
}
return G_SOURCE_REMOVE;
}
- static int result;
static GMainLoop *loop;
static Plugin *plugin;
- static int oldval;
+ static bool cb1Called;
+ static bool cb2Called;
};
-int VconfPluginTest::oldval = 0;
-int VconfPluginTest::result = -1;
+bool VconfPluginTest::cb1Called = false;
+bool VconfPluginTest::cb2Called = false;
Plugin *VconfPluginTest::plugin = nullptr;
GMainLoop *VconfPluginTest::loop = NULL;
-TEST_F(VconfPluginTest, setPluginVconfInt)
+TEST_F(VconfPluginTest, VconfInt)
{
int ret;
- int oldval;
+ const char *key = "db.setting.psmode";
+
+ ret = plugin->set(key, 0, nullptr);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+ int val = plugin->getInt(key);
+ EXPECT_EQ(val, 0);
- ret = plugin->set("db.setting.psmode", 3, nullptr);
+ PluginAction *action;
+ ret = plugin->set(key, 1, &action);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->set("db.setting.psmode", 1, &oldval);
+
+ ret = plugin->undo(action);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(oldval, 3);
+
+ val = plugin->getInt(key);
+ EXPECT_EQ(val, 0);
}
-TEST_F(VconfPluginTest, setPluginVconfDouble)
+TEST_F(VconfPluginTest, VconfDouble)
{
int ret;
- double oldval;
+ const char *key = "db.system.timechange_external";
- ret = plugin->set("db.system.timechange_external", 1.0, nullptr);
+ ret = plugin->set(key, 0.0, nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->set("db.system.timechange_external", 0.0, &oldval);
+
+ double val = plugin->getDouble(key);
+ EXPECT_EQ(val, 0.0);
+
+ PluginAction *action;
+ ret = plugin->set(key, 1.0, &action);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(oldval, 1.0);
+
+ ret = plugin->undo(action);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+ val = plugin->getDouble(key);
+ EXPECT_EQ(val, 0.0);
}
-TEST_F(VconfPluginTest, setPluginVconfBool)
+TEST_F(VconfPluginTest, VconfBool)
{
int ret;
- bool oldval;
+ const char *key = "db.setting.sound.button_sounds";
- ret = plugin->set("db.setting.sound.button_sounds", false, nullptr);
+ ret = plugin->set(key, true, nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->set("db.setting.sound.button_sounds", true, &oldval);
+
+ double val = plugin->getBool(key);
+ EXPECT_EQ(val, true);
+
+ PluginAction *action;
+ ret = plugin->set(key, false, &action);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+ ret = plugin->undo(action);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(oldval, false);
+
+ val = plugin->getBool(key);
+ EXPECT_EQ(val, true);
}
-TEST_F(VconfPluginTest, setPluginVconfStr)
+TEST_F(VconfPluginTest, VconfStr)
{
int ret;
- std::string oldval;
+ const char *key = "db.setting.device_name";
+ const std::string devName = "Tizen";
+ const std::string tmpName = "ModesTest";
- std::string testVal = "org.tizen.menu-screen.test";
- ret = plugin->set("db.setting.menuscreen.package_name", testVal, nullptr);
+ ret = plugin->set(key, devName, nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->set("db.setting.menuscreen.package_name", "org.tizen.menu-screen", &oldval);
+
+ std::string val = plugin->getString(key);
+ EXPECT_STREQ(val.c_str(), devName.c_str());
+
+ PluginAction *action;
+ ret = plugin->set(key, tmpName, &action);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(oldval.compare(testVal), 0);
+
+ ret = plugin->undo(action);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+ val = plugin->getString(key);
+ EXPECT_STREQ(val.c_str(), devName.c_str());
}
TEST_F(VconfPluginTest, callbackPluginVconf)
{
- vconf_get_int("db/setting/psmode", &oldval);
- int ret = plugin->setChangedCallback(valChangedCb,
- "db.setting.psmode", nullptr);
+ int oldVal = 0;
+ vconf_get_int("db/setting/psmode", &oldVal);
+ int ret = plugin->setChangedCallback(valChangedCb, "db.setting.psmode", nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
g_idle_add(changedCallbackidler, nullptr);
g_main_loop_run(loop);
ret = plugin->unSetChangedCallback(valChangedCb, "db.setting.psmode", nullptr);
EXPECT_EQ(ret, MODES_ERROR_NO_DATA);
- vconf_set_int("db/setting/psmode", oldval);
+
+ ret = plugin->setChangedCallback(shoudNotBeCalled, "db.setting.psmode", nullptr);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = plugin->unSetChangedCallback(shoudNotBeCalled, "db.setting.psmode", nullptr);
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ vconf_set_int("db/setting/psmode", oldVal);
}
TEST_F(VconfPluginTest, callbackPluginVconfReset)
{
int ret;
- ret = plugin->set("db.setting.psmode", 4, &oldval);
+ ret = plugin->set("db.setting.psmode", 4, nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->setChangedCallback(valChangedResetStoredCb, "db.setting.psmode", nullptr);
+ ret = plugin->setChangedCallback(callback1, "db.setting.psmode", nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
ret = plugin->set("db.setting.psmode", 2, nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(MODES_ERROR_NONE, result);
- ret = plugin->setChangedCallback(valChangedResetCb, "db.setting.psmode", nullptr);
+ EXPECT_TRUE(cb1Called);
+ ret = plugin->setChangedCallback(callback2, "db.setting.psmode", nullptr);
EXPECT_EQ(ret, MODES_ERROR_NONE);
g_idle_add(changedCallbackidler, nullptr);
g_main_loop_run(loop);
+ EXPECT_TRUE(cb2Called);
- DBG("loop end and unregister callback start");
- ret = plugin->unSetChangedCallback(valChangedResetCb, "db.setting.psmode", nullptr);
+ ret = plugin->unSetChangedCallback(callback2, "db.setting.psmode", nullptr);
EXPECT_EQ(ret, MODES_ERROR_NO_DATA);
- vconf_set_int("db/setting/psmode", oldval);
- EXPECT_EQ(MODES_ERROR_NONE, result);
+ vconf_set_int("db/setting/psmode", 0);
}
int main(int argc, char **argv) {
--- /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 "VconfActionBool.h"
+#include <string>
+#include <algorithm>
+#include <vconf.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+VconfActionBool::VconfActionBool(const std::string &vconfKey)
+ :key(vconfKey), oldVal(false)
+{
+}
+
+int VconfActionBool::set(bool val)
+{
+ int ret;
+ DBG("setBool(%s, %d)", key.c_str(), val);
+
+ int prev;
+ ret = vconf_get_bool(key.c_str(), &prev);
+ if (0 != ret) {
+ ERR("vconf_get_bool(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ oldVal = prev;
+
+ ret = vconf_set_bool(key.c_str(), val);
+ if (0 != ret) {
+ ERR("vconf_set_bool(%s, %d) Fail(%d)", key.c_str(), val, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ return MODES_ERROR_NONE;
+}
+
+bool VconfActionBool::get()
+{
+ int value = 0;
+ int ret = vconf_get_bool(key.c_str(), &value);
+ if (0 != ret) {
+ ERR("vconf_get_bool(%s) Fail(%d)", key.c_str(), ret);
+ return false;
+ }
+
+ return value ? true : false;
+}
+
+int VconfActionBool::undo()
+{
+ int ret;
+ DBG("undoBool(%s, %d)", key.c_str(), oldVal);
+
+ ret = vconf_set_bool(key.c_str(), oldVal ? 1 : 0);
+ if (0 != ret) {
+ ERR("vconf_set_bool(%s, %d) Fail(%d)", key.c_str(), oldVal, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ return MODES_ERROR_NONE;
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "PkgAction.h"
-#include <modes_errors.h>
+#pragma once
-MODES_NAMESPACE_USE;
+#include <string>
+#include <PluginAction.h>
+#include "plugin-def.h"
-PkgAction::PkgAction()
-{
-}
+MODES_NAMESPACE_BEGIN
-PkgAction::~PkgAction()
-{
-}
+class VconfActionBool : public PluginAction {
+public:
+ VconfActionBool(const std::string &vconfKey);
+ virtual ~VconfActionBool() = default;
-int PkgAction::set(int val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
+ int set(bool val);
+ bool get();
+ virtual int undo() override;
+private:
+ std::string key;
+ bool oldVal;
+};
-int PkgAction::undo(int val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
+MODES_NAMESPACE_END
-int PkgAction::get(int *val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
-
-void PkgAction::setName(std::string name)
-{
- this->name = name;
-}
-
-std::string PkgAction::getName()
-{
- return name;
-}
--- /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 "VconfActionDbl.h"
+#include <string>
+#include <algorithm>
+#include <vconf.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+VconfActionDbl::VconfActionDbl(const std::string &vconfKey)
+ :key(vconfKey), oldVal(0.0)
+{
+}
+
+int VconfActionDbl::set(double val)
+{
+ int ret;
+ DBG("setDbl(%s, %f)", key.c_str(), val);
+
+ ret = vconf_get_dbl(key.c_str(), &oldVal);
+ if (0 != ret) {
+ ERR("vconf_get_dbl(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ ret = vconf_set_dbl(key.c_str(), val);
+ if (0 != ret) {
+ ERR("vconf_set_dbl(%s, %f) Fail(%d)", key.c_str(), val, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ return MODES_ERROR_NONE;
+}
+
+double VconfActionDbl::get()
+{
+ double value = 0.0;
+ int ret = vconf_get_dbl(key.c_str(), &value);
+ if (0 != ret) {
+ ERR("vconf_get_dbl(%s) Fail(%d)", key.c_str(), ret);
+ return 0.0;
+ }
+
+ return value;
+}
+
+int VconfActionDbl::undo()
+{
+ int ret;
+ DBG("undoDbl(%s, %f)", key.c_str(), oldVal);
+
+ ret = vconf_set_dbl(key.c_str(), oldVal);
+ if (0 != ret) {
+ ERR("vconf_set_dbl(%s, %f) Fail(%d)", key.c_str(), oldVal, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ return MODES_ERROR_NONE;
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "AppAction.h"
-#include <modes_errors.h>
+#pragma once
-MODES_NAMESPACE_USE;
+#include <string>
+#include <PluginAction.h>
+#include "plugin-def.h"
-AppAction::AppAction()
-{
-}
+MODES_NAMESPACE_BEGIN
-AppAction::~AppAction()
-{
-}
+class VconfActionDbl : public PluginAction {
+public:
+ VconfActionDbl(const std::string &vconfKey);
+ virtual ~VconfActionDbl() = default;
-int AppAction::set(const std::string &val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
+ int set(double val);
+ double get();
+ virtual int undo() override;
+private:
+ std::string key;
+ double oldVal;
+};
-int AppAction::undo(const std::string &val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
+MODES_NAMESPACE_END
-int AppAction::get(std::string *val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
-
-void AppAction::setName(std::string name)
-{
- this->name = name;
-}
-
-std::string AppAction::getName()
-{
- return name;
-}
--- /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 "VconfActionInt.h"
+#include <string>
+#include <algorithm>
+#include <vconf.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+VconfActionInt::VconfActionInt(const std::string &vconfKey)
+ :key(vconfKey), oldVal(0)
+{
+}
+
+int VconfActionInt::set(int val)
+{
+ int ret;
+ DBG("setInt(%s, %d)", key.c_str(), val);
+
+ ret = vconf_get_int(key.c_str(), &oldVal);
+ if (0 != ret) {
+ ERR("vconf_get_int(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ ret = vconf_set_int(key.c_str(), val);
+ if (0 != ret) {
+ ERR("vconf_set_int(%s, %d) Fail(%d)", key.c_str(), val, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ return MODES_ERROR_NONE;
+}
+
+int VconfActionInt::get()
+{
+ int value = 0;
+ int ret = vconf_get_int(key.c_str(), &value);
+ if (0 != ret) {
+ ERR("vconf_get_int(%s) Fail(%d)", key.c_str(), ret);
+ return 0;
+ }
+
+ return value;
+}
+
+int VconfActionInt::undo()
+{
+ int ret;
+ DBG("undoInt(%s, %d)", key.c_str(), oldVal);
+
+ ret = vconf_set_int(key.c_str(), oldVal);
+ if (0 != ret) {
+ ERR("vconf_set_int(%s, %d) Fail(%d)", key.c_str(), oldVal, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ return MODES_ERROR_NONE;
+}
--- /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 <PluginAction.h>
+#include "plugin-def.h"
+
+MODES_NAMESPACE_BEGIN
+
+class VconfActionInt : public PluginAction {
+public:
+ VconfActionInt(const std::string &vconfKey);
+ virtual ~VconfActionInt() = default;
+
+ int set(int val);
+ int get();
+ virtual int undo() override;
+private:
+ std::string key;
+ int oldVal;
+};
+
+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 "VconfActionStr.h"
+#include <string>
+#include <algorithm>
+#include <vconf.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+VconfActionStr::VconfActionStr(const std::string &vconfKey)
+ :key(vconfKey)
+{
+}
+
+int VconfActionStr::set(const std::string &val)
+{
+ int ret;
+ DBG("setStr(%s, %s)", key.c_str(), val.c_str());
+
+ char *prev = vconf_get_str(key.c_str());
+ if (NULL == prev) {
+ ERR("vconf_get_str(%s) Fail()", key.c_str());
+ return MODES_ERROR_SYSTEM;
+ }
+ oldVal = prev;
+ free(prev);
+
+ ret = vconf_set_str(key.c_str(), val.c_str());
+ if (0 != ret) {
+ ERR("vconf_set_str(%s, %s) Fail(%d)", key.c_str(), val.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ return MODES_ERROR_NONE;
+}
+
+std::string VconfActionStr::get()
+{
+ char *value = vconf_get_str(key.c_str());
+ if (NULL == value) {
+ ERR("vconf_get_str(%s) Fail()", key.c_str());
+ return std::string();
+ }
+
+ std::string retStr = value;
+ free(value);
+
+ return retStr;
+}
+
+int VconfActionStr::undo()
+{
+ int ret;
+ DBG("undoStr(%s, %s)", key.c_str(), oldVal.c_str());
+
+ ret = vconf_set_str(key.c_str(), oldVal.c_str());
+ if (0 != ret) {
+ ERR("vconf_set_str(%s, %s) Fail(%d)", key.c_str(), oldVal.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ return MODES_ERROR_NONE;
+}
--- /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 <PluginAction.h>
+#include "plugin-def.h"
+
+MODES_NAMESPACE_BEGIN
+
+class VconfActionStr : public PluginAction {
+public:
+ VconfActionStr(const std::string &vconfKey);
+ ~VconfActionStr() = default;
+
+ int set(const std::string &val);
+ std::string get();
+ virtual int undo() override;
+private:
+ std::string key;
+ std::string oldVal;
+};
+
+MODES_NAMESPACE_END
+
#include <Plugin.h>
#include "plugin-log.h"
#include "plugin-def.h"
-
+#include "VconfActionInt.h"
+#include "VconfActionDbl.h"
+#include "VconfActionBool.h"
+#include "VconfActionStr.h"
MODES_NAMESPACE_USE;
public:
VconfPlugin();
- int set(const std::string &key, int val, int *oldVal) override;
- int set(const std::string &key, double val, double *oldVal) override;
- int set(const std::string &key, bool val, bool *oldVal) override;
- int set(const std::string &key, const std::string &val, std::string *oldVal) override;
+ int set(const std::string &key, int val, PluginAction **pluginAction) override;
+ int set(const std::string &key, double val, PluginAction **pluginAction) override;
+ int set(const std::string &key, bool val, PluginAction **pluginAction) override;
+ int set(const std::string &key, const std::string &val, PluginAction **pluginAction) override;
int getInt(const std::string &key) override;
double getDouble(const std::string &key) override;
setName("vconf");
}
-int VconfPlugin::set(const std::string &key, int val, int *oldVal)
+int VconfPlugin::set(const std::string &key, int val, PluginAction **pluginAction)
{
int ret;
DBG("set<int>(%s, %d)", key.c_str(), val);
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- if (oldVal) {
- ret = vconf_get_int(newKey.c_str(), oldVal);
- if (0 != ret) {
- ERR("vconf_get_int(%s) Fail(%d)", newKey.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
- }
-
ret = handleChange(newKey);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", newKey.c_str(), ret);
return ret;
}
- ret = vconf_set_int(newKey.c_str(), val);
- if (0 != ret) {
- ERR("vconf_set_int(%s, %d) Fail(%d)", newKey.c_str(), val, ret);
- return MODES_ERROR_SYSTEM;
- }
- return MODES_ERROR_NONE;
+ VconfActionInt *action = new VconfActionInt(newKey);
+ ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ delete action;
+ return ret;
}
-int VconfPlugin::set(const std::string &key, double val, double *oldVal)
+int VconfPlugin::set(const std::string &key, double val, PluginAction **pluginAction)
{
int ret;
DBG("set<double>(%s, %lf)", key.c_str(), val);
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- if (oldVal) {
- ret = vconf_get_dbl(newKey.c_str(), oldVal);
- if (0 != ret) {
- ERR("vconf_get_dbl(%s) Fail(%d)", newKey.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
- }
-
ret = handleChange(newKey);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", newKey.c_str(), ret);
return ret;
}
- ret = vconf_set_dbl(newKey.c_str(), val);
- if (0 != ret) {
- ERR("vconf_set_int(%s, %lf) Fail(%d)", newKey.c_str(), val, ret);
- return MODES_ERROR_SYSTEM;
- }
- return MODES_ERROR_NONE;
+ VconfActionDbl *action = new VconfActionDbl(newKey);
+ ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ delete action;
+ return ret;
}
-int VconfPlugin::set(const std::string &key, bool val, bool *oldVal)
+int VconfPlugin::set(const std::string &key, bool val, PluginAction **pluginAction)
{
int ret;
DBG("set<bool>(%s, %d)", key.c_str(), val);
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- if (oldVal) {
- int prev;
- ret = vconf_get_bool(newKey.c_str(), &prev);
- if (0 != ret) {
- ERR("vconf_get_bool(%s) Fail(%d)", newKey.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
- *oldVal = prev;
- }
-
ret = handleChange(newKey);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", newKey.c_str(), ret);
return ret;
}
- ret = vconf_set_bool(newKey.c_str(), val);
- if (0 != ret) {
- ERR("vconf_set_bool(%s, %d) Fail(%d)", newKey.c_str(), val, ret);
- return MODES_ERROR_SYSTEM;
- }
- return MODES_ERROR_NONE;
+ VconfActionBool *action = new VconfActionBool(newKey);
+ ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ delete action;
+ return ret;
}
-int VconfPlugin::set(const std::string &key, const std::string &val, std::string *oldVal)
+int VconfPlugin::set(const std::string &key, const std::string &val, PluginAction **pluginAction)
{
DBG("set<string>(%s, %s)", key.c_str(), val.c_str());
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- if (oldVal) {
- char *prevStr = vconf_get_str(newKey.c_str());
- if (NULL == prevStr) {
- ERR("vconf_get_str(%s) Fail()", newKey.c_str());
- return MODES_ERROR_SYSTEM;
- }
- *oldVal = std::string(prevStr);
- free(prevStr);
- }
-
int ret = handleChange(newKey);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", newKey.c_str(), ret);
return ret;
}
- ret = vconf_set_str(newKey.c_str(), val.c_str());
- if (0 != ret) {
- ERR("vconf_set_str(%s, %s) Fail(%d)", newKey.c_str(), val.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
-
- return MODES_ERROR_NONE;
+ VconfActionStr *action = new VconfActionStr(newKey);
+ ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ delete action;
+ return ret;
}
int VconfPlugin::getInt(const std::string &key)
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- int value = 0;
- int ret = vconf_get_int(newKey.c_str(), &value);
- if (0 != ret) {
- ERR("vconf_get_int(%s) Fail(%d)", newKey.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
- return value;
+ VconfActionInt action(newKey);
+
+ return action.get();
}
double VconfPlugin::getDouble(const std::string &key)
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- double value = 0.0;
- int ret = vconf_get_dbl(newKey.c_str(), &value);
- if (0 != ret) {
- ERR("vconf_get_int(%s) Fail(%d)", newKey.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
- return value;
+ VconfActionDbl action(newKey);
+
+ return action.get();
}
bool VconfPlugin::getBool(const std::string &key)
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- int value = 0;
- int ret = vconf_get_bool(newKey.c_str(), &value);
- if (0 != ret) {
- ERR("vconf_get_bool(%s) Fail(%d)", newKey.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
- return (value) ? true : false;
+ VconfActionBool action(newKey);
+
+ return action.get();
}
std::string VconfPlugin::getString(const std::string &key)
std::string newKey(key);
std::replace(newKey.begin(), newKey.end(), '.', '/');
- char *value = NULL;
- value = vconf_get_str(newKey.c_str());
- if (NULL == value) {
- ERR("vconf_get_str(%s) Fail()", newKey.c_str());
- return std::string();
- }
- std::string retStr = value;
- free(value);
+ VconfActionStr action(newKey);
- return retStr;
+ return action.get();
}
int VconfPlugin::setChangedCallback(valueChangedCb callback, const std::string &key, void *userData)
{
return wifiErrorMessage.get(err);
}
-
-void WifiAction::setName(std::string name)
-{
- this->name = name;
-}
-
-std::string WifiAction::getName()
-{
- return name;
-}
#include <string>
#include <wifi-manager.h>
+#include <PluginAction.h>
#include "WifiErrorMessage.h"
MODES_NAMESPACE_BEGIN
-class WifiAction {
+class WifiAction : public PluginAction {
public:
WifiAction();
virtual ~WifiAction();
bool isWifiActivate();
- std::string getName();
virtual int set(int val);
virtual int set(double val);
virtual int set(bool val);
protected:
bool isWifiManagerEnable();
const std::string& strErr(int err);
- void setName(std::string name);
wifi_manager_h wifiManagerHandle;
WifiErrorMessage wifiErrorMessage;
-private:
- std::string name;
};
MODES_NAMESPACE_END
MODES_NAMESPACE_USE;
WifiActionPower::WifiActionPower()
+ :oldVal(false)
{
setName("power");
}
{
RETV_IF(!isWifiManagerEnable(), MODES_ERROR_NOT_SUPPORTED);
- if (isWifiActivate() == val) {
+ oldVal = isWifiActivate();
+ if (oldVal == val) {
INFO("Already wifi is [%s]", val ? "On" : "Off");
return MODES_ERROR_NONE;
}
return MODES_ERROR_NONE;
}
+
+int WifiActionPower::undo()
+{
+ RETV_IF(!isWifiManagerEnable(), MODES_ERROR_NOT_SUPPORTED);
+
+ if (isWifiActivate() == oldVal) {
+ INFO("Already wifi is [%s]", oldVal ? "On" : "Off");
+ return MODES_ERROR_NONE;
+ }
+
+ if (oldVal) {
+ int wifiRet = wifi_manager_activate(wifiManagerHandle, activate_cb, this);
+ if (WIFI_MANAGER_ERROR_NONE != wifiRet) {
+ ERR("wifi_manager_activate() Fail(%d, %s)", wifiRet, strErr(wifiRet).c_str());
+ return MODES_ERROR_SYSTEM;
+ }
+ } else {
+ int wifiRet = wifi_manager_deactivate(wifiManagerHandle, deactivate_cb, this);
+ if (WIFI_MANAGER_ERROR_NONE != wifiRet) {
+ ERR("wifi_manager_activate() Fail(%d, %s)", wifiRet, strErr(wifiRet).c_str());
+ return MODES_ERROR_SYSTEM;
+ }
+ }
+
+ INFO("Wifi power [%s]", oldVal ? "On" : "Off");
+ return MODES_ERROR_NONE;
+}
int set(bool val) override;
int get(bool *val) override;
+ int undo() override;
private:
static void activate_cb(wifi_manager_error_e result, void *user_data);
static void deactivate_cb(wifi_manager_error_e result, void *user_data);
+ bool oldVal;
};
MODES_NAMESPACE_END
void WifiFactory::destroyAction(WifiAction *action)
{
- RET_IF(action == NULL);
delete action;
}
MODES_NAMESPACE_USE;
-class WifiOperation;
class WifiPlugin : public Plugin {
public:
WifiPlugin();
~WifiPlugin();
- int set(const std::string &key, int val, int *oldVal) override;
- int set(const std::string &key, double val, double *oldVal) override;
- int set(const std::string &key, bool val, bool *oldVal) override;
- int set(const std::string &key, const std::string &val, std::string *oldVal) override;
+ int set(const std::string &key, int val, PluginAction **pluginAction) override;
+ int set(const std::string &key, double val, PluginAction **pluginAction) override;
+ int set(const std::string &key, bool val, PluginAction **pluginAction) override;
+ int set(const std::string &key, const std::string &val, PluginAction **pluginAction) override;
+ int undo(PluginAction *pluginAction) override;
private:
WifiFactory wifiFactory;
};
{
}
-int WifiPlugin::set(const std::string &key, int val, int *oldVal)
+int WifiPlugin::set(const std::string &key, int val, PluginAction **pluginAction)
{
WifiAction *action = wifiFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %d]", key.c_str(), val);
- if (oldVal)
- ERR("Not Supported");
-
int ret = action->set(val);
- wifiFactory.destroyAction(action);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ wifiFactory.destroyAction(action);
+
return ret;
}
-int WifiPlugin::set(const std::string &key, double val, double *oldVal)
+int WifiPlugin::set(const std::string &key, double val, PluginAction **pluginAction)
{
WifiAction *action = wifiFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %f]", key.c_str(), val);
- if (oldVal)
- ERR("Not Supported");
-
int ret = action->set(val);
- wifiFactory.destroyAction(action);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ wifiFactory.destroyAction(action);
+
return ret;
}
-int WifiPlugin::set(const std::string &key, bool val, bool *oldVal)
+int WifiPlugin::set(const std::string &key, bool val, PluginAction **pluginAction)
{
WifiAction *action = wifiFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %s]", key.c_str(), (val ? "on" : "off"));
- if (oldVal)
- action->get(oldVal);
int ret = action->set(val);
-
- wifiFactory.destroyAction(action);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ wifiFactory.destroyAction(action);
return ret;
}
-int WifiPlugin::set(const std::string &key, const std::string &val, std::string *oldVal)
+int WifiPlugin::set(const std::string &key, const std::string &val, PluginAction **pluginAction)
{
WifiAction *action = wifiFactory.createAction(key);
RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
DBG("set [%s, %s]", key.c_str(), val.c_str());
- if (oldVal)
- ERR("Not Supported");
-
int ret = action->set(val);
+ if (pluginAction)
+ *pluginAction = action;
+ else
+ wifiFactory.destroyAction(action);
+
+ return ret;
+}
+
+int WifiPlugin::undo(PluginAction *pluginAction)
+{
+ WifiAction *action = static_cast<WifiAction*>(pluginAction);
+ RETV_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER);
+
+ DBG("Action(%s) undo", action->getName().c_str());
+
+ int ret = action->undo();
wifiFactory.destroyAction(action);
+
return ret;
}