power: add conf file to adjust power lock auto release timeout 00/98600/1 accepted/tizen/3.0/common/20161123.140537 accepted/tizen/3.0/ivi/20161123.082818 accepted/tizen/3.0/mobile/20161123.082728 accepted/tizen/3.0/tv/20161123.082742 accepted/tizen/3.0/wearable/20161123.082755 submit/tizen_3.0/20161121.105249
authortaeyoung <ty317.kim@samsung.com>
Thu, 29 Sep 2016 04:17:40 +0000 (13:17 +0900)
committertaeyoung <ty317.kim@samsung.com>
Fri, 18 Nov 2016 01:53:51 +0000 (10:53 +0900)
- Power Lock Auto Release timeout can be changed
  while developing plarform by modifying the conf file.

Change-Id: I82d42980a1076a400cecd0b3894fadb92ef0e64f
Signed-off-by: taeyoung <ty317.kim@samsung.com>
CMakeLists.txt
packaging/capi-system-device.spec
src/common.c [new file with mode: 0644]
src/common.h
src/power.c
src/power.conf [new file with mode: 0644]

index a6a39f9..feb4090 100755 (executable)
@@ -76,6 +76,8 @@ CONFIGURE_FILE(
 )
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/power.conf DESTINATION /etc/deviced/device)
+
 IF(UNIX)
 
 ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
index cc57d41..28302d0 100644 (file)
@@ -57,6 +57,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %manifest %{name}.manifest
 %license LICENSE.APLv2
 %{_libdir}/libcapi-system-device.so.*
+/etc/deviced/device/*.conf
 
 %files devel
 %manifest %{name}.manifest
diff --git a/src/common.c b/src/common.c
new file mode 100644 (file)
index 0000000..4936577
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2016 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 <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include "common.h"
+
+#define MAX_LINE       128
+#define MAX_SECTION    64
+#define WHITESPACE     " \t"
+#define NEWLINE                "\n\r"
+#define COMMENT                '#'
+
+static inline char *trim_str(char *s)
+{
+       char *t;
+       /* left trim */
+       s += strspn(s, WHITESPACE);
+
+       /* right trim */
+       for (t = strchr(s, 0); t > s; t--)
+               if (!strchr(WHITESPACE, t[-1]))
+                       break;
+       *t = 0;
+       return s;
+}
+
+int config_parse(const char *file_name, int cb(struct parse_result *result,
+                       void *user_data), void *user_data)
+{
+       FILE *f = NULL;
+       struct parse_result result;
+       /* use stack for parsing */
+       char line[MAX_LINE];
+       char section[MAX_SECTION];
+       char *start, *end, *name, *value;
+       int lineno = 0, ret = 0;
+
+       if (!file_name || !cb) {
+               ret = -EINVAL;
+               goto error;
+       }
+
+       /* open conf file */
+       f = fopen(file_name, "r");
+       if (!f) {
+               if (errno == ENOENT) {
+                       _I("There is no power config file");
+                       return 0;
+               }
+
+               _E("Failed to open file %s", file_name);
+               ret = -EIO;
+               goto error;
+       }
+
+       /* parsing line by line */
+       while (fgets(line, MAX_LINE, f) != NULL) {
+               lineno++;
+
+               start = line;
+               start[strcspn(start, NEWLINE)] = '\0';
+               start = trim_str(start);
+
+               if (*start == COMMENT) {
+                       continue;
+               } else if (*start == '[') {
+                       /* parse section */
+                       end = strchr(start, ']');
+                       if (!end || *end != ']') {
+                               ret = -EBADMSG;
+                               goto error;
+                       }
+
+                       *end = '\0';
+                       strncpy(section, start + 1, sizeof(section));
+                       section[MAX_SECTION-1] = '\0';
+               } else if (*start) {
+                       /* parse name & value */
+                       end = strchr(start, '=');
+                       if (!end || *end != '=') {
+                               ret = -EBADMSG;
+                               goto error;
+                       }
+                       *end = '\0';
+                       name = trim_str(start);
+                       value = trim_str(end + 1);
+                       end = strchr(value, COMMENT);
+                       if (end && *end == COMMENT) {
+                               *end = '\0';
+                               value = trim_str(value);
+                       }
+
+                       result.section = section;
+                       result.name = name;
+                       result.value = value;
+                       /* callback with parse result */
+                       ret = cb(&result, user_data);
+                       if (ret < 0) {
+                               ret = -EBADMSG;
+                               goto error;
+                       }
+               }
+       }
+       _D("Success to load %s", file_name);
+       fclose(f);
+       return 0;
+
+error:
+       if (f)
+               fclose(f);
+       _E("Failed to read %s:%d!", file_name, lineno);
+       return ret;
+}
index 3bf15f9..1f8a96c 100644 (file)
@@ -56,4 +56,14 @@ static inline int errno_to_device_error(int err)
        }
 }
 
+struct parse_result {
+       char *section;
+       char *name;
+       char *value;
+};
+
+int config_parse(const char *file_name,
+               int cb(struct parse_result *result, void *data),
+               void *user_data);
+
 #endif /* __COMMON_H__ */
index d2c7400..2f6f713 100644 (file)
 #define STR_LCD_DIM   "lcddim"
 #define STR_LCD_ON    "lcdon"
 
-#define LOCK_CPU_TIMEOUT_MAX       (60*60*1000) /* milliseconds */
+#define LOCK_CPU_TIMEOUT_MAX       (24*60*60*1000) /* milliseconds */
 #define LOCK_CPU_PADDING_TIMEOUT   (20*1000) /* milliseconds */
 
+#define POWER_CONF "/etc/deviced/device/power.conf"
+
 #ifdef TIZEN_FEATURE_TRACKER
 static guint off_lock_timeout;
 static guint padding_timeout;
 static int prev_count;
 #endif
 
+static struct _lock_timeout {
+       unsigned int release;
+       unsigned int padding;
+} lock_timeout = {
+       .release = LOCK_CPU_TIMEOUT_MAX,
+       .padding = LOCK_CPU_PADDING_TIMEOUT,
+};
+
 static char *get_state_str(display_state_e state)
 {
        switch (state) {
@@ -157,7 +167,7 @@ static void add_padding_timeout(void)
 
        _I("Padding timeout handler added");
 
-       id = g_timeout_add(LOCK_CPU_PADDING_TIMEOUT,
+       id = g_timeout_add(lock_timeout.padding,
                        padding_timeout_expired, NULL);
        if (id)
                padding_timeout = id;
@@ -201,7 +211,7 @@ static void add_off_lock_timeout(void)
 
        _I("Power lock timeout handler added");
 
-       id = g_timeout_add(LOCK_CPU_TIMEOUT_MAX,
+       id = g_timeout_add(lock_timeout.release,
                        off_lock_timeout_expired, NULL);
        if (id)
                off_lock_timeout = id;
@@ -322,7 +332,7 @@ int device_power_request_lock(power_lock_e type, int timeout_ms)
        if (type == POWER_LOCK_CPU) {
                ret = lock_state(DISPLAY_STATE_SCREEN_OFF, STAY_CUR_STATE, timeout_ms);
                if (ret == 0 &&
-                       (timeout_ms == 0 || timeout_ms > LOCK_CPU_TIMEOUT_MAX))
+                       (timeout_ms == 0 || timeout_ms > lock_timeout.release))
                        add_off_lock_timeout();
        } else if (type == POWER_LOCK_DISPLAY) {
                _W("DEPRECATION WARNING: This power lock enum is deprecated and will be removed from next release. Use efl_util_set_window_screen_mode() instead.");
@@ -384,3 +394,37 @@ int device_power_reboot(const char *reason)
        return errno_to_device_error(ret);
 }
 //LCOV_EXCL_STOP
+
+static int power_load_config(struct parse_result *result, void *data)
+{
+       unsigned int value;
+
+       if (!result)
+               return 0;
+
+       if (strncmp(result->section, "Power", 6))
+               return 0;
+
+       value = strtoul(result->value, NULL, 10);
+       if (value == 0)
+               return 0;
+
+       if (!strncmp(result->name, "LockTimeout", 12)) {
+               _I("Power Lock Auto Release Timeout: %ld msec", value);
+               lock_timeout.release = value;
+       } else if (!strncmp(result->name, "LockPaddingTimeout", 12)) {
+               _I("Power Lock Auto Release Padding Timeout: %ld msec", value);
+               lock_timeout.padding = value;
+       }
+
+       return 0;
+}
+
+static void __CONSTRUCTOR__ power_init(void)
+{
+       int ret;
+
+       ret = config_parse(POWER_CONF, power_load_config, NULL);
+       if (ret < 0)
+               _E("Failed to load config file (%d)", ret);
+}
diff --git a/src/power.conf b/src/power.conf
new file mode 100644 (file)
index 0000000..19e5cdd
--- /dev/null
@@ -0,0 +1,5 @@
+[Power]
+# milliseconds
+LockTimeout=86400000
+# milliseconds
+LockPaddingTimeout=20000