-SUBDIRS = . include protocol client src tools
+SUBDIRS = . include protocol common src client tools
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libtdm.pc
libtdm_client_la_LTLIBRARIES = libtdm-client.la
libtdm_client_ladir = $(libdir)
libtdm_client_la_LDFLAGS = $(LDFLAGS)
-libtdm_client_la_LIBADD = $(TDM_CLIENT_LIBS)
+libtdm_client_la_LIBADD = $(TDM_CLIENT_LIBS) ../common/libtdm-common.la
libtdm_client_la_CFLAGS = \
$(CFLAGS) \
$(WARN_CFLAGS) \
#include "tdm_list.h"
#include "tdm-client-protocol.h"
-int tdm_debug;
-
typedef struct _tdm_private_client_vblank tdm_private_client_vblank;
typedef struct _tdm_private_client {
tdm_client_create(tdm_error *error)
{
tdm_private_client *private_client;
- const char *debug;
-
- debug = getenv("TDM_DEBUG");
- if (debug && (strstr(debug, "1")))
- tdm_debug = 1;
private_client = calloc(1, sizeof *private_client);
if (!private_client) {
--- /dev/null
+noinst_LTLIBRARIES = libtdm-common.la
+
+libtdm_common_la_SOURCES = tdm_log.c
+libtdm_common_la_LIBADD = ${LDFLAGS} $(TDM_LDFLAGS)
+libtdm_common_la_LDFLAGS = ${LDFLAGS} $(TDM_LDFLAGS)
+libtdm_common_la_CFLAGS = \
+ $(CFLAGS) \
+ $(WARN_CFLAGS) \
+ $(TDM_CFLAGS) \
+ -I$(top_srcdir)/include \
+ -I$(top_srcdir)/protocol \
+ -I$(top_srcdir)/src
--- /dev/null
+/**************************************************************************
+ *
+ * libtdm
+ *
+ * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
+ * JinYoung Jeon <jy0.jeon@samsung.com>,
+ * Taeheon Kim <th908.kim@samsung.com>,
+ * YoungJun Cho <yj44.cho@samsung.com>,
+ * SooChan Lim <sc1.lim@samsung.com>,
+ * Boram Park <sc1.lim@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <assert.h>
+#include <sys/syscall.h>
+#include <dlog.h>
+
+#include "tdm.h"
+#include "tdm_log.h"
+#include "tdm_macro.h"
+
+//#define TDM_CONFIG_ASSERT
+
+#define LOG_MAX_LEN 4076
+
+#define COLOR_RED "\x1b[31m" /* for error */
+#define COLOR_YELLOW "\x1b[33m" /* for warning */
+#define COLOR_GREEN "\x1b[32m" /* for info */
+#define COLOR_RESET "\x1b[0m"
+
+#undef LOG_TAG
+#define LOG_TAG "TDM"
+
+static unsigned int dlog_enable;
+static unsigned int debug_enable;
+
+static unsigned int need_check_env = 1;
+
+static void
+_tdm_log_check_env(void)
+{
+ const char *str;
+
+ str = getenv("TDM_DEBUG");
+ if (str && (strstr(str, "1")))
+ debug_enable = 1;
+
+ str = getenv("TDM_DLOG");
+ if (str && (strstr(str, "1")))
+ dlog_enable = 1;
+}
+
+EXTERN void
+tdm_log_enable_dlog(unsigned int enable)
+{
+ dlog_enable = enable;
+}
+
+EXTERN void
+tdm_log_enable_debug(unsigned int enable)
+{
+ debug_enable = enable;
+}
+
+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 > 3 && !debug_enable)
+ return;
+
+ if (dlog_enable) {
+ log_priority dlog_prio;
+ switch (level) {
+ case TDM_LOG_LEVEL_ERR:
+ dlog_prio = DLOG_ERROR;
+ break;
+ case TDM_LOG_LEVEL_WRN:
+ dlog_prio = DLOG_WARN;
+ break;
+ case TDM_LOG_LEVEL_INFO:
+ dlog_prio = DLOG_INFO;
+ break;
+ case TDM_LOG_LEVEL_DBG:
+ dlog_prio = DLOG_DEBUG;
+ break;
+ default:
+ return;
+ }
+ va_start(arg, fmt);
+ dlog_vprint(dlog_prio, LOG_TAG, fmt, arg);
+ va_end(arg);
+ } else {
+ struct timespec ts;
+ char *lvl_str[] = {"TDM_NON", "TDM_ERR", "TDM_WRN", "TDM_INF", "TDM_DBG"};
+ char *color[] = {COLOR_RESET, COLOR_RED, COLOR_YELLOW, COLOR_GREEN, COLOR_RESET};
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+
+ printf("%s", color[level]);
+ printf("[%s]", lvl_str[level]);
+ printf(COLOR_RESET"[%d.%06d]", (int)ts.tv_sec, (int)ts.tv_nsec / 1000);
+ va_start(arg, fmt);
+ vprintf(fmt, arg);
+ va_end(arg);
+ }
+
+#ifdef TDM_CONFIG_ASSERT
+ if (level < 3)
+ assert(0);
+#endif
+}
libtdm.pc
include/Makefile
protocol/Makefile
+ common/Makefile
+ src/Makefile
client/libtdm-client.pc
client/Makefile
- src/Makefile
tools/Makefile])
echo ""
#ifndef _TDM_LOG_H_
#define _TDM_LOG_H_
+#include <unistd.h>
+#include <sys/syscall.h>
#ifdef __cplusplus
extern "C" {
#endif
-#include <unistd.h>
-#include <time.h>
-#include <assert.h>
-#include <sys/syscall.h>
-
-
/**
* @file tdm_log.h
* @brief The header file to print logs in frontend and backend modules
* @details
- * The TDM debug log can be enable by setting "TDM_DEBUG" enviroment
+ * The TDM debug log can be enable by setting "TDM_DEBUG" enviroment. And also,
+ * the TDM dlog can be enable by setting "TDM_DLOG" enviroment.
* @par Example
* @code
* $ export TDM_DEBUG=1
* @endcode
*/
-extern int tdm_debug;
-
-//#define TDM_CONFIG_DLOG
-//#define TDM_CONFIG_ASSERT
-
-#undef TDM_ASSERT
-#ifdef TDM_CONFIG_ASSERT
-#define TDM_ASSERT(o) assert(o)
-#else
-#define TDM_ASSERT(o)
-#endif
-
-#ifdef TDM_CONFIG_DLOG
-
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "TDM"
-#define TDM_DBG(fmt, args...) \
- do { \
- if (tdm_debug) { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGD("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_DBG][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- } \
- } while (0)
-
-#define TDM_INFO(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_INF][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- } while (0)
-
-#define TDM_WRN(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_WRN][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- } while (0)
-
-#define TDM_ERR(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGE("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_ERR][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- } while (0)
+enum {
+ TDM_LOG_LEVEL_NONE,
+ TDM_LOG_LEVEL_ERR,
+ TDM_LOG_LEVEL_WRN,
+ TDM_LOG_LEVEL_INFO,
+ TDM_LOG_LEVEL_DBG,
+};
-#else /* TDM_CONFIG_DLOG */
-
-#include <stdio.h>
-
-#define COLOR_RED "\x1b[31m" /* for error */
-#define COLOR_YELLOW "\x1b[33m" /* for warning */
-#define COLOR_GREEN "\x1b[32m" /* for info */
-#define COLOR_RESET "\x1b[0m"
+void tdm_log_enable_dlog(unsigned int enable);
+void tdm_log_enable_debug(unsigned int enable);
+void tdm_log_print(int level, const char *fmt, ...);
#define TDM_DBG(fmt, args...) \
- do { \
- if (tdm_debug) { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf("[TDM_DBG][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- } \
- } while (0)
-
+ tdm_log_print(TDM_LOG_LEVEL_DBG, "[%d][%s %d]"fmt"\n", \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
#define TDM_INFO(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf(COLOR_GREEN"[TDM_INF]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- } while (0)
-
+ tdm_log_print(TDM_LOG_LEVEL_INFO, "[%d][%s %d]"fmt"\n", \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
#define TDM_WRN(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf(COLOR_YELLOW"[TDM_WRN]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- TDM_ASSERT(0); \
- } while (0)
-
+ tdm_log_print(TDM_LOG_LEVEL_WRN, "[%d][%s %d]"fmt"\n", \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
#define TDM_ERR(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf(COLOR_RED"[TDM_ERR]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
- TDM_ASSERT(0); \
- } while (0)
-
-#endif /* TDM_CONFIG_DLOG */
+ tdm_log_print(TDM_LOG_LEVEL_ERR, "[%d][%s %d]"fmt"\n", \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
#ifdef __cplusplus
}
libtdm_la_LTLIBRARIES = libtdm.la
libtdm_ladir = $(libdir)
libtdm_la_LDFLAGS = -version-number 1:0:0 -no-undefined
-libtdm_la_LIBADD = $(TDM_LIBS) -ldl -lpthread
+libtdm_la_LIBADD = $(TDM_LIBS) -ldl -lpthread ../common/libtdm-common.la
libtdm_la_CFLAGS = \
$(CFLAGS) \
$(WARN_CFLAGS) \
#define SUFFIX_MODULE ".so"
#define DEFAULT_MODULE "libtdm-default"SUFFIX_MODULE
-int tdm_debug;
int tdm_debug_buffer;
int tdm_debug_thread;
int tdm_debug_mutex;
return g_private_display;
}
- debug = getenv("TDM_DEBUG");
- if (debug && (strstr(debug, "1")))
- tdm_debug = 1;
-
debug = getenv("TDM_DEBUG_BUFFER");
if (debug && (strstr(debug, "1")))
tdm_debug_buffer = 1;
failed_mutex_init:
free(private_display);
failed_alloc:
- tdm_debug = 0;
tdm_debug_buffer = 0;
if (error)
*error = ret;
pthread_mutex_destroy(&private_display->lock);
free(private_display);
g_private_display = NULL;
- tdm_debug = 0;
tdm_debug_buffer = 0;
_pthread_mutex_unlock(&gLock);
#include <time.h>
#include <stdint.h>
-#include "tdm_macro.h"
-
#include <tdm_client.h>
-#include <tdm_helper.h>
-
-int tdm_debug;
+#include "tdm_macro.h"
typedef struct _tdm_test_client_arg {
char output_name[512];
if (cur - vbl > 2000) /* 2ms */
printf("kernel -> tdm-client: %ld us\n", cur - vbl);
- if (tdm_debug) {
- static unsigned long p_cur = 0;
- printf("vblank event interval: %ld %ld\n",
- vbl - p_vbl, cur - p_cur);
- p_cur = cur;
- }
-
p_vbl = vbl;
}
{
tdm_test_client *data = &ttc_data;
tdm_error error;
- const char *debug;
-
- debug = getenv("TDM_DEBUG");
- if (debug && (strstr(debug, "1")))
- tdm_debug = 1;
parse_args(data, argc, argv);