revise vconf changed callbacks
authorYoungjae Shin <yj99.shin@samsung.com>
Wed, 4 Mar 2020 03:11:30 +0000 (12:11 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Mar 2020 04:30:37 +0000 (13:30 +0900)
23 files changed:
CMakeLists.txt
common/VconfCbHandler.cpp [moved from vconf/VconfAction.cpp with 54% similarity]
display/CMakeLists.txt
display/DisplayActVconf.cpp [new file with mode: 0644]
display/DisplayActVconf.h [moved from display/DisplayAutoBrightness.h with 76% similarity]
display/DisplayAutoBrightness.cpp [deleted file]
display/DisplayFactory.cpp
display/DisplayFactory.h
display/DisplayTimeout.cpp [deleted file]
include/VconfCbHandler.h [moved from vconf/VconfAction.h with 58% similarity]
include/VconfChangeAction.h [moved from display/DisplayTimeout.h with 67% similarity]
unittests/CMakeLists.txt
unittests/mdsp_test_vconf.cpp
vconf/CMakeLists.txt
vconf/VconfActionBool.cpp
vconf/VconfActionBool.h
vconf/VconfActionDbl.cpp
vconf/VconfActionDbl.h
vconf/VconfActionInt.cpp
vconf/VconfActionInt.h
vconf/VconfActionStr.cpp
vconf/VconfActionStr.h
vconf/VconfPlugin.cpp

index fd4247e..cf8ccb2 100644 (file)
@@ -15,6 +15,8 @@ IF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR)
        SET(MODES_PLUGIN_DEFAULT_DIR "/usr/lib/modes-plugins/")
 ENDIF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR)
 
+SET(VCONF_COMMON_SRC ${CMAKE_SOURCE_DIR}/common/VconfCbHandler.cpp)
+
 ADD_SUBDIRECTORY(wifi)
 ADD_SUBDIRECTORY(vconf)
 ADD_SUBDIRECTORY(app)
similarity index 54%
rename from vconf/VconfAction.cpp
rename to common/VconfCbHandler.cpp
index 32a551f..e4577ca 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "VconfAction.h"
+#include "VconfCbHandler.h"
 
 #include <string>
 #include <algorithm>
 #include <vconf.h>
+#include <modes_errors.h>
 #include "plugin-log.h"
+#include "VconfChangeAction.h"
 
 MODES_NAMESPACE_USE;
 
-std::map<std::string, VconfAction::CallbackData> VconfAction::callbackMap;
+std::map<std::string, VconfChangeAction*> VconfCbHandler::callbackMap;
 
-VconfAction::VconfAction(const std::string &name, const std::string &vconfKey)
-       : PluginAction(name), key(vconfKey)
+int VconfCbHandler::handleSubscription(const std::string &key)
 {
+       auto found = callbackMap.find(key);
+       if (callbackMap.end() != found) {
+               WARN("Acition(%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;
 }
 
-int VconfAction::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfCbHandler::setChangedCB(const std::string &key, VconfChangeAction *action)
 {
-       callbackMap[key].userData = userData;
-       callbackMap[key].callback = callback;
+       RETV_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER);
 
-       int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCallback, &callbackMap[key]);
+       int ret = vconf_notify_key_changed(key.c_str(), vconfCallback, NULL);
        if (0 != ret) {
                ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
                return MODES_ERROR_SYSTEM;
        }
 
-       DBG("setChangedCallback(%s) Success", key.c_str());
+       callbackMap[key] = action;
+
        return MODES_ERROR_NONE;
 }
 
-void VconfAction::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfCbHandler::unSetChangedCB(const std::string &key)
 {
        auto found = callbackMap.find(key);
-       if (found == callbackMap.end()) {
+       if (callbackMap.end() == found) {
                ERR("No Changed Callback(%s)", key.c_str());
                return;
        }
 
        callbackMap.erase(found);
-       int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCallback);
+       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;
        }
-
-       DBG("unSetChangedCallback(%s) Success", key.c_str());
 }
 
-int VconfAction::handleChange()
+void VconfCbHandler::vconfCallback(keynode_t *node, void *userData)
 {
-       auto found = callbackMap.find(key);
-       if (callbackMap.end() != found) {
-               DBG("Acition(%s) already exist", key.c_str());
-               found->second.callback(found->second.userData);
-
-               callbackMap.erase(found);
-               int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCallback);
-               if (0 != ret) {
-                       ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
-                       return MODES_ERROR_SYSTEM;
-               }
-       }
-       return MODES_ERROR_NONE;
-}
-
-void VconfAction::vconfChangedCallback(keynode_t *node, void *userData)
-{
-       CallbackData *cbData = (CallbackData*)userData;
-
-       RET_IF(NULL == userData);
-
        auto found = callbackMap.find(node->keyname);
-       if (&(found->second) != cbData) {
-               ERR("Unknown callbackData(%s)", node->keyname);
+       if (callbackMap.end() == found) {
+               ERR("No VconfAction(%s)", node->keyname);
                return;
        }
 
-       cbData->callback(cbData->userData);
+       found->second->vconfChangedCB(node);
        DBG("Action(%s) is Changed", node->keyname);
 }
index 85bf7cc..e6add36 100644 (file)
@@ -7,7 +7,7 @@ PKG_CHECK_MODULES(DISPLAY_pkgs REQUIRED modes dlog capi-base-common capi-system-
 INCLUDE_DIRECTORIES(${DISPLAY_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${DISPLAY_pkgs_LIBRARY_DIRS})
 
-ADD_LIBRARY(${DISPLAY_PLUGIN} SHARED ${DISPLAY_SRCS})
+ADD_LIBRARY(${DISPLAY_PLUGIN} SHARED ${DISPLAY_SRCS} ${VCONF_COMMON_SRC})
 TARGET_LINK_LIBRARIES(${DISPLAY_PLUGIN} ${DISPLAY_pkgs_LIBRARIES})
 SET_TARGET_PROPERTIES(${DISPLAY_PLUGIN} PROPERTIES NO_SONAME 1 )
 INSTALL(TARGETS ${DISPLAY_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR})
diff --git a/display/DisplayActVconf.cpp b/display/DisplayActVconf.cpp
new file mode 100644 (file)
index 0000000..a9e8d07
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2019-2020 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 "DisplayActVconf.h"
+
+#include <sstream>
+#include <string>
+#include <vconf.h>
+#include <modes_errors.h>
+#include "plugin-log.h"
+#include "VconfCbHandler.h"
+
+MODES_NAMESPACE_USE;
+
+// It should align with actionKey in DisplayFactory
+const std::string DisplayActVconf::NAME[2] = {
+       "autoBrightness",
+       "timeout",
+};
+const char* const DisplayActVconf::KEY[2] = {
+       VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT,
+       VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL,
+};
+
+DisplayActVconf::DisplayActVconf(int type)
+       :DisplayAction(NAME[type]), keyType(type),
+       requestVal(-1), oldVal(-1), cb(nullptr), cbData(nullptr)
+{
+}
+
+int DisplayActVconf::set(int val)
+{
+       requestVal = val;
+
+       int ret = cbHandler.handleSubscription(KEY[keyType]);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("handleChange(%s) Fail(%d)", KEY[keyType], ret);
+               return ret;
+       }
+
+       ret = vconf_get_int(KEY[keyType], &oldVal);
+       if (0 != ret) {
+               ERR("vconf_get_int(%s) Fail(%d)", KEY[keyType], ret);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       if (oldVal == val) {
+               INFO("%s already set(%d)", NAME[keyType].c_str(), val);
+       } else {
+               ret = vconf_set_int(KEY[keyType], val);
+               if (0 != ret) {
+                       ERR("vconf_set_int(%s, %d) Fail(%d)", KEY[keyType], val, ret);
+                       return MODES_ERROR_SYSTEM;
+               }
+       }
+
+       return MODES_ERROR_NONE;
+}
+
+void DisplayActVconf::undo()
+{
+       RET_IF(-1 == oldVal);
+
+       int ret = vconf_set_int(KEY[keyType], oldVal);
+       if (0 != ret)
+               ERR("vconf_set_int(%s, %d) Fail(%d)", KEY[keyType], oldVal, ret);
+}
+
+std::string DisplayActVconf::serialize()
+{
+       std::ostringstream ostr;
+
+       ostr << oldVal;
+       return ostr.str();
+}
+
+int DisplayActVconf::parse(const std::string &archive)
+{
+       std::istringstream iss(archive);
+       iss >> oldVal;
+
+       return MODES_ERROR_NONE;
+}
+
+int DisplayActVconf::setChangedCallback(valueChangedCB callback, void *userData)
+{
+       RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
+
+       int ret = cbHandler.setChangedCB(KEY[keyType], this);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("setChangedCB(%s) Fail(%d)", KEY[keyType], ret);
+               return ret;
+       }
+
+       cb = callback;
+       cbData = userData;
+
+       return MODES_ERROR_NONE;
+}
+
+void DisplayActVconf::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+       RET_IF(nullptr == callback);
+
+       cbHandler.unSetChangedCB(KEY[keyType]);
+
+       cbData = nullptr;
+       cb = nullptr;
+}
+
+void DisplayActVconf::vconfChangedCB()
+{
+       //The value will be changed by Modes. That's why the callback is always called.
+       if (cb)
+               cb(cbData);
+}
+
+void DisplayActVconf::vconfChangedCB(keynode_t *node)
+{
+       const char *vconfKey = vconf_keynode_get_name(node);
+       if (vconfKey != KEY[keyType]) {
+               WARN("Unknown vconf(%s) notification", vconfKey);
+               return;
+       }
+
+       int val = vconf_keynode_get_int(node);
+
+       if (cb && (val != requestVal))
+               cb(cbData);
+}
similarity index 76%
rename from display/DisplayAutoBrightness.h
rename to display/DisplayActVconf.h
index 528664e..2d2d7cc 100644 (file)
 #pragma once
 
 #include <string>
-#include <vconf.h>
 #include "plugin-def.h"
 #include "DisplayAction.h"
+#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class DisplayAutoBrightness : public DisplayAction {
+class DisplayActVconf : public DisplayAction, public VconfChangeAction {
 public:
-       DisplayAutoBrightness();
-       ~DisplayAutoBrightness();
+       DisplayActVconf(int type);
 
        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;
 
-       static const std::string NAME;
+       void vconfChangedCB() override;
+       void vconfChangedCB(keynode_t *node) override;
 
+       static const std::string NAME[2];
+       static const char* const KEY[2];
 private:
-       static void autoBrightnessChangedCB(keynode_t *node, void *userData);
-
-       static const char* const key;
+       int keyType;
+       int requestVal;
        int oldVal;
+       VconfCbHandler cbHandler;
        valueChangedCB cb;
        void *cbData;
 };
diff --git a/display/DisplayAutoBrightness.cpp b/display/DisplayAutoBrightness.cpp
deleted file mode 100644 (file)
index cb24efb..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2019-2020 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 "DisplayAutoBrightness.h"
-#include <sstream>
-#include <string>
-#include <vconf.h>
-#include <modes_errors.h>
-#include "plugin-log.h"
-
-MODES_NAMESPACE_USE;
-
-const std::string DisplayAutoBrightness::NAME = "autoBrightness";
-const char* const DisplayAutoBrightness::key = VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT;
-
-DisplayAutoBrightness::DisplayAutoBrightness()
-       :DisplayAction(NAME), oldVal(-1), cb(nullptr), cbData(nullptr)
-{
-}
-
-DisplayAutoBrightness::~DisplayAutoBrightness()
-{
-}
-
-int DisplayAutoBrightness::set(int val)
-{
-       int ret = vconf_get_int(key, &oldVal);
-       if (0 != ret) {
-               ERR("vconf_get_int(%s) Fail(%d)", key, ret);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       if (oldVal == val) {
-               INFO("Auto brightness already set(%d)", val);
-               return MODES_ERROR_NONE;
-       }
-
-       ret = vconf_set_int(key, val);
-       if (0 != ret) {
-               ERR("vconf_set_int(%s, %d) Fail(%d)", key, val, ret);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       return MODES_ERROR_NONE;
-}
-
-void DisplayAutoBrightness::undo()
-{
-       RET_IF(-1 == oldVal);
-
-       int ret = vconf_set_int(key, oldVal);
-       if (0 != ret)
-               ERR("vconf_set_int(%s, %d) Fail(%d)", key, oldVal, ret);
-}
-
-std::string DisplayAutoBrightness::serialize()
-{
-       std::ostringstream ostr;
-
-       ostr << oldVal;
-       return ostr.str();
-}
-
-int DisplayAutoBrightness::parse(const std::string &archive)
-{
-       std::istringstream iss(archive);
-       iss >> oldVal;
-
-       return MODES_ERROR_NONE;
-}
-
-int DisplayAutoBrightness::setChangedCallback(valueChangedCB callback, void *userData)
-{
-       cbData = userData;
-       cb = callback;
-       int ret = vconf_notify_key_changed(key, autoBrightnessChangedCB, this);
-       if (0 != ret) {
-               ERR("vconf_notify_key_changed(%s) Fail(%d)", key, ret);
-               return MODES_ERROR_SYSTEM;
-       }
-       return MODES_ERROR_NONE;
-}
-
-void DisplayAutoBrightness::unSetChangedCallback(valueChangedCB callback, void *userData)
-{
-       int ret = vconf_ignore_key_changed(key, autoBrightnessChangedCB);
-       if (0 != ret)
-               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key, ret);
-
-       cbData = NULL;
-       cb = NULL;
-}
-
-void DisplayAutoBrightness::autoBrightnessChangedCB(keynode_t *node, void *userData)
-{
-       DisplayAutoBrightness *action = (DisplayAutoBrightness*)userData;
-
-       RET_IF(NULL == userData);
-
-       int val = 0;
-       int ret = vconf_get_int(key, &val);
-       if (0 != ret) {
-               ERR("vconf_get_int(%s) Fail(%d)", key, ret);
-               return;
-       }
-
-       if (action->cb && (val != action->oldVal))
-               action->cb(action->cbData);
-}
index b3e2dda..8497b8a 100644 (file)
 #include <string>
 #include <device/power.h>
 #include "plugin-log.h"
+#include "DisplayActVconf.h"
 #include "DisplayBrightness.h"
-#include "DisplayAutoBrightness.h"
-#include "DisplayTimeout.h"
 #include "DisplayAllowPalmTouch.h"
 
 MODES_NAMESPACE_USE;
 
 DisplayFactory::DisplayFactory()
 {
+       actionMap[DisplayActVconf::NAME[AUTO_BRIGHTNESS_VCONF]] = AUTO_BRIGHTNESS_VCONF;
+       actionMap[DisplayActVconf::NAME[TIMEOUT_VCONF]] = TIMEOUT_VCONF;
        actionMap[DisplayBrightness::NAME] = BRIGHTNESS;
-       actionMap[DisplayAutoBrightness::NAME] = AUTO_BRIGHTNESS;
-       actionMap[DisplayTimeout::NAME] = TIMEOUT;
        actionMap[DisplayAllowPalmTouch::NAME] = ALLOW_PALM_TOUCH;
 }
 
@@ -42,14 +41,14 @@ DisplayAction* DisplayFactory::createAction(const std::string &key)
 
        DisplayAction *action;
        switch (search->second) {
-       case BRIGHTNESS:
-               action = new DisplayBrightness();
+       case AUTO_BRIGHTNESS_VCONF:
+               action = new DisplayActVconf(AUTO_BRIGHTNESS_VCONF);
                break;
-       case AUTO_BRIGHTNESS:
-               action = new DisplayAutoBrightness();
+       case TIMEOUT_VCONF:
+               action = new DisplayActVconf(TIMEOUT_VCONF);
                break;
-       case TIMEOUT:
-               action = new DisplayTimeout();
+       case BRIGHTNESS:
+               action = new DisplayBrightness();
                break;
        case ALLOW_PALM_TOUCH:
                action = new DisplayAllowPalmTouch();
index a440e3d..f0602a9 100644 (file)
@@ -30,9 +30,9 @@ public:
        void destroyAction(DisplayAction *action);
 private:
        enum actionKey{
+               AUTO_BRIGHTNESS_VCONF,
+               TIMEOUT_VCONF,
                BRIGHTNESS,
-               AUTO_BRIGHTNESS,
-               TIMEOUT,
                ALLOW_PALM_TOUCH,
        };
 
diff --git a/display/DisplayTimeout.cpp b/display/DisplayTimeout.cpp
deleted file mode 100644 (file)
index d68f0e9..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2019-2020 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 "DisplayTimeout.h"
-#include <sstream>
-#include <string>
-#include <vconf.h>
-#include <modes_errors.h>
-#include "plugin-log.h"
-
-MODES_NAMESPACE_USE;
-
-const std::string DisplayTimeout::NAME = "timeout";
-DisplayTimeout::DisplayTimeout()
-       :DisplayAction(NAME), key(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL), oldDisplayTimeout(-1)
-{
-}
-
-DisplayTimeout::~DisplayTimeout()
-{
-}
-
-int DisplayTimeout::set(int val)
-{
-       int ret = vconf_get_int(key, &oldDisplayTimeout);
-       if (0 != ret) {
-               ERR("vconf_get_int(%s) Fail(%d)", key, ret);
-               return MODES_ERROR_SYSTEM;
-       }
-       ret = vconf_set_int(key, val);
-       if (0 != ret) {
-               ERR("vconf_set_int(%s, %d) Fail(%d)", key, val, ret);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       return MODES_ERROR_NONE;
-}
-
-void DisplayTimeout::undo()
-{
-       DBG("undo Display Timeout(%s, %d)", key, oldDisplayTimeout);
-       int ret = vconf_set_int(key, oldDisplayTimeout);
-       if (0 != ret)
-               ERR("vconf_set_int(%s, %d) Fail(%d)", key, oldDisplayTimeout, ret);
-}
-
-std::string DisplayTimeout::serialize()
-{
-       std::ostringstream ostr;
-
-       ostr << oldDisplayTimeout;
-       return ostr.str();
-}
-
-int DisplayTimeout::parse(const std::string &archive)
-{
-       std::istringstream iss(archive);
-       iss >> oldDisplayTimeout;
-
-       return MODES_ERROR_NONE;
-}
similarity index 58%
rename from vconf/VconfAction.h
rename to include/VconfCbHandler.h
index 5bc0af3..7e0d379 100644 (file)
 #include <map>
 #include <string>
 #include <vconf.h>
-#include <PluginAction.h>
 #include "plugin-def.h"
+#include "VconfChangeAction.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfAction : public PluginAction {
+class VconfCbHandler {
 public:
-       VconfAction(const std::string &name, const std::string &vconfKey);
-       virtual ~VconfAction() = default;
-
-       int setChangedCallback(valueChangedCB callback, void *userData) override;
-       void unSetChangedCallback(valueChangedCB callback, void *userData) override;
-protected:
-       int handleChange();
-       std::string key;
+       int handleSubscription(const std::string &key);
+       int setChangedCB(const std::string &key, VconfChangeAction *action);
+       void unSetChangedCB(const std::string &key);
 private:
-       struct CallbackData {
-               void *userData;
-               valueChangedCB callback;
-       };
-       static void vconfChangedCallback(keynode_t *node, void *userData);
-       static std::map<std::string, CallbackData> callbackMap;
+       static void vconfCallback(keynode_t *node, void *userData);
+       static std::map<std::string, VconfChangeAction*> callbackMap;
 };
 
 MODES_NAMESPACE_END
similarity index 67%
rename from display/DisplayTimeout.h
rename to include/VconfChangeAction.h
index c908e15..108a08b 100644 (file)
  */
 #pragma once
 
-#include <string>
+#include <vconf.h>
 #include "plugin-def.h"
-#include "DisplayAction.h"
 
 MODES_NAMESPACE_BEGIN
 
-class DisplayTimeout : public DisplayAction {
+class VconfChangeAction {
 public:
-       DisplayTimeout();
-       ~DisplayTimeout();
-
-       int set(int val) override;
-       void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
-
-       static const std::string NAME;
-private:
-       const char* const key;
-       int oldDisplayTimeout;
+       virtual void vconfChangedCB() = 0;
+       virtual void vconfChangedCB(keynode_t *node) = 0;
 };
 
 MODES_NAMESPACE_END
index 65d9a7f..48927dd 100644 (file)
@@ -60,7 +60,7 @@ SET(VCONF_PLUGIN_TEST "modes-plugintest-vconf")
 FILE(GLOB VCONF_SRCS ${VCONF_SRC_DIR}/*.cpp)
 SET(VCONF_SRCS ${VCONF_SRCS} "mdsp_test_vconf.cpp")
 
-ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS})
+ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS} ${VCONF_COMMON_SRC})
 TARGET_LINK_LIBRARIES(${VCONF_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
 INSTALL(TARGETS ${VCONF_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
 #===================================================================#
@@ -78,6 +78,6 @@ SET(DISPLAY_PLUGIN_TEST "modes-plugintest-display")
 FILE(GLOB DISPLAY_SRCS ${DISPLAY_SRC_DIR}/*.cpp)
 SET(DISPLAY_SRCS ${DISPLAY_SRCS} "mdsp_test_display.cpp")
 
-ADD_EXECUTABLE(${DISPLAY_PLUGIN_TEST} ${DISPLAY_SRCS})
+ADD_EXECUTABLE(${DISPLAY_PLUGIN_TEST} ${DISPLAY_SRCS} ${VCONF_COMMON_SRC})
 TARGET_LINK_LIBRARIES(${DISPLAY_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
 INSTALL(TARGETS ${DISPLAY_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
index e364e11..7feb4f1 100644 (file)
@@ -71,7 +71,7 @@ protected:
 
        static gboolean changedCallbackidler(gpointer data)
        {
-               DBG("start change the value db/setting/mode");
+               DBG("start change the value db/setting/psmode");
                vconf_set_int("db/setting/psmode", 7);
                return G_SOURCE_REMOVE;
        }
@@ -96,17 +96,11 @@ TEST_F(VconfPluginTest, VconfInt)
        ret = plugin->set(key, 0, nullptr);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       int val = plugin->getInt(key);
-       EXPECT_EQ(val, 0);
-
        PluginAction *action;
        ret = plugin->set(key, 1, &action);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
        plugin->undo(action);
-
-       val = plugin->getInt(key);
-       EXPECT_EQ(val, 0);
 }
 
 TEST_F(VconfPluginTest, VconfDouble)
@@ -117,17 +111,11 @@ TEST_F(VconfPluginTest, VconfDouble)
        ret = plugin->set(key, 0.0, nullptr);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       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);
 
        plugin->undo(action);
-
-       val = plugin->getDouble(key);
-       EXPECT_EQ(val, 0.0);
 }
 
 TEST_F(VconfPluginTest, VconfBool)
@@ -138,17 +126,11 @@ TEST_F(VconfPluginTest, VconfBool)
        ret = plugin->set(key, true, nullptr);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       double val = plugin->getBool(key);
-       EXPECT_EQ(val, true);
-
        PluginAction *action;
        ret = plugin->set(key, false, &action);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
        plugin->undo(action);
-
-       val = plugin->getBool(key);
-       EXPECT_EQ(val, true);
 }
 
 TEST_F(VconfPluginTest, VconfStr)
@@ -161,17 +143,11 @@ TEST_F(VconfPluginTest, VconfStr)
        ret = plugin->set(key, devName, nullptr);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       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);
 
        plugin->undo(action);
-
-       val = plugin->getString(key);
-       EXPECT_STREQ(val.c_str(), devName.c_str());
 }
 
 TEST_F(VconfPluginTest, callbackPluginVconf)
index 6a83822..cb97410 100644 (file)
@@ -2,19 +2,11 @@ SET(VCONF_PLUGIN "modes-plugin-vconf")
 
 FILE(GLOB VCONF_SRCS *.cpp)
 
-pkg_check_modules(vconf_pkgs REQUIRED modes dlog capi-base-common vconf)
+PKG_CHECK_MODULES(vconf_pkgs REQUIRED modes dlog capi-base-common vconf)
 INCLUDE_DIRECTORIES(${vconf_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${vconf_pkgs_LIBRARY_DIRS})
 
-# ==== WifiErrorMessage Header genertor ====
-#ADD_CUSTOM_TARGET(
-#    genWifiErrorMessage
-#    COMMAND echo "Run WifiErrorMessage Generator"
-#    COMMAND tool/WifiErrorMessageGenerator.sh
-#)
-#ADD_DEPENDENCIES(${VCONF_PLUGIN} genWifiErrorMessage)
-
-ADD_LIBRARY(${VCONF_PLUGIN} SHARED ${VCONF_SRCS})
+ADD_LIBRARY(${VCONF_PLUGIN} SHARED ${VCONF_SRCS} ${VCONF_COMMON_SRC})
 TARGET_LINK_LIBRARIES(${VCONF_PLUGIN} ${vconf_pkgs_LIBRARIES})
 SET_TARGET_PROPERTIES(${VCONF_PLUGIN} PROPERTIES NO_SONAME 1 )
 INSTALL(TARGETS ${VCONF_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR})
index c58b06e..23209ad 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include "VconfActionBool.h"
+
 #include <string>
 #include <sstream>
 #include <vconf.h>
 
 MODES_NAMESPACE_USE;
 
-VconfActionBool::VconfActionBool(const std::string &key)
-       : VconfAction("boolVconf", key), oldVal(false)
+VconfActionBool::VconfActionBool(const std::string &vconfKey)
+       : PluginAction("boolVconf"), key(vconfKey), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr)
 {
 }
 
 int VconfActionBool::set(bool val)
 {
-       int ret;
-       DBG("setBool(%s, %d)", key.c_str(), val);
+       requestVal = val;
 
-       ret = handleChange();
+       int ret = cbHandler.handleSubscription(key);
        if (MODES_ERROR_NONE != ret) {
                ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
                return ret;
@@ -45,32 +45,22 @@ int VconfActionBool::set(bool val)
        }
        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;
+       if (oldVal == val) {
+               INFO("vconf(%s) already set(%d)", key.c_str(), val);
+       } else {
+               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 value ? true : false;
+       return MODES_ERROR_NONE;
 }
 
 void VconfActionBool::undo()
 {
-       int ret;
-       DBG("undoBool(%s, %d)", key.c_str(), oldVal);
-
-       ret = vconf_set_bool(key.c_str(), oldVal ? 1 : 0);
+       int 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);
 }
@@ -90,3 +80,49 @@ int VconfActionBool::parse(const std::string &archive)
 
        return MODES_ERROR_NONE;
 }
+
+int VconfActionBool::setChangedCallback(valueChangedCB callback, void *userData)
+{
+       RETV_IF(NULL == callback, MODES_ERROR_INVALID_PARAMETER);
+
+       int ret = cbHandler.setChangedCB(key, this);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
+               return ret;
+       }
+
+       cb = callback;
+       cbData = userData;
+
+       return MODES_ERROR_NONE;
+}
+
+void VconfActionBool::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+       RET_IF(NULL == callback);
+
+       cbHandler.unSetChangedCB(key);
+
+       cbData = NULL;
+       cb = NULL;
+}
+
+void VconfActionBool::vconfChangedCB()
+{
+       //The value will be changed by Modes. That's why the callback is always called.
+       if (cb)
+               cb(cbData);
+}
+
+void VconfActionBool::vconfChangedCB(keynode_t *node)
+{
+       const char *vconfKey = vconf_keynode_get_name(node);
+       if (vconfKey != key) {
+               WARN("Unknown vconf(%s) notification", vconfKey);
+               return;
+       }
+
+       bool val = vconf_keynode_get_bool(node);
+       if (cb && (val != requestVal))
+               cb(cbData);
+}
index 90644ae..2e8c989 100644 (file)
 #pragma once
 
 #include <string>
-#include "VconfAction.h"
+#include <PluginAction.h>
 #include "plugin-def.h"
+#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionBool : public VconfAction {
+class VconfActionBool : public PluginAction, public VconfChangeAction {
 public:
-       VconfActionBool(const std::string &key);
-       virtual ~VconfActionBool() = default;
+       VconfActionBool(const std::string &vconfKey);
 
        int set(bool val);
-       bool get();
        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;
+
+       void vconfChangedCB() override;
+       void vconfChangedCB(keynode_t *node) override;
 private:
+       std::string key;
+       bool requestVal;
        bool oldVal;
+       VconfCbHandler cbHandler;
+       valueChangedCB cb;
+       void *cbData;
 };
 
 MODES_NAMESPACE_END
-
index e5765f0..15bca08 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include "VconfActionDbl.h"
+
 #include <string>
 #include <sstream>
 #include <vconf.h>
 
 MODES_NAMESPACE_USE;
 
-VconfActionDbl::VconfActionDbl(const std::string &key)
-       : VconfAction("dblVconf", key), oldVal(0.0)
+VconfActionDbl::VconfActionDbl(const std::string &vconfKey)
+       : PluginAction("dblVconf"), key(vconfKey), requestVal(0.0), oldVal(0.0), cb(nullptr), cbData(nullptr)
 {
 }
 
 int VconfActionDbl::set(double val)
 {
-       int ret;
-       DBG("setDbl(%s, %f)", key.c_str(), val);
+       requestVal = val;
 
-       ret = handleChange();
+       int ret = cbHandler.handleSubscription(key);
        if (MODES_ERROR_NONE != ret) {
                ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
                return ret;
@@ -43,32 +43,22 @@ int VconfActionDbl::set(double val)
                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;
+       if (oldVal == val) {
+               INFO("vconf(%s) already set(%f)", key.c_str(), val);
+       } else {
+               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 value;
+       return MODES_ERROR_NONE;
 }
 
 void VconfActionDbl::undo()
 {
-       int ret;
-       DBG("undoDbl(%s, %f)", key.c_str(), oldVal);
-
-       ret = vconf_set_dbl(key.c_str(), oldVal);
+       int ret = vconf_set_dbl(key.c_str(), oldVal);
        if (0 != ret)
                ERR("vconf_set_dbl(%s, %f) Fail(%d)", key.c_str(), oldVal, ret);
 }
@@ -88,3 +78,49 @@ int VconfActionDbl::parse(const std::string &archive)
 
        return MODES_ERROR_NONE;
 }
+
+int VconfActionDbl::setChangedCallback(valueChangedCB callback, void *userData)
+{
+       RETV_IF(NULL == callback, MODES_ERROR_INVALID_PARAMETER);
+
+       int ret = cbHandler.setChangedCB(key, this);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
+               return ret;
+       }
+
+       cb = callback;
+       cbData = userData;
+
+       return MODES_ERROR_NONE;
+}
+
+void VconfActionDbl::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+       RET_IF(NULL == callback);
+
+       cbHandler.unSetChangedCB(key);
+
+       cbData = NULL;
+       cb = NULL;
+}
+
+void VconfActionDbl::vconfChangedCB()
+{
+       //The value will be changed by Modes. That's why the callback is always called.
+       if (cb)
+               cb(cbData);
+}
+
+void VconfActionDbl::vconfChangedCB(keynode_t *node)
+{
+       const char *vconfKey = vconf_keynode_get_name(node);
+       if (vconfKey != key) {
+               WARN("Unknown vconf(%s) notification", vconfKey);
+               return;
+       }
+
+       double val = vconf_keynode_get_dbl(node);
+       if (cb && (val != requestVal))
+               cb(cbData);
+}
index 0fd0bdf..3a98ebe 100644 (file)
 #pragma once
 
 #include <string>
-#include "VconfAction.h"
+#include <PluginAction.h>
 #include "plugin-def.h"
+#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionDbl : public VconfAction {
+class VconfActionDbl : public PluginAction, public VconfChangeAction {
 public:
-       VconfActionDbl(const std::string &key);
-       virtual ~VconfActionDbl() = default;
+       VconfActionDbl(const std::string &vconfKey);
 
        int set(double val);
-       double get();
        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;
+
+       void vconfChangedCB() override;
+       void vconfChangedCB(keynode_t *node) override;
 private:
+       std::string key;
+       double requestVal;
        double oldVal;
+       VconfCbHandler cbHandler;
+       valueChangedCB cb;
+       void *cbData;
 };
 
 MODES_NAMESPACE_END
-
index b6e2bb8..08504f5 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include "VconfActionInt.h"
+
 #include <string>
 #include <sstream>
 #include <vconf.h>
 
 MODES_NAMESPACE_USE;
 
-VconfActionInt::VconfActionInt(const std::string &key)
-       : VconfAction("intVconf", key), oldVal(0)
+VconfActionInt::VconfActionInt(const std::string &vconfKey)
+       : PluginAction("intVconf"), key(vconfKey), requestVal(0), oldVal(0), cb(nullptr), cbData(nullptr)
 {
 }
 
 int VconfActionInt::set(int val)
 {
-       int ret;
-       DBG("setInt(%s, %d)", key.c_str(), val);
+       requestVal = val;
 
-       ret = handleChange();
+       int ret = cbHandler.handleSubscription(key);
        if (MODES_ERROR_NONE != ret) {
                ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
                return ret;
@@ -43,32 +43,22 @@ int VconfActionInt::set(int val)
                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;
+       if (oldVal == val) {
+               INFO("vconf(%s) already set(%d)", key.c_str(), val);
+       } else {
+               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 value;
+       return MODES_ERROR_NONE;
 }
 
 void VconfActionInt::undo()
 {
-       int ret;
-       DBG("undoInt(%s, %d)", key.c_str(), oldVal);
-
-       ret = vconf_set_int(key.c_str(), oldVal);
+       int ret = vconf_set_int(key.c_str(), oldVal);
        if (0 != ret)
                ERR("vconf_set_int(%s, %d) Fail(%d)", key.c_str(), oldVal, ret);
 }
@@ -88,3 +78,49 @@ int VconfActionInt::parse(const std::string &archive)
 
        return MODES_ERROR_NONE;
 }
+
+int VconfActionInt::setChangedCallback(valueChangedCB callback, void *userData)
+{
+       RETV_IF(NULL == callback, MODES_ERROR_INVALID_PARAMETER);
+
+       int ret = cbHandler.setChangedCB(key, this);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
+               return ret;
+       }
+
+       cb = callback;
+       cbData = userData;
+
+       return MODES_ERROR_NONE;
+}
+
+void VconfActionInt::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+       RET_IF(NULL == callback);
+
+       cbHandler.unSetChangedCB(key);
+
+       cbData = NULL;
+       cb = NULL;
+}
+
+void VconfActionInt::vconfChangedCB()
+{
+       //The value will be changed by Modes. That's why the callback is always called.
+       if (cb)
+               cb(cbData);
+}
+
+void VconfActionInt::vconfChangedCB(keynode_t *node)
+{
+       const char *vconfKey = vconf_keynode_get_name(node);
+       if (vconfKey != key) {
+               WARN("Unknown vconf(%s) notification", vconfKey);
+               return;
+       }
+
+       int val = vconf_keynode_get_int(node);
+       if (cb && (val != requestVal))
+               cb(cbData);
+}
index 086665d..49108e8 100644 (file)
 #pragma once
 
 #include <string>
-#include "VconfAction.h"
+#include <PluginAction.h>
 #include "plugin-def.h"
+#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionInt : public VconfAction {
+class VconfActionInt : public PluginAction, public VconfChangeAction {
 public:
-       VconfActionInt(const std::string &key);
-       virtual ~VconfActionInt() = default;
+       VconfActionInt(const std::string &vconfKey);
 
        int set(int val);
-       int get();
        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;
+
+       void vconfChangedCB() override;
+       void vconfChangedCB(keynode_t *node) override;
 private:
+       std::string key;
+       int requestVal;
        int oldVal;
+       VconfCbHandler cbHandler;
+       valueChangedCB cb;
+       void *cbData;
 };
 
 MODES_NAMESPACE_END
-
index 024e128..b483261 100644 (file)
  * limitations under the License.
  */
 #include "VconfActionStr.h"
+
 #include <string>
 #include <vconf.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
 
-VconfActionStr::VconfActionStr(const std::string &key)
-       : VconfAction("strVconf", key)
+VconfActionStr::VconfActionStr(const std::string &vconfKey)
+       : PluginAction("strVconf"), key(vconfKey), cb(nullptr), cbData(nullptr)
 {
 }
 
 int VconfActionStr::set(const std::string &val)
 {
-       int ret;
-       DBG("setStr(%s, %s)", key.c_str(), val.c_str());
+       requestVal = val;
 
-       ret = handleChange();
+       int ret = cbHandler.handleSubscription(key);
        if (MODES_ERROR_NONE != ret) {
                ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
                return ret;
@@ -44,34 +44,22 @@ int VconfActionStr::set(const std::string &val)
        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;
+       if (oldVal == val) {
+               INFO("vconf(%s) already set(%s)", key.c_str(), val.c_str());
+       } else {
+               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;
+       return MODES_ERROR_NONE;
 }
 
 void VconfActionStr::undo()
 {
-       int ret;
-       DBG("undoStr(%s, %s)", key.c_str(), oldVal.c_str());
-
-       ret = vconf_set_str(key.c_str(), oldVal.c_str());
+       int 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);
 }
@@ -86,3 +74,49 @@ int VconfActionStr::parse(const std::string &archive)
        oldVal = archive;
        return MODES_ERROR_NONE;
 }
+
+int VconfActionStr::setChangedCallback(valueChangedCB callback, void *userData)
+{
+       RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
+
+       int ret = cbHandler.setChangedCB(key, this);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
+               return ret;
+       }
+
+       cb = callback;
+       cbData = userData;
+
+       return MODES_ERROR_NONE;
+}
+
+void VconfActionStr::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+       RET_IF(nullptr == callback);
+
+       cbHandler.unSetChangedCB(key);
+
+       cbData = nullptr;
+       cb = nullptr;
+}
+
+void VconfActionStr::vconfChangedCB()
+{
+       //The value will be changed by Modes. That's why the callback is always called.
+       if (cb)
+               cb(cbData);
+}
+
+void VconfActionStr::vconfChangedCB(keynode_t *node)
+{
+       const char *vconfKey = vconf_keynode_get_name(node);
+       if (vconfKey != key) {
+               WARN("Unknown vconf(%s) notification", vconfKey);
+               return;
+       }
+
+       char *val = vconf_keynode_get_str(node);
+       if (cb && (val != requestVal))
+               cb(cbData);
+}
index 38af35c..ad84154 100644 (file)
 #pragma once
 
 #include <string>
-#include "VconfAction.h"
+#include <PluginAction.h>
 #include "plugin-def.h"
+#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionStr : public VconfAction {
+class VconfActionStr : public PluginAction, public VconfChangeAction {
 public:
-       VconfActionStr(const std::string &key);
-       ~VconfActionStr() = default;
+       VconfActionStr(const std::string &vconfKey);
 
        int set(const std::string &val);
-       std::string get();
        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;
+
+       void vconfChangedCB() override;
+       void vconfChangedCB(keynode_t *node) override;
 private:
+       std::string key;
+       std::string requestVal;
        std::string oldVal;
+       VconfCbHandler cbHandler;
+       valueChangedCB cb;
+       void *cbData;
 };
 
 MODES_NAMESPACE_END
index e0739e4..c748893 100644 (file)
@@ -37,11 +37,6 @@ public:
        int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
        PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
        std::string serializeAction(PluginAction *piAction) override;
-
-       int getInt(const std::string &key) override;
-       double getDouble(const std::string &key) override;
-       bool getBool(const std::string &key) override;
-       std::string getString(const std::string &key) override;
 };
 
 extern "C" API Plugin *objectCreate(void)
@@ -166,51 +161,3 @@ std::string VconfPlugin::serializeAction(PluginAction *piAction)
        std::string rawStr = piAction->serialize();
        return piAction->getName().front() + rawStr;
 }
-
-int VconfPlugin::getInt(const std::string &key)
-{
-       DBG("getInt(%s)", key.c_str());
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionInt action(newKey);
-
-       return action.get();
-}
-
-double VconfPlugin::getDouble(const std::string &key)
-{
-       DBG("getDouble(%s)", key.c_str());
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionDbl action(newKey);
-
-       return action.get();
-}
-
-bool VconfPlugin::getBool(const std::string &key)
-{
-       DBG("getBool(%s)", key.c_str());
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionBool action(newKey);
-
-       return action.get();
-}
-
-std::string VconfPlugin::getString(const std::string &key)
-{
-       DBG("getString(%s)", key.c_str());
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionStr action(newKey);
-
-       return action.get();
-}