#include "tdm_log.h"
#include "tdm_macro.h"
-//#define TDM_CONFIG_ASSERT
-
#define LOG_MAX_LEN 4076
#define COLOR_RED "\x1b[31m" /* for error */
static unsigned int dlog_enable = 1;
static unsigned int color_enable = 1;
-static unsigned int need_check_env = 1;
+static unsigned int assert_level = TDM_LOG_LEVEL_NONE;
static unsigned int log_lock_init;
static pthread_mutex_t log_lock;
unsigned int tdm_log_debug_level = TDM_LOG_LEVEL_INFO;
-static void
-_tdm_log_check_env(void)
-{
- const char *str;
- char *end;
-
- str = getenv("TDM_DEBUG_LEVEL");
- if (str)
- tdm_log_debug_level = strtol(str, &end, 10);
-
- str = getenv("TDM_DEBUG");
- if (str && (strstr(str, "1")))
- tdm_log_debug_level = TDM_LOG_LEVEL_DBG;
-
- str = getenv("TDM_DLOG");
- if (str && (strstr(str, "0")))
- dlog_enable = 0;
-}
-
EXTERN void
tdm_log_enable_color(unsigned int enable)
{
}
EXTERN void
+tdm_log_set_assert_level(int level)
+{
+ assert_level = level;
+}
+
+EXTERN void
+tdm_log_set_path(const char *path)
+{
+ char fd_name[TDM_PATH_LEN];
+ int log_fd = -1;
+ FILE *log_fl;
+
+ snprintf(fd_name, TDM_PATH_LEN, "%s", path);
+
+ log_fl = fopen(fd_name, "a");
+ if (!log_fl) {
+ TDM_ERR("failed: open file(%s)\n", fd_name);
+ return;
+ }
+
+ fflush(stdout);
+ close(STDOUT_FILENO);
+
+ setvbuf(log_fl, NULL, _IOLBF, 512);
+ log_fd = fileno(log_fl);
+
+ dup2(log_fd, STDOUT_FILENO);
+ fclose(log_fl);
+}
+
+EXTERN void
tdm_log_print(int level, const char *fmt, ...)
{
va_list arg;
}
- if (need_check_env) {
- need_check_env = 0;
- _tdm_log_check_env();
- }
-
if (level > tdm_log_debug_level)
return;
}
#ifdef TDM_CONFIG_ASSERT
- if (level < 3)
+ if (level <= assert_level)
assert(0);
#endif
}
void tdm_log_enable_dlog(unsigned int enable);
void tdm_log_enable_debug(unsigned int enable);
void tdm_log_set_debug_level(int level);
+void tdm_log_set_assert_level(int level);
+void tdm_log_set_path(const char *path);
void tdm_log_print(int level, const char *fmt, ...);
extern unsigned int tdm_log_debug_level;
static tdm_error
_tdm_display_load_module(tdm_private_display *private_display)
{
- const char *module_name;
- struct dirent **namelist;
- int n, len;
+ const char *module_names;
tdm_error ret = 0;
+ char temp[TDM_PATH_LEN];
+ char *arg;
+ char *end;
- module_name = getenv("TDM_MODULE");
- if (!module_name)
- module_name = TDM_DEFAULT_MODULE;
+ module_names = tdm_config_get_string(TDM_CONFIG_KEY_GENERAL_BACKENDS, TDM_DEFAULT_MODULE);
- len = strlen(module_name);
- if (len > TDM_NAME_LEN - 1) {
- TDM_ERR("TDM_MODULE is too long\n");
- return TDM_ERROR_OPERATION_FAILED;
- }
+ snprintf(temp, TDM_PATH_LEN, "%s", module_names);
- /* load bufmgr priv from default lib */
- ret = _tdm_display_load_module_with_file(private_display, module_name);
- if (ret == TDM_ERROR_NONE)
- return TDM_ERROR_NONE;
+ arg = strtok_r(temp, TDM_CONFIG_DELIM, &end);
+ while (arg) {
+ ret = _tdm_display_load_module_with_file(private_display, arg);
+ if (ret == TDM_ERROR_NONE)
+ return TDM_ERROR_NONE;
+
+ arg = strtok_r(NULL, TDM_CONFIG_DELIM, &end);
+ }
/* load bufmgr priv from dummy lib */
ret = _tdm_display_load_module_with_file(private_display, TDM_DUMMY_MODULE);
if (ret == TDM_ERROR_NONE)
return TDM_ERROR_NONE;
- /* load bufmgr priv from configured path */
- n = scandir(TDM_MODULE_PATH, &namelist, 0, alphasort);
- if (n < 0) {
- TDM_ERR("no module in '%s'\n", TDM_MODULE_PATH);
- return TDM_ERROR_BAD_MODULE;
- }
-
- ret = TDM_ERROR_BAD_MODULE;
- while (n--) {
- if (ret < 0 && strstr(namelist[n]->d_name, SUFFIX_MODULE))
- ret = _tdm_display_load_module_with_file(private_display, namelist[n]->d_name);
-
- free(namelist[n]);
- }
- free(namelist);
-
return ret;
}
const char *str;
tdm_error ret;
double stamp1, stamp2, start;
+ int mode;
pthread_mutex_lock(&gLock);
start = stamp1 = tdm_helper_get_time();
+ /* tdm_config_init should be called first of all tdm apis for tdm_log */
ret = tdm_config_init();
if (ret != TDM_ERROR_NONE)
goto failed_config;
stamp2 = tdm_helper_get_time();
- TDM_DBG("config init time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ TDM_INFO("config init time: %.3f ms", (stamp2 - stamp1) * 1000.0);
stamp1 = stamp2;
private_display = calloc(1, sizeof(tdm_private_display));
/* LCOV_EXCL_STOP */
}
- str = getenv("TDM_DEBUG_MODULE");
+ str = tdm_config_get_string(TDM_CONFIG_KEY_DEBUG_MODULE, NULL);
if (str)
tdm_display_enable_debug_module(str);
- str = getenv("TDM_DEBUG_DUMP");
+ str = tdm_config_get_string(TDM_CONFIG_KEY_DEBUG_DUMP, NULL);
if (str)
tdm_display_enable_dump(private_display, str, NULL, NULL);
- str = getenv("TDM_DEBUG_PATH");
- if (str)
- tdm_display_enable_path(str);
-
if (pthread_mutex_init(&private_display->lock, NULL)) {
/* LCOV_EXCL_START */
ret = TDM_ERROR_OPERATION_FAILED;
goto failed_event;
stamp2 = tdm_helper_get_time();
- TDM_DBG("creating event loop time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ TDM_INFO("event loop init time: %.3f ms", (stamp2 - stamp1) * 1000.0);
stamp1 = stamp2;
ret = _tdm_display_load_module(private_display);
goto failed_load;
stamp2 = tdm_helper_get_time();
- TDM_DBG("loading backend time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ TDM_INFO("loading backend time: %.3f ms", (stamp2 - stamp1) * 1000.0);
stamp1 = stamp2;
#ifdef INIT_BUFMGR
/* the COMMIT_PER_VBLANK functionality is ability of an output to support
* several operational modes (commit_per_vblank modes) related to tdm_commit;
* this functionality can be turned off which means a default mode */
- str = getenv("TDM_COMMIT_PER_VBLANK");
- if (str) {
+ mode = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0);
+ if (mode > 0) {
tdm_private_output *o = NULL;
- char *end;
- int mode = strtol(str, &end, 10);
/* outputs which support hwc capability can work only
* if commit_per_vblank mode is '0' (default mode) */
tdm_debug_module = 0;
- arg = strtok_r(temp, TDM_DELIM, &end);
+ arg = strtok_r(temp, TDM_CONFIG_DELIM, &end);
while (arg) {
if (!strncmp(arg, "none", 4)) {
tdm_debug_module = 0;
else if (!strncmp(arg, "commit", 6))
tdm_debug_module |= TDM_DEBUG_COMMIT;
- arg = strtok_r(NULL, TDM_DELIM, &end);
+ arg = strtok_r(NULL, TDM_CONFIG_DELIM, &end);
}
TDM_INFO("module debugging... '%s'", modules);
return TDM_ERROR_NONE;
}
-INTERN tdm_error
-tdm_display_enable_path(const char *path)
-{
- static int old_stdout = -1;
- char fd_name[TDM_PATH_LEN];
- int log_fd = -1;
- FILE *log_fl;
-
- if (old_stdout == -1)
- old_stdout = dup(STDOUT_FILENO);
-
- tdm_log_enable_dlog(0);
-
- snprintf(fd_name, TDM_PATH_LEN, "%s", path);
-
- log_fl = fopen(fd_name, "a");
- if (!log_fl) {
- TDM_ERR("failed: open file(%s)\n", fd_name);
- return TDM_ERROR_OPERATION_FAILED;
- }
-
- fflush(stderr);
- close(STDOUT_FILENO);
-
- setvbuf(log_fl, NULL, _IOLBF, 512);
- log_fd = fileno(log_fl);
-
- dup2(log_fd, STDOUT_FILENO);
- fclose(log_fl);
-
- return TDM_ERROR_NONE;
-}
-
static void
_tdm_display_ttrace_vblank_cb(tdm_vblank *vblank, tdm_error error, unsigned int sequence,
unsigned int tv_sec, unsigned int tv_usec, void *user_data)
return ret;
}
- arg = strtok_r(temp, TDM_DELIM, &end);
+ arg = strtok_r(temp, TDM_CONFIG_DELIM, &end);
while (arg) {
if (!strncmp(arg, "none", 4))
tdm_ttrace_module = 0;
return TDM_ERROR_NONE;
}
- arg = strtok_r(NULL, TDM_DELIM, &end);
+ arg = strtok_r(NULL, TDM_CONFIG_DELIM, &end);
}
TDM_SNPRINTF(reply, len, "ttrace debugging... '%s' %x\n", ttrace, tdm_ttrace_module);
return dic;
}
-static dictionary *
-_tdm_config_load(void)
+static void
+_tdm_config_check_logs(void)
{
- dictionary *dic = NULL;
-
-#if 0
- /* not allowed: try to read from RW directory */
- dic = _tdm_config_load_file(TDM_SYSCONF_PATH, TDM_CONFIG_FILENAME);
-#endif
-
- if (!dic) {
- /* try to read from RO directory */
- dic = _tdm_config_load_file(TDM_DATA_PATH, TDM_CONFIG_FILENAME);
+ const char *path;
+ int level;
+
+ level = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_LOG_LEVEL, 3);
+ tdm_log_set_debug_level(level);
+
+ level = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_ASSERT_LEVEL, 0);
+ tdm_log_set_assert_level(level);
+
+ /* if TDM_CONFIG_KEY_DEBUG_LOG_PATH is setted, TDM_CONFIG_KEY_DEBUG_DLOG will be ignored. */
+ path = tdm_config_get_string(TDM_CONFIG_KEY_DEBUG_LOG_PATH, NULL);
+ if (path) {
+ tdm_log_enable_dlog(0);
+ tdm_log_set_path(path);
+ } else {
+ int dlog = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1);
+ tdm_log_enable_dlog(dlog);
}
-
- return dic;
}
INTERN tdm_error
return TDM_ERROR_OUT_OF_MEMORY;
}
- g_dic = _tdm_config_load();
- if (!g_dic) {
- if (!getenv("TDM_NO_CONFIG")) {
- TDM_ERR("Loading config file failed!!");
- pthread_mutex_destroy(&g_dic_lock);
- return TDM_ERROR_NONE;
- }
- }
+ g_dic = _tdm_config_load_file(TDM_DATA_PATH, TDM_CONFIG_FILENAME);
+
+ _tdm_config_check_logs();
TDM_INFO("tdm config init done (%p)", g_dic);
pthread_mutex_lock(&g_dic_lock);
ret = iniparser_set(g_dic, key, (const char*)temp);
+
+ _tdm_config_check_logs();
+
pthread_mutex_unlock(&g_dic_lock);
TDM_RETURN_VAL_IF_FAIL(ret == 0, TDM_ERROR_OPERATION_FAILED);
pthread_mutex_lock(&g_dic_lock);
ret = iniparser_set(g_dic, key, value);
+
+ _tdm_config_check_logs();
+
pthread_mutex_unlock(&g_dic_lock);
TDM_RETURN_VAL_IF_FAIL(ret == 0, TDM_ERROR_OPERATION_FAILED);
tdm_config_set_string(const char *key, const char *value);
+#define TDM_CONFIG_DELIM ", "
+
+/*** general keys ************************************************************/
+
+/* backends order list to load.
+ * default: libtdm-default.so
+ * ex) libtdm-default.so,libtdm-dummy.so
+ */
+#define TDM_CONFIG_KEY_GENERAL_BACKENDS "general:backends"
+
+/* enable thd tdm thread. [0(disable), 1(enable)]
+ * default: 0
+ * ex) 1
+ */
+#define TDM_CONFIG_KEY_GENERAL_THREAD "general:thread"
+
+/* enable the tdm commit-per-vblank functionality. [0(disable), 1(enable)]
+ * default: 0
+ * ex) 1
+ */
+#define TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK "general:commit_per_vblank"
+
+
+/*** debug keys **************************************************************/
+
+/* debugging module list. [0(disable), 1(enable)]
+ * default: 1
+ * ex) 0
+ */
+#define TDM_CONFIG_KEY_DEBUG_DLOG "debug:dlog"
+
+/* debugging module list. [none,all,buffer,thread,mutex,vblank,commit]
+ * default: none
+ * ex) mutex,vblank
+ */
+#define TDM_CONFIG_KEY_DEBUG_MODULE "debug:module"
+
+/* debugging dump list. [none,current,all,layer,pp,capture,window]
+ * default: none
+ * ex) layer,capture
+ */
+#define TDM_CONFIG_KEY_DEBUG_DUMP "debug:dump"
+
+/* debugging log path. [{filepath}]
+ * default:
+ * ex) /var/tdm.log
+ */
+#define TDM_CONFIG_KEY_DEBUG_LOG_PATH "debug:log_path"
+
+/* debugging log level. [1(ERR),2(WRN),3(INFO),4(DBG)]
+ * default: 3
+ * ex) 4
+ */
+#define TDM_CONFIG_KEY_DEBUG_LOG_LEVEL "debug:log_level"
+
+/* debugging log level to assert. [0(NONE),1(ERR),2(WRN),3(INFO),4(DBG)]
+ * default: 0
+ * ex) 1
+ */
+#define TDM_CONFIG_KEY_DEBUG_ASSERT_LEVEL "debug:assert_level"
+
+
#ifdef __cplusplus
}
#endif
tdm_log_enable_color(0);
}
- if (tdm_display_enable_path((const char*)fd_name) != TDM_ERROR_NONE) {
- TDM_SNPRINTF(reply, len, "failed: '%s'\n", path);
- return;
- }
+ tdm_log_set_path((const char*)fd_name);
done:
TDM_SNPRINTF(reply, len, "log path: '%s'\n", path);
tdm_error
tdm_display_enable_dump(tdm_private_display *private_display, const char *dump_str, char *reply, int *len);
tdm_error
-tdm_display_enable_path(const char *path);
-tdm_error
tdm_display_enable_ttrace(tdm_private_display *private_display, const char *ttrace, int output_id, char *reply, int *len);
tdm_error
tdm_display_enable_fps(tdm_private_display *private_display, int enable);
{
tdm_private_display *private_display;
tdm_private_thread *private_thread;
- const char *thread;
+ int thread;
TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
TDM_RETURN_VAL_IF_FAIL(private_loop->dpy, TDM_ERROR_OPERATION_FAILED);
return TDM_ERROR_NONE;
/* enable as default */
- thread = getenv("TDM_THREAD");
- if (!thread || strncmp(thread, "1", 1)) {
- TDM_INFO("not using a TDM event thread: %s", (thread) ? thread : "none");
+ thread = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1);
+ if (!thread) {
+ TDM_INFO("not using a TDM event thread");
return TDM_ERROR_NONE;
}