From aca730facd69f47285b69d287ac7426a0b04f93c Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Thu, 9 Apr 2020 14:18:09 +0900 Subject: [PATCH] fix the handler of vconf callback --- common/VconfCbHandler.cpp | 11 ++--------- display/DisplayActVconf.cpp | 4 ++-- display/DisplayBrightness.cpp | 5 +++-- display/DisplayPlugin.cpp | 2 ++ include/VconfCbHandler.h | 2 +- unittests/mdsp_test_vconf.cpp | 11 ++++++++--- vconf/VconfActionBool.cpp | 4 ++-- vconf/VconfActionDbl.cpp | 4 ++-- vconf/VconfActionInt.cpp | 4 ++-- vconf/VconfActionStr.cpp | 4 ++-- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/common/VconfCbHandler.cpp b/common/VconfCbHandler.cpp index e4577ca..f8a6581 100644 --- a/common/VconfCbHandler.cpp +++ b/common/VconfCbHandler.cpp @@ -26,19 +26,12 @@ MODES_NAMESPACE_USE; std::map VconfCbHandler::callbackMap; -int VconfCbHandler::handleSubscription(const std::string &key) +int VconfCbHandler::invokeChangedCB(const std::string &key) { auto found = callbackMap.find(key); if (callbackMap.end() != found) { - WARN("Acition(%s) already exist", key.c_str()); + WARN("Action(%s) already exist", key.c_str()); found->second->vconfChangedCB(); - - callbackMap.erase(found); - int ret = vconf_ignore_key_changed(key.c_str(), vconfCallback); - if (0 != ret) { - ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret); - return MODES_ERROR_SYSTEM; - } } return MODES_ERROR_NONE; } diff --git a/display/DisplayActVconf.cpp b/display/DisplayActVconf.cpp index a9e8d07..626a225 100644 --- a/display/DisplayActVconf.cpp +++ b/display/DisplayActVconf.cpp @@ -44,7 +44,7 @@ int DisplayActVconf::set(int val) { requestVal = val; - int ret = cbHandler.handleSubscription(KEY[keyType]); + int ret = cbHandler.invokeChangedCB(KEY[keyType]); if (MODES_ERROR_NONE != ret) { ERR("handleChange(%s) Fail(%d)", KEY[keyType], ret); return ret; @@ -120,9 +120,9 @@ void DisplayActVconf::unSetChangedCallback(valueChangedCB callback, void *userDa cb = nullptr; } +//This funcion handles changes made by the Modes void DisplayActVconf::vconfChangedCB() { - //The value will be changed by Modes. That's why the callback is always called. if (cb) cb(cbData); } diff --git a/display/DisplayBrightness.cpp b/display/DisplayBrightness.cpp index 339da6b..bf96829 100644 --- a/display/DisplayBrightness.cpp +++ b/display/DisplayBrightness.cpp @@ -38,7 +38,7 @@ int DisplayBrightness::set(int val) { requestVal = val; - int ret = cbHandler.handleSubscription(KEY); + int ret = cbHandler.invokeChangedCB(KEY); if (MODES_ERROR_NONE != ret) { ERR("handleChange(%s) Fail(%d)", KEY, ret); return ret; @@ -124,6 +124,7 @@ int DisplayBrightness::setChangedCallback(valueChangedCB callback, void *userDat return MODES_ERROR_NONE; } + void DisplayBrightness::unSetChangedCallback(valueChangedCB callback, void *userData) { RET_IF(nullptr == callback); @@ -134,9 +135,9 @@ void DisplayBrightness::unSetChangedCallback(valueChangedCB callback, void *user cb = nullptr; } +//This funcion handles changes made by the Modes void DisplayBrightness::vconfChangedCB() { - //The value will be changed by Modes. That's why the callback is always called. if (cb) cb(cbData); } diff --git a/display/DisplayPlugin.cpp b/display/DisplayPlugin.cpp index 4e24e0d..9930cad 100644 --- a/display/DisplayPlugin.cpp +++ b/display/DisplayPlugin.cpp @@ -70,6 +70,7 @@ int DisplayPlugin::set(const std::string &key, int val, PluginAction **pluginAct *pluginAction = action; else displayFactory.destroyAction(action); + return ret; } @@ -86,6 +87,7 @@ int DisplayPlugin::set(const std::string &key, bool val, PluginAction **pluginAc *pluginAction = action; else displayFactory.destroyAction(action); + return ret; } diff --git a/include/VconfCbHandler.h b/include/VconfCbHandler.h index 7e0d379..ff4d72f 100644 --- a/include/VconfCbHandler.h +++ b/include/VconfCbHandler.h @@ -25,7 +25,7 @@ MODES_NAMESPACE_BEGIN class VconfCbHandler { public: - int handleSubscription(const std::string &key); + int invokeChangedCB(const std::string &key); int setChangedCB(const std::string &key, VconfChangeAction *action); void unSetChangedCB(const std::string &key); private: diff --git a/unittests/mdsp_test_vconf.cpp b/unittests/mdsp_test_vconf.cpp index 7feb4f1..c8e642f 100644 --- a/unittests/mdsp_test_vconf.cpp +++ b/unittests/mdsp_test_vconf.cpp @@ -58,7 +58,12 @@ protected: static void callback1(void *userData) { - DBG("%s changed callback called!", (char*)userData); + PluginAction *action = (PluginAction*)userData; + DBG("%s changed callback called!", action->getName().c_str()); + + //In practice, it is handled by Action. refer to Action.cpp + action->unSetChangedCallback(callback1, nullptr); + cb1Called = true; } @@ -184,13 +189,13 @@ TEST_F(VconfPluginTest, callbackPluginVconfReset) ret = plugin->set(key, 4, &action1); EXPECT_EQ(ret, MODES_ERROR_NONE); - ret = action1->setChangedCallback(callback1, nullptr); + ret = action1->setChangedCallback(callback1, (void*)action1); EXPECT_EQ(ret, MODES_ERROR_NONE); PluginAction *action2; ret = plugin->set(key, 2, &action2); EXPECT_EQ(ret, MODES_ERROR_NONE); EXPECT_TRUE(cb1Called); - ret = action2->setChangedCallback(callback2, nullptr); + ret = action2->setChangedCallback(callback2, (void*)key); EXPECT_EQ(ret, MODES_ERROR_NONE); g_idle_add(changedCallbackidler, nullptr); g_main_loop_run(loop); diff --git a/vconf/VconfActionBool.cpp b/vconf/VconfActionBool.cpp index 4540990..8c6b717 100644 --- a/vconf/VconfActionBool.cpp +++ b/vconf/VconfActionBool.cpp @@ -31,7 +31,7 @@ int VconfActionBool::set(bool val) { requestVal = val; - int ret = cbHandler.handleSubscription(key); + int ret = cbHandler.invokeChangedCB(key); if (MODES_ERROR_NONE != ret) { ERR("handleChange(%s) Fail(%d)", key.c_str(), ret); return ret; @@ -107,9 +107,9 @@ void VconfActionBool::unSetChangedCallback(valueChangedCB callback, void *userDa cb = nullptr; } +//This funcion handles changes made by the Modes void VconfActionBool::vconfChangedCB() { - //The value will be changed by Modes. That's why the callback is always called. if (cb) cb(cbData); } diff --git a/vconf/VconfActionDbl.cpp b/vconf/VconfActionDbl.cpp index 913124f..fae68c1 100644 --- a/vconf/VconfActionDbl.cpp +++ b/vconf/VconfActionDbl.cpp @@ -31,7 +31,7 @@ int VconfActionDbl::set(double val) { requestVal = val; - int ret = cbHandler.handleSubscription(key); + int ret = cbHandler.invokeChangedCB(key); if (MODES_ERROR_NONE != ret) { ERR("handleChange(%s) Fail(%d)", key.c_str(), ret); return ret; @@ -105,9 +105,9 @@ void VconfActionDbl::unSetChangedCallback(valueChangedCB callback, void *userDat cb = nullptr; } +//This funcion handles changes made by the Modes void VconfActionDbl::vconfChangedCB() { - //The value will be changed by Modes. That's why the callback is always called. if (cb) cb(cbData); } diff --git a/vconf/VconfActionInt.cpp b/vconf/VconfActionInt.cpp index 268caa2..ca28987 100644 --- a/vconf/VconfActionInt.cpp +++ b/vconf/VconfActionInt.cpp @@ -31,7 +31,7 @@ int VconfActionInt::set(int val) { requestVal = val; - int ret = cbHandler.handleSubscription(key); + int ret = cbHandler.invokeChangedCB(key); if (MODES_ERROR_NONE != ret) { ERR("handleChange(%s) Fail(%d)", key.c_str(), ret); return ret; @@ -105,9 +105,9 @@ void VconfActionInt::unSetChangedCallback(valueChangedCB callback, void *userDat cb = nullptr; } +//This funcion handles changes made by the Modes void VconfActionInt::vconfChangedCB() { - //The value will be changed by Modes. That's why the callback is always called. if (cb) cb(cbData); } diff --git a/vconf/VconfActionStr.cpp b/vconf/VconfActionStr.cpp index 67b7db6..bb887a7 100644 --- a/vconf/VconfActionStr.cpp +++ b/vconf/VconfActionStr.cpp @@ -30,7 +30,7 @@ int VconfActionStr::set(const std::string &val) { requestVal = val; - int ret = cbHandler.handleSubscription(key); + int ret = cbHandler.invokeChangedCB(key); if (MODES_ERROR_NONE != ret) { ERR("handleChange(%s) Fail(%d)", key.c_str(), ret); return ret; @@ -101,9 +101,9 @@ void VconfActionStr::unSetChangedCallback(valueChangedCB callback, void *userDat cb = nullptr; } +//This funcion handles changes made by the Modes void VconfActionStr::vconfChangedCB() { - //The value will be changed by Modes. That's why the callback is always called. if (cb) cb(cbData); } -- 2.34.1