apply new plugin architecture accepted/tizen/unified/20200422.032229 submit/tizen/20200421.092050
authorYoungjae Shin <yj99.shin@samsung.com>
Tue, 21 Apr 2020 07:34:16 +0000 (16:34 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Tue, 21 Apr 2020 07:39:43 +0000 (16:39 +0900)
72 files changed:
CMakeLists.txt
app/AppAction.h [deleted file]
app/AppActionLaunch.cpp
app/AppActionLaunch.h
app/AppFactory.cpp
app/AppFactory.h
app/AppPlugin.cpp
bluetooth/BtAction.cpp
bluetooth/BtAction.h
bluetooth/BtActionAudioConnect.cpp
bluetooth/BtActionAudioConnect.h
bluetooth/BtActionPower.cpp
bluetooth/BtActionPower.h
bluetooth/BtFactory.cpp
bluetooth/BtFactory.h
bluetooth/BtPlugin.cpp
common/VconfCbHandler.cpp [deleted file]
display/CMakeLists.txt
display/DisplayActVconf.cpp
display/DisplayActVconf.h
display/DisplayAction.cpp [deleted file]
display/DisplayAction.h [deleted file]
display/DisplayBrightness.cpp
display/DisplayBrightness.h
display/DisplayDenyPalmTouch.cpp
display/DisplayDenyPalmTouch.h
display/DisplayFactory.cpp
display/DisplayFactory.h
display/DisplayPlugin.cpp
include/VconfCbHandler.h [deleted file]
include/VconfChangeAction.h [deleted file]
include/plugin-def.h
media/MediaAction.h [deleted file]
media/MediaFactory.cpp
media/MediaFactory.h
media/MediaPlayer.cpp
media/MediaPlayer.h
media/MediaPlugin.cpp
media/SoundVolume.cpp
media/SoundVolume.h
pkg/PkgEnableSupportMode.cpp
pkg/PkgEnableSupportMode.h
pkg/PkgFactory.cpp
pkg/PkgFactory.h
pkg/PkgPlugin.cpp
unittests/CMakeLists.txt
unittests/mdsp_test_app.cpp
unittests/mdsp_test_bt.cpp
unittests/mdsp_test_display.cpp
unittests/mdsp_test_media.cpp
unittests/mdsp_test_pkg.cpp
unittests/mdsp_test_vconf.cpp
unittests/mdsp_test_wifi.cpp
vconf/CMakeLists.txt
vconf/VconfBool.cpp [moved from vconf/VconfActionBool.cpp with 54% similarity]
vconf/VconfBool.h [moved from vconf/VconfActionBool.h with 74% similarity]
vconf/VconfDbl.cpp [moved from vconf/VconfActionDbl.cpp with 55% similarity]
vconf/VconfDbl.h [moved from vconf/VconfActionDbl.h with 74% similarity]
vconf/VconfFactory.cpp [new file with mode: 0644]
vconf/VconfFactory.h [moved from pkg/PkgAction.h with 75% similarity]
vconf/VconfInt.cpp [moved from vconf/VconfActionInt.cpp with 55% similarity]
vconf/VconfInt.h [moved from vconf/VconfActionInt.h with 74% similarity]
vconf/VconfPlugin.cpp
vconf/VconfStr.cpp [moved from vconf/VconfActionStr.cpp with 56% similarity]
vconf/VconfStr.h [moved from vconf/VconfActionStr.h with 73% similarity]
wifi/WifiAction.cpp
wifi/WifiAction.h
wifi/WifiActionPower.cpp
wifi/WifiActionPower.h
wifi/WifiFactory.cpp
wifi/WifiFactory.h
wifi/WifiPlugin.cpp

index cf8ccb2..fd4247e 100644 (file)
@@ -15,8 +15,6 @@ 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)
diff --git a/app/AppAction.h b/app/AppAction.h
deleted file mode 100644 (file)
index a6ee8f9..0000000
+++ /dev/null
@@ -1,43 +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.
- */
-#pragma once
-
-#include <string>
-#include <PluginAction.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class AppAction : public PluginAction {
-public:
-       AppAction(const std::string &name)
-               : PluginAction(name)
-       {
-       }
-       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
-
index 1d1fa5e..c8f4bc0 100644 (file)
@@ -20,7 +20,6 @@
 #include <app_control.h>
 #include <app_manager.h>
 #include <app_manager_extension.h>
-#include <modes_errors.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
@@ -28,23 +27,27 @@ MODES_NAMESPACE_USE;
 const std::string AppActionLaunch::NAME = "launch";
 
 AppActionLaunch::AppActionLaunch()
-       : AppAction(NAME), cb(nullptr), cbData(nullptr)
+       : PluginAction(NAME), cb(nullptr), cbData(nullptr)
 {
        aul_launch_init(NULL, NULL);
 }
 
-int AppActionLaunch::set(const std::string &val)
+bool AppActionLaunch::IsCurrentValue(const std::string &val)
 {
-       requestVal = val;
-
        bool running;
        int ret = app_manager_is_running(val.c_str(), &running);
        if (APP_MANAGER_ERROR_NONE != ret) {
                ERR("app_manager_is_running(%s) Fail(%d)", val.c_str(), ret);
        } else if (running) {
                INFO("It's already running");
-               return MODES_ERROR_NONE;
+               return true;
        }
+       return false;
+}
+
+int AppActionLaunch::set(const std::string &val)
+{
+       requestVal = val;
 
        app_control_h service;
        app_control_create(&service);
@@ -52,7 +55,7 @@ int AppActionLaunch::set(const std::string &val)
        app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
        app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_SINGLE);
 
-       ret = app_control_send_launch_request(service, NULL, NULL);
+       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_SYSTEM;
@@ -85,14 +88,14 @@ void AppActionLaunch::undo()
                ERR("app_manager_terminate_app() Fail(%s)", get_error_message(ret));
 }
 
-std::string AppActionLaunch::serialize()
+std::string AppActionLaunch::getUndoInfo()
 {
        return requestVal;
 }
 
-int AppActionLaunch::parse(const std::string &archive)
+int AppActionLaunch::setUndoInfo(const std::string &info)
 {
-       requestVal = archive;
+       requestVal = info;
        return MODES_ERROR_NONE;
 }
 
index f2bb7fb..d735d27 100644 (file)
  */
 #pragma once
 
-#include <list>
 #include <string>
 #include <app_manager.h>
 #include <app_manager_extension.h>
-#include "AppAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
-class AppActionLaunch : public AppAction {
+class AppActionLaunch : public PluginAction {
 public:
        static const std::string NAME;
        AppActionLaunch();
 
+       bool IsCurrentValue(const std::string &val) override;
        int set(const std::string &val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &data) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 private:
index 250b307..933b0a5 100644 (file)
@@ -24,11 +24,11 @@ AppFactory::AppFactory()
        actionMap[AppActionLaunch::NAME] = APP_ACT_LAUNCH;
 }
 
-AppAction* AppFactory::createAction(const std::string &key)
+PluginAction* AppFactory::createAction(const std::string &key)
 {
        auto search = actionMap.find(key);
        if (actionMap.end() == search) {
-               ERR("No AppAction(%s)", key.c_str());
+               ERR("No App PluginAction(%s)", key.c_str());
                return nullptr;
        }
 
@@ -42,7 +42,7 @@ AppAction* AppFactory::createAction(const std::string &key)
        return nullptr;
 }
 
-void AppFactory::destroyAction(AppAction *action)
+void AppFactory::destroyAction(PluginAction *action)
 {
        delete action;
 }
index fcd1afe..18da635 100644 (file)
@@ -17,7 +17,8 @@
 
 #include <map>
 #include <string>
-#include "AppAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -26,8 +27,8 @@ public:
        AppFactory();
        ~AppFactory() = default;
 
-       AppAction* createAction(const std::string &key);
-       void destroyAction(AppAction *action);
+       PluginAction* createAction(const std::string &key);
+       void destroyAction(PluginAction *action);
 private:
        enum actionKey{
                APP_ACT_LAUNCH
index cbe286b..78af2c1 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 #include <string>
-#include <modes_errors.h>
 #include <Plugin.h>
 #include "plugin-log.h"
 #include "AppFactory.h"
@@ -24,18 +23,17 @@ MODES_NAMESPACE_USE;
 class AppPlugin : public Plugin {
 public:
        AppPlugin();
-       ~AppPlugin();
+       ~AppPlugin() override = default;
 
-       int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
-       void undo(PluginAction *piAction) override;
-       PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+       PluginAction* newAction(const std::string &key) override;
+       void deleteAction(PluginAction *piAction) override;
 private:
        AppFactory appFactory;
 };
 
-extern "C" API Plugin *objectCreate(void)
+extern "C" API PluginobjectCreate(void)
 {
-       return new AppPlugin;
+       return new AppPlugin();
 }
 
 extern "C" API void objectDelete(Plugin *plugin)
@@ -48,48 +46,12 @@ AppPlugin::AppPlugin()
        setName("app");
 }
 
-AppPlugin::~AppPlugin()
+PluginAction* AppPlugin::newAction(const std::string &key)
 {
+       return appFactory.createAction(key);
 }
 
-int AppPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
+void AppPlugin::deleteAction(PluginAction *piAction)
 {
-       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 ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               appFactory.destroyAction(action);
-
-       return ret;
-}
-
-void AppPlugin::undo(PluginAction *piAction)
-{
-       AppAction *action = static_cast<AppAction*>(piAction);
-       RET_IF(nullptr == piAction);
-
-       DBG("Action(%s) undo", action->getName().c_str());
-
-       action->undo();
-       appFactory.destroyAction(action);
-}
-
-PluginAction* AppPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
-       AppAction *action = appFactory.createAction(key);
-       RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
-       int ret = action->parse(info);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
-               appFactory.destroyAction(action);
-               return nullptr;
-       }
-
-       return action;
+       appFactory.destroyAction(piAction);
 }
index 4078760..ba0ee46 100644 (file)
@@ -16,7 +16,6 @@
 #include "BtAction.h"
 
 #include <bluetooth.h>
-#include <modes_errors.h>
 
 MODES_NAMESPACE_USE;
 
@@ -46,13 +45,3 @@ bool BtAction::getAdapterStatus()
        else
                return true;
 }
-
-int BtAction::set(bool val)
-{
-       return MODES_ERROR_NOT_SUPPORTED;
-}
-
-int BtAction::set(const std::string &val)
-{
-       return MODES_ERROR_NOT_SUPPORTED;
-}
index c894dc8..c2a1596 100644 (file)
@@ -25,10 +25,8 @@ MODES_NAMESPACE_BEGIN
 class BtAction : public PluginAction {
 public:
        BtAction(const std::string &name);
-       virtual ~BtAction();
-
-       virtual int set(bool val);
-       virtual int set(const std::string &val);
+       ~BtAction() override;
+protected:
        bool getAdapterStatus();
 };
 
index 9ca30db..80c4752 100644 (file)
@@ -15,7 +15,6 @@
  */
 #include "BtActionAudioConnect.h"
 
-#include <modes_errors.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
@@ -33,6 +32,11 @@ BtActionAudioConnect::~BtActionAudioConnect()
        bt_audio_deinitialize();
 }
 
+bool BtActionAudioConnect::IsCurrentValue(const std::string &val)
+{
+       return false;
+}
+
 int BtActionAudioConnect::set(const std::string &val)
 {
        if (!getAdapterStatus()) {
@@ -79,14 +83,14 @@ void BtActionAudioConnect::undo()
                ERR("bt_audio_disconnect(%s) Fail(%s)", requestVal.c_str(), get_error_message(ret));
 }
 
-std::string BtActionAudioConnect::serialize()
+std::string BtActionAudioConnect::getUndoInfo()
 {
        return requestVal;
 }
 
-int BtActionAudioConnect::parse(const std::string &archive)
+int BtActionAudioConnect::setUndoInfo(const std::string &info)
 {
-       requestVal = archive;
+       requestVal = info;
        return MODES_ERROR_NONE;
 }
 
index cf0586c..266b4db 100644 (file)
@@ -27,10 +27,12 @@ public:
        BtActionAudioConnect();
        ~BtActionAudioConnect();
 
+       bool IsCurrentValue(const std::string &val);
+
        int set(const std::string &val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData);
        void unSetChangedCallback(valueChangedCB callback, void *userData);
 private:
index cf7c731..671907b 100644 (file)
@@ -16,7 +16,6 @@
 #include "BtActionPower.h"
 
 #include <sstream>
-#include <modes_errors.h>
 #include <bluetooth.h>
 #include <bluetooth_internal.h>
 #include "plugin-log.h"
@@ -30,6 +29,11 @@ BtActionPower::BtActionPower()
 {
 }
 
+bool BtActionPower::IsCurrentValue(bool val)
+{
+       return true;
+}
+
 int BtActionPower::set(bool val)
 {
        requestVal = val;
@@ -66,7 +70,7 @@ void BtActionPower::undo()
        set(oldVal);
 }
 
-std::string BtActionPower::serialize()
+std::string BtActionPower::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -74,9 +78,9 @@ std::string BtActionPower::serialize()
        return ostr.str();
 }
 
-int BtActionPower::parse(const std::string &archive)
+int BtActionPower::setUndoInfo(const std::string &info)
 {
-       std::istringstream iss(archive);
+       std::istringstream iss(info);
        iss >> oldVal;
 
        return MODES_ERROR_NONE;
index cf8b621..dc085f0 100644 (file)
@@ -26,10 +26,11 @@ public:
        static const std::string NAME;
        BtActionPower();
 
+       bool IsCurrentValue(bool val) override;
        int set(bool val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string & archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData);
        void unSetChangedCallback(valueChangedCB callback, void *userData);
 private:
index 9df05dd..2dd78e2 100644 (file)
@@ -29,7 +29,7 @@ BtFactory::BtFactory()
        actionMap[BtActionAudioConnect::NAME] = AUDIO_CONNECT;
 }
 
-BtAction* BtFactory::createAction(const std::string &key)
+PluginAction* BtFactory::createAction(const std::string &key)
 {
        auto search = actionMap.find(key);
        if (actionMap.end() == search) {
@@ -48,7 +48,7 @@ BtAction* BtFactory::createAction(const std::string &key)
        return nullptr;
 }
 
-void BtFactory::destroyAction(BtAction *action)
+void BtFactory::destroyAction(PluginAction *action)
 {
        delete action;
 }
index 791ad9e..137b0f9 100644 (file)
  */
 #pragma once
 
-#include <string>
 #include <map>
-#include "BtAction.h"
+#include <string>
+#include <PluginAction.h>
+#include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -26,8 +27,8 @@ public:
        BtFactory();
        ~BtFactory() = default;
 
-       BtAction *createAction(const std::string &key);
-       void destroyAction(BtAction *action);
+       PluginAction* createAction(const std::string &key);
+       void destroyAction(PluginAction *action);
 private:
        enum actionKey {
                POWER,
index b594500..ae3d6ee 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 #include <string>
-#include <modes_errors.h>
 #include <bluetooth.h>
 #include <Plugin.h>
 #include "plugin-log.h"
@@ -25,19 +24,17 @@ MODES_NAMESPACE_USE;
 class BtPlugin : public Plugin {
 public:
        BtPlugin();
-       ~BtPlugin();
+       ~BtPlugin() override = default;
 
-       int set(const std::string &key, bool val, PluginAction **piAction) override;
-       int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
-       void undo(PluginAction *piAction) override;
-       PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+       PluginAction* newAction(const std::string &key) override;
+       void deleteAction(PluginAction *piAction) override;
 private:
        BtFactory btFactory;
 };
 
-extern "C" API Plugin *objectCreate(void)
+extern "C" API PluginobjectCreate(void)
 {
-       return new BtPlugin;
+       return new BtPlugin();
 }
 
 extern "C" API void objectDelete(Plugin *plugin)
@@ -50,66 +47,12 @@ BtPlugin::BtPlugin()
        setName("bluetooth");
 }
 
-BtPlugin::~BtPlugin()
+PluginAction* BtPlugin::newAction(const std::string &key)
 {
+       return btFactory.createAction(key);
 }
 
-//For BtActionPower
-int BtPlugin::set(const std::string &key, bool val, PluginAction **piAction)
+void BtPlugin::deleteAction(PluginAction *piAction)
 {
-       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 ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               btFactory.destroyAction(action);
-
-       return ret;
-}
-
-//For BtActionAudioConnect
-int BtPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
-{
-       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 ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               btFactory.destroyAction(action);
-
-       return ret;
-}
-
-void BtPlugin::undo(PluginAction *piAction)
-{
-       BtAction *action = static_cast<BtAction*>(piAction);
-       RET_IF(nullptr == piAction);
-
-       DBG("Action(%s) undo", action->getName().c_str());
-
-       action->undo();
-       btFactory.destroyAction(action);
-}
-
-PluginAction* BtPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
-       BtAction *action = btFactory.createAction(key);
-       RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
-       int ret = action->parse(info);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
-               btFactory.destroyAction(action);
-               return nullptr;
-       }
-
-       return action;
+       btFactory.destroyAction(piAction);
 }
diff --git a/common/VconfCbHandler.cpp b/common/VconfCbHandler.cpp
deleted file mode 100644 (file)
index f8a6581..0000000
+++ /dev/null
@@ -1,80 +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 "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, VconfChangeAction*> VconfCbHandler::callbackMap;
-
-int VconfCbHandler::invokeChangedCB(const std::string &key)
-{
-       auto found = callbackMap.find(key);
-       if (callbackMap.end() != found) {
-               WARN("Action(%s) already exist", key.c_str());
-               found->second->vconfChangedCB();
-       }
-       return MODES_ERROR_NONE;
-}
-
-int VconfCbHandler::setChangedCB(const std::string &key, VconfChangeAction *action)
-{
-       RETV_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER);
-
-       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;
-       }
-
-       callbackMap[key] = action;
-
-       return MODES_ERROR_NONE;
-}
-
-void VconfCbHandler::unSetChangedCB(const std::string &key)
-{
-       auto found = callbackMap.find(key);
-       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(), vconfCallback);
-       if (0 != ret) {
-               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
-               return;
-       }
-}
-
-void VconfCbHandler::vconfCallback(keynode_t *node, void *userData)
-{
-       auto found = callbackMap.find(node->keyname);
-       if (callbackMap.end() == found) {
-               ERR("No VconfAction(%s)", node->keyname);
-               return;
-       }
-
-       found->second->vconfChangedCB(node);
-       DBG("Action(%s) is Changed", node->keyname);
-}
index e6add36..85bf7cc 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} ${VCONF_COMMON_SRC})
+ADD_LIBRARY(${DISPLAY_PLUGIN} SHARED ${DISPLAY_SRCS})
 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})
index 626a225..4500b75 100644 (file)
@@ -18,9 +18,7 @@
 #include <sstream>
 #include <string>
 #include <vconf.h>
-#include <modes_errors.h>
 #include "plugin-log.h"
-#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_USE;
 
@@ -35,35 +33,35 @@ const char* const DisplayActVconf::KEY[2] = {
 };
 
 DisplayActVconf::DisplayActVconf(int type)
-       :DisplayAction(NAME[type]), keyType(type),
-       requestVal(-1), oldVal(-1), cb(nullptr), cbData(nullptr)
+       : PluginAction(NAME[type]), keyType(type), requestVal(-1), oldVal(-1), cb(nullptr),
+       cbData(nullptr)
 {
 }
 
-int DisplayActVconf::set(int val)
+bool DisplayActVconf::IsCurrentValue(int val)
 {
-       requestVal = val;
-
-       int ret = cbHandler.invokeChangedCB(KEY[keyType]);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("handleChange(%s) Fail(%d)", KEY[keyType], ret);
-               return ret;
-       }
-
-       ret = vconf_get_int(KEY[keyType], &oldVal);
+       int ret = vconf_get_int(KEY[keyType], &oldVal);
        if (0 != ret) {
                ERR("vconf_get_int(%s) Fail(%d)", KEY[keyType], ret);
-               return MODES_ERROR_SYSTEM;
+               return false;
        }
 
        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 true;
+       }
+
+       return false;
+}
+
+int DisplayActVconf::set(int val)
+{
+       requestVal = val;
+
+       int 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;
@@ -71,14 +69,12 @@ int DisplayActVconf::set(int val)
 
 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::string DisplayActVconf::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -86,9 +82,9 @@ std::string DisplayActVconf::serialize()
        return ostr.str();
 }
 
-int DisplayActVconf::parse(const std::string &archive)
+int DisplayActVconf::setUndoInfo(const std::string &info)
 {
-       std::istringstream iss(archive);
+       std::istringstream iss(info);
        iss >> oldVal;
 
        return MODES_ERROR_NONE;
@@ -98,10 +94,10 @@ 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;
+       int ret = vconf_notify_key_changed(KEY[keyType], vconfChangedCB, this);
+       if (0 != ret) {
+               ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
        }
 
        cb = callback;
@@ -114,29 +110,33 @@ void DisplayActVconf::unSetChangedCallback(valueChangedCB callback, void *userDa
 {
        RET_IF(nullptr == callback);
 
-       cbHandler.unSetChangedCB(KEY[keyType]);
+       int ret = vconf_ignore_key_changed(KEY[keyType], vconfChangedCB);
+       if (0 != ret) {
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return;
+       }
 
        cbData = nullptr;
        cb = nullptr;
 }
 
-//This funcion handles changes made by the Modes
-void DisplayActVconf::vconfChangedCB()
-{
-       if (cb)
-               cb(cbData);
-}
-
-void DisplayActVconf::vconfChangedCB(keynode_t *node)
+void DisplayActVconf::changedCB(keynode_t *node)
 {
        const char *vconfKey = vconf_keynode_get_name(node);
-       if (vconfKey != KEY[keyType]) {
-               WARN("Unknown vconf(%s) notification", vconfKey);
+       if (nullptr == vconfKey || MDSP_EQUAL != strcmp(KEY[keyType], vconfKey)) {
+               WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
                return;
        }
 
        int val = vconf_keynode_get_int(node);
-
        if (cb && (val != requestVal))
                cb(cbData);
 }
+
+void DisplayActVconf::vconfChangedCB(keynode_t *node, void *userData)
+{
+       RET_IF(nullptr == userData);
+
+       DisplayActVconf *action = (DisplayActVconf*)userData;
+       action->changedCB(node);
+}
index 2d2d7cc..323b4cf 100644 (file)
 #pragma once
 
 #include <string>
+#include <vconf.h>
+#include <PluginAction.h>
 #include "plugin-def.h"
-#include "DisplayAction.h"
-#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class DisplayActVconf : public DisplayAction, public VconfChangeAction {
+class DisplayActVconf : public PluginAction {
 public:
        DisplayActVconf(int type);
+       ~DisplayActVconf() override = default;
 
+       bool IsCurrentValue(int val) override;
        int set(int val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 
-       void vconfChangedCB() override;
-       void vconfChangedCB(keynode_t *node) override;
-
        static const std::string NAME[2];
        static const char* const KEY[2];
 private:
+       void changedCB(keynode_t *node);
+       static void vconfChangedCB(keynode_t *node, void *userData);
+
        int keyType;
        int requestVal;
        int oldVal;
-       VconfCbHandler cbHandler;
        valueChangedCB cb;
        void *cbData;
 };
diff --git a/display/DisplayAction.cpp b/display/DisplayAction.cpp
deleted file mode 100644 (file)
index bb549b3..0000000
+++ /dev/null
@@ -1,36 +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 "DisplayAction.h"
-
-#include <modes_errors.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_USE;
-
-DisplayAction::DisplayAction(const std::string &name)
-       :PluginAction(name)
-{
-}
-
-int DisplayAction::set(int val)
-{
-       return MODES_ERROR_NOT_SUPPORTED;
-}
-
-int DisplayAction::set(bool val)
-{
-       return MODES_ERROR_NOT_SUPPORTED;
-}
diff --git a/display/DisplayAction.h b/display/DisplayAction.h
deleted file mode 100644 (file)
index 90fa952..0000000
+++ /dev/null
@@ -1,33 +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.
- */
-#pragma once
-
-#include <PluginAction.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class DisplayAction : public PluginAction {
-public:
-       DisplayAction(const std::string &name);
-       ~DisplayAction() = default;
-
-       virtual int set(int val);
-       virtual int set(bool val);
-};
-
-MODES_NAMESPACE_END
-
index bf96829..0acb6c5 100644 (file)
@@ -20,7 +20,6 @@
 #include <vconf.h>
 #include <device/display.h>
 #include <device/callback.h>
-#include <modes_errors.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
@@ -29,21 +28,33 @@ const std::string DisplayBrightness::NAME = "brightness";
 const char* const DisplayBrightness::KEY = VCONFKEY_SETAPPL_LCD_BRIGHTNESS;
 
 DisplayBrightness::DisplayBrightness()
-       :DisplayAction(NAME), requestVal(0), cb(nullptr), cbData(nullptr)
+       :PluginAction(NAME), requestVal(0), cb(nullptr), cbData(nullptr)
 {
        device_display_get_numbers(&numDisplay);
 }
 
-int DisplayBrightness::set(int val)
+bool DisplayBrightness::IsCurrentValue(int val)
 {
-       requestVal = val;
+       int old;
+       int ret = vconf_get_int(KEY, &old);
+       if (0 != ret) {
+               ERR("vconf_get_int(%s) Fail(%d)", KEY, ret);
+               return false;
+       }
 
-       int ret = cbHandler.invokeChangedCB(KEY);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("handleChange(%s) Fail(%d)", KEY, ret);
-               return ret;
+       if (old == val) {
+               INFO("%s already set(%d)", NAME.c_str(), val);
+               return true;
        }
 
+       return false;
+}
+
+int DisplayBrightness::set(int val)
+{
+       int ret;
+       requestVal = val;
+
        for (int i = 0; i < numDisplay ; i++) {
                int oldVal = 0;
                ret = device_display_get_brightness(i, &oldVal);
@@ -83,7 +94,7 @@ void DisplayBrightness::undo()
        }
 }
 
-std::string DisplayBrightness::serialize()
+std::string DisplayBrightness::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -93,7 +104,7 @@ std::string DisplayBrightness::serialize()
        return ostr.str();
 }
 
-int DisplayBrightness::parse(const std::string &data)
+int DisplayBrightness::setUndoInfo(const std::string &data)
 {
        size_t pos;
        size_t start = 0;
@@ -113,10 +124,10 @@ int DisplayBrightness::setChangedCallback(valueChangedCB callback, void *userDat
 {
        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, ret);
-               return ret;
+       int ret = vconf_notify_key_changed(KEY, vconfChangedCB, this);
+       if (0 != ret) {
+               ERR("vconf_notify_key_changed(%s) Fail(%d)", KEY, ret);
+               return MODES_ERROR_SYSTEM;
        }
 
        cb = callback;
@@ -129,24 +140,21 @@ void DisplayBrightness::unSetChangedCallback(valueChangedCB callback, void *user
 {
        RET_IF(nullptr == callback);
 
-       cbHandler.unSetChangedCB(KEY);
+       int ret = vconf_ignore_key_changed(KEY, vconfChangedCB);
+       if (0 != ret) {
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", KEY, ret);
+               return;
+       }
 
        cbData = nullptr;
        cb = nullptr;
 }
 
-//This funcion handles changes made by the Modes
-void DisplayBrightness::vconfChangedCB()
-{
-       if (cb)
-               cb(cbData);
-}
-
-void DisplayBrightness::vconfChangedCB(keynode_t *node)
+void DisplayBrightness::changedCB(keynode_t *node)
 {
        const char *vconfKey = vconf_keynode_get_name(node);
-       if (vconfKey != KEY) {
-               WARN("Unknown vconf(%s) notification", vconfKey);
+       if (nullptr == vconfKey || MDSP_EQUAL != strcmp(KEY, vconfKey)) {
+               WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
                return;
        }
 
@@ -158,6 +166,14 @@ void DisplayBrightness::vconfChangedCB(keynode_t *node)
        }
 
        int val = vconf_keynode_get_int(node);
-       if (cb && (val != realVal))
+       if (cb && (val != requestVal))
                cb(cbData);
 }
+
+void DisplayBrightness::vconfChangedCB(keynode_t *node, void *userData)
+{
+       RET_IF(nullptr == userData);
+
+       DisplayBrightness *action = (DisplayBrightness*)userData;
+       action->changedCB(node);
+}
index e908506..5eaea1f 100644 (file)
 
 #include <list>
 #include <string>
+#include <vconf.h>
+#include <PluginAction.h>
 #include "plugin-def.h"
-#include "DisplayAction.h"
-#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class DisplayBrightness : public DisplayAction, public VconfChangeAction {
+class DisplayBrightness : public PluginAction {
 public:
        DisplayBrightness();
-       ~DisplayBrightness() = default;
+       ~DisplayBrightness() override = default;
 
+       bool IsCurrentValue(int val) override;
        int set(int val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 
-       void vconfChangedCB() override;
-       void vconfChangedCB(keynode_t *node) override;
-
        static const std::string NAME;
        static const char* const KEY;
 private:
+       void changedCB(keynode_t *node);
+       static void vconfChangedCB(keynode_t *node, void *userData);
+
        const char delimiter = '#';
        int numDisplay;
        int requestVal;
        std::list<int> oldValList;
-       VconfCbHandler cbHandler;
        valueChangedCB cb;
        void *cbData;
 };
index 8ff0428..8cc27b9 100644 (file)
@@ -20,7 +20,6 @@
 #include <Ecore_Wl2.h>
 #include <efl_util.h>
 #include <Ecore.h>
-#include <modes_errors.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
@@ -28,7 +27,7 @@ MODES_NAMESPACE_USE;
 const std::string DisplayDenyPalmTouch::NAME = "denyPalmTouch";
 
 DisplayDenyPalmTouch::DisplayDenyPalmTouch()
-       :DisplayAction(NAME)
+       : PluginAction(NAME), oldVal(false)
 {
 }
 
@@ -68,13 +67,13 @@ void DisplayDenyPalmTouch::undo()
        set(false);
 }
 
-std::string DisplayDenyPalmTouch::serialize()
+std::string DisplayDenyPalmTouch::getUndoInfo()
 {
-       //Not Support
+       WARN("Not Support getUndoInfo()");
        return std::string();
 }
 
-int DisplayDenyPalmTouch::parse(const std::string &archive)
+int DisplayDenyPalmTouch::setUndoInfo(const std::string &info)
 {
        WARN("Palm Touch setting is volatile");
        return MODES_ERROR_NOT_SUPPORTED;
@@ -82,11 +81,11 @@ int DisplayDenyPalmTouch::parse(const std::string &archive)
 
 int DisplayDenyPalmTouch::setChangedCallback(valueChangedCB callback, void *userData)
 {
-       ERR("Not Support Changed Callback");
+       WARN("Not Support Changed Callback");
        return MODES_ERROR_NOT_SUPPORTED;
 }
 
 void DisplayDenyPalmTouch::unSetChangedCallback(valueChangedCB callback, void *userData)
 {
-       ERR("Not Support Changed Callback");
+       WARN("Not Support Changed Callback");
 }
index 046ef14..f9474ff 100644 (file)
 #pragma once
 
 #include <string>
+#include <PluginAction.h>
 #include "plugin-def.h"
-#include "DisplayAction.h"
 
 MODES_NAMESPACE_BEGIN
 
-class DisplayDenyPalmTouch : public DisplayAction {
+class DisplayDenyPalmTouch : public PluginAction {
 public:
        DisplayDenyPalmTouch();
-       ~DisplayDenyPalmTouch() = default;
+       ~DisplayDenyPalmTouch() override = default;
 
        int set(bool val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 
index cfbaa46..3f3adff 100644 (file)
@@ -32,15 +32,15 @@ DisplayFactory::DisplayFactory()
        actionMap[DisplayDenyPalmTouch::NAME] = DENY_PALM_TOUCH;
 }
 
-DisplayAction* DisplayFactory::createAction(const std::string &key)
+PluginAction* DisplayFactory::createAction(const std::string &key)
 {
        auto search = actionMap.find(key);
        if (actionMap.end() == search) {
-               ERR("No DisplayAction(%s)", key.c_str());
+               ERR("No Display PluginAction(%s)", key.c_str());
                return nullptr;
        }
 
-       DisplayAction *action;
+       PluginAction *action;
        switch (search->second) {
        case AUTO_BRIGHTNESS_VCONF:
                action = new DisplayActVconf(AUTO_BRIGHTNESS_VCONF);
@@ -62,7 +62,7 @@ DisplayAction* DisplayFactory::createAction(const std::string &key)
        return action;
 }
 
-void DisplayFactory::destroyAction(DisplayAction *action)
+void DisplayFactory::destroyAction(PluginAction *action)
 {
        delete action;
 }
index b265d65..8b0a4ce 100644 (file)
@@ -17,7 +17,8 @@
 
 #include <map>
 #include <string>
-#include "DisplayAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -26,8 +27,8 @@ public:
        DisplayFactory();
        ~DisplayFactory() = default;
 
-       DisplayAction* createAction(const std::string &key);
-       void destroyAction(DisplayAction *action);
+       PluginAction* createAction(const std::string &key);
+       void destroyAction(PluginAction *action);
 private:
        enum actionKey{
                AUTO_BRIGHTNESS_VCONF,
index 9930cad..40c46b9 100644 (file)
  * limitations under the License.
  */
 #include <string>
-#include <modes_errors.h>
 #include <Plugin.h>
 #include "plugin-log.h"
 #include "plugin-def.h"
 #include "DisplayFactory.h"
-#include "DisplayAction.h"
 
 MODES_NAMESPACE_USE;
 
 class DisplayPlugin : public Plugin {
 public:
        DisplayPlugin();
-       ~DisplayPlugin();
-
-       int set(const std::string &key, int val, PluginAction **pluginAction) override;
-       int set(const std::string &key, bool val, PluginAction **pluginAction) override;
-       PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
-
-       void undo(PluginAction *pluginAction) override;
+       ~DisplayPlugin() override = default;
 
+       PluginAction* newAction(const std::string &key) override;
+       void deleteAction(PluginAction *piAction) override;
 private:
        DisplayFactory displayFactory;
 };
 
-extern "C" API Plugin *objectCreate(void)
+extern "C" API PluginobjectCreate(void)
 {
        return new DisplayPlugin;
 }
@@ -53,67 +47,12 @@ DisplayPlugin::DisplayPlugin()
        setName("display");
 }
 
-DisplayPlugin::~DisplayPlugin()
-{
-}
-
-int DisplayPlugin::set(const std::string &key, int val, PluginAction **pluginAction)
-{
-       DisplayAction *action = displayFactory.createAction(key);
-       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
-       int ret = action->set(val);
-
-       DBG("Action(%s) set(%d)", key.c_str(), val);
-
-       if ((ret == MODES_ERROR_NONE) && pluginAction)
-               *pluginAction = action;
-       else
-               displayFactory.destroyAction(action);
-
-       return ret;
-}
-
-int DisplayPlugin::set(const std::string &key, bool val, PluginAction **pluginAction)
+PluginAction* DisplayPlugin::newAction(const std::string &key)
 {
-       DisplayAction *action = displayFactory.createAction(key);
-       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
-       int ret = action->set(val);
-
-       DBG("Action(%s) set(%d)", key.c_str(), val);
-
-       if ((ret == MODES_ERROR_NONE) && pluginAction)
-               *pluginAction = action;
-       else
-               displayFactory.destroyAction(action);
-
-       return ret;
-}
-
-PluginAction* DisplayPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
-       DisplayAction *action = displayFactory.createAction(key);
-       RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
-       int ret = action->parse(info);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
-               displayFactory.destroyAction(action);
-               return nullptr;
-       }
-
-       return action;
+       return displayFactory.createAction(key);
 }
 
-void DisplayPlugin::undo(PluginAction *pluginAction)
+void DisplayPlugin::deleteAction(PluginAction *piAction)
 {
-       DisplayAction *action = static_cast<DisplayAction*>(pluginAction);
-       RET_IF(nullptr == pluginAction);
-
-       DBG("Action(%s) undo", action->getName().c_str());
-
-       action->undo();
-       displayFactory.destroyAction(action);
+       displayFactory.destroyAction(piAction);
 }
-
diff --git a/include/VconfCbHandler.h b/include/VconfCbHandler.h
deleted file mode 100644 (file)
index ff4d72f..0000000
+++ /dev/null
@@ -1,37 +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.
- */
-#pragma once
-
-#include <map>
-#include <string>
-#include <vconf.h>
-#include "plugin-def.h"
-#include "VconfChangeAction.h"
-
-MODES_NAMESPACE_BEGIN
-
-class VconfCbHandler {
-public:
-       int invokeChangedCB(const std::string &key);
-       int setChangedCB(const std::string &key, VconfChangeAction *action);
-       void unSetChangedCB(const std::string &key);
-private:
-       static void vconfCallback(keynode_t *node, void *userData);
-       static std::map<std::string, VconfChangeAction*> callbackMap;
-};
-
-MODES_NAMESPACE_END
-
diff --git a/include/VconfChangeAction.h b/include/VconfChangeAction.h
deleted file mode 100644 (file)
index 108a08b..0000000
+++ /dev/null
@@ -1,29 +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.
- */
-#pragma once
-
-#include <vconf.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class VconfChangeAction {
-public:
-       virtual void vconfChangedCB() = 0;
-       virtual void vconfChangedCB(keynode_t *node) = 0;
-};
-
-MODES_NAMESPACE_END
index d5fecaa..07b66ba 100644 (file)
@@ -22,7 +22,7 @@
 #endif
 #define API __attribute__((visibility("default")))
 
-#define MDS_EQUAL 0
+#define MDSP_EQUAL 0
 
 #define MODES_NAMESPACE_BEGIN namespace ModeSupervisorNamespace {
 #define MODES_NAMESPACE_END }
diff --git a/media/MediaAction.h b/media/MediaAction.h
deleted file mode 100644 (file)
index 23c3fbd..0000000
+++ /dev/null
@@ -1,43 +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.
- */
-#pragma once
-
-#include <string>
-#include <PluginAction.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class MediaAction : public PluginAction {
-public:
-       MediaAction(const std::string &name)
-               : PluginAction(name)
-       {
-       }
-       ~MediaAction() = default;
-
-       virtual int set(const std::string &val)
-       {
-               return MODES_ERROR_NOT_SUPPORTED;
-       }
-       virtual int set(int val)
-       {
-               return MODES_ERROR_NOT_SUPPORTED;
-       }
-};
-
-MODES_NAMESPACE_END
-
index 0b8f1cf..514afe2 100644 (file)
@@ -30,15 +30,15 @@ MediaFactory::MediaFactory()
        actionMap[MediaPlayer::NAME] = PLAYER;
 }
 
-MediaAction* MediaFactory::createAction(const std::string &key)
+PluginAction* MediaFactory::createAction(const std::string &key)
 {
        auto search = actionMap.find(key);
        if (actionMap.end() == search) {
-               ERR("No MediaAction(%s)", key.c_str());
+               ERR("No Media PluginAction(%s)", key.c_str());
                return nullptr;
        }
 
-       MediaAction *action;
+       PluginAction *action;
        switch (search->second) {
        case SYSTEM_VOL:
                action = new SoundVolume(SYSTEM_VOL, SOUND_TYPE_SYSTEM);
@@ -63,7 +63,7 @@ MediaAction* MediaFactory::createAction(const std::string &key)
        return action;
 }
 
-void MediaFactory::destroyAction(MediaAction *action)
+void MediaFactory::destroyAction(PluginAction *action)
 {
        delete action;
 }
index 43465b7..cd1ba17 100644 (file)
@@ -17,7 +17,8 @@
 
 #include <map>
 #include <string>
-#include "MediaAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -26,8 +27,8 @@ public:
        MediaFactory();
        ~MediaFactory() = default;
 
-       MediaAction* createAction(const std::string &key);
-       void destroyAction(MediaAction *action);
+       PluginAction* createAction(const std::string &key);
+       void destroyAction(PluginAction *action);
 private:
        enum actionKey{
                SYSTEM_VOL,
index 42319f3..5740066 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <string>
 #include <player.h>
-#include <modes_errors.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
@@ -25,7 +24,7 @@ MODES_NAMESPACE_USE;
 const std::string MediaPlayer::NAME = "player";
 
 MediaPlayer::MediaPlayer()
-       : MediaAction(NAME), player(NULL), streamInfo(NULL), cb(nullptr), cbData(nullptr)
+       : PluginAction(NAME), player(NULL), streamInfo(NULL), cb(nullptr), cbData(nullptr)
 {
        int ret = player_create(&player);
        if (PLAYER_ERROR_NONE != ret) {
@@ -89,13 +88,13 @@ void MediaPlayer::undo()
        player_stop(player);
 }
 
-std::string MediaPlayer::serialize()
+std::string MediaPlayer::getUndoInfo()
 {
        //Not Support
        return std::string();
 }
 
-int MediaPlayer::parse(const std::string &archive)
+int MediaPlayer::setUndoInfo(const std::string &info)
 {
        WARN("MediaPlayer is volatile");
        return MODES_ERROR_NOT_SUPPORTED;
index 2385a01..3ab948f 100644 (file)
 
 #include <player.h>
 #include <sound_manager.h>
+#include <PluginAction.h>
 #include "plugin-def.h"
-#include "MediaAction.h"
 
 MODES_NAMESPACE_BEGIN
 
-class MediaPlayer : public MediaAction {
+class MediaPlayer : public PluginAction {
 public:
        MediaPlayer();
-       ~MediaPlayer();
+       ~MediaPlayer() override;
 
        int set(const std::string &val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 
index 0cfe1ce..e521018 100644 (file)
  * limitations under the License.
  */
 #include <string>
-#include <modes_errors.h>
 #include <Plugin.h>
 #include "plugin-log.h"
 #include "plugin-def.h"
 #include "MediaFactory.h"
-#include "MediaAction.h"
 
 MODES_NAMESPACE_USE;
 
 class MediaPlugin : public Plugin {
 public:
        MediaPlugin();
-       ~MediaPlugin();
+       ~MediaPlugin() override = default;
 
-       int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
-       int set(const std::string &key, int val, PluginAction **piAction) override;
-       PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
-
-       void undo(PluginAction *piAction) override;
+       PluginAction* newAction(const std::string &key) override;
+       void deleteAction(PluginAction *piAction) override;
 private:
        MediaFactory mediaFactory;
 };
 
-extern "C" API Plugin *objectCreate(void)
+extern "C" API PluginobjectCreate(void)
 {
        return new MediaPlugin;
 }
@@ -52,68 +47,12 @@ MediaPlugin::MediaPlugin()
        setName("media");
 }
 
-MediaPlugin::~MediaPlugin()
+PluginAction* MediaPlugin::newAction(const std::string &key)
 {
+       return mediaFactory.createAction(key);
 }
 
-int MediaPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
+void MediaPlugin::deleteAction(PluginAction *piAction)
 {
-       MediaAction *action = mediaFactory.createAction(key);
-       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
-       int ret = action->set(val);
-       if (ret != MODES_ERROR_NONE) {
-               ERR("Action(%s) set(%s) Fail(%d)", key.c_str(), val.c_str(), ret);
-               mediaFactory.destroyAction(action);
-               return ret;
-       }
-
-       if (piAction)
-               *piAction = action;
-       else
-               mediaFactory.destroyAction(action);
-       return ret;
-}
-
-int MediaPlugin::set(const std::string &key, int val, PluginAction **piAction)
-{
-       MediaAction *action = mediaFactory.createAction(key);
-       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
-       int ret = action->set(val);
-       if (ret != MODES_ERROR_NONE) {
-               ERR("Action(%s) set(%d) Fail(%d)", key.c_str(), val, ret);
-               mediaFactory.destroyAction(action);
-               return ret;
-       }
-
-       if (piAction)
-               *piAction = action;
-       else
-               mediaFactory.destroyAction(action);
-       return ret;
-}
-
-PluginAction* MediaPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
-       MediaAction *action = mediaFactory.createAction(key);
-       RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
-       int ret = action->parse(info);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
-               mediaFactory.destroyAction(action);
-               return nullptr;
-       }
-
-       return action;
-}
-
-void MediaPlugin::undo(PluginAction *piAction)
-{
-       MediaAction *action = static_cast<MediaAction*>(piAction);
-       RET_IF(nullptr == piAction);
-
-       action->undo();
-       mediaFactory.destroyAction(action);
+       mediaFactory.destroyAction(piAction);
 }
index 7140772..7d6fd85 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <string>
 #include <sstream>
-#include <modes_errors.h>
 #include <player.h>
 #include "plugin-log.h"
 
@@ -32,41 +31,57 @@ const std::string SoundVolume::NAME[4] = {
 };
 
 SoundVolume::SoundVolume(int key, sound_type_e soundType)
-       : MediaAction(NAME[key]), type(soundType),
+       : PluginAction(NAME[key]), type(soundType),
        requestVal(-1), oldVal(-1), callbackID(0), cb(nullptr), cbData(nullptr)
 {
 }
 
-int SoundVolume::set(int val)
+bool SoundVolume::IsCurrentValue(int val)
 {
-       requestVal = val;
-
-       int ret = sound_manager_get_volume(type, &oldVal);
-       if (SOUND_MANAGER_ERROR_NONE != ret) {
-               ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret));
-               return MODES_ERROR_SYSTEM;
-       }
+       int ret;
 
        if (-1 == val) {
                ret = sound_manager_get_max_volume(type, &val);
                if (SOUND_MANAGER_ERROR_NONE != ret) {
                        ERR("sound_manager_get_max_volume() Fail(%s)", get_error_message(ret));
-                       return MODES_ERROR_SYSTEM;
+                       return false;
                }
-               DBG("sound_manager_get_max_volume(%s) is (%d)", getName().c_str(), val);
+               INFO("sound_manager_get_max_volume(%s) is (%d)", getKey().c_str(), val);
        }
 
+       ret = sound_manager_get_volume(type, &oldVal);
+       if (SOUND_MANAGER_ERROR_NONE != ret) {
+               ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret));
+               return false;
+       }
 
        if (oldVal == val) {
-               INFO("%s already set[%d]", getName().c_str(), val);
-       } else {
-               ret = sound_manager_set_volume(type, val);
+               INFO("%s already set[%d]", getKey().c_str(), val);
+               return true;
+       }
+
+       return false;
+}
+
+int SoundVolume::set(int val)
+{
+       int ret;
+       requestVal = val;
+
+       if (-1 == val) {
+               ret = sound_manager_get_max_volume(type, &val);
                if (SOUND_MANAGER_ERROR_NONE != ret) {
-                       ERR("sound_manager_set_volume(%s) Fail(%s)", getName().c_str(), get_error_message(ret));
+                       ERR("sound_manager_get_max_volume() Fail(%s)", get_error_message(ret));
                        return MODES_ERROR_SYSTEM;
                }
+               INFO("sound_manager_get_max_volume(%s) is (%d)", getKey().c_str(), val);
        }
 
+       ret = sound_manager_set_volume(type, val);
+       if (SOUND_MANAGER_ERROR_NONE != ret) {
+               ERR("sound_manager_set_volume(%s) Fail(%s)", getKey().c_str(), get_error_message(ret));
+               return MODES_ERROR_SYSTEM;
+       }
        return MODES_ERROR_NONE;
 }
 
@@ -77,7 +92,7 @@ void SoundVolume::undo()
                ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret));
 }
 
-std::string SoundVolume::serialize()
+std::string SoundVolume::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -85,9 +100,9 @@ std::string SoundVolume::serialize()
        return ostr.str();
 }
 
-int SoundVolume::parse(const std::string &archive)
+int SoundVolume::setUndoInfo(const std::string &info)
 {
-       std::istringstream iss(archive);
+       std::istringstream iss(info);
        iss >> oldVal;
 
        return MODES_ERROR_NONE;
index 9f04e74..ba6ac2f 100644 (file)
 
 #include <string>
 #include <sound_manager.h>
+#include <PluginAction.h>
 #include "plugin-def.h"
-#include "MediaAction.h"
 
 MODES_NAMESPACE_BEGIN
 
-class SoundVolume : public MediaAction {
+class SoundVolume : public PluginAction {
 public:
        SoundVolume(int key, sound_type_e soundType);
-       ~SoundVolume() = default;
+       ~SoundVolume() override = default;
 
+       bool IsCurrentValue(int val);
        int set(int val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 
index bfcf38d..7895de2 100644 (file)
  * limitations under the License.
  */
 #include "PkgEnableSupportMode.h"
+
 #include <glib.h>
 #include <list>
 #include <string>
 #include <sstream>
 #include <pkgmgr-info.h>
 #include <package-manager.h>
-#include <modes_errors.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
@@ -28,7 +28,7 @@ MODES_NAMESPACE_USE;
 const std::string PkgSupportMode::NAME = "supportMode";
 
 PkgSupportMode::PkgSupportMode()
-       : PkgAction(NAME), requestVal(0)
+       : PluginAction(NAME), requestVal(0)
 {
 }
 
@@ -94,12 +94,9 @@ void PkgSupportMode::undo()
        DBG("Request id[%d] count[%d]", reqId, nApps);
 
        pkgmgr_client_free(pc);
-
-       //The caller(Plugin undo function) includes destruction of this instance.
-       //Therefore, appList will be automatically cleared by the destructor.
 }
 
-std::string PkgSupportMode::serialize()
+std::string PkgSupportMode::getUndoInfo()
 {
        std::ostringstream ostr;
        for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++)
@@ -108,12 +105,12 @@ std::string PkgSupportMode::serialize()
        return ostr.str();
 }
 
-int PkgSupportMode::parse(const std::string &data)
+int PkgSupportMode::setUndoInfo(const std::string &info)
 {
        size_t pos;
        size_t start = 0;
-       while ((pos = data.find(delimiter, start)) != std::string::npos) {
-               inactiveApps.push_back(data.substr(start, pos - start));
+       while ((pos = info.find(delimiter, start)) != std::string::npos) {
+               inactiveApps.push_back(info.substr(start, pos - start));
                start = pos + 1;
        }
        return MODES_ERROR_NONE;
index c66fb17..3c9f93b 100644 (file)
 #include <list>
 #include <string>
 #include <pkgmgr-info.h>
+#include <PluginAction.h>
 #include "plugin-def.h"
-#include "PkgAction.h"
 
 MODES_NAMESPACE_BEGIN
 
-class PkgSupportMode : public PkgAction {
+class PkgSupportMode : public PluginAction {
 public:
        PkgSupportMode();
 
        int set(int val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &data) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &data) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 
index 0183e3f..5193538 100644 (file)
@@ -24,15 +24,15 @@ PkgFactory::PkgFactory()
        actionMap[PkgSupportMode::NAME] = PKG_ACT_SUPPORTMODE;
 }
 
-PkgAction* PkgFactory::createAction(const std::string &key)
+PluginAction* PkgFactory::createAction(const std::string &key)
 {
        auto search = actionMap.find(key);
        if (actionMap.end() == search) {
-               ERR("No PkgAction(%s)", key.c_str());
+               ERR("No Pkg PluginAction(%s)", key.c_str());
                return nullptr;
        }
 
-       PkgAction *action;
+       PluginAction *action;
        switch (search->second) {
        case PKG_ACT_SUPPORTMODE:
                action = new PkgSupportMode();
@@ -45,7 +45,7 @@ PkgAction* PkgFactory::createAction(const std::string &key)
        return action;
 }
 
-void PkgFactory::destroyAction(PkgAction *action)
+void PkgFactory::destroyAction(PluginAction *action)
 {
        delete action;
 }
index 4503735..0bf4e82 100644 (file)
@@ -17,7 +17,8 @@
 
 #include <map>
 #include <string>
-#include "PkgAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -26,8 +27,8 @@ public:
        PkgFactory();
        ~PkgFactory() = default;
 
-       PkgAction* createAction(const std::string &key);
-       void destroyAction(PkgAction *action);
+       PluginAction* createAction(const std::string &key);
+       void destroyAction(PluginAction *action);
 private:
        enum actionKey{
                PKG_ACT_SUPPORTMODE
index fa80c89..9e7e6cf 100644 (file)
  * limitations under the License.
  */
 #include <string>
-#include <modes_errors.h>
 #include <Plugin.h>
 #include "plugin-log.h"
 #include "plugin-def.h"
 #include "PkgFactory.h"
-#include "PkgAction.h"
 
 MODES_NAMESPACE_USE;
 
 class PkgPlugin : public Plugin {
 public:
        PkgPlugin();
-       ~PkgPlugin() = default;
+       ~PkgPlugin() override = default;
 
-       int set(const std::string &key, int val, PluginAction **piAction) override;
-       void undo(PluginAction *piAction) override;
-       PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+       PluginAction* newAction(const std::string &key) override;
+       void deleteAction(PluginAction *piAction) override;
 private:
        PkgFactory pkgFactory;
 };
 
-extern "C" API Plugin *objectCreate(void)
+extern "C" API PluginobjectCreate(void)
 {
-       return new PkgPlugin;
+       return new PkgPlugin();
 }
 
 extern "C" API void objectDelete(Plugin *plugin)
@@ -50,39 +47,12 @@ PkgPlugin::PkgPlugin()
        setName("pkg");
 }
 
-int PkgPlugin::set(const std::string &key, int val, PluginAction **piAction)
+PluginAction* PkgPlugin::newAction(const std::string &key)
 {
-       PkgAction *action = pkgFactory.createAction(key);
-       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
-       int ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               pkgFactory.destroyAction(action);
-       return ret;
+       return pkgFactory.createAction(key);
 }
 
-void PkgPlugin::undo(PluginAction *piAction)
+void PkgPlugin::deleteAction(PluginAction *piAction)
 {
-       PkgAction *action = static_cast<PkgAction*>(piAction);
-       RET_IF(nullptr == piAction);
-
-       action->undo();
-       pkgFactory.destroyAction(action);
-}
-
-PluginAction* PkgPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
-       PkgAction *action = pkgFactory.createAction(key);
-       RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
-       int ret = action->parse(info);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
-               pkgFactory.destroyAction(action);
-               return nullptr;
-       }
-
-       return action;
+       pkgFactory.destroyAction(piAction);
 }
index 48927dd..65d9a7f 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} ${VCONF_COMMON_SRC})
+ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS})
 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} ${VCONF_COMMON_SRC})
+ADD_EXECUTABLE(${DISPLAY_PLUGIN_TEST} ${DISPLAY_SRCS})
 TARGET_LINK_LIBRARIES(${DISPLAY_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
 INSTALL(TARGETS ${DISPLAY_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
index 5a81489..67eed26 100644 (file)
 #include <glib.h>
 #include <aul.h>
 #include <Plugin.h>
-#include <modes_errors.h>
 #include <app_manager.h>
 #include <app_manager_extension.h>
 #include "plugin-def.h"
 
 MODES_NAMESPACE_USE;
 
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
 
 class AppPluginTest : public ::testing::Test {
 protected:
@@ -49,22 +48,25 @@ protected:
        static gboolean appUndoTimeout(gpointer data)
        {
                PluginAction *action = (PluginAction*)data;
-               plugin->undo(action);
+               action->undo();
                g_main_loop_quit(loop);
+               plugin->deleteAction(action);
                return false;
        }
 
        static gboolean checkSetUndoIdler(gpointer data)
        {
-               PluginAction *action;
-               result = plugin->set("launch", std::string(testApp), &action);
+               PluginAction *action = plugin->newAction("launch");
+               EXPECT_FALSE(action->IsCurrentValue(std::string(testApp)));
+               result = action->set(std::string(testApp));
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               if (MODES_ERROR_NONE == result)
+               if (MODES_ERROR_NONE == result) {
                        g_timeout_add(1000, appUndoTimeout, action);
-               else
+               } else {
                        g_main_loop_quit(loop);
-
+                       plugin->deleteAction(action);
+               }
                return G_SOURCE_REMOVE;
        }
 
@@ -76,8 +78,9 @@ protected:
 
        static gboolean checkChangedCBIdler(gpointer data)
        {
-               PluginAction *action;
-               result = plugin->set("launch", std::string(testApp), &action);
+               PluginAction *action = plugin->newAction("launch");
+               EXPECT_FALSE(action->IsCurrentValue(std::string(testApp)));
+               result = action->set(std::string(testApp));
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
                int ret = action->setChangedCallback(changedCB, (void*)testApp);
@@ -87,10 +90,12 @@ protected:
                app_manager_get_app_context(testApp, &runAppContext);
                app_manager_terminate_app(runAppContext);
 
-               if (MODES_ERROR_NONE == result)
-                       g_timeout_add(3000, appUndoTimeout, action);
-               else
+               if (MODES_ERROR_NONE == result) {
+                       g_timeout_add(1000, appUndoTimeout, action);
+               } else {
                        g_main_loop_quit(loop);
+                       plugin->deleteAction(action);
+               }
 
                return G_SOURCE_REMOVE;
        }
index 18a0abc..3c5d4c5 100644 (file)
@@ -22,7 +22,7 @@
 
 MODES_NAMESPACE_USE;
 
-extern "C" Plugin *objectCreate(void);
+extern "C" PluginobjectCreate(void);
 extern "C" void objectDelete(Plugin *plugin);
 
 class BtPluginTest : public ::testing::Test {
@@ -101,21 +101,22 @@ TEST_F(BtPluginTest, btTest)
 
        ASSERT_TRUE(nullptr != plugin);
 
-       ret = plugin->set("power", false, nullptr);
+       PluginAction *action = plugin->newAction("power");
+       ret = action->set(false);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
        sleep(3);//for avoiding the NOW_IN_PROGRESS error
 
-       ret = plugin->set("power", true, nullptr);
+       ret = action->set(true);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       ret = plugin->set("power", std::string("on"), nullptr);
+       ret = action->set(std::string("on"));
        EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
+       plugin->deleteAction(action);
 
-       ret = plugin->set("abcdefg", true, nullptr);
-       EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER);
+       action = plugin->newAction("abcdefg");
+       EXPECT_EQ(action, nullptr);
 }
 
-
 int main(int argc, char **argv)
 {
        testing::InitGoogleTest(&argc, argv);
index 2820043..f774dbd 100644 (file)
 #include <glib.h>
 #include <gtest/gtest.h>
 #include <Plugin.h>
-#include <modes_errors.h>
 #include "plugin-def.h"
 
 MODES_NAMESPACE_USE;
 
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
 
 class displayPluginTest : public ::testing::Test {
 protected:
@@ -42,56 +41,62 @@ protected:
 
        static gboolean displayPluginBrightnessIdler(gpointer data)
        {
-               PluginAction *action;
-               result = plugin->set("brightness", 100, &action);
+               PluginAction *action = plugin->newAction("brightness");
+               int value = 100;
+               if (action->IsCurrentValue(value))
+                       value--;
+               result = action->set(value);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               plugin->undo(action);
+               action->undo();
 
+               plugin->deleteAction(action);
                g_main_loop_quit(loop);
-
                return G_SOURCE_REMOVE;
        }
 
        static gboolean displayPluginDenyPalmTouchIdler(gpointer data)
        {
-               PluginAction *action;
-               result = plugin->set("denyPalmTouch", true, &action);
+               PluginAction *action = plugin->newAction("denyPalmTouch");
+               EXPECT_FALSE(action->IsCurrentValue(true));
+               result = action->set(true);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               plugin->undo(action);
+               action->undo();
 
+               plugin->deleteAction(action);
                g_main_loop_quit(loop);
-
                return G_SOURCE_REMOVE;
        }
 
        static gboolean displayPluginAlwaysOnIdler(gpointer data)
        {
-               PluginAction *action;
-               result = plugin->set("timeout", 0, &action);
+               PluginAction *action = plugin->newAction("timeout");
+               EXPECT_FALSE(action->IsCurrentValue(0));
+               result = action->set(0);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               plugin->undo(action);
+               action->undo();
 
+               plugin->deleteAction(action);
                g_main_loop_quit(loop);
-
                return G_SOURCE_REMOVE;
        }
 
        static gboolean displayPluginAutoBrightnessIdler(gpointer data)
        {
-               PluginAction *action;
-               result = plugin->set("autoBrightness", 1, &action);
+               PluginAction *action = plugin->newAction("autoBrightness");
+               EXPECT_FALSE(action->IsCurrentValue(1));
+               result = action->set(1);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               plugin->undo(action);
+               action->undo();
 
-               result = plugin->set("autoBrightness", 2, &action);
+               result = action->set(2);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
+               plugin->deleteAction(action);
                g_main_loop_quit(loop);
-
                return G_SOURCE_REMOVE;
        }
        static int result;
index 40d1279..fa1ddd5 100644 (file)
 #include <string>
 #include <gtest/gtest.h>
 #include <Plugin.h>
-#include <modes_errors.h>
 #include "plugin-def.h"
 
 MODES_NAMESPACE_USE;
 
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
 
 class MediaPluginTest : public ::testing::Test {
 protected:
@@ -44,17 +43,22 @@ protected:
        static gboolean mediaPlaySetUndoTimeout(gpointer data)
        {
                PluginAction *action = (PluginAction*)data;
-               plugin->undo(action);
+               action->undo();
                g_main_loop_quit(loop);
                return false;
        }
 
        static gboolean mediaPlaySetUndoIdler(gpointer data)
        {
-               PluginAction *action;
-               result = plugin->set("player", std::string("/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"), &action);
-               if (MODES_ERROR_NONE != result)
-                       result = plugin->set("player", std::string("/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg"), &action);
+               PluginAction *action = (PluginAction*)data;
+               const std::string file = "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3";
+               EXPECT_FALSE(action->IsCurrentValue(file));
+               result = action->set(file);
+               if (MODES_ERROR_NONE != result) {
+                       const std::string wearableFile = "/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg";
+                       EXPECT_FALSE(action->IsCurrentValue(wearableFile));
+                       result = action->set(wearableFile);
+               }
 
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
@@ -69,45 +73,61 @@ protected:
        static gboolean VolumeSetUndoIdler(gpointer data)
        {
                PluginAction *action;
-               action = nullptr;
-               result = plugin->set("mediaVolume", 5, &action);
+               action = plugin->newAction("mediaVolume");
+               EXPECT_FALSE(action->IsCurrentValue(5));
+               result = action->set(5);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
-               action = nullptr;
-               result = plugin->set("systemVolume", 2, &action);
+               action = plugin->newAction("systemVolume");
+               EXPECT_FALSE(action->IsCurrentValue(2));
+               result = action->set(2);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
-               action = nullptr;
-               result = plugin->set("ringtoneVolume", 9, &action);
+               action = plugin->newAction("ringtoneVolume");
+               EXPECT_FALSE(action->IsCurrentValue(9));
+               result = action->set(9);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
-               action = nullptr;
-               result = plugin->set("notificationVolume", 1, &action);
+               action = plugin->newAction("notificationVolume");
+               EXPECT_FALSE(action->IsCurrentValue(1));
+               result = action->set(1);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
-               action = nullptr;
-               result = plugin->set("mediaVolume", -1, &action);
+               action = plugin->newAction("mediaVolume");
+               EXPECT_FALSE(action->IsCurrentValue(-1));
+               result = action->set(-1);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
-               action = nullptr;
-               result = plugin->set("systemVolume", -1, &action);
+               action = plugin->newAction("systemVolume");
+               EXPECT_FALSE(action->IsCurrentValue(-1));
+               result = action->set(-1);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
-               action = nullptr;
-               result = plugin->set("ringtoneVolume", -1, &action);
+               action = plugin->newAction("ringtoneVolume");
+               EXPECT_FALSE(action->IsCurrentValue(-1));
+               result = action->set(-1);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
-               action = nullptr;
-               result = plugin->set("notificationVolume", -1, &action);
+               action = plugin->newAction("notificationVolume");
+               EXPECT_FALSE(action->IsCurrentValue(-1));
+               result = action->set(-1);
                EXPECT_EQ(MODES_ERROR_NONE, result);
-               plugin->undo(action);
+               action->undo();
+               plugin->deleteAction(action);
 
                g_main_loop_quit(loop);
 
@@ -121,17 +141,19 @@ protected:
 
 int MediaPluginTest::result = 0;
 Plugin *MediaPluginTest::plugin = nullptr;
-GMainLoop *MediaPluginTest::loop = NULL;
+GMainLoop *MediaPluginTest::loop = nullptr;
 
 TEST_F(MediaPluginTest, setUndoMediaPlay)
 {
-       g_idle_add(mediaPlaySetUndoIdler, plugin);
+       PluginAction *action = plugin->newAction("player");
+       g_idle_add(mediaPlaySetUndoIdler, action);
        g_main_loop_run(loop);
+       plugin->deleteAction(action);
 }
 
 TEST_F(MediaPluginTest, setUndoMediaVolume)
 {
-       g_idle_add(VolumeSetUndoIdler, plugin);
+       g_idle_add(VolumeSetUndoIdler, NULL);
        g_main_loop_run(loop);
 }
 
index 1f3a9ef..e6bb2a3 100644 (file)
 #include <string>
 #include <gtest/gtest.h>
 #include <Plugin.h>
-#include <modes_errors.h>
 #include "plugin-def.h"
 
 MODES_NAMESPACE_USE;
 
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
 
 class PkgPluginTest : public ::testing::Test {
 protected:
@@ -56,17 +55,19 @@ GMainLoop *PkgPluginTest::loop = NULL;
 
 TEST_F(PkgPluginTest, setUndoTest)
 {
-       PluginAction *action;
-       int ret = plugin->set("supportMode", 1, &action);
+       PluginAction *action = plugin->newAction("supportMode");
+       EXPECT_FALSE(action->IsCurrentValue(1));
+       int ret = action->set(1);
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 
        g_idle_add(pkgPluginIdler, plugin);
        g_main_loop_run(loop);
 
-       plugin->undo(action);
+       action->undo();
 
        g_idle_add(pkgPluginIdler, plugin);
        g_main_loop_run(loop);
+       plugin->deleteAction(action);
 }
 
 int main(int argc, char **argv) {
index c8e642f..e457149 100644 (file)
 #include <vconf.h>
 #include <gtest/gtest.h>
 #include <Plugin.h>
-#include <modes_errors.h>
 #include "plugin-log.h"
 #include "plugin-def.h"
 
 MODES_NAMESPACE_USE;
 
-extern "C" Plugin *objectCreate(void);
+extern "C" PluginobjectCreate(void);
 extern "C" void objectDelete(Plugin *plugin);
 
 class VconfPluginTest : public ::testing::Test {
@@ -59,7 +58,7 @@ protected:
        static void callback1(void *userData)
        {
                PluginAction *action = (PluginAction*)userData;
-               DBG("%s changed callback called!", action->getName().c_str());
+               DBG("%s changed callback called!", action->getKey().c_str());
 
                //In practice, it is handled by Action. refer to Action.cpp
                action->unSetChangedCallback(callback1, nullptr);
@@ -98,14 +97,16 @@ TEST_F(VconfPluginTest, VconfInt)
        int ret;
        const char *key = "db.setting.psmode";
 
-       ret = plugin->set(key, 0, nullptr);
+       PluginAction *action = plugin->newAction(key);;
+       ret = action->set(0);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       PluginAction *action;
-       ret = plugin->set(key, 1, &action);
+       EXPECT_FALSE(action->IsCurrentValue(1));
+       ret = action->set(1);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       plugin->undo(action);
+       action->undo();
+       plugin->deleteAction(action);
 }
 
 TEST_F(VconfPluginTest, VconfDouble)
@@ -113,14 +114,16 @@ TEST_F(VconfPluginTest, VconfDouble)
        int ret;
        const char *key = "db.system.timechange_external";
 
-       ret = plugin->set(key, 0.0, nullptr);
+       PluginAction *action = plugin->newAction(key);;
+       ret = action->set(0.0);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       PluginAction *action;
-       ret = plugin->set(key, 1.0, &action);
+       EXPECT_FALSE(action->IsCurrentValue(1.0));
+       ret = action->set(1.0);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       plugin->undo(action);
+       action->undo();
+       plugin->deleteAction(action);
 }
 
 TEST_F(VconfPluginTest, VconfBool)
@@ -128,14 +131,16 @@ TEST_F(VconfPluginTest, VconfBool)
        int ret;
        const char *key = "db.setting.sound.button_sounds";
 
-       ret = plugin->set(key, true, nullptr);
+       PluginAction *action = plugin->newAction(key);;
+       ret = action->set(true);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       PluginAction *action;
-       ret = plugin->set(key, false, &action);
+       EXPECT_FALSE(action->IsCurrentValue(false));
+       ret = action->set(false);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       plugin->undo(action);
+       action->undo();
+       plugin->deleteAction(action);
 }
 
 TEST_F(VconfPluginTest, VconfStr)
@@ -145,14 +150,16 @@ TEST_F(VconfPluginTest, VconfStr)
        const std::string devName = "Tizen";
        const std::string tmpName = "ModesTest";
 
-       ret = plugin->set(key, devName, nullptr);
+       PluginAction *action = plugin->newAction(key);
+       ret = action->set(devName);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       PluginAction *action;
-       ret = plugin->set(key, tmpName, &action);
+       EXPECT_FALSE(action->IsCurrentValue(tmpName));
+       ret = action->set(tmpName);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       plugin->undo(action);
+       action->undo();
+       plugin->deleteAction(action);
 }
 
 TEST_F(VconfPluginTest, callbackPluginVconf)
@@ -162,8 +169,8 @@ TEST_F(VconfPluginTest, callbackPluginVconf)
        int ret = vconf_get_int("db/setting/psmode", &oldVal);
        EXPECT_EQ(ret, 0);
 
-       PluginAction *action;
-       ret = plugin->set(key, 0, &action);
+       PluginAction *action = plugin->newAction(key);
+       ret = action->set(0);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
        ret = action->setChangedCallback(valChangedCb, (void*)key);
@@ -177,34 +184,10 @@ TEST_F(VconfPluginTest, callbackPluginVconf)
        ret = action->setChangedCallback(shoudNotBeCalled, (void*)key);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
        action->unSetChangedCallback(shoudNotBeCalled, (void*)key);
+       plugin->deleteAction(action);
        vconf_set_int("db/setting/psmode", oldVal);
 }
 
-TEST_F(VconfPluginTest, callbackPluginVconfReset)
-{
-       int ret;
-       const char *key = "db.setting.psmode";
-
-       PluginAction *action1;
-       ret = plugin->set(key, 4, &action1);
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-
-       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, (void*)key);
-       EXPECT_EQ(ret, MODES_ERROR_NONE);
-       g_idle_add(changedCallbackidler, nullptr);
-       g_main_loop_run(loop);
-       EXPECT_TRUE(cb2Called);
-
-       action2->unSetChangedCallback(callback2, nullptr);
-       vconf_set_int("db/setting/psmode", 0);
-}
-
 int main(int argc, char **argv) {
        testing::InitGoogleTest(&argc, argv);
        return RUN_ALL_TESTS();
index fdb2ff9..3b49df8 100644 (file)
@@ -21,7 +21,7 @@
 
 MODES_NAMESPACE_USE;
 
-extern "C" Plugin *objectCreate(void);
+extern "C" PluginobjectCreate(void);
 extern "C" void objectDelete(Plugin *plugin);
 
 class WifiPluginTest : public ::testing::Test {
@@ -37,6 +37,13 @@ protected:
                plugin = nullptr;
        }
 
+       static gboolean timer(gpointer data)
+       {
+               GMainLoop *loop = (GMainLoop*)data;
+               g_main_loop_quit(loop);
+               return G_SOURCE_REMOVE;
+       }
+
        Plugin *plugin;
 };
 
@@ -46,32 +53,40 @@ TEST_F(WifiPluginTest, wifiTest)
 
        ASSERT_TRUE(nullptr != plugin);
 
-       ret = plugin->set("power", false, nullptr);
+       bool val;
+       PluginAction *action = plugin->newAction("power");
+       val = action->IsCurrentValue(false);
+       ret = action->set(val);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       ret = plugin->set("power", true, nullptr);
+       GMainLoop *loop = g_main_loop_new(NULL, FALSE);
+       g_timeout_add(1000, timer, (gpointer)loop);
+       g_main_loop_run(loop);
+
+       ret = action->set(!val);
        EXPECT_EQ(ret, MODES_ERROR_NONE);
 
-       ret = plugin->set("power", 0, nullptr);
+       ret = action->set(0);
        EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
 
-       ret = plugin->set("power", 1, nullptr);
+       ret = action->set(1);
        EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
 
-       ret = plugin->set("power", 0.0, nullptr);
+       ret = action->set(0.0);
        EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
 
-       ret = plugin->set("power", 1.0, nullptr);
+       ret = action->set(1.0);
        EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
 
-       ret = plugin->set("power", std::string("off"), nullptr);
+       ret = action->set(std::string("off"));
        EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
 
-       ret = plugin->set("power", std::string("on"), nullptr);
+       ret = action->set(std::string("on"));
        EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
+       plugin->deleteAction(action);
 
-       ret = plugin->set("abcdefg", true, nullptr);
-       EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER);
+       action = plugin->newAction("abcdefg");
+       EXPECT_EQ(action, nullptr);
 }
 
 int main(int argc, char **argv) {
index cb97410..9304a17 100644 (file)
@@ -6,7 +6,7 @@ PKG_CHECK_MODULES(vconf_pkgs REQUIRED modes dlog capi-base-common vconf)
 INCLUDE_DIRECTORIES(${vconf_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${vconf_pkgs_LIBRARY_DIRS})
 
-ADD_LIBRARY(${VCONF_PLUGIN} SHARED ${VCONF_SRCS} ${VCONF_COMMON_SRC})
+ADD_LIBRARY(${VCONF_PLUGIN} SHARED ${VCONF_SRCS})
 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})
similarity index 54%
rename from vconf/VconfActionBool.cpp
rename to vconf/VconfBool.cpp
index 8c6b717..7819909 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "VconfActionBool.h"
+#include "VconfBool.h"
 
 #include <string>
 #include <sstream>
 
 MODES_NAMESPACE_USE;
 
-VconfActionBool::VconfActionBool(const std::string &vconfKey)
+VconfBool::VconfBool(const std::string &vconfKey)
        : PluginAction("boolVconf"), key(vconfKey), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr)
 {
 }
 
-int VconfActionBool::set(bool val)
+bool VconfBool::IsCurrentValue(bool val)
 {
-       requestVal = val;
-
-       int ret = cbHandler.invokeChangedCB(key);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
-               return ret;
-       }
-
-       int prev;
-       ret = vconf_get_bool(key.c_str(), &prev);
+       int tmp;
+       int ret = vconf_get_bool(key.c_str(), &tmp);
        if (0 != ret) {
                ERR("vconf_get_bool(%s) Fail(%d)", key.c_str(), ret);
-               return MODES_ERROR_SYSTEM;
+               return false;
        }
-       oldVal = prev;
+       oldVal = tmp;
 
        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 true;
+       }
+
+       return false;
+}
+
+int VconfBool::set(bool val)
+{
+       requestVal = val;
+
+       int 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;
 }
 
-void VconfActionBool::undo()
+void VconfBool::undo()
 {
        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);
 }
 
-std::string VconfActionBool::serialize()
+std::string VconfBool::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -73,22 +73,22 @@ std::string VconfActionBool::serialize()
        return ostr.str();
 }
 
-int VconfActionBool::parse(const std::string &archive)
+int VconfBool::setUndoInfo(const std::string &info)
 {
-       std::istringstream iss(archive);
+       std::istringstream iss(info);
        iss >> oldVal;
 
        return MODES_ERROR_NONE;
 }
 
-int VconfActionBool::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfBool::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;
+       int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+       if (0 != ret) {
+               ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
        }
 
        cb = callback;
@@ -97,32 +97,37 @@ int VconfActionBool::setChangedCallback(valueChangedCB callback, void *userData)
        return MODES_ERROR_NONE;
 }
 
-void VconfActionBool::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfBool::unSetChangedCallback(valueChangedCB callback, void *userData)
 {
        RET_IF(nullptr == callback);
 
-       cbHandler.unSetChangedCB(key);
+       int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+       if (0 != ret) {
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return;
+       }
 
        cbData = nullptr;
        cb = nullptr;
 }
 
-//This funcion handles changes made by the Modes
-void VconfActionBool::vconfChangedCB()
-{
-       if (cb)
-               cb(cbData);
-}
-
-void VconfActionBool::vconfChangedCB(keynode_t *node)
+void VconfBool::changedCB(keynode_t *node)
 {
        const char *vconfKey = vconf_keynode_get_name(node);
-       if (vconfKey != key) {
-               WARN("Unknown vconf(%s) notification", vconfKey);
+       if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+               WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
                return;
        }
 
-       bool val = vconf_keynode_get_bool(node);
+       int val = vconf_keynode_get_bool(node);
        if (cb && (val != requestVal))
                cb(cbData);
 }
+
+void VconfBool::vconfChangedCB(keynode_t *node, void *userData)
+{
+       RET_IF(nullptr == userData);
+
+       VconfBool *action = (VconfBool*)userData;
+       action->changedCB(node);
+}
similarity index 74%
rename from vconf/VconfActionBool.h
rename to vconf/VconfBool.h
index 2e8c989..9566fb1 100644 (file)
 #pragma once
 
 #include <string>
+#include <vconf.h>
 #include <PluginAction.h>
 #include "plugin-def.h"
-#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionBool : public PluginAction, public VconfChangeAction {
+class VconfBool : public PluginAction {
 public:
-       VconfActionBool(const std::string &vconfKey);
+       VconfBool(const std::string &vconfKey);
 
-       int set(bool val);
+       bool IsCurrentValue(bool val) override;
+       int set(bool val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) 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:
+       void changedCB(keynode_t *node);
+       static void vconfChangedCB(keynode_t *node, void *userData);
+
        std::string key;
        bool requestVal;
        bool oldVal;
-       VconfCbHandler cbHandler;
        valueChangedCB cb;
        void *cbData;
 };
similarity index 55%
rename from vconf/VconfActionDbl.cpp
rename to vconf/VconfDbl.cpp
index fae68c1..a63985f 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "VconfActionDbl.h"
+#include "VconfDbl.h"
 
 #include <string>
 #include <sstream>
 
 MODES_NAMESPACE_USE;
 
-VconfActionDbl::VconfActionDbl(const std::string &vconfKey)
+VconfDbl::VconfDbl(const std::string &vconfKey)
        : PluginAction("dblVconf"), key(vconfKey), requestVal(0.0), oldVal(0.0), cb(nullptr), cbData(nullptr)
 {
 }
 
-int VconfActionDbl::set(double val)
+bool VconfDbl::IsCurrentValue(double val)
 {
-       requestVal = val;
-
-       int ret = cbHandler.invokeChangedCB(key);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
-               return ret;
-       }
-
-       ret = vconf_get_dbl(key.c_str(), &oldVal);
+       int 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;
+               return false;
        }
 
        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 true;
+       }
+
+       return false;
+}
+
+int VconfDbl::set(double val)
+{
+       requestVal = val;
+
+       int 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;
 }
 
-void VconfActionDbl::undo()
+void VconfDbl::undo()
 {
        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);
 }
 
-std::string VconfActionDbl::serialize()
+std::string VconfDbl::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -71,22 +71,22 @@ std::string VconfActionDbl::serialize()
        return ostr.str();
 }
 
-int VconfActionDbl::parse(const std::string &archive)
+int VconfDbl::setUndoInfo(const std::string &info)
 {
-       std::istringstream iss(archive);
+       std::istringstream iss(info);
        iss >> oldVal;
 
        return MODES_ERROR_NONE;
 }
 
-int VconfActionDbl::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfDbl::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;
+       int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+       if (0 != ret) {
+               ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
        }
 
        cb = callback;
@@ -95,28 +95,25 @@ int VconfActionDbl::setChangedCallback(valueChangedCB callback, void *userData)
        return MODES_ERROR_NONE;
 }
 
-void VconfActionDbl::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfDbl::unSetChangedCallback(valueChangedCB callback, void *userData)
 {
        RET_IF(nullptr == callback);
 
-       cbHandler.unSetChangedCB(key);
+       int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+       if (0 != ret) {
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return;
+       }
 
        cbData = nullptr;
        cb = nullptr;
 }
 
-//This funcion handles changes made by the Modes
-void VconfActionDbl::vconfChangedCB()
-{
-       if (cb)
-               cb(cbData);
-}
-
-void VconfActionDbl::vconfChangedCB(keynode_t *node)
+void VconfDbl::changedCB(keynode_t *node)
 {
        const char *vconfKey = vconf_keynode_get_name(node);
-       if (vconfKey != key) {
-               WARN("Unknown vconf(%s) notification", vconfKey);
+       if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+               WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
                return;
        }
 
@@ -124,3 +121,11 @@ void VconfActionDbl::vconfChangedCB(keynode_t *node)
        if (cb && (val != requestVal))
                cb(cbData);
 }
+
+void VconfDbl::vconfChangedCB(keynode_t *node, void *userData)
+{
+       RET_IF(nullptr == userData);
+
+       VconfDbl *action = (VconfDbl*)userData;
+       action->changedCB(node);
+}
similarity index 74%
rename from vconf/VconfActionDbl.h
rename to vconf/VconfDbl.h
index 3a98ebe..b8f733d 100644 (file)
 #pragma once
 
 #include <string>
+#include <vconf.h>
 #include <PluginAction.h>
 #include "plugin-def.h"
-#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionDbl : public PluginAction, public VconfChangeAction {
+class VconfDbl : public PluginAction {
 public:
-       VconfActionDbl(const std::string &vconfKey);
+       VconfDbl(const std::string &vconfKey);
 
-       int set(double val);
+       bool IsCurrentValue(double val) override;
+       int set(double val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) 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:
+       void changedCB(keynode_t *node);
+       static void vconfChangedCB(keynode_t *node, void *userData);
+
        std::string key;
        double requestVal;
        double oldVal;
-       VconfCbHandler cbHandler;
        valueChangedCB cb;
        void *cbData;
 };
diff --git a/vconf/VconfFactory.cpp b/vconf/VconfFactory.cpp
new file mode 100644 (file)
index 0000000..f3466cd
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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 "VconfFactory.h"
+
+#include <algorithm>
+#include "plugin-log.h"
+#include "VconfBool.h"
+#include "VconfDbl.h"
+#include "VconfInt.h"
+#include "VconfStr.h"
+
+MODES_NAMESPACE_USE;
+
+template<typename T> PluginAction* newVconf(const std::string &key)
+{
+       return new T(key);
+}
+
+VconfFactory::VconfFactory()
+{
+       actionMap["db.setting.psmode"] = &newVconf<VconfInt>;
+       actionMap["db.setting.sound.sound_on"] = &newVconf<VconfBool>;
+       actionMap["db.setting.sound.vibration_on"] = &newVconf<VconfBool>;
+       actionMap["db.location.setting.Usemylocation"] = &newVconf<VconfInt>;
+       actionMap["db.setting.auto_rotate_screen"] = &newVconf<VconfBool>;
+       actionMap["db.setting.menuscreen.package_name"] = &newVconf<VconfStr>;
+#ifdef MDS_TEST
+       actionMap["db.system.timechange_external"] = &newVconf<VconfDbl>;
+       actionMap["db.setting.sound.button_sounds"] = &newVconf<VconfBool>;
+       actionMap["db.setting.device_name"] = &newVconf<VconfStr>;
+#endif
+}
+
+PluginAction* VconfFactory::createAction(const std::string &key)
+{
+       auto found = actionMap.find(key);
+       if (actionMap.end() == found) {
+               ERR("No PluginAction(%s)", key.c_str());
+               return nullptr;
+       }
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       return found->second(newKey);;
+}
+
+void VconfFactory::destroyAction(PluginAction *action)
+{
+       delete action;
+}
similarity index 75%
rename from pkg/PkgAction.h
rename to vconf/VconfFactory.h
index 30eb892..ec29376 100644 (file)
  */
 #pragma once
 
+#include <map>
 #include <string>
 #include <PluginAction.h>
 #include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
-class PkgAction : public PluginAction {
+class VconfFactory {
 public:
-       PkgAction(const std::string &name)
-               : PluginAction(name)
-       {
-       }
-       ~PkgAction() = default;
+       VconfFactory();
+       ~VconfFactory() = default;
 
-       virtual int set(int val)
-       {
-               return MODES_ERROR_NOT_SUPPORTED;
-       }
+       PluginAction* createAction(const std::string &key);
+       void destroyAction(PluginAction *action);
+private:
+       std::map<std::string, PluginAction*(*)(const std::string&)> actionMap;
 };
 
 MODES_NAMESPACE_END
-
similarity index 55%
rename from vconf/VconfActionInt.cpp
rename to vconf/VconfInt.cpp
index ca28987..43cfb4f 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "VconfActionInt.h"
+#include "VconfInt.h"
 
 #include <string>
 #include <sstream>
 
 MODES_NAMESPACE_USE;
 
-VconfActionInt::VconfActionInt(const std::string &vconfKey)
+VconfInt::VconfInt(const std::string &vconfKey)
        : PluginAction("intVconf"), key(vconfKey), requestVal(0), oldVal(0), cb(nullptr), cbData(nullptr)
 {
 }
 
-int VconfActionInt::set(int val)
+bool VconfInt::IsCurrentValue(int val)
 {
-       requestVal = val;
-
-       int ret = cbHandler.invokeChangedCB(key);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
-               return ret;
-       }
-
-       ret = vconf_get_int(key.c_str(), &oldVal);
+       int 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;
+               return false;
        }
 
        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 true;
+       }
+
+       return false;
+}
+
+int VconfInt::set(int val)
+{
+       requestVal = val;
+
+       int 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;
 }
 
-void VconfActionInt::undo()
+void VconfInt::undo()
 {
        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);
 }
 
-std::string VconfActionInt::serialize()
+std::string VconfInt::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -71,22 +71,22 @@ std::string VconfActionInt::serialize()
        return ostr.str();
 }
 
-int VconfActionInt::parse(const std::string &archive)
+int VconfInt::setUndoInfo(const std::string &info)
 {
-       std::istringstream iss(archive);
+       std::istringstream iss(info);
        iss >> oldVal;
 
        return MODES_ERROR_NONE;
 }
 
-int VconfActionInt::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfInt::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;
+       int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+       if (0 != ret) {
+               ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
        }
 
        cb = callback;
@@ -95,28 +95,25 @@ int VconfActionInt::setChangedCallback(valueChangedCB callback, void *userData)
        return MODES_ERROR_NONE;
 }
 
-void VconfActionInt::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfInt::unSetChangedCallback(valueChangedCB callback, void *userData)
 {
        RET_IF(nullptr == callback);
 
-       cbHandler.unSetChangedCB(key);
+       int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+       if (0 != ret) {
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return;
+       }
 
        cbData = nullptr;
        cb = nullptr;
 }
 
-//This funcion handles changes made by the Modes
-void VconfActionInt::vconfChangedCB()
-{
-       if (cb)
-               cb(cbData);
-}
-
-void VconfActionInt::vconfChangedCB(keynode_t *node)
+void VconfInt::changedCB(keynode_t *node)
 {
        const char *vconfKey = vconf_keynode_get_name(node);
-       if (vconfKey != key) {
-               WARN("Unknown vconf(%s) notification", vconfKey);
+       if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+               WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
                return;
        }
 
@@ -124,3 +121,11 @@ void VconfActionInt::vconfChangedCB(keynode_t *node)
        if (cb && (val != requestVal))
                cb(cbData);
 }
+
+void VconfInt::vconfChangedCB(keynode_t *node, void *userData)
+{
+       RET_IF(nullptr == userData);
+
+       VconfInt *action = (VconfInt*)userData;
+       action->changedCB(node);
+}
similarity index 74%
rename from vconf/VconfActionInt.h
rename to vconf/VconfInt.h
index 49108e8..c48e3ed 100644 (file)
 #pragma once
 
 #include <string>
+#include <vconf.h>
 #include <PluginAction.h>
 #include "plugin-def.h"
-#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionInt : public PluginAction, public VconfChangeAction {
+class VconfInt : public PluginAction {
 public:
-       VconfActionInt(const std::string &vconfKey);
+       VconfInt(const std::string &vconfKey);
 
-       int set(int val);
+       bool IsCurrentValue(int val) override;
+       int set(int val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) 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:
+       void changedCB(keynode_t *node);
+       static void vconfChangedCB(keynode_t *node, void *userData);
+
        std::string key;
        int requestVal;
        int oldVal;
-       VconfCbHandler cbHandler;
        valueChangedCB cb;
        void *cbData;
 };
index c748893..7adbad8 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <string>
-#include <algorithm>
 #include <vconf.h>
-#include <modes_errors.h>
 #include <Plugin.h>
 #include "plugin-log.h"
 #include "plugin-def.h"
-#include "VconfActionInt.h"
-#include "VconfActionDbl.h"
-#include "VconfActionBool.h"
-#include "VconfActionStr.h"
+#include "VconfFactory.h"
 
 MODES_NAMESPACE_USE;
 
 class VconfPlugin : public Plugin {
 public:
        VconfPlugin();
+       ~VconfPlugin() override = default;
 
-       int set(const std::string &key, int val, PluginAction **piAction) override;
-       int set(const std::string &key, double val, PluginAction **piAction) override;
-       int set(const std::string &key, bool val, PluginAction **piAction) override;
-       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;
+       PluginAction* newAction(const std::string &key) override;
+       void deleteAction(PluginAction *piAction) override;
+private:
+       VconfFactory vconfFactory;
 };
 
-extern "C" API Plugin *objectCreate(void)
+extern "C" API PluginobjectCreate(void)
 {
-       return new VconfPlugin;
+       return new VconfPlugin();
 }
 
 extern "C" API void objectDelete(Plugin *plugin)
@@ -54,110 +47,12 @@ VconfPlugin::VconfPlugin()
        setName("vconf");
 }
 
-int VconfPlugin::set(const std::string &key, int val, PluginAction **piAction)
+PluginAction* VconfPlugin::newAction(const std::string &key)
 {
-       int ret;
-       DBG("set<int>(%s, %d)", key.c_str(), val);
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionInt *action = new VconfActionInt(newKey);
-       ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               delete action;
-       return ret;
-}
-
-int VconfPlugin::set(const std::string &key, double val, PluginAction **piAction)
-{
-       int ret;
-       DBG("set<double>(%s, %lf)", key.c_str(), val);
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionDbl *action = new VconfActionDbl(newKey);
-       ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               delete action;
-       return ret;
-}
-
-int VconfPlugin::set(const std::string &key, bool val, PluginAction **piAction)
-{
-       int ret;
-       DBG("set<bool>(%s, %d)", key.c_str(), val);
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionBool *action = new VconfActionBool(newKey);
-       ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-                delete action;
-       return ret;
+       return vconfFactory.createAction(key);
 }
 
-int VconfPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
+void VconfPlugin::deleteAction(PluginAction *piAction)
 {
-       DBG("set<string>(%s, %s)", key.c_str(), val.c_str());
-
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       VconfActionStr *action = new VconfActionStr(newKey);
-       int ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               delete action;
-       return ret;
-}
-
-PluginAction* VconfPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
-       std::string newKey(key);
-       std::replace(newKey.begin(), newKey.end(), '.', '/');
-
-       PluginAction *piAction;
-       switch (info.front()) {
-       case 's':
-               piAction = new VconfActionStr(newKey);
-               break;
-       case 'i':
-               piAction = new VconfActionInt(newKey);
-               break;
-       case 'd':
-               piAction = new VconfActionDbl(newKey);
-               break;
-       case 'b':
-               piAction = new VconfActionBool(newKey);
-               break;
-       default:
-               ERR("Unknown Undo Information(%s)", info.c_str());
-               return nullptr;
-       }
-       int ret = piAction->parse(info);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
-               delete piAction;
-               return nullptr;
-       }
-
-       return piAction;
-}
-
-std::string VconfPlugin::serializeAction(PluginAction *piAction)
-{
-       RETV_IF(nullptr == piAction, std::string());
-
-       std::string rawStr = piAction->serialize();
-       return piAction->getName().front() + rawStr;
+       vconfFactory.destroyAction(piAction);
 }
similarity index 56%
rename from vconf/VconfActionStr.cpp
rename to vconf/VconfStr.cpp
index bb887a7..215a135 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "VconfActionStr.h"
+#include "VconfStr.h"
 
 #include <string>
 #include <vconf.h>
 
 MODES_NAMESPACE_USE;
 
-VconfActionStr::VconfActionStr(const std::string &vconfKey)
+VconfStr::VconfStr(const std::string &vconfKey)
        : PluginAction("strVconf"), key(vconfKey), cb(nullptr), cbData(nullptr)
 {
 }
 
-int VconfActionStr::set(const std::string &val)
+bool VconfStr::IsCurrentValue(const std::string &val)
 {
-       requestVal = val;
-
-       int ret = cbHandler.invokeChangedCB(key);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
-               return ret;
-       }
-
        char *prev = vconf_get_str(key.c_str());
        if (nullptr == prev) {
                ERR("vconf_get_str(%s) Fail()", key.c_str());
-               return MODES_ERROR_SYSTEM;
+               return false;
        }
        oldVal = prev;
        free(prev);
 
        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 true;
+       }
+       return false;
+}
+
+int VconfStr::set(const std::string &val)
+{
+       requestVal = val;
+
+       int 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;
 }
 
-void VconfActionStr::undo()
+void VconfStr::undo()
 {
        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);
 }
 
-std::string VconfActionStr::serialize()
+std::string VconfStr::getUndoInfo()
 {
        return oldVal;
 }
 
-int VconfActionStr::parse(const std::string &archive)
+int VconfStr::setUndoInfo(const std::string &info)
 {
-       oldVal = archive;
+       oldVal = info;
        return MODES_ERROR_NONE;
 }
 
-int VconfActionStr::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfStr::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;
+       int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+       if (0 != ret) {
+               ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
        }
 
        cb = callback;
@@ -91,28 +90,25 @@ int VconfActionStr::setChangedCallback(valueChangedCB callback, void *userData)
        return MODES_ERROR_NONE;
 }
 
-void VconfActionStr::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfStr::unSetChangedCallback(valueChangedCB callback, void *userData)
 {
        RET_IF(nullptr == callback);
 
-       cbHandler.unSetChangedCB(key);
+       int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+       if (0 != ret) {
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+               return;
+       }
 
        cbData = nullptr;
        cb = nullptr;
 }
 
-//This funcion handles changes made by the Modes
-void VconfActionStr::vconfChangedCB()
-{
-       if (cb)
-               cb(cbData);
-}
-
-void VconfActionStr::vconfChangedCB(keynode_t *node)
+void VconfStr::changedCB(keynode_t * node)
 {
        const char *vconfKey = vconf_keynode_get_name(node);
-       if (vconfKey != key) {
-               WARN("Unknown vconf(%s) notification", vconfKey);
+       if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+               WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
                return;
        }
 
@@ -120,3 +116,11 @@ void VconfActionStr::vconfChangedCB(keynode_t *node)
        if (cb && (val != requestVal))
                cb(cbData);
 }
+
+void VconfStr::vconfChangedCB(keynode_t *node, void *userData)
+{
+       RET_IF(nullptr == userData);
+
+       VconfStr *action = (VconfStr*)userData;
+       action->changedCB(node);
+}
similarity index 73%
rename from vconf/VconfActionStr.h
rename to vconf/VconfStr.h
index ad84154..7dc8d57 100644 (file)
 #pragma once
 
 #include <string>
+#include <vconf.h>
 #include <PluginAction.h>
 #include "plugin-def.h"
-#include "VconfCbHandler.h"
 
 MODES_NAMESPACE_BEGIN
 
-class VconfActionStr : public PluginAction, public VconfChangeAction {
+class VconfStr : public PluginAction {
 public:
-       VconfActionStr(const std::string &vconfKey);
+       VconfStr(const std::string &vconfKey);
 
-       int set(const std::string &val);
+       bool IsCurrentValue(const std::string &val) override;
+       int set(const std::string &val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) 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:
+       void changedCB(keynode_t *node);
+       static void vconfChangedCB(keynode_t *node, void *userData);
+
        std::string key;
        std::string requestVal;
        std::string oldVal;
-       VconfCbHandler cbHandler;
        valueChangedCB cb;
        void *cbData;
 };
index cd5ef00..b6e6698 100644 (file)
@@ -15,7 +15,6 @@
  */
 #include "WifiAction.h"
 
-#include <modes_errors.h>
 #include "plugin-log.h"
 #include "plugin-def.h"
 
index 8b9bc9a..278c031 100644 (file)
@@ -27,7 +27,6 @@ public:
        WifiAction(const std::string &name);
        ~WifiAction();
 
-       virtual int set(bool val) = 0;
 protected:
        wifi_manager_h handle;
 };
index 5eda9c8..69c4e23 100644 (file)
@@ -16,7 +16,6 @@
 #include "WifiActionPower.h"
 
 #include <sstream>
-#include <modes_errors.h>
 #include "plugin-log.h"
 
 MODES_NAMESPACE_USE;
@@ -28,15 +27,21 @@ WifiActionPower::WifiActionPower()
 {
 }
 
-int WifiActionPower::set(bool val)
+bool WifiActionPower::IsCurrentValue(bool val)
 {
-       requestVal = val;
        wifi_manager_is_activated(handle, &oldVal);
        if (oldVal == val) {
                INFO("Already wifi is [%s]", val ? "On" : "Off");
-               return MODES_ERROR_NONE;
+               return true;
        }
 
+       return false;
+}
+
+int WifiActionPower::set(bool val)
+{
+       requestVal = val;
+
        if (val) {
                int ret = wifi_manager_activate(handle, activateCB, this);
                if (WIFI_MANAGER_ERROR_NONE != ret) {
@@ -60,7 +65,7 @@ void WifiActionPower::undo()
        set(oldVal);
 }
 
-std::string WifiActionPower::serialize()
+std::string WifiActionPower::getUndoInfo()
 {
        std::ostringstream ostr;
 
@@ -68,9 +73,9 @@ std::string WifiActionPower::serialize()
        return ostr.str();
 }
 
-int WifiActionPower::parse(const std::string &archive)
+int WifiActionPower::setUndoInfo(const std::string &info)
 {
-       std::istringstream iss(archive);
+       std::istringstream iss(info);
        iss >> oldVal;
 
        return MODES_ERROR_NONE;
index 04da771..032b2be 100644 (file)
@@ -24,10 +24,11 @@ class WifiActionPower : public WifiAction {
 public:
        WifiActionPower();
 
+       bool IsCurrentValue(bool val) override;
        int set(bool val) override;
        void undo() override;
-       std::string serialize() override;
-       int parse(const std::string &archive) override;
+       std::string getUndoInfo() override;
+       int setUndoInfo(const std::string &info) override;
        int setChangedCallback(valueChangedCB callback, void *userData) override;
        void unSetChangedCallback(valueChangedCB callback, void *userData) override;
 
index a8589f3..95ddd7c 100644 (file)
 
 MODES_NAMESPACE_USE;
 
+template<typename T> PluginAction* newWifiAction() { return new T(); }
+
 WifiFactory::WifiFactory()
 {
-       actionMap[WifiActionPower::NAME] = POWER;
+       actionMap[WifiActionPower::NAME] = &newWifiAction<WifiActionPower>;
 }
 
-WifiAction* WifiFactory::createAction(const std::string &key)
+PluginAction* WifiFactory::createAction(const std::string &key)
 {
-       auto search = actionMap.find(key);
-       if (actionMap.end() == search) {
+       auto found = actionMap.find(key);
+       if (actionMap.end() == found) {
                ERR("No WifiAction(%s)", key.c_str());
                return nullptr;
        }
 
-       switch (search->second) {
-       case POWER:
-               WifiActionPower *wifiActionPower = new WifiActionPower();
-               return wifiActionPower;
-               break;
-       }
-
-       return nullptr;
+       return found->second();
 }
 
-void WifiFactory::destroyAction(WifiAction *action)
+void WifiFactory::destroyAction(PluginAction *action)
 {
        delete action;
 }
index 80ebb81..64b57e2 100644 (file)
@@ -26,14 +26,14 @@ public:
        WifiFactory();
        ~WifiFactory() = default;
 
-       WifiAction *createAction(const std::string &key);
-       void destroyAction(WifiAction *action);
+       PluginAction* createAction(const std::string &key);
+       void destroyAction(PluginAction *action);
 private:
        enum actionKey {
                POWER
        };
 
-       std::map<std::string, actionKey> actionMap;
+       std::map<std::string, PluginAction*(*)()> actionMap;
 };
 
 MODES_NAMESPACE_END
index 56af3b4..cfc80c5 100644 (file)
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 #include <string>
-#include <modes_errors.h>
-#include <wifi-manager.h>
 #include <Plugin.h>
 #include "plugin-log.h"
 #include "WifiFactory.h"
@@ -25,17 +23,17 @@ MODES_NAMESPACE_USE;
 class WifiPlugin : public Plugin {
 public:
        WifiPlugin();
+       ~WifiPlugin() override = default;
 
-       int set(const std::string &key, bool val, PluginAction **piAction) override;
-       void undo(PluginAction *piAction) override;
-       PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+       PluginAction* newAction(const std::string &key) override;
+       void deleteAction(PluginAction *piAction) override;
 private:
        WifiFactory wifiFactory;
 };
 
-extern "C" API Plugin *objectCreate(void)
+extern "C" API PluginobjectCreate(void)
 {
-       return new WifiPlugin;
+       return new WifiPlugin();
 }
 
 extern "C" API void objectDelete(Plugin *plugin)
@@ -48,44 +46,12 @@ WifiPlugin::WifiPlugin()
        setName("wifi");
 }
 
-int WifiPlugin::set(const std::string &key, bool val, PluginAction **piAction)
+PluginAction* WifiPlugin::newAction(const std::string &key)
 {
-       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"));
-
-       int ret = action->set(val);
-       if (piAction)
-               *piAction = action;
-       else
-               wifiFactory.destroyAction(action);
-
-       return ret;
-}
-
-void WifiPlugin::undo(PluginAction *piAction)
-{
-       WifiAction *action = static_cast<WifiAction*>(piAction);
-       RET_IF(nullptr == piAction);
-
-       DBG("Action(%s) undo", action->getName().c_str());
-
-       action->undo();
-       wifiFactory.destroyAction(action);
+       return wifiFactory.createAction(key);
 }
 
-PluginAction* WifiPlugin::getUndoAction(const std::string &key, const std::string &info)
+void WifiPlugin::deleteAction(PluginAction *piAction)
 {
-       WifiAction *action = wifiFactory.createAction(key);
-       RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
-       int ret = action->parse(info);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
-               wifiFactory.destroyAction(action);
-               return nullptr;
-       }
-
-       return action;
+       wifiFactory.destroyAction(piAction);
 }