revise display actions(changedCB)
authorYoungjae Shin <yj99.shin@samsung.com>
Tue, 10 Mar 2020 03:15:58 +0000 (12:15 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Mar 2020 04:30:37 +0000 (13:30 +0900)
display/DisplayAction.h
display/DisplayAllowPalmTouch.cpp [deleted file]
display/DisplayAllowPalmTouch.h [deleted file]
display/DisplayBrightness.cpp
display/DisplayBrightness.h
display/DisplayDenyPalmTouch.cpp [new file with mode: 0644]
display/DisplayDenyPalmTouch.h [new file with mode: 0644]
display/DisplayFactory.cpp
display/DisplayFactory.h
display/tizen_display_rule.xml
unittests/mdsp_test_display.cpp

index 9c187ffcaeba45a1d126cdb4e3ce0c73873afa2d..90fa9527107a241f4c5fd9a41938639ea99d1e87 100644 (file)
@@ -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 (file)
index b472a02..0000000
+++ /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 <sstream>
-#include <string>
-#include <Ecore_Wl2.h>
-#include <efl_util.h>
-#include <Ecore.h>
-#include <modes_errors.h>
-#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 (file)
index 1c2cafe..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 <string>
-#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
index 015d7d521bb85dc2418313ff56b2b631924ad59e..339da6bef923c1ab933ea15465cd526f9d645665 100644 (file)
 #include <list>
 #include <sstream>
 #include <string>
-#include <stdlib.h>
+#include <vconf.h>
 #include <device/display.h>
+#include <device/callback.h>
 #include <modes_errors.h>
 #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);
+}
index 8e6e9d0e3630293a293a4c18b3cb0ec47a85051a..e908506c3aff42143a42e91ec230df2ced1d7794 100644 (file)
  */
 #pragma once
 
-#include <string>
 #include <list>
+#include <string>
 #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<int> oldValList;
+       VconfCbHandler cbHandler;
+       valueChangedCB cb;
+       void *cbData;
 };
 
 MODES_NAMESPACE_END
diff --git a/display/DisplayDenyPalmTouch.cpp b/display/DisplayDenyPalmTouch.cpp
new file mode 100644 (file)
index 0000000..8ff0428
--- /dev/null
@@ -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 <sstream>
+#include <string>
+#include <Ecore_Wl2.h>
+#include <efl_util.h>
+#include <Ecore.h>
+#include <modes_errors.h>
+#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 (file)
index 0000000..046ef14
--- /dev/null
@@ -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 <string>
+#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
index 8497b8afb87782757eec5300fb39c7d1743afaa5..cfbaa46b436f3fd1376ff593b0f6dc55da7936cc 100644 (file)
  * limitations under the License.
  */
 #include "DisplayFactory.h"
+
 #include <string>
 #include <device/power.h>
 #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;
index f0602a9d4e6a5da55fe67aea109f8dcf65eee54f..b265d656208728dd84cfbfca1d00a02259eaa33d 100644 (file)
@@ -33,7 +33,7 @@ private:
                AUTO_BRIGHTNESS_VCONF,
                TIMEOUT_VCONF,
                BRIGHTNESS,
-               ALLOW_PALM_TOUCH,
+               DENY_PALM_TOUCH,
        };
 
        std::map<std::string, enum actionKey> actionMap;
index 542619fe12f965b4bf46e78959d9d27fb34de9ab..80f9d176a1a5b06e1d3d10ee485c68208cfc0bb2 100644 (file)
       <desc>Display Timeout</desc>
       <domain>System</domain>
     </rule>
-    <rule name="display.allowPalmTouch" type="bool" since="6.0" plugin="display">
+    <rule name="display.denyPalmTouch" type="bool" since="6.0" plugin="display">
       <alias name="on">1</alias>
-      <alias name="off">0</alias>
-      <desc>Allow palm touch on display</desc>
+      <desc>Deny palm touch on display. False will be ignored</desc>
       <domain>Graphics System</domain>
     </rule>
   </actionRule>
index fb8610623aea96b7403306c387bddda2f37b4efc..226760e9f9c6ef025609e6cccbaa3513a5794259 100644 (file)
@@ -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)