display: Relocate __device_flags_to_string() from plugins to core 71/294871/4
authorYunhee Seo <yuni.seo@samsung.com>
Wed, 28 Jun 2023 04:09:03 +0000 (13:09 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 29 Jun 2023 04:56:37 +0000 (13:56 +0900)
__device_flags_to_string() is used for getting string name according to device_flags.
These functions have same logic, thus it is relocated to display-util.

This function is added to display-util.
- int display_util_get_device_flags_name(enum device_flags flags, const char **flag_name);
    -> It replaces __device_flags_to_string().

Change-Id: Ia84ae6d7ff71419e22b700c12a7bca4e76413293
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
plugins/iot-headed/display/core.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/display/display-plugin.c
src/display/display-plugin.h
src/display/display-signal.c
src/display/display-util.c [new file with mode: 0644]
src/display/display-util.h [new file with mode: 0644]

index 4ae48ae..226f141 100644 (file)
@@ -146,22 +146,6 @@ inline struct state* state_st(enum state_t state)
        return &states[state];
 }
 
-static const char* __device_flags_to_string(enum device_flags flags)
-{
-       if (flags & LCD_ON_BY_GESTURE)
-               return GESTURE_STR;
-       else if (flags & (LCD_ON_BY_POWER_KEY | LCD_OFF_BY_POWER_KEY))
-               return POWER_KEY_STR;
-       else if (flags & (LCD_ON_BY_EVENT | LCD_OFF_BY_EVENT))
-               return EVENT_STR;
-       else if (flags & LCD_ON_BY_TOUCH)
-               return TOUCH_STR;
-       else if (flags & LCD_OFF_BY_TIMEOUT)
-               return TIMEOUT_STR;
-       else
-               return UNKNOWN_STR;
-}
-
 static void init_lcd_operation(void)
 {
        const struct device_ops *ops = NULL;
@@ -268,7 +252,6 @@ static int display_probe(void *data)
 
        /* display_plugin instance initialization */
        init_pm_internal(data);
-       disp_plgn->device_flags_to_string = __device_flags_to_string;
 
        return 0;
 }
index e63af04..d6553b6 100644 (file)
@@ -148,27 +148,6 @@ inline struct state* state_st(enum state_t state)
        return &states[state];
 }
 
-static const char* __device_flags_to_string(enum device_flags flags)
-{
-
-       if (flags & (LCD_ON_BY_GESTURE | LCD_OFF_BY_GESTURE))
-               return GESTURE_STR;
-       else if (flags & (LCD_ON_BY_POWER_KEY | LCD_OFF_BY_POWER_KEY))
-               return POWER_KEY_STR;
-       else if (flags & (LCD_ON_BY_EVENT | LCD_OFF_BY_EVENT))
-               return EVENT_STR;
-       else if (flags & LCD_ON_BY_TOUCH)
-               return TOUCH_STR;
-       else if (flags & LCD_OFF_BY_TIMEOUT)
-               return TIMEOUT_STR;
-       else if (flags & LCD_OFF_BY_PROXIMITY)
-               return PROXI_STR;
-       else if (flags & LCD_OFF_BY_PALM)
-               return PALM_STR;
-       else
-               return UNKNOWN_STR;
-}
-
 static int default_proc_change_state(unsigned int cond, pid_t pid)
 {
        enum state_t next;
@@ -322,7 +301,6 @@ static int display_probe(void *data)
 
        /* display_plugin instance initialization */
        init_pm_internal(data);
-       disp_plgn->device_flags_to_string = __device_flags_to_string;
 
        return 0;
 }
index 5f72896..7f73e9b 100644 (file)
@@ -146,22 +146,6 @@ inline struct state* state_st(enum state_t state)
        return &states[state];
 }
 
-static const char* __device_flags_to_string(enum device_flags flags)
-{
-       if (flags & LCD_ON_BY_GESTURE)
-               return GESTURE_STR;
-       else if (flags & (LCD_ON_BY_POWER_KEY | LCD_OFF_BY_POWER_KEY))
-               return POWER_KEY_STR;
-       else if (flags & (LCD_ON_BY_EVENT | LCD_OFF_BY_EVENT))
-               return EVENT_STR;
-       else if (flags & LCD_ON_BY_TOUCH)
-               return TOUCH_STR;
-       else if (flags & LCD_OFF_BY_TIMEOUT)
-               return TIMEOUT_STR;
-       else
-               return UNKNOWN_STR;
-}
-
 static void init_lcd_operation(void)
 {
        const struct device_ops *ops = NULL;
@@ -265,7 +249,6 @@ static int display_probe(void *data)
 
        /* display_plugin instance initialization */
        init_pm_internal(data);
-       disp_plgn->device_flags_to_string = __device_flags_to_string;
 
        return 0;
 }
index 16e8c4e..81a1f01 100644 (file)
@@ -180,32 +180,6 @@ static int display_auto_brightness_sensing(void *data)
        return 0;
 }
 
-static const char* __device_flags_to_string(enum device_flags flags)
-{
-       if (flags & (LCD_ON_BY_GESTURE | LCD_OFF_BY_GESTURE))
-               return GESTURE_STR;
-       else if (flags & (LCD_ON_BY_POWER_KEY | LCD_OFF_BY_POWER_KEY))
-               return POWER_KEY_STR;
-       else if (flags & (LCD_ON_BY_EVENT | LCD_OFF_BY_EVENT))
-               return EVENT_STR;
-       else if (flags & LCD_ON_BY_BACK_KEY)
-               return BACK_KEY_STR;
-       else if (flags & LCD_ON_BY_TOUCH)
-               return TOUCH_STR;
-       else if (flags & LCD_ON_BY_BEZEL)
-               return BEZEL_STR;
-       else if (flags & LCD_OFF_BY_TIMEOUT)
-               return TIMEOUT_STR;
-       else if (flags & LCD_OFF_BY_PROXIMITY)
-               return PROXI_STR;
-       else if (flags & LCD_OFF_BY_PALM)
-               return PALM_STR;
-       else if (flags & LCD_OFF_BY_DISPLAY_DETACH)
-               return DISPLAY_DETACH_STR;
-       else
-               return UNKNOWN_STR;
-}
-
 static int get_device_flags(unsigned long *device_flags)
 {
        if (!device_flags)
@@ -1032,7 +1006,6 @@ static int display_probe(void *data)
 
        /* display_plugin instance initialization */
        init_pm_internal(data);
-       disp_plgn->device_flags_to_string = __device_flags_to_string;
 
        return 0;
 }
index 06426d9..1e8171a 100644 (file)
@@ -91,14 +91,6 @@ int display_plugin_set_system_wakeup_flag(bool flag)
        return 0;
 }
 
-const char* display_plugin_device_flags_to_string(enum device_flags flags)
-{
-       if (g_display_plugin.device_flags_to_string)
-               return g_display_plugin.device_flags_to_string(flags);
-
-       return NULL;
-}
-
 int display_plugin_auto_brightness_control(enum brightness_request_e request, int set_brightness)
 {
        if (g_display_plugin.auto_brightness_control)
index 728e01f..3b38dd4 100644 (file)
@@ -62,7 +62,6 @@ struct display_plugin {
        int (*update_pm_setting) (int key_idx, int val);
        int (*get_lock_screen_state) (void);
        bool system_wakeup_flag;
-       const char* (*device_flags_to_string) (enum device_flags flags);
        int (*auto_brightness_control) (enum brightness_request_e request, int set_brightness);
        /* FIXME: function names will be redefined */
        void (*set_dim_state) (bool on);
@@ -92,7 +91,6 @@ bool display_plugin_is_there_update_pm_setting(void);
 int display_plugin_get_lock_screen_state(void);
 int display_plugin_get_system_wakeup_flag(bool *flag);
 int display_plugin_set_system_wakeup_flag(bool flag);
-const char* display_plugin_device_flags_to_string(enum device_flags flags);
 int display_plugin_auto_brightness_control(enum brightness_request_e request, int set_brightness);
 int display_plugin_set_dim_state(bool on);
 int display_plugin_get_device_flags(unsigned long *device_flags);
index 6d22330..65b33bd 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "display-signal.h"
+#include "display-util.h"
 #include "poll.h"
 #include "shared/plugin.h"
 #include "shared/time.h"
@@ -51,12 +52,7 @@ void broadcast_lcd_on(enum signal_type type, enum device_flags flags)
        if (type == SIGNAL_PRE && displayoff_time != 0)
                diff = clock_gettime_to_long() - displayoff_time;
 
-       if (!disp_plgn->device_flags_to_string) {
-               _E("Cannot convert device_flags to string.");
-               return;
-       }
-
-       str = disp_plgn->device_flags_to_string(flags);
+       display_util_get_device_flags_name(flags, &str);
 
        signal = lcdon_sig_lookup[type];
        _I("lcdstep : Broadcast signal(%s:%s).", signal, str);
@@ -85,12 +81,7 @@ void broadcast_lcd_off(enum signal_type type, enum device_flags flags)
 
        signal = lcdoff_sig_lookup[type];
 
-       if (!disp_plgn->device_flags_to_string) {
-               _E("Cannot convert device_flags to string.");
-               return;
-       }
-
-       str = disp_plgn->device_flags_to_string(flags);
+       display_util_get_device_flags_name(flags, &str);
 
        _I("lcdstep : Broadcast signal(%s).", signal);
        ret = gdbus_signal_emit_sync(NULL,
diff --git a/src/display/display-util.c b/src/display/display-util.c
new file mode 100644 (file)
index 0000000..2cd8c5e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * 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 "display-util.h"
+
+int display_util_get_device_flags_name(enum device_flags flags, const char **flag_name)
+{
+       if (!flag_name)
+               return -EINVAL;
+
+       if (flags & (LCD_ON_BY_GESTURE | LCD_OFF_BY_GESTURE))
+               *flag_name = GESTURE_STR;
+       else if (flags & (LCD_ON_BY_POWER_KEY | LCD_OFF_BY_POWER_KEY))
+               *flag_name = POWER_KEY_STR;
+       else if (flags & (LCD_ON_BY_EVENT | LCD_OFF_BY_EVENT))
+               *flag_name = EVENT_STR;
+       else if (flags & LCD_ON_BY_BACK_KEY)
+               *flag_name = BACK_KEY_STR;
+       else if (flags & LCD_ON_BY_TOUCH)
+               *flag_name = TOUCH_STR;
+       else if (flags & LCD_ON_BY_BEZEL)
+               *flag_name = BEZEL_STR;
+       else if (flags & LCD_OFF_BY_TIMEOUT)
+               *flag_name = TIMEOUT_STR;
+       else if (flags & LCD_OFF_BY_PROXIMITY)
+               *flag_name = PROXI_STR;
+       else if (flags & LCD_OFF_BY_PALM)
+               *flag_name = PALM_STR;
+       else if (flags & LCD_OFF_BY_DISPLAY_DETACH)
+               *flag_name = DISPLAY_DETACH_STR;
+       else
+               *flag_name = UNKNOWN_STR;
+
+       return 0;
+}
\ No newline at end of file
diff --git a/src/display/display-util.h b/src/display/display-util.h
new file mode 100644 (file)
index 0000000..f201487
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+#ifndef __DISPLAY_UTIL_H__
+#define __DISPLAY_UTIL_H__
+
+#include "shared/devices.h"
+
+int display_util_get_device_flags_name(enum device_flags flags, const char **flag_name);
+
+#endif /* __DISPLAY_UTIL_H__ */
\ No newline at end of file