From: Youngjae Shin Date: Tue, 10 Mar 2020 03:15:58 +0000 (+0900) Subject: revise display actions(changedCB) X-Git-Tag: submit/tizen/20200406.072014~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f9e2f902acbc20e241f8b8ff786ac00749eac67;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git revise display actions(changedCB) --- diff --git a/display/DisplayAction.h b/display/DisplayAction.h index 9c187ff..90fa952 100644 --- a/display/DisplayAction.h +++ b/display/DisplayAction.h @@ -23,7 +23,7 @@ MODES_NAMESPACE_BEGIN class DisplayAction : public PluginAction { public: DisplayAction(const std::string &name); - virtual ~DisplayAction() = default; + ~DisplayAction() = default; virtual int set(int val); virtual int set(bool val); diff --git a/display/DisplayAllowPalmTouch.cpp b/display/DisplayAllowPalmTouch.cpp deleted file mode 100644 index b472a02..0000000 --- a/display/DisplayAllowPalmTouch.cpp +++ /dev/null @@ -1,98 +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 "DisplayAllowPalmTouch.h" -#include -#include -#include -#include -#include -#include -#include "plugin-log.h" - -MODES_NAMESPACE_USE; - -const std::string DisplayAllowPalmTouch::NAME = "allowPalmTouch"; - -DisplayAllowPalmTouch::DisplayAllowPalmTouch() - :DisplayAction(NAME) -{ -} - -DisplayAllowPalmTouch::~DisplayAllowPalmTouch() -{ -} - -int DisplayAllowPalmTouch::set(bool val) -{ - int ret = EFL_UTIL_ERROR_NONE; - int modesRet; - Ecore_Wl2_Display *displayHandle; - efl_util_gesture_h gestureHandle = NULL; - - char *envString = getenv("XDG_RUNTIME_DIR"); - if (NULL == envString) - setenv("XDG_RUNTIME_DIR", "/run", 1); - - ecore_wl2_init(); - displayHandle = ecore_wl2_display_connect(NULL); - if (!displayHandle) { - ret = get_last_result(); - ERR("ecore_wl2_display_connect() Fail(%d)", ret); - return MODES_ERROR_SYSTEM; - } - - gestureHandle = efl_util_gesture_initialize(); - if (NULL == gestureHandle) { - ret = get_last_result(); - ERR("efl_util_gesture_initialize() Fail(%d)", ret); - return MODES_ERROR_SYSTEM; - } - - ret = efl_util_gesture_activate_set(gestureHandle, - EFL_UTIL_GESTURE_TYPE_PALM_COVER, val); - - - if (EFL_UTIL_ERROR_NONE == ret) { - modesRet = MODES_ERROR_NONE; - } else { - ERR("efl_util_gesture_activate_set() Fail(%d)", ret); - modesRet = MODES_ERROR_SYSTEM; - } - - ecore_wl2_display_disconnect(displayHandle); - ecore_wl2_shutdown(); - return modesRet; -} - -void DisplayAllowPalmTouch::undo() -{ - set(true); -} - -std::string DisplayAllowPalmTouch::serialize() -{ - std::ostringstream ostr; - - ostr << 1; - return ostr.str(); -} - -int DisplayAllowPalmTouch::parse(const std::string &archive) -{ - DBG("parse() Called()"); - - return MODES_ERROR_NONE; -} diff --git a/display/DisplayAllowPalmTouch.h b/display/DisplayAllowPalmTouch.h deleted file mode 100644 index 1c2cafe..0000000 --- a/display/DisplayAllowPalmTouch.h +++ /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 -#include "plugin-def.h" -#include "DisplayAction.h" - -MODES_NAMESPACE_BEGIN - -class DisplayAllowPalmTouch : public DisplayAction { -public: - DisplayAllowPalmTouch(); - ~DisplayAllowPalmTouch(); - - int set(bool val) override; - void undo() override; - std::string serialize() override; - int parse(const std::string &archive) override; - - static const std::string NAME; -}; - -MODES_NAMESPACE_END diff --git a/display/DisplayBrightness.cpp b/display/DisplayBrightness.cpp index 015d7d5..339da6b 100644 --- a/display/DisplayBrightness.cpp +++ b/display/DisplayBrightness.cpp @@ -17,30 +17,36 @@ #include #include #include -#include +#include #include +#include #include #include "plugin-log.h" MODES_NAMESPACE_USE; const std::string DisplayBrightness::NAME = "brightness"; +const char* const DisplayBrightness::KEY = VCONFKEY_SETAPPL_LCD_BRIGHTNESS; DisplayBrightness::DisplayBrightness() - :DisplayAction(NAME) + :DisplayAction(NAME), requestVal(0), cb(nullptr), cbData(nullptr) { device_display_get_numbers(&numDisplay); } -DisplayBrightness::~DisplayBrightness() -{ -} - int DisplayBrightness::set(int val) { + requestVal = val; + + int ret = cbHandler.handleSubscription(KEY); + if (MODES_ERROR_NONE != ret) { + ERR("handleChange(%s) Fail(%d)", KEY, ret); + return ret; + } + for (int i = 0; i < numDisplay ; i++) { int oldVal = 0; - int ret = device_display_get_brightness(i, &oldVal); + ret = device_display_get_brightness(i, &oldVal); if (DEVICE_ERROR_NONE != ret) { ERR("device_display_get_brightness(%d) Fail(%s)", i, get_error_message(ret)); return MODES_ERROR_SYSTEM; @@ -49,9 +55,17 @@ int DisplayBrightness::set(int val) } for (int i = 0; i < numDisplay ; i++) { - int ret = device_display_set_brightness(i, val); + int realVal = val; + if (realVal < 0) { + int realVal = 100; + ret = device_display_get_max_brightness(i, &realVal); + if (DEVICE_ERROR_NONE != ret) + ERR("device_display_get_max_brightness() Fail(%d)", ret); + } + + ret = device_display_set_brightness(i, realVal); if (DEVICE_ERROR_NONE != ret) { - ERR("device_display_set_brightness(%d, %d) Fail(%s)", i, val, get_error_message(ret)); + ERR("device_display_set_brightness(%d, %d) Fail(%s)", i, realVal, get_error_message(ret)); return MODES_ERROR_SYSTEM; } } @@ -94,3 +108,55 @@ int DisplayBrightness::parse(const std::string &data) return MODES_ERROR_NONE; } + +int DisplayBrightness::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, ret); + return ret; + } + + cb = callback; + cbData = userData; + + return MODES_ERROR_NONE; +} +void DisplayBrightness::unSetChangedCallback(valueChangedCB callback, void *userData) +{ + RET_IF(nullptr == callback); + + cbHandler.unSetChangedCB(KEY); + + cbData = nullptr; + cb = nullptr; +} + +void DisplayBrightness::vconfChangedCB() +{ + //The value will be changed by Modes. That's why the callback is always called. + if (cb) + cb(cbData); +} + +void DisplayBrightness::vconfChangedCB(keynode_t *node) +{ + const char *vconfKey = vconf_keynode_get_name(node); + if (vconfKey != KEY) { + WARN("Unknown vconf(%s) notification", vconfKey); + return; + } + + int realVal = requestVal; + if (realVal < 0) { + int ret = device_display_get_max_brightness(0, &realVal); + if (DEVICE_ERROR_NONE != ret) + ERR("device_display_get_max_brightness() Fail(%d)", ret); + } + + int val = vconf_keynode_get_int(node); + if (cb && (val != realVal)) + cb(cbData); +} diff --git a/display/DisplayBrightness.h b/display/DisplayBrightness.h index 8e6e9d0..e908506 100644 --- a/display/DisplayBrightness.h +++ b/display/DisplayBrightness.h @@ -15,29 +15,39 @@ */ #pragma once -#include #include +#include #include "plugin-def.h" #include "DisplayAction.h" +#include "VconfCbHandler.h" MODES_NAMESPACE_BEGIN -class DisplayBrightness : public DisplayAction { +class DisplayBrightness : public DisplayAction, public VconfChangeAction { public: DisplayBrightness(); - ~DisplayBrightness(); + ~DisplayBrightness() = default; int set(int val) override; void undo() override; std::string serialize() override; int parse(const std::string &archive) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback, void *userData) override; - static const std::string NAME; + void vconfChangedCB() override; + void vconfChangedCB(keynode_t *node) override; + static const std::string NAME; + static const char* const KEY; private: const char delimiter = '#'; int numDisplay; + int requestVal; std::list oldValList; + VconfCbHandler cbHandler; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/display/DisplayDenyPalmTouch.cpp b/display/DisplayDenyPalmTouch.cpp new file mode 100644 index 0000000..8ff0428 --- /dev/null +++ b/display/DisplayDenyPalmTouch.cpp @@ -0,0 +1,92 @@ +/* + * 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 "DisplayDenyPalmTouch.h" + +#include +#include +#include +#include +#include +#include +#include "plugin-log.h" + +MODES_NAMESPACE_USE; + +const std::string DisplayDenyPalmTouch::NAME = "denyPalmTouch"; + +DisplayDenyPalmTouch::DisplayDenyPalmTouch() + :DisplayAction(NAME) +{ +} + +int DisplayDenyPalmTouch::set(bool val) +{ + char *envString = getenv("XDG_RUNTIME_DIR"); + if (nullptr == envString) + setenv("XDG_RUNTIME_DIR", "/run", 1); + + ecore_wl2_init(); + Ecore_Wl2_Display *displayHandle = ecore_wl2_display_connect(NULL); + if (nullptr == displayHandle) { + ERR("ecore_wl2_display_connect() Fail(%d)", get_last_result()); + return MODES_ERROR_SYSTEM; + } + + efl_util_gesture_h gestureHandle = efl_util_gesture_initialize(); + if (nullptr == gestureHandle) { + ERR("efl_util_gesture_initialize() Fail(%d)", get_last_result()); + return MODES_ERROR_SYSTEM; + } + + int ret = efl_util_gesture_activate_set(gestureHandle, EFL_UTIL_GESTURE_TYPE_PALM_COVER, !val); + ecore_wl2_display_disconnect(displayHandle); + ecore_wl2_shutdown(); + + if (EFL_UTIL_ERROR_NONE != ret) { + ERR("efl_util_gesture_activate_set() Fail(%d)", ret); + return MODES_ERROR_SYSTEM; + } + + return MODES_ERROR_NONE; +} + +void DisplayDenyPalmTouch::undo() +{ + set(false); +} + +std::string DisplayDenyPalmTouch::serialize() +{ + //Not Support + return std::string(); +} + +int DisplayDenyPalmTouch::parse(const std::string &archive) +{ + WARN("Palm Touch setting is volatile"); + return MODES_ERROR_NOT_SUPPORTED; +} + +int DisplayDenyPalmTouch::setChangedCallback(valueChangedCB callback, void *userData) +{ + ERR("Not Support Changed Callback"); + return MODES_ERROR_NOT_SUPPORTED; +} + +void DisplayDenyPalmTouch::unSetChangedCallback(valueChangedCB callback, void *userData) +{ + ERR("Not Support Changed Callback"); +} diff --git a/display/DisplayDenyPalmTouch.h b/display/DisplayDenyPalmTouch.h new file mode 100644 index 0000000..046ef14 --- /dev/null +++ b/display/DisplayDenyPalmTouch.h @@ -0,0 +1,41 @@ +/* + * 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 +#include "plugin-def.h" +#include "DisplayAction.h" + +MODES_NAMESPACE_BEGIN + +class DisplayDenyPalmTouch : public DisplayAction { +public: + DisplayDenyPalmTouch(); + ~DisplayDenyPalmTouch() = default; + + int set(bool val) override; + void undo() override; + std::string serialize() override; + int parse(const std::string &archive) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback, void *userData) override; + + static const std::string NAME; +private: + bool oldVal; +}; + +MODES_NAMESPACE_END diff --git a/display/DisplayFactory.cpp b/display/DisplayFactory.cpp index 8497b8a..cfbaa46 100644 --- a/display/DisplayFactory.cpp +++ b/display/DisplayFactory.cpp @@ -14,12 +14,13 @@ * limitations under the License. */ #include "DisplayFactory.h" + #include #include #include "plugin-log.h" #include "DisplayActVconf.h" #include "DisplayBrightness.h" -#include "DisplayAllowPalmTouch.h" +#include "DisplayDenyPalmTouch.h" MODES_NAMESPACE_USE; @@ -28,13 +29,13 @@ DisplayFactory::DisplayFactory() actionMap[DisplayActVconf::NAME[AUTO_BRIGHTNESS_VCONF]] = AUTO_BRIGHTNESS_VCONF; actionMap[DisplayActVconf::NAME[TIMEOUT_VCONF]] = TIMEOUT_VCONF; actionMap[DisplayBrightness::NAME] = BRIGHTNESS; - actionMap[DisplayAllowPalmTouch::NAME] = ALLOW_PALM_TOUCH; + actionMap[DisplayDenyPalmTouch::NAME] = DENY_PALM_TOUCH; } DisplayAction* DisplayFactory::createAction(const std::string &key) { auto search = actionMap.find(key); - if (search == actionMap.end()) { + if (actionMap.end() == search) { ERR("No DisplayAction(%s)", key.c_str()); return nullptr; } @@ -50,8 +51,8 @@ DisplayAction* DisplayFactory::createAction(const std::string &key) case BRIGHTNESS: action = new DisplayBrightness(); break; - case ALLOW_PALM_TOUCH: - action = new DisplayAllowPalmTouch(); + case DENY_PALM_TOUCH: + action = new DisplayDenyPalmTouch(); break; default: action = nullptr; diff --git a/display/DisplayFactory.h b/display/DisplayFactory.h index f0602a9..b265d65 100644 --- a/display/DisplayFactory.h +++ b/display/DisplayFactory.h @@ -33,7 +33,7 @@ private: AUTO_BRIGHTNESS_VCONF, TIMEOUT_VCONF, BRIGHTNESS, - ALLOW_PALM_TOUCH, + DENY_PALM_TOUCH, }; std::map actionMap; diff --git a/display/tizen_display_rule.xml b/display/tizen_display_rule.xml index 542619f..80f9d17 100644 --- a/display/tizen_display_rule.xml +++ b/display/tizen_display_rule.xml @@ -17,10 +17,9 @@ Display Timeout System - + 1 - 0 - Allow palm touch on display + Deny palm touch on display. False will be ignored Graphics System diff --git a/unittests/mdsp_test_display.cpp b/unittests/mdsp_test_display.cpp index fb86106..226760e 100644 --- a/unittests/mdsp_test_display.cpp +++ b/unittests/mdsp_test_display.cpp @@ -37,7 +37,7 @@ protected: g_main_loop_unref(loop); loop = NULL; objectDelete(plugin); - plugin = NULL; + plugin = nullptr; } static gboolean displayPluginBrightnessIdler(gpointer data) @@ -100,7 +100,7 @@ protected: }; int displayPluginTest::result = 0; -Plugin *displayPluginTest::plugin = NULL; +Plugin *displayPluginTest::plugin = nullptr; GMainLoop *displayPluginTest::loop = NULL; TEST_F(displayPluginTest, setBrightness)