fix the handler of vconf callback accepted/tizen/unified/20200409.083703 submit/tizen/20200409.052214
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 9 Apr 2020 05:18:09 +0000 (14:18 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 9 Apr 2020 05:21:33 +0000 (14:21 +0900)
common/VconfCbHandler.cpp
display/DisplayActVconf.cpp
display/DisplayBrightness.cpp
display/DisplayPlugin.cpp
include/VconfCbHandler.h
unittests/mdsp_test_vconf.cpp
vconf/VconfActionBool.cpp
vconf/VconfActionDbl.cpp
vconf/VconfActionInt.cpp
vconf/VconfActionStr.cpp

index e4577ca..f8a6581 100644 (file)
@@ -26,19 +26,12 @@ MODES_NAMESPACE_USE;
 
 std::map<std::string, VconfChangeAction*> 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;
 }
index a9e8d07..626a225 100644 (file)
@@ -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);
 }
index 339da6b..bf96829 100644 (file)
@@ -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);
 }
index 4e24e0d..9930cad 100644 (file)
@@ -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;
 }
 
index 7e0d379..ff4d72f 100644 (file)
@@ -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:
index 7feb4f1..c8e642f 100644 (file)
@@ -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);
index 4540990..8c6b717 100644 (file)
@@ -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);
 }
index 913124f..fae68c1 100644 (file)
@@ -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);
 }
index 268caa2..ca28987 100644 (file)
@@ -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);
 }
index 67b7db6..bb887a7 100644 (file)
@@ -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);
 }