From 6b17e468595af689abfd115cba6e40afca32ef25 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Mon, 5 Feb 2018 17:56:25 +0900 Subject: [PATCH 01/16] log: check log level Change-Id: I314e2b31ecfd402b75dabaa66ffd8d6198a3d5cd --- common/tdm_log.c | 15 ++++++++------- include/tdm_log.h | 50 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/common/tdm_log.c b/common/tdm_log.c index 7cce09c..2f7152b 100644 --- a/common/tdm_log.c +++ b/common/tdm_log.c @@ -63,13 +63,14 @@ static unsigned int dlog_enable = 1; static unsigned int color_enable = 1; -static unsigned int debug_level = TDM_LOG_LEVEL_INFO; static unsigned int need_check_env = 1; 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) { @@ -78,11 +79,11 @@ _tdm_log_check_env(void) str = getenv("TDM_DEBUG_LEVEL"); if (str) - debug_level = strtol(str, &end, 10); + tdm_log_debug_level = strtol(str, &end, 10); str = getenv("TDM_DEBUG"); if (str && (strstr(str, "1"))) - debug_level = TDM_LOG_LEVEL_DBG; + tdm_log_debug_level = TDM_LOG_LEVEL_DBG; str = getenv("TDM_DLOG"); if (str && (strstr(str, "0"))) @@ -105,15 +106,15 @@ EXTERN void tdm_log_enable_debug(unsigned int enable) { if (enable) - debug_level = TDM_LOG_LEVEL_DBG; + tdm_log_debug_level = TDM_LOG_LEVEL_DBG; else - debug_level = TDM_LOG_LEVEL_INFO; + tdm_log_debug_level = TDM_LOG_LEVEL_INFO; } EXTERN void tdm_log_set_debug_level(int level) { - debug_level = level; + tdm_log_debug_level = level; } EXTERN void @@ -132,7 +133,7 @@ tdm_log_print(int level, const char *fmt, ...) _tdm_log_check_env(); } - if (level > debug_level) + if (level > tdm_log_debug_level) return; if (dlog_enable) { diff --git a/include/tdm_log.h b/include/tdm_log.h index d402a99..1cab32d 100644 --- a/include/tdm_log.h +++ b/include/tdm_log.h @@ -70,37 +70,47 @@ void tdm_log_enable_debug(unsigned int enable); void tdm_log_set_debug_level(int level); void tdm_log_print(int level, const char *fmt, ...); +extern unsigned int tdm_log_debug_level; + #define TDM_DBG(fmt, args...) \ do { \ - struct timespec ts; \ - clock_gettime(CLOCK_MONOTONIC, &ts); \ - tdm_log_print(TDM_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt"\n", \ - (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + if (tdm_log_debug_level >= TDM_LOG_LEVEL_DBG) { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } \ } while (0) #define TDM_INFO(fmt, args...) \ do { \ - struct timespec ts; \ - clock_gettime(CLOCK_MONOTONIC, &ts); \ - tdm_log_print(TDM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt"\n", \ - (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + if (tdm_log_debug_level >= TDM_LOG_LEVEL_INFO) { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } \ } while (0) #define TDM_WRN(fmt, args...) \ do { \ - struct timespec ts; \ - clock_gettime(CLOCK_MONOTONIC, &ts); \ - tdm_log_print(TDM_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt"\n", \ - (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + if (tdm_log_debug_level >= TDM_LOG_LEVEL_WRN) { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } \ } while (0) #define TDM_ERR(fmt, args...) \ do { \ - struct timespec ts; \ - clock_gettime(CLOCK_MONOTONIC, &ts); \ - tdm_log_print(TDM_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt"\n", \ - (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ - (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + if (tdm_log_debug_level >= TDM_LOG_LEVEL_ERR) { \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + tdm_log_print(TDM_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt"\n", \ + (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \ + (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \ + } \ } while (0) #ifdef __cplusplus -- 2.7.4 From 505b4dc6d1b806180064f836a75459652f6a4873 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 8 Feb 2018 14:04:02 +0900 Subject: [PATCH 02/16] client: handling wayland protocol error Change-Id: I2d064e7808298820dd7e44f0c185aea673fa9999 --- client/tdm_client.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/tdm_common.h | 1 + src/tdm_macro.h | 1 + 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/client/tdm_client.c b/client/tdm_client.c index 51e5c5e..9d00023 100644 --- a/client/tdm_client.c +++ b/client/tdm_client.c @@ -134,6 +134,30 @@ typedef struct _tdm_client_wait_info { struct list_head call_link; } tdm_client_wait_info; +static unsigned int +_tdm_client_check_wl_error(tdm_private_client *private_client, const char *func, int line) +{ + uint32_t ec, id; + const struct wl_interface *intf; + int err; + + err = wl_display_get_error(private_client->display); + if (!err) + return false; + + if (err == EINVAL || err == ENOMEM || err == EFAULT || err == EPROTO) { + ec = wl_display_get_protocol_error(private_client->display, &intf, &id); + TDM_ERR("[%s,%d] errno(%d) Got protocol error '%u' on interface '%s' (object '%u')", + func, line, err, ec, (intf) ? intf->name : "destroyed", id); + } else { + TDM_ERR("[%s,%d] errno(%d)", func, line, err); + } + + return true; +} + +#define CHECK_WL_PROTOCOL_ERROR(pc) _tdm_client_check_wl_error(pc, __FUNCTION__, __LINE__) + static void _tdm_client_vblank_cb_stamp(void *data, struct wl_tdm_vblank *wl_tdm_vblank, uint32_t stamp) { @@ -435,6 +459,9 @@ tdm_client_create(tdm_error *error) &tdm_client_registry_listener, private_client); wl_display_roundtrip(private_client->display); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) + goto create_failed; + /* check global objects */ TDM_GOTO_IF_FAIL(private_client->tdm != NULL, create_failed); @@ -516,6 +543,11 @@ tdm_client_handle_events(tdm_client *client) pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (private_client->enable_ttrace) TDM_TRACE_ASYNC_BEGIN((int)private_client->stamp, "TDM_Client_Events:%u", (unsigned int)private_client->stamp); @@ -524,6 +556,11 @@ tdm_client_handle_events(tdm_client *client) if (private_client->enable_ttrace) TDM_TRACE_ASYNC_END((int)private_client->stamp, "TDM_Client_Events:%u", (unsigned int)private_client->stamp); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + pthread_mutex_unlock(&private_client->lock); return TDM_ERROR_NONE; @@ -575,6 +612,9 @@ tdm_client_wait_vblank(tdm_client *client, char *name, TDM_RETURN_VAL_IF_FAIL(interval > 0, TDM_ERROR_INVALID_PARAMETER); TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) + return TDM_ERROR_PROTOCOL_ERROR; + if (!private_client->temp_vblank) { output = tdm_client_get_output(client, name, &ret); TDM_RETURN_VAL_IF_FAIL(output != NULL, ret); @@ -617,6 +657,13 @@ tdm_client_get_output(tdm_client *client, char *name, tdm_error *error) pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + if (error) + *error = TDM_ERROR_PROTOCOL_ERROR; + pthread_mutex_unlock(&private_client->lock); + return NULL; + } + if (!name) name = "primary"; @@ -671,7 +718,6 @@ tdm_client_get_output(tdm_client *client, char *name, tdm_error *error) LIST_INITHEAD(&private_output->vblank_list); LIST_INITHEAD(&private_output->change_handler_list); - LIST_ADDTAIL(&private_output->link, &private_client->output_list); wl_tdm_output_add_listener(private_output->output, &tdm_client_output_listener, private_output); @@ -679,6 +725,17 @@ tdm_client_get_output(tdm_client *client, char *name, tdm_error *error) wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + wl_tdm_output_destroy(private_output->output); + free(private_output); + if (error) + *error = TDM_ERROR_PROTOCOL_ERROR; + pthread_mutex_unlock(&private_client->lock); + return NULL; + } + + LIST_ADDTAIL(&private_output->link, &private_client->output_list); + pthread_mutex_unlock(&private_client->lock); return (tdm_client_output*)private_output; @@ -704,6 +761,12 @@ tdm_client_output_add_change_handler(tdm_client_output *output, pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + free(h); + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (LIST_IS_EMPTY(&private_output->change_handler_list)) { wl_tdm_output_watch_output_changes(private_output->output, 1); @@ -751,8 +814,10 @@ tdm_client_output_remove_change_handler(tdm_client_output *output, LIST_DEL(&h->link); free(h); - if (LIST_IS_EMPTY(&private_output->change_handler_list)) - wl_tdm_output_watch_output_changes(private_output->output, 0); + if (LIST_IS_EMPTY(&private_output->change_handler_list)) { + if (!CHECK_WL_PROTOCOL_ERROR(private_client)) + wl_tdm_output_watch_output_changes(private_output->output, 0); + } pthread_mutex_unlock(&private_client->lock); @@ -782,11 +847,21 @@ tdm_client_output_get_refresh_rate(tdm_client_output *output, unsigned int *refr return TDM_ERROR_NONE; } + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue); wl_tdm_output_get_mode(private_output->output); wl_display_roundtrip_queue(private_client->display, private_client->queue); wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + *refresh = private_output->refresh; pthread_mutex_unlock(&private_client->lock); @@ -814,11 +889,21 @@ tdm_client_output_get_conn_status(tdm_client_output *output, tdm_output_conn_sta return TDM_ERROR_NONE; } + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue); wl_tdm_output_get_connection(private_output->output); wl_display_roundtrip_queue(private_client->display, private_client->queue); wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + *status = private_output->connection; pthread_mutex_unlock(&private_client->lock); @@ -845,11 +930,21 @@ tdm_client_output_get_dpms(tdm_client_output *output, tdm_output_dpms *dpms) pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue); wl_tdm_output_get_dpms(private_output->output); wl_display_roundtrip_queue(private_client->display, private_client->queue); wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + *dpms = private_output->dpms; pthread_mutex_unlock(&private_client->lock); @@ -880,6 +975,13 @@ tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error) pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + if (error) + *error = TDM_ERROR_PROTOCOL_ERROR; + pthread_mutex_unlock(&private_client->lock); + return NULL; + } + wrapper = wl_proxy_create_wrapper(private_output->output); if (!wrapper) { TDM_ERR("create output_wrapper failed"); @@ -928,7 +1030,6 @@ tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error) private_vblank->enable_fake = 0; LIST_INITHEAD(&private_vblank->wait_list); - LIST_ADDTAIL(&private_vblank->link, &private_output->vblank_list); wl_tdm_vblank_add_listener(private_vblank->vblank, &tdm_client_vblank_listener, private_vblank); @@ -936,6 +1037,17 @@ tdm_client_output_create_vblank(tdm_client_output *output, tdm_error *error) wl_proxy_set_queue((struct wl_proxy *)private_vblank->vblank, NULL); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + wl_tdm_vblank_destroy(private_vblank->vblank); + free(private_vblank); + if (error) + *error = TDM_ERROR_PROTOCOL_ERROR; + pthread_mutex_unlock(&private_client->lock); + return NULL; + } + + LIST_ADDTAIL(&private_vblank->link, &private_output->vblank_list); + pthread_mutex_unlock(&private_client->lock); return (tdm_client_vblank*)private_vblank; @@ -982,6 +1094,11 @@ tdm_client_vblank_set_name(tdm_client_vblank *vblank, const char *name) pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (!name) name = TDM_VBLANK_DEFAULT_NAME; @@ -1027,6 +1144,11 @@ tdm_client_vblank_set_fps(tdm_client_vblank *vblank, unsigned int fps) pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (private_vblank->fps == fps) { pthread_mutex_unlock(&private_client->lock); return TDM_ERROR_NONE; @@ -1056,6 +1178,11 @@ tdm_client_vblank_set_offset(tdm_client_vblank *vblank, int offset_ms) pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (private_vblank->offset == offset_ms) { pthread_mutex_unlock(&private_client->lock); return TDM_ERROR_NONE; @@ -1083,6 +1210,11 @@ tdm_client_vblank_set_enable_fake(tdm_client_vblank *vblank, unsigned int enable pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (private_vblank->enable_fake == enable_fake) { pthread_mutex_unlock(&private_client->lock); return TDM_ERROR_NONE; @@ -1122,6 +1254,11 @@ tdm_client_vblank_wait(tdm_client_vblank *vblank, unsigned int interval, tdm_cli pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (!private_vblank->started) private_vblank->started = 1; @@ -1196,6 +1333,11 @@ tdm_client_vblank_wait(tdm_client_vblank *vblank, unsigned int interval, tdm_cli LIST_DEL(&w->link); free(w); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + pthread_mutex_unlock(&private_client->lock); return TDM_ERROR_NONE; @@ -1224,6 +1366,11 @@ tdm_client_vblank_wait_seq(tdm_client_vblank *vblank, unsigned int sequence, pthread_mutex_lock(&private_client->lock); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + if (!private_vblank->started) private_vblank->started = 1; @@ -1298,6 +1445,11 @@ tdm_client_vblank_wait_seq(tdm_client_vblank *vblank, unsigned int sequence, LIST_DEL(&w->link); free(w); + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + pthread_mutex_unlock(&private_client->lock); return TDM_ERROR_NONE; diff --git a/include/tdm_common.h b/include/tdm_common.h index dd01247..4c264ed 100644 --- a/include/tdm_common.h +++ b/include/tdm_common.h @@ -68,6 +68,7 @@ typedef enum { TDM_ERROR_NO_CAPABILITY = -9, /**< no capability */ TDM_ERROR_DPMS_OFF = -10, /**< dpms off */ TDM_ERROR_OUTPUT_DISCONNECTED = -11, /**< output disconnected */ + TDM_ERROR_PROTOCOL_ERROR = -12, /**< protocol error */ } tdm_error; /** diff --git a/src/tdm_macro.h b/src/tdm_macro.h index 0cafffe..e75220c 100644 --- a/src/tdm_macro.h +++ b/src/tdm_macro.h @@ -169,6 +169,7 @@ static struct tdm_type_name tdm_error_names[] = { { TDM_ERROR_NO_CAPABILITY, "no capability" }, { TDM_ERROR_DPMS_OFF, "dpms off" }, { TDM_ERROR_OUTPUT_DISCONNECTED, "output disconnected" }, + { TDM_ERROR_PROTOCOL_ERROR, "protocol error" }, }; TDM_TYPE_NAME_FN(error) -- 2.7.4 From 2dc316b1fc5cfd77b254416313a858c8c3909df4 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 20 Feb 2018 16:05:00 +0900 Subject: [PATCH 04/16] package version up to 1.14.0 Change-Id: Iaf72619db33492b9609c3f509f1f0505c87d5433 --- configure.ac | 2 +- doc/tdm_doc.h | 2 +- packaging/libtdm.spec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 26ba06d..9a706cf 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ AC_PREREQ([2.60]) m4_define([tdm_major_version], [1]) -m4_define([tdm_minor_version], [11]) +m4_define([tdm_minor_version], [14]) m4_define([tdm_micro_version], [0]) m4_define([tdm_version], [tdm_major_version.tdm_minor_version.tdm_micro_version]) diff --git a/doc/tdm_doc.h b/doc/tdm_doc.h index 02d418c..0c14af6 100644 --- a/doc/tdm_doc.h +++ b/doc/tdm_doc.h @@ -39,7 +39,7 @@ /** * @mainpage TDM * @author Boram Park, boram1288.park@samsung.com - * @version 1.11.0 + * @version 1.14.0 * @par Introduction * TDM stands for Tizen Display Manager. It's the display HAL layer for tizen * display server. It offers the frontend APIs(@ref tdm.h) for a frontend user diff --git a/packaging/libtdm.spec b/packaging/libtdm.spec index 4cb9d26..876648f 100644 --- a/packaging/libtdm.spec +++ b/packaging/libtdm.spec @@ -2,7 +2,7 @@ %define UTEST_GCOV 0 Name: libtdm -Version: 1.13.1 +Version: 1.14.0 Release: 0 Summary: User Library of Tizen Display Manager Group: Development/Libraries -- 2.7.4 From 3bf98d8cee5f7abf33073b1590b39c9aa6773a7c Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 18 Jan 2018 09:50:54 +0900 Subject: [PATCH 05/16] output: remove unused params Change-Id: Id92aa4041890a16d87e564800dbc017c50701554 --- src/tdm_output.c | 17 ++++++++--------- src/tdm_private.h | 3 +-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/tdm_output.c b/src/tdm_output.c index 54ad8dc..918940d 100644 --- a/src/tdm_output.c +++ b/src/tdm_output.c @@ -234,7 +234,7 @@ tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status, tdm_output_call_change_handler_internal(private_output, &private_output->change_handler_list_sub, TDM_OUTPUT_CHANGE_CONNECTION, - value, 0); + value); ret = tdm_thread_send_cb(private_display->private_loop, &output_status.base); TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE); @@ -252,7 +252,7 @@ tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status, tdm_output_call_change_handler_internal(private_output, &private_output->change_handler_list_main, TDM_OUTPUT_CHANGE_CONNECTION, - value, 0); + value); } /* LCOV_EXCL_STOP */ @@ -1179,7 +1179,7 @@ _tdm_output_dpms_changed_timeout(void *user_data) tdm_output_call_change_handler_internal(private_output, &private_output->change_handler_list_sub, TDM_OUTPUT_CHANGE_DPMS, - value, 0); + value); return TDM_ERROR_NONE; } @@ -1212,7 +1212,7 @@ tdm_output_call_dpms_change_handler(tdm_output *output) tdm_output_call_change_handler_internal(private_output, &private_output->change_handler_list_main, TDM_OUTPUT_CHANGE_DPMS, - value, 0); + value); if (!LIST_IS_EMPTY(&private_output->change_handler_list_sub)) { tdm_error ret = tdm_event_loop_source_timer_update(private_output->dpms_changed_timer, 1); @@ -1252,7 +1252,7 @@ tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_ tdm_output_call_change_handler_internal(private_output, &private_output->change_handler_list_sub, TDM_OUTPUT_CHANGE_DPMS, - value, 0); + value); ret = tdm_thread_send_cb(private_display->private_loop, &output_dpms.base); TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE); @@ -1269,7 +1269,7 @@ tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_ tdm_output_call_change_handler_internal(private_output, &private_output->change_handler_list_main, TDM_OUTPUT_CHANGE_DPMS, - value, 0); + value); } /* LCOV_EXCL_STOP */ @@ -2021,8 +2021,7 @@ INTERN void tdm_output_call_change_handler_internal(tdm_private_output *private_output, struct list_head *change_handler_list, tdm_output_change_type type, - tdm_value value, - int no_check_thread_id) + tdm_value value) { tdm_private_display *private_display; tdm_private_change_handler *change_handler = NULL; @@ -2044,7 +2043,7 @@ tdm_output_call_change_handler_internal(tdm_private_output *private_output, return; LIST_FOR_EACH_ENTRY(change_handler, change_handler_list, link) { - if (!no_check_thread_id && change_handler->owner_tid != syscall(SYS_gettid)) + if (change_handler->owner_tid != syscall(SYS_gettid)) TDM_NEVER_GET_HERE(); _pthread_mutex_unlock(&private_display->lock); diff --git a/src/tdm_private.h b/src/tdm_private.h index 0424dd2..5a07b89 100644 --- a/src/tdm_private.h +++ b/src/tdm_private.h @@ -176,8 +176,7 @@ void tdm_output_call_change_handler_internal(tdm_private_output *private_output, struct list_head *change_handler_list, tdm_output_change_type type, - tdm_value value, - int no_check_thread_id); + tdm_value value); tdm_private_pp * tdm_pp_create_internal(tdm_private_display *private_display, tdm_error *error); -- 2.7.4 From ad05aa68c250148cf799f0769a37724549582080 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 18 Jan 2018 10:10:55 +0900 Subject: [PATCH 06/16] types: move to the frontned's types header Change-Id: I322acc5654651122661ec5bc0f68541df7818e38 --- include/tdm.h | 18 ------------------ include/tdm_types.h | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/tdm.h b/include/tdm.h index 70c99af..7ee3edc 100644 --- a/include/tdm.h +++ b/include/tdm.h @@ -58,24 +58,6 @@ extern "C" { */ /** - * @brief The display capability enumeration - */ -typedef enum { - TDM_DISPLAY_CAPABILITY_PP = (1 << 0), /**< if hardware supports pp operation */ - TDM_DISPLAY_CAPABILITY_CAPTURE = (1 << 1), /**< if hardware supports capture operation */ -} tdm_display_capability; - -/** - * @brief The output change handler - * @details This handler will be called when the status of a output object is - * changed in runtime. - */ -typedef void (*tdm_output_change_handler)(tdm_output *output, - tdm_output_change_type type, - tdm_value value, - void *user_data); - -/** * @brief Initialize a display object * @param[out] error #TDM_ERROR_NONE if success. Otherwise, error value. * @return A display object diff --git a/include/tdm_types.h b/include/tdm_types.h index d2013b7..055005f 100644 --- a/include/tdm_types.h +++ b/include/tdm_types.h @@ -67,6 +67,14 @@ typedef enum { } tdm_event_loop_mask; /** + * @brief The display capability enumeration + */ +typedef enum { + TDM_DISPLAY_CAPABILITY_PP = (1 << 0), /**< if hardware supports pp operation */ + TDM_DISPLAY_CAPABILITY_CAPTURE = (1 << 1), /**< if hardware supports capture operation */ +} tdm_display_capability; + +/** * @brief The output mode structure */ typedef struct _tdm_output_mode { @@ -244,6 +252,16 @@ typedef void tdm_pp; typedef void tdm_vblank; /** + * @brief The output change handler + * @details This handler will be called when the status of a output object is + * changed in runtime. + */ +typedef void (*tdm_output_change_handler)(tdm_output *output, + tdm_output_change_type type, + tdm_value value, + void *user_data); + +/** * @brief The vblank handler * @see output_set_vblank_handler() function of #tdm_func_display */ -- 2.7.4 From d80a43a53be5839b954d446e099e19ee3f0941d1 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 18 Jan 2018 10:23:52 +0900 Subject: [PATCH 07/16] types: give a detail name to structure Change-Id: Id3f0471e1d040f38810c85c1b2dcab6b6c83b208 --- src/tdm.c | 2 +- src/tdm_output.c | 8 ++++---- src/tdm_private_types.h | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/tdm.c b/src/tdm.c index 33b27a7..312bac9 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -157,7 +157,7 @@ _tdm_display_destroy_private_output(tdm_private_output *private_output) tdm_private_vblank_handler *v = NULL, *vv = NULL; tdm_private_output_commit_handler *om = NULL, *omm = NULL; tdm_private_layer_commit_handler *lm = NULL, *lmm = NULL; - tdm_private_change_handler *h = NULL, *hh = NULL; + tdm_private_output_change_handler *h = NULL, *hh = NULL; LIST_DEL(&private_output->link); diff --git a/src/tdm_output.c b/src/tdm_output.c index 918940d..1edf7fc 100644 --- a/src/tdm_output.c +++ b/src/tdm_output.c @@ -261,14 +261,14 @@ tdm_output_add_change_handler(tdm_output *output, tdm_output_change_handler func, void *user_data) { - tdm_private_change_handler *change_handler; + tdm_private_output_change_handler *change_handler; OUTPUT_FUNC_ENTRY(); TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER); _pthread_mutex_lock(&private_display->lock); - change_handler = calloc(1, sizeof(tdm_private_change_handler)); + change_handler = calloc(1, sizeof(tdm_private_output_change_handler)); if (!change_handler) { /* LCOV_EXCL_START */ TDM_ERR("failed: alloc memory"); @@ -299,7 +299,7 @@ tdm_output_remove_change_handler(tdm_output *output, { tdm_private_display *private_display; tdm_private_output *private_output; - tdm_private_change_handler *h = NULL, *hh = NULL; + tdm_private_output_change_handler *h = NULL, *hh = NULL; TDM_RETURN_IF_FAIL(tdm_output_is_valid(output)); TDM_RETURN_IF_FAIL(func != NULL); @@ -2024,7 +2024,7 @@ tdm_output_call_change_handler_internal(tdm_private_output *private_output, tdm_value value) { tdm_private_display *private_display; - tdm_private_change_handler *change_handler = NULL; + tdm_private_output_change_handler *change_handler = NULL; TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED()); TDM_RETURN_IF_FAIL(private_output); diff --git a/src/tdm_private_types.h b/src/tdm_private_types.h index 26b4b12..cc234c0 100644 --- a/src/tdm_private_types.h +++ b/src/tdm_private_types.h @@ -105,12 +105,12 @@ typedef struct _tdm_private_loop tdm_private_loop; typedef struct _tdm_private_server tdm_private_server; typedef struct _tdm_private_thread tdm_private_thread; typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler; +typedef struct _tdm_private_output_change_handler tdm_private_output_change_handler; typedef struct _tdm_private_output_commit_handler tdm_private_output_commit_handler; typedef struct _tdm_private_layer_commit_handler tdm_private_layer_commit_handler; typedef struct _tdm_private_hwc_window_commit_handler tdm_private_hwc_window_commit_handler; typedef struct _tdm_private_output_hwc_target_buffer_window_commit_handler tdm_private_output_hwc_target_buffer_commit_handler; -typedef struct _tdm_private_change_handler tdm_private_change_handler; typedef struct _tdm_private_layer_buffer tdm_private_layer_buffer; struct _tdm_private_display { @@ -355,24 +355,24 @@ struct _tdm_private_vblank_handler { pid_t owner_tid; }; -struct _tdm_private_output_commit_handler { +struct _tdm_private_output_change_handler { struct list_head link; tdm_private_output *private_output; - tdm_output_commit_handler func; + tdm_output_change_handler func; void *user_data; pid_t owner_tid; }; -struct _tdm_private_layer_commit_handler { +struct _tdm_private_output_commit_handler { struct list_head link; - tdm_private_layer *private_layer; - tdm_layer_commit_handler func; + tdm_private_output *private_output; + tdm_output_commit_handler func; void *user_data; - tdm_private_layer_buffer *committed_buffer; /* for layer_commit */ + pid_t owner_tid; }; struct _tdm_private_hwc_window_commit_handler { @@ -387,14 +387,14 @@ struct _tdm_private_output_hwc_target_buffer_window_commit_handler { void *user_data; }; -struct _tdm_private_change_handler { +struct _tdm_private_layer_commit_handler { struct list_head link; - tdm_private_output *private_output; - tdm_output_change_handler func; + tdm_private_layer *private_layer; + tdm_layer_commit_handler func; void *user_data; - pid_t owner_tid; + tdm_private_layer_buffer *committed_buffer; /* for layer_commit */ }; struct _tdm_private_layer_buffer { -- 2.7.4 From 9dc1c7cc7ea2b379fa3f5e26bd8c61bb71998c88 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 18 Jan 2018 14:39:19 +0900 Subject: [PATCH 08/16] vblank: add description Change-Id: I516ed249e61a26640968cfcc53d32ed99daa89c8 --- src/tdm_vblank.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tdm_vblank.c b/src/tdm_vblank.c index 73f7214..ad4b9c0 100644 --- a/src/tdm_vblank.c +++ b/src/tdm_vblank.c @@ -584,8 +584,11 @@ tdm_vblank_cb_vblank_create(tdm_vblank *vblank, double vblank_stamp) } LIST_FOR_EACH_ENTRY_SAFE(ch_info, hh, &create_handler_list, link) { + /* use in_create_handler instead of mutext unlock/lock */ private_vblank->in_create_handler = 1; + //_pthread_mutex_unlock(&private_display->lock); ch_info->func(private_vblank, ch_info->user_data); + //_pthread_mutex_lock(&private_display->lock); private_vblank->in_create_handler = 0; } -- 2.7.4 From 5cf857010133d1048d03ad93623cdc3d79d20c61 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 23 Jan 2018 08:19:58 +0900 Subject: [PATCH 09/16] tests: correct capture information Change-Id: Ib03a067db3c7e885495005ba27c7730cee77a1a6 --- tools/tdm_test_server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/tdm_test_server.c b/tools/tdm_test_server.c index 7dff9eb..52e0f61 100644 --- a/tools/tdm_test_server.c +++ b/tools/tdm_test_server.c @@ -1360,6 +1360,7 @@ capture_setup(tdm_test_server_capture *c, tbm_surface_h b) c->info.dst_config.size.v = info.height; } c->info.dst_config.format = info.format; + c->info.type = TDM_CAPTURE_TYPE_ONESHOT; ret = tdm_capture_set_info(c->capture, &c->info); TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE); -- 2.7.4 From fd7c7be65d642a0dd6e7f4260c85cf7ba62cae27 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 23 Jan 2018 08:21:17 +0900 Subject: [PATCH 10/16] capture: use correct function Change-Id: I53a21fa01c6347085b492bfc38685fd43c22f391 --- src/tdm_capture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tdm_capture.c b/src/tdm_capture.c index de7439c..2ba0e5f 100644 --- a/src/tdm_capture.c +++ b/src/tdm_capture.c @@ -555,7 +555,7 @@ tdm_capture_attach(tdm_capture *capture, tbm_surface_h buffer) if (tdm_debug_module & TDM_DEBUG_BUFFER) { TDM_INFO("capture(%p) attached:", private_capture); - tdm_buffer_list_dump(&private_capture->buffer_list); + _tdm_capture_print_list(&private_capture->buffer_list); } if (tdm_ttrace_module & TDM_TTRACE_CAPTURE) { -- 2.7.4 From aff08f43b31fb88160915b27b19dfb70233313f7 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 23 Jan 2018 08:20:50 +0900 Subject: [PATCH 11/16] buffer: remove unused functions Change-Id: I6c73f3978a3f89422904390cb9683c8fd7b25b40 --- src/tdm_buffer.c | 36 ------------------------------------ src/tdm_private.h | 5 ----- 2 files changed, 41 deletions(-) diff --git a/src/tdm_buffer.c b/src/tdm_buffer.c index 3c9fb48..5d501b0 100644 --- a/src/tdm_buffer.c +++ b/src/tdm_buffer.c @@ -275,39 +275,3 @@ tdm_buffer_remove_destroy_handler(tbm_surface_h buffer, } } -INTERN tbm_surface_h -tdm_buffer_list_get_first_entry(struct list_head *list) -{ - tdm_buffer_info *buf_info = NULL; - - TDM_RETURN_VAL_IF_FAIL(list != NULL, NULL); - - if (LIST_IS_EMPTY(list)) - return NULL; - - buf_info = container_of((list)->next, buf_info, link); - - return buf_info->buffer; -} - -INTERN void -tdm_buffer_list_dump(struct list_head *list) -{ - tdm_buffer_info *buf_info = NULL; - char str[256], *p; - int len = sizeof(str); - - TDM_RETURN_IF_FAIL(list != NULL); - - p = str; - LIST_FOR_EACH_ENTRY(buf_info, list, link) { - if (len > 0) { - int l = snprintf(p, len, " %p", buf_info->buffer); - p += l; - len -= l; - } else - break; - } - - TDM_INFO("\t %s", str); -} diff --git a/src/tdm_private.h b/src/tdm_private.h index 5a07b89..a055105 100644 --- a/src/tdm_private.h +++ b/src/tdm_private.h @@ -200,11 +200,6 @@ tdm_capture_destroy_internal(tdm_private_capture *private_capture); /* utility buffer functions for private */ tdm_buffer_info* tdm_buffer_get_info(tbm_surface_h buffer); -tbm_surface_h -tdm_buffer_list_get_first_entry(struct list_head *list); -void -tdm_buffer_list_dump(struct list_head *list); - void tdm_buffer_remove_release_handler_internal(tbm_surface_h buffer); -- 2.7.4 From 7951d09e6a7d1029481935ac3399084dbc673427 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Fri, 12 Jan 2018 17:31:29 +0900 Subject: [PATCH 12/16] ini: first implementation Change-Id: I9e2fd2892279fbc84d1265802b5b33ef6d68dc27 --- configure.ac | 11 +- include/tdm_backend.h | 23 ++++ packaging/libtdm.spec | 2 + src/Makefile.am | 1 + src/tdm.c | 12 ++ src/tdm_config.c | 283 ++++++++++++++++++++++++++++++++++++++++++++++++ src/tdm_config.h | 67 ++++++++++++ src/tdm_private.h | 1 + tools/tdm_test_server.c | 4 +- 9 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 src/tdm_config.c create mode 100644 src/tdm_config.h diff --git a/configure.ac b/configure.ac index 9a706cf..02919f8 100644 --- a/configure.ac +++ b/configure.ac @@ -44,7 +44,7 @@ fi PKG_CHECK_MODULES(WAYLAND_SCANNER, wayland-scanner >= 1.7.0) -PKG_CHECK_MODULES(TDM, dlog libtbm libpng pixman-1 wayland-server) +PKG_CHECK_MODULES(TDM, dlog libtbm libpng pixman-1 wayland-server iniparser) PKG_CHECK_MODULES(TDM_CLIENT, dlog wayland-client) PKG_CHECK_MODULES(TTRACE, @@ -72,6 +72,14 @@ AC_ARG_WITH(tdm-module-path, AS_HELP_STRING([--with-tdm-module-path=PATH], [tdm AC_DEFINE_UNQUOTED(TDM_MODULE_PATH, "${TDM_MODULE_PATH}", [Directory for the modules of tdm]) AC_SUBST(TDM_MODULE_PATH) +# set the data dir for the tdm config +DEFAULT_TDM_DATA_PATH="${datadir}/tdm" +AC_ARG_WITH(tdm-data-path, AS_HELP_STRING([--with-tdm-data-path=PATH], [tdm data dir]), + [ TDM_DATA_PATH="$withval" ], + [ TDM_DATA_PATH="${DEFAULT_TDM_DATA_PATH}" ]) +AC_DEFINE_UNQUOTED(TDM_DATA_PATH, "${TDM_DATA_PATH}", [Directory for the data of tdm]) +AC_SUBST(TDM_DATA_PATH) + AC_SUBST([TDM_MAJOR_VERSION], [tdm_major_version]) AC_SUBST([TDM_MINOR_VERSION], [tdm_minor_version]) AC_SUBST([TDM_MICRO_VERSION], [tdm_micro_version]) @@ -105,4 +113,5 @@ echo "TDM_LIBS : $TDM_LIBS" echo "TDM_CLIENT_CFLAGS : $TDM_CLIENT_CFLAGS" echo "TDM_CLIENT_LIBS : $TDM_CLIENT_LIBS" echo "TDM_MODULE_PATH : $TDM_MODULE_PATH" +echo "TDM_DATA_PATH : $TDM_DATA_PATH" echo "" diff --git a/include/tdm_backend.h b/include/tdm_backend.h index 09b1377..de6fb24 100644 --- a/include/tdm_backend.h +++ b/include/tdm_backend.h @@ -1446,6 +1446,29 @@ void tdm_event_loop_source_remove(tdm_event_loop_source *source); /** + * @brief Get the ini value with given key + * @details + * @param[in] key The given key + * @param[in] default_value The default value + * @return the value of given key if success. Otherwise, default_value. + * @see #tdm_config_get_string + */ +int +tdm_config_get_int(const char *key, int default_value); + +/** + * @brief Get the ini value with given key + * @details + * @param[in] key The given key + * @param[in] default_value The default value + * @return the value of given key if success. Otherwise, default_value. + * @see #tdm_config_get_int + */ +const char * +tdm_config_get_string(const char *key, const char *default_value); + + +/** * @brief Trigger a 'need to validate' event. * @param[in] output The output the event should be triggered for. * @note The global display lock has to be locked before the call to this function. diff --git a/packaging/libtdm.spec b/packaging/libtdm.spec index 876648f..7140089 100644 --- a/packaging/libtdm.spec +++ b/packaging/libtdm.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(libtbm) BuildRequires: pkgconfig(libpng) BuildRequires: pkgconfig(ttrace) BuildRequires: pkgconfig(wayland-server) +BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(pixman-1) BuildRequires: gtest-devel @@ -82,6 +83,7 @@ LDFLAGS+=" -lgcov" %endif %reconfigure --disable-static --with-utests=${UTEST} \ + --with-tdm-data-path=%{TZ_SYS_RO_SHARE}/tdm \ CFLAGS="${CFLAGS} -Wall -Werror" \ CXXFLAGS="${CXXFLAGS} -Wall -Werror" \ LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed" diff --git a/src/Makefile.am b/src/Makefile.am index feabb5d..7ec1cd4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,7 @@ libtdm_la_CFLAGS = \ libtdm_la_SOURCES = \ $(top_srcdir)/protocol/tdm-protocol.c \ tdm_backend.c \ + tdm_config.c \ tdm_server.c \ tdm_vblank.c \ tdm_event_loop.c \ diff --git a/src/tdm.c b/src/tdm.c index 312bac9..96bed27 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -943,6 +943,14 @@ tdm_display_init(tdm_error *error) start = stamp1 = tdm_helper_get_time(); + 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); + stamp1 = stamp2; + private_display = calloc(1, sizeof(tdm_private_display)); if (!private_display) { /* LCOV_EXCL_START */ @@ -1077,6 +1085,8 @@ failed_vblank: failed_mutex_init: free(private_display); failed_alloc: + tdm_config_deinit(); +failed_config: if (error) *error = ret; pthread_mutex_unlock(&gLock); @@ -1131,6 +1141,8 @@ tdm_display_deinit(tdm_display *dpy) tdm_debug_dump_dir = NULL; } + tdm_config_deinit(); + pthread_mutex_unlock(&gLock); TDM_INFO("done"); diff --git a/src/tdm_config.c b/src/tdm_config.c new file mode 100644 index 0000000..6686769 --- /dev/null +++ b/src/tdm_config.c @@ -0,0 +1,283 @@ +/************************************************************************** + * + * libtdm + * + * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Eunchul Kim , + * JinYoung Jeon , + * Taeheon Kim , + * YoungJun Cho , + * SooChan Lim , + * Boram Park + * + * 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 + +#include "tdm_log.h" +#include "tdm_macro.h" +#include "tdm_list.h" +#include "tdm.h" +#include "tdm_private.h" +#include "tdm_config.h" + +#define TDM_CONFIG_FILENAME "tdm.ini" +#define TDM_CONFIG_GENERAL_SECTION "general" + +static dictionary *g_dic = NULL; +static pthread_mutex_t g_dic_lock; + +static int +_tdm_config_check_file_owner(const char *filepath) +{ + struct stat sb; + + if (stat(filepath, &sb) < 0) { + TDM_WRN("%s: %m", filepath); + return -1; + } + + if (sb.st_uid != getuid()) { + TDM_WRN("'%s': not owned by %u", filepath, getuid()); + return -1; + } + + return 0; +} + +static dictionary * +_tdm_config_load_file(const char *dir, const char *filename) +{ + char filepath[TDM_PATH_LEN]; + dictionary *dic; + + snprintf(filepath, sizeof filepath, "%s/%s", dir, filename); + + if (_tdm_config_check_file_owner(filepath) < 0) + return NULL; + + dic = iniparser_load(filepath); + TDM_RETURN_VAL_IF_FAIL(dic != NULL, NULL); + + if (!iniparser_find_entry(dic, TDM_CONFIG_GENERAL_SECTION)) { + TDM_ERR("no '%s' section: '%s'", TDM_CONFIG_GENERAL_SECTION, filepath); + iniparser_freedict(dic); + return NULL; + } + + TDM_INFO("opened successed: '%s'", filepath); + + return dic; +} + +static dictionary * +_tdm_config_load(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); + } + + return dic; +} + +INTERN tdm_error +tdm_config_init(void) +{ + if (g_dic) { + TDM_ERR("init failed: twice"); + return TDM_ERROR_OPERATION_FAILED; + } + + if (pthread_mutex_init(&g_dic_lock, NULL)) { + TDM_ERR("mutex init failed: %m"); + 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; + } + } + + TDM_INFO("tdm config init done (%p)", g_dic); + + return TDM_ERROR_NONE; +} + +INTERN void +tdm_config_deinit(void) +{ + if (!g_dic) { + return; + } + + iniparser_freedict(g_dic); + g_dic = NULL; + + /* we don't need to lock/unlock here because we come here + * after tdm_thread has been destroyed + */ + pthread_mutex_destroy(&g_dic_lock); + + TDM_INFO("tdm config deinit done"); +} + +static const char* +_tdm_config_get_string_internal(dictionary *dic, const char *key, const char *default_value) +{ + char *temp = NULL; + const char *result; + + if (default_value) { + temp = strdup(default_value); + if (!temp) { + TDM_ERR("strdup failed: %m"); + return default_value; + } + } + + result = (const char *)iniparser_getstring(dic, key, temp); + if (!result || strlen(result) == 0) { + free(temp); + return default_value; + } + + free(temp); + + return result; +} + +INTERN int +tdm_config_get_int(const char *key, int default_value) +{ + const char *result; + int value; + + TDM_RETURN_VAL_IF_FAIL(key != NULL, default_value); + + if (!g_dic) { + TDM_INFO("%s = %d: default", key, default_value); + return default_value; + } + + pthread_mutex_lock(&g_dic_lock); + result = _tdm_config_get_string_internal(g_dic, key, NULL); + pthread_mutex_unlock(&g_dic_lock); + + if (!result) { + TDM_INFO("%s = %d: no key", key, default_value); + return default_value; + } + + value = (int)strtol(result, NULL, 0); + + TDM_INFO("%s = %d", key, value); + + return value; +} + +INTERN const char* +tdm_config_get_string(const char *key, const char *default_value) +{ + const char *result; + + TDM_RETURN_VAL_IF_FAIL(key != NULL, default_value); + + if (!g_dic) { + TDM_INFO("%s = %s: default", key, default_value); + return default_value; + } + + pthread_mutex_lock(&g_dic_lock); + result = _tdm_config_get_string_internal(g_dic, key, default_value); + pthread_mutex_unlock(&g_dic_lock); + + TDM_INFO("%s = %s", key, result); + + return result; +} + +INTERN tdm_error +tdm_config_set_int(const char *key, int value) +{ + char temp[TDM_NAME_LEN]; + int ret; + + TDM_RETURN_VAL_IF_FAIL(key != NULL, TDM_ERROR_INVALID_PARAMETER); + + if (!g_dic) { + TDM_INFO("%s = %d set failed", key, value); + return TDM_ERROR_BAD_REQUEST; + } + + snprintf(temp, sizeof temp, "%d", value); + + pthread_mutex_lock(&g_dic_lock); + ret = iniparser_set(g_dic, key, (const char*)temp); + pthread_mutex_unlock(&g_dic_lock); + + TDM_RETURN_VAL_IF_FAIL(ret == 0, TDM_ERROR_OPERATION_FAILED); + + TDM_INFO("%s = %d set done", key, value); + + return TDM_ERROR_NONE; +} + +INTERN tdm_error +tdm_config_set_string(const char *key, const char *value) +{ + int ret; + + TDM_RETURN_VAL_IF_FAIL(key != NULL, TDM_ERROR_INVALID_PARAMETER); + + if (!g_dic) { + TDM_INFO("%s = %s set failed", key, value); + return TDM_ERROR_BAD_REQUEST; + } + + pthread_mutex_lock(&g_dic_lock); + ret = iniparser_set(g_dic, key, value); + pthread_mutex_unlock(&g_dic_lock); + + TDM_RETURN_VAL_IF_FAIL(ret == 0, TDM_ERROR_OPERATION_FAILED); + + TDM_INFO("%s = %s set done", key, value); + + return TDM_ERROR_NONE; +} diff --git a/src/tdm_config.h b/src/tdm_config.h new file mode 100644 index 0000000..b743f93 --- /dev/null +++ b/src/tdm_config.h @@ -0,0 +1,67 @@ +/************************************************************************** + * + * libtdm + * + * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Eunchul Kim , + * JinYoung Jeon , + * Taeheon Kim , + * YoungJun Cho , + * SooChan Lim , + * Boram Park + * + * 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. + * +**************************************************************************/ + +#ifndef _TDM_CONFIG_H_ +#define _TDM_CONFIG_H_ + +#include "tdm_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tdm_common.h" + +/** + * @file tdm_config.h + * @brief The config header file for a frontend library + */ + +tdm_error +tdm_config_init(void); +void +tdm_config_deinit(void); + +tdm_error +tdm_config_set_int(const char *key, int value); +tdm_error +tdm_config_set_string(const char *key, const char *value); + + +#ifdef __cplusplus +} +#endif + +#endif /* _TDM_CONFIG_H_ */ diff --git a/src/tdm_private.h b/src/tdm_private.h index a055105..f7c2a11 100644 --- a/src/tdm_private.h +++ b/src/tdm_private.h @@ -64,6 +64,7 @@ #include "tdm_macro.h" #include "tdm_helper.h" #include "tdm_thread.h" +#include "tdm_config.h" #ifdef __cplusplus extern "C" { diff --git a/tools/tdm_test_server.c b/tools/tdm_test_server.c index 52e0f61..db70668 100644 --- a/tools/tdm_test_server.c +++ b/tools/tdm_test_server.c @@ -183,7 +183,6 @@ usage(char *app_name) printf("\t%s\n", usages[t].desc); } printf("\n"); - exit(0); } //////////////////////////////////////////////////////////////////////////////// @@ -316,6 +315,7 @@ struct _tdm_test_server { tdm_display *display; }; +static void destroy(tdm_test_server *data); static void run_test(tdm_test_server *data); static void output_setup(tdm_test_server_output *o); static void layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b); @@ -517,6 +517,7 @@ parse_args(tdm_test_server *data, int argc, char *argv[]) if (argc < 2) { usage(argv[0]); + destroy(data); exit(0); } @@ -597,6 +598,7 @@ parse_args(tdm_test_server *data, int argc, char *argv[]) data->do_vblank = 1; } else { usage(argv[0]); + destroy(data); exit(0); } } -- 2.7.4 From 6cb389489783e8ef807cb31da6c1f22a17dad06f Mon Sep 17 00:00:00 2001 From: Boram Park Date: Mon, 29 Jan 2018 16:54:28 +0900 Subject: [PATCH 13/16] ini: not using getenv Change-Id: I82ccecd7a09d5b4e1e5c391b4499ac47e307c96c --- common/tdm_log.c | 61 ++++++++++++++------------ include/tdm_log.h | 2 + src/tdm.c | 108 ++++++++++++----------------------------------- src/tdm_config.c | 50 ++++++++++++---------- src/tdm_config.h | 62 +++++++++++++++++++++++++++ src/tdm_monitor_server.c | 5 +-- src/tdm_private.h | 2 - src/tdm_thread.c | 8 ++-- 8 files changed, 157 insertions(+), 141 deletions(-) diff --git a/common/tdm_log.c b/common/tdm_log.c index 2f7152b..0bad256 100644 --- a/common/tdm_log.c +++ b/common/tdm_log.c @@ -49,8 +49,6 @@ #include "tdm_log.h" #include "tdm_macro.h" -//#define TDM_CONFIG_ASSERT - #define LOG_MAX_LEN 4076 #define COLOR_RED "\x1b[31m" /* for error */ @@ -64,32 +62,13 @@ 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) { @@ -118,6 +97,37 @@ tdm_log_set_debug_level(int level) } 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; @@ -128,11 +138,6 @@ tdm_log_print(int level, const char *fmt, ...) } - if (need_check_env) { - need_check_env = 0; - _tdm_log_check_env(); - } - if (level > tdm_log_debug_level) return; @@ -180,7 +185,7 @@ tdm_log_print(int level, const char *fmt, ...) } #ifdef TDM_CONFIG_ASSERT - if (level < 3) + if (level <= assert_level) assert(0); #endif } diff --git a/include/tdm_log.h b/include/tdm_log.h index 1cab32d..7ee4d95 100644 --- a/include/tdm_log.h +++ b/include/tdm_log.h @@ -68,6 +68,8 @@ void tdm_log_enable_color(unsigned int enable); 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; diff --git a/src/tdm.c b/src/tdm.c index 96bed27..2b0de50 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -865,47 +865,30 @@ failed_load: 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; } @@ -930,6 +913,7 @@ tdm_display_init(tdm_error *error) const char *str; tdm_error ret; double stamp1, stamp2, start; + int mode; pthread_mutex_lock(&gLock); @@ -943,12 +927,13 @@ tdm_display_init(tdm_error *error) 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)); @@ -960,18 +945,14 @@ tdm_display_init(tdm_error *error) /* 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; @@ -995,7 +976,7 @@ tdm_display_init(tdm_error *error) 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); @@ -1003,7 +984,7 @@ tdm_display_init(tdm_error *error) 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 @@ -1048,11 +1029,9 @@ tdm_display_init(tdm_error *error) /* 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) */ @@ -1193,7 +1172,7 @@ tdm_display_enable_debug_module(const char*modules) 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; @@ -1214,7 +1193,7 @@ tdm_display_enable_debug_module(const char*modules) 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); @@ -1314,39 +1293,6 @@ done: 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) @@ -1436,7 +1382,7 @@ tdm_display_enable_ttrace(tdm_private_display *private_display, const char *ttra 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; @@ -1464,7 +1410,7 @@ tdm_display_enable_ttrace(tdm_private_display *private_display, const char *ttra 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); diff --git a/src/tdm_config.c b/src/tdm_config.c index 6686769..15cc877 100644 --- a/src/tdm_config.c +++ b/src/tdm_config.c @@ -95,22 +95,27 @@ _tdm_config_load_file(const char *dir, const char *filename) 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 @@ -126,14 +131,9 @@ tdm_config_init(void) 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); @@ -250,6 +250,9 @@ tdm_config_set_int(const char *key, int value) 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); @@ -273,6 +276,9 @@ tdm_config_set_string(const char *key, const char *value) 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); diff --git a/src/tdm_config.h b/src/tdm_config.h index b743f93..2592643 100644 --- a/src/tdm_config.h +++ b/src/tdm_config.h @@ -60,6 +60,68 @@ tdm_error 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 diff --git a/src/tdm_monitor_server.c b/src/tdm_monitor_server.c index 6fdb190..f1edee7 100644 --- a/src/tdm_monitor_server.c +++ b/src/tdm_monitor_server.c @@ -181,10 +181,7 @@ _tdm_monitor_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[] 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); diff --git a/src/tdm_private.h b/src/tdm_private.h index f7c2a11..ff8e244 100644 --- a/src/tdm_private.h +++ b/src/tdm_private.h @@ -247,8 +247,6 @@ tdm_display_enable_debug_module(const char*modules); 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); diff --git a/src/tdm_thread.c b/src/tdm_thread.c index f71f3a1..a3e7cf0 100644 --- a/src/tdm_thread.c +++ b/src/tdm_thread.c @@ -120,7 +120,7 @@ tdm_thread_init(tdm_private_loop *private_loop) { 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); @@ -132,9 +132,9 @@ tdm_thread_init(tdm_private_loop *private_loop) 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; } -- 2.7.4 From 60f1b2e516e4ea7bfa581a77897ce1a8d21b3603 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 20 Feb 2018 18:17:32 +0900 Subject: [PATCH 14/16] config: export tdm_config functions Change-Id: I95bcd81ba94b21a7383f88e99a5b254effb10597 --- include/Makefile.am | 1 + {src => include}/tdm_config.h | 0 packaging/libtdm.spec | 1 + src/tdm.c | 7 ----- src/tdm_config.c | 71 +++++++++++++++++++++++-------------------- 5 files changed, 40 insertions(+), 40 deletions(-) rename {src => include}/tdm_config.h (100%) diff --git a/include/Makefile.am b/include/Makefile.am index aa1d502..ce83e6e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -4,6 +4,7 @@ libtdminclude_HEADERS = \ tdm_common.h \ tdm_types.h \ tdm_list.h \ + tdm_config.h \ tdm_log.h \ tdm_backend.h \ tdm_helper.h diff --git a/src/tdm_config.h b/include/tdm_config.h similarity index 100% rename from src/tdm_config.h rename to include/tdm_config.h diff --git a/packaging/libtdm.spec b/packaging/libtdm.spec index 7140089..a8f8003 100644 --- a/packaging/libtdm.spec +++ b/packaging/libtdm.spec @@ -128,6 +128,7 @@ rm -f %{_unitdir_user}/basic.target.wants/tdm-socket-user.path %{_includedir}/tdm_list.h %{_includedir}/tdm_log.h %{_includedir}/tdm_types.h +%{_includedir}/tdm_config.h %{_libdir}/pkgconfig/libtdm.pc %{_libdir}/libtdm.so diff --git a/src/tdm.c b/src/tdm.c index 2b0de50..6306966 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -927,11 +927,6 @@ tdm_display_init(tdm_error *error) 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_INFO("config init time: %.3f ms", (stamp2 - stamp1) * 1000.0); stamp1 = stamp2; @@ -1064,8 +1059,6 @@ failed_vblank: failed_mutex_init: free(private_display); failed_alloc: - tdm_config_deinit(); -failed_config: if (error) *error = ret; pthread_mutex_unlock(&gLock); diff --git a/src/tdm_config.c b/src/tdm_config.c index 15cc877..4c66e07 100644 --- a/src/tdm_config.c +++ b/src/tdm_config.c @@ -49,8 +49,8 @@ #define TDM_CONFIG_FILENAME "tdm.ini" #define TDM_CONFIG_GENERAL_SECTION "general" +static pthread_mutex_t g_dic_lock = PTHREAD_MUTEX_INITIALIZER; static dictionary *g_dic = NULL; -static pthread_mutex_t g_dic_lock; static int _tdm_config_check_file_owner(const char *filepath) @@ -101,6 +101,8 @@ _tdm_config_check_logs(void) const char *path; int level; + pthread_mutex_unlock(&g_dic_lock); + level = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_LOG_LEVEL, 3); tdm_log_set_debug_level(level); @@ -116,46 +118,41 @@ _tdm_config_check_logs(void) int dlog = tdm_config_get_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); tdm_log_enable_dlog(dlog); } + + pthread_mutex_lock(&g_dic_lock); } -INTERN tdm_error -tdm_config_init(void) +static unsigned int +_tdm_config_check_init(void) { - if (g_dic) { - TDM_ERR("init failed: twice"); - return TDM_ERROR_OPERATION_FAILED; - } - - if (pthread_mutex_init(&g_dic_lock, NULL)) { - TDM_ERR("mutex init failed: %m"); - return TDM_ERROR_OUT_OF_MEMORY; - } + if (g_dic) + return 1; 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); + TDM_INFO("tdm config init %s (%p)", (g_dic) ? "successed" : "failed", g_dic); - return TDM_ERROR_NONE; + return (g_dic) ? 1 : 0; } INTERN void tdm_config_deinit(void) { + pthread_mutex_lock(&g_dic_lock); + if (!g_dic) { + pthread_mutex_unlock(&g_dic_lock); return; } iniparser_freedict(g_dic); g_dic = NULL; - /* we don't need to lock/unlock here because we come here - * after tdm_thread has been destroyed - */ - pthread_mutex_destroy(&g_dic_lock); - TDM_INFO("tdm config deinit done"); + + pthread_mutex_unlock(&g_dic_lock); } static const char* @@ -183,7 +180,7 @@ _tdm_config_get_string_internal(dictionary *dic, const char *key, const char *de return result; } -INTERN int +EXTERN int tdm_config_get_int(const char *key, int default_value) { const char *result; @@ -191,12 +188,14 @@ tdm_config_get_int(const char *key, int default_value) TDM_RETURN_VAL_IF_FAIL(key != NULL, default_value); - if (!g_dic) { + pthread_mutex_lock(&g_dic_lock); + + if (!_tdm_config_check_init()) { TDM_INFO("%s = %d: default", key, default_value); + pthread_mutex_unlock(&g_dic_lock); return default_value; } - pthread_mutex_lock(&g_dic_lock); result = _tdm_config_get_string_internal(g_dic, key, NULL); pthread_mutex_unlock(&g_dic_lock); @@ -212,19 +211,21 @@ tdm_config_get_int(const char *key, int default_value) return value; } -INTERN const char* +EXTERN const char* tdm_config_get_string(const char *key, const char *default_value) { const char *result; TDM_RETURN_VAL_IF_FAIL(key != NULL, default_value); - if (!g_dic) { + pthread_mutex_lock(&g_dic_lock); + + if (!_tdm_config_check_init()) { TDM_INFO("%s = %s: default", key, default_value); + pthread_mutex_unlock(&g_dic_lock); return default_value; } - pthread_mutex_lock(&g_dic_lock); result = _tdm_config_get_string_internal(g_dic, key, default_value); pthread_mutex_unlock(&g_dic_lock); @@ -233,7 +234,7 @@ tdm_config_get_string(const char *key, const char *default_value) return result; } -INTERN tdm_error +EXTERN tdm_error tdm_config_set_int(const char *key, int value) { char temp[TDM_NAME_LEN]; @@ -241,14 +242,16 @@ tdm_config_set_int(const char *key, int value) TDM_RETURN_VAL_IF_FAIL(key != NULL, TDM_ERROR_INVALID_PARAMETER); - if (!g_dic) { + snprintf(temp, sizeof temp, "%d", value); + + pthread_mutex_lock(&g_dic_lock); + + if (!_tdm_config_check_init()) { TDM_INFO("%s = %d set failed", key, value); + pthread_mutex_unlock(&g_dic_lock); return TDM_ERROR_BAD_REQUEST; } - snprintf(temp, sizeof temp, "%d", value); - - pthread_mutex_lock(&g_dic_lock); ret = iniparser_set(g_dic, key, (const char*)temp); _tdm_config_check_logs(); @@ -262,19 +265,21 @@ tdm_config_set_int(const char *key, int value) return TDM_ERROR_NONE; } -INTERN tdm_error +EXTERN tdm_error tdm_config_set_string(const char *key, const char *value) { int ret; TDM_RETURN_VAL_IF_FAIL(key != NULL, TDM_ERROR_INVALID_PARAMETER); - if (!g_dic) { + pthread_mutex_lock(&g_dic_lock); + + if (!_tdm_config_check_init()) { TDM_INFO("%s = %s set failed", key, value); + pthread_mutex_unlock(&g_dic_lock); return TDM_ERROR_BAD_REQUEST; } - pthread_mutex_lock(&g_dic_lock); ret = iniparser_set(g_dic, key, value); _tdm_config_check_logs(); -- 2.7.4 From 7f9b27be3fc997cc631dc6f0a98409a29bd326ec Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 20 Feb 2018 18:17:58 +0900 Subject: [PATCH 15/16] utests: not using setenv Change-Id: I734c97d423ddf0dc85068fea9cf3f7393d6ab681 --- utests/src/ut_tdm_buffer.cpp | 10 ++++------ utests/src/ut_tdm_capture.cpp | 12 ++++-------- utests/src/ut_tdm_client.cpp | 4 ++++ utests/src/ut_tdm_display.cpp | 15 +++++++-------- utests/src/ut_tdm_event_loop.cpp | 10 ++++------ utests/src/ut_tdm_helper.cpp | 8 ++++---- utests/src/ut_tdm_hwc_window.cpp | 16 ++++------------ utests/src/ut_tdm_layer.cpp | 35 +++++++++++------------------------ utests/src/ut_tdm_output.cpp | 17 +++++------------ utests/src/ut_tdm_pp.cpp | 12 ++++-------- utests/src/ut_tdm_vblank.cpp | 8 ++++++-- 11 files changed, 57 insertions(+), 90 deletions(-) diff --git a/utests/src/ut_tdm_buffer.cpp b/utests/src/ut_tdm_buffer.cpp index db5c4ca..6896547 100644 --- a/utests/src/ut_tdm_buffer.cpp +++ b/utests/src/ut_tdm_buffer.cpp @@ -4,6 +4,7 @@ extern "C" { #include "tdm.h" +#include "tdm_config.h" #include "tdm_backend.h" #include "tbm_bufmgr.h" #include "tbm_surface.h" @@ -23,18 +24,15 @@ protected: static void SetEnv(void) { - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); - setenv("TDM_THREAD", "0", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } static void UnsetEnv(void) { - unsetenv("TDM_DEBUG_MODULE"); - unsetenv("TDM_DEBUG"); - unsetenv("TDM_THREAD"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DISPLAY_SERVER"); } diff --git a/utests/src/ut_tdm_capture.cpp b/utests/src/ut_tdm_capture.cpp index 068220a..4ebcc5a 100644 --- a/utests/src/ut_tdm_capture.cpp +++ b/utests/src/ut_tdm_capture.cpp @@ -31,6 +31,7 @@ #include "gtest/gtest.h" #include "ut_tdm.h" #include "tdm.h" +#include "tdm_config.h" extern "C" { #include "tbm_bufmgr.h" #include "tbm_drm_helper.h" @@ -50,21 +51,16 @@ protected: virtual void SetEnvs() { - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } virtual void UnsetEnvs() { - unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); - unsetenv("TDM_DEBUG_MODULE"); - unsetenv("TDM_DEBUG"); unsetenv("TBM_DISPLAY_SERVER"); } diff --git a/utests/src/ut_tdm_client.cpp b/utests/src/ut_tdm_client.cpp index adb71d5..1b65ed4 100644 --- a/utests/src/ut_tdm_client.cpp +++ b/utests/src/ut_tdm_client.cpp @@ -47,6 +47,7 @@ extern "C" { #include "tdm.h" +#include "tdm_config.h" #include "tdm_client.h" #include "tbm_surface.h" @@ -151,6 +152,9 @@ private: { setenv("XDG_RUNTIME_DIR", "/run", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } void unset_env_vars(void) diff --git a/utests/src/ut_tdm_display.cpp b/utests/src/ut_tdm_display.cpp index 2ba98ca..a80fb47 100644 --- a/utests/src/ut_tdm_display.cpp +++ b/utests/src/ut_tdm_display.cpp @@ -31,6 +31,7 @@ #include "gtest/gtest.h" extern "C" { #include "tdm.h" +#include "tdm_config.h" #include "tbm_bufmgr.h" #include "tbm_drm_helper.h" } @@ -40,10 +41,11 @@ protected: int master_fd = -42, tbm_fd = -42; void SetUp(void) { - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } void TearDown(void) { @@ -61,9 +63,7 @@ protected: exit(1); close(tbm_fd); } - unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); unsetenv("TBM_DISPLAY_SERVER"); } }; @@ -75,10 +75,11 @@ protected: int master_fd = -42, tbm_fd = -42; void SetUp(void) { - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); tbm_bufmgr = tbm_bufmgr_init(-1); ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; @@ -108,9 +109,7 @@ protected: exit(1); close(tbm_fd); } - unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); unsetenv("TBM_DISPLAY_SERVER"); } }; diff --git a/utests/src/ut_tdm_event_loop.cpp b/utests/src/ut_tdm_event_loop.cpp index b0dc4e7..e8ecaaa 100644 --- a/utests/src/ut_tdm_event_loop.cpp +++ b/utests/src/ut_tdm_event_loop.cpp @@ -5,6 +5,7 @@ extern "C" { #include "tdm.h" +#include "tdm_config.h" #include "tdm_backend.h" #include "tbm_bufmgr.h" #include "tbm_surface.h" @@ -22,18 +23,15 @@ protected: static void SetEnv(void) { - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); - setenv("TDM_THREAD", "0", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 0); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } static void UnsetEnv(void) { - unsetenv("TDM_DEBUG_MODULE"); - unsetenv("TDM_DEBUG"); - unsetenv("TDM_THREAD"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DISPLAY_SERVER"); } diff --git a/utests/src/ut_tdm_helper.cpp b/utests/src/ut_tdm_helper.cpp index b9d8ba4..a093ffc 100644 --- a/utests/src/ut_tdm_helper.cpp +++ b/utests/src/ut_tdm_helper.cpp @@ -7,6 +7,7 @@ extern "C" { #include "tdm.h" +#include "tdm_config.h" #include "tdm_helper.h" #include "tdm_backend.h" #include "tbm_bufmgr.h" @@ -31,16 +32,15 @@ protected: tbm_surface_h surface; virtual void SetEnv() { - setenv("TDM_THREAD", "0", 1); - setenv("TDM_COMMIT_PER_VBLANK", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 1); } void UnsetEnv() { - unsetenv("TDM_THREAD"); - unsetenv("TDM_COMMIT_PER_VBLANK"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DISPLAY_SERVER"); } diff --git a/utests/src/ut_tdm_hwc_window.cpp b/utests/src/ut_tdm_hwc_window.cpp index 52ebc5b..aaa5d50 100644 --- a/utests/src/ut_tdm_hwc_window.cpp +++ b/utests/src/ut_tdm_hwc_window.cpp @@ -34,6 +34,7 @@ #include "stdint.h" #include "tdm.h" +#include "tdm_config.h" #include "tdm_backend.h" extern "C" { #include "tbm_bufmgr.h" @@ -52,27 +53,18 @@ protected: tdm_error error ; virtual void SetEnv() { - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); - setenv("TDM_THREAD", "1", 1); - setenv("TDM_COMMIT_PER_VBLANK", "1", 1); - setenv("TDM_DLOG", "1", 1); setenv("TDM_HWC", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 1); } void UnsetEnv() { - unsetenv("TDM_DEBUG_MODULE"); - unsetenv("TDM_DEBUG"); - unsetenv("TDM_THREAD"); - unsetenv("TDM_COMMIT_PER_VBLANK"); - unsetenv("TDM_DLOG"); unsetenv("TDM_HWC"); unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); unsetenv("TBM_DISPLAY_SERVER"); } diff --git a/utests/src/ut_tdm_layer.cpp b/utests/src/ut_tdm_layer.cpp index 051c41f..dba3023 100644 --- a/utests/src/ut_tdm_layer.cpp +++ b/utests/src/ut_tdm_layer.cpp @@ -36,6 +36,8 @@ #include #include "tdm.h" +#include "tdm_config.h" + extern "C" { #include "tbm_bufmgr.h" #include "tbm_drm_helper.h" @@ -56,14 +58,11 @@ protected: bool has_layers = false; virtual void SetEnv() { - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); - setenv("TDM_THREAD", "0", 1); - setenv("TDM_COMMIT_PER_VBLANK", "1", 1); - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 1); } void SetUp(void) { @@ -200,13 +199,7 @@ protected: close(tbm_fd); } - unsetenv("TDM_DEBUG_MODULE"); - unsetenv("TDM_DEBUG"); - unsetenv("TDM_THREAD"); - unsetenv("TDM_COMMIT_PER_VBLANK"); - unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); unsetenv("TBM_DISPLAY_SERVER"); } @@ -359,14 +352,11 @@ class TDMLayerCommitThread : public TDMLayerCommit protected: void SetEnv() { - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); - setenv("TDM_THREAD", "1", 1); - setenv("TDM_COMMIT_PER_VBLANK", "1", 1); - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 1); } }; @@ -375,14 +365,11 @@ class TDMLayerCommitWithDisabledCommitPerVblank : public TDMLayerCommit protected: void SetEnv() { - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); - setenv("TDM_THREAD", "0", 1); - setenv("TDM_COMMIT_PER_VBLANK", "0", 1); - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } }; diff --git a/utests/src/ut_tdm_output.cpp b/utests/src/ut_tdm_output.cpp index 0355065..db15445 100644 --- a/utests/src/ut_tdm_output.cpp +++ b/utests/src/ut_tdm_output.cpp @@ -32,6 +32,7 @@ #include "ut_tdm.h" #include #include "tdm.h" +#include "tdm_config.h" extern "C" { #include "tbm_bufmgr.h" #include "tbm_drm_helper.h" @@ -59,24 +60,17 @@ protected: } virtual void SetEnvs() { - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); - setenv("TDM_COMMIT_PER_VBLANK", "0", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } virtual void UnsetEnvs() { - unsetenv("TDM_DEBUG_MODULE"); - unsetenv("TDM_DEBUG"); - unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); unsetenv("TBM_DISPLAY_SERVER"); - unsetenv("TDM_COMMIT_PER_VBLANK"); } void SetUp(void) @@ -397,12 +391,11 @@ class TDMOutputCommitPerVblankEnabled : public TDMOutputCommit { { TDMOutputCommit::SetEnvs(); - setenv("TDM_COMMIT_PER_VBLANK", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 1); } void UnsetEnvs(void) { TDMOutputCommit::UnsetEnvs(); - unsetenv("TDM_COMMIT_PER_VBLANK"); } }; diff --git a/utests/src/ut_tdm_pp.cpp b/utests/src/ut_tdm_pp.cpp index d420204..dd26f0e 100644 --- a/utests/src/ut_tdm_pp.cpp +++ b/utests/src/ut_tdm_pp.cpp @@ -31,6 +31,7 @@ #include "gtest/gtest.h" #include "ut_tdm.h" #include "tdm.h" +#include "tdm_config.h" extern "C" { #include "tbm_bufmgr.h" #include "tbm_drm_helper.h" @@ -53,21 +54,16 @@ protected: virtual void SetEnvs() { - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); } virtual void UnsetEnvs() { - unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); - unsetenv("TDM_DEBUG_MODULE"); - unsetenv("TDM_DEBUG"); unsetenv("TBM_DISPLAY_SERVER"); } diff --git a/utests/src/ut_tdm_vblank.cpp b/utests/src/ut_tdm_vblank.cpp index 9eed3dc..a1cdc4d 100644 --- a/utests/src/ut_tdm_vblank.cpp +++ b/utests/src/ut_tdm_vblank.cpp @@ -30,6 +30,7 @@ #include "gtest/gtest.h" #include "tdm.h" +#include "tdm_config.h" #include "tbm_bufmgr.h" #include "ut_tdm.h" #include @@ -52,10 +53,13 @@ protected: tdm_output_conn_status status; tdm_error error = TDM_ERROR_NONE; - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", "/run", 1); - setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_DLOG, 1); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, 0); + tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0); + tdm_config_set_int(TDM_CONFIG_KEY_DEBUG_LOG_LEVEL, 4); + tdm_config_set_string(TDM_CONFIG_KEY_DEBUG_MODULE, "vblank,thread"); /* FIXME: fix the error. If we initialize TBM before TDM we get fail * in the tdm_output_set_dpms */ -- 2.7.4 From ee6ae6a14f40cdae1c458e37d82c6b6f49bb444d Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 16 Jan 2018 11:12:55 +0900 Subject: [PATCH 16/16] server: remove useless codes Change-Id: I09d265a0a5ab8eda71826f55ce9e4b23e1a25048 --- src/tdm_private.h | 1 - src/tdm_server.c | 132 ------------------------------------------------------ 2 files changed, 133 deletions(-) diff --git a/src/tdm_private.h b/src/tdm_private.h index ff8e244..30dfb81 100644 --- a/src/tdm_private.h +++ b/src/tdm_private.h @@ -52,7 +52,6 @@ #include #include #include -#include #include #include diff --git a/src/tdm_server.c b/src/tdm_server.c index 8fc2336..1bb5683 100644 --- a/src/tdm_server.c +++ b/src/tdm_server.c @@ -808,136 +808,6 @@ _tdm_server_bind(struct wl_client *client, void *data, wl_resource_set_implementation(resource, &tdm_implementation, data, destroy_client); } -static int -_tdm_getgrnam_r(const char *name) -{ - struct group *grp = NULL; - struct group *grp_res = NULL; - char* buf = NULL; - size_t buf_len; - int ret; - int id; - - buf_len = sysconf(_SC_GETGR_R_SIZE_MAX); - if (buf_len == -1) - buf_len = 2048; - - buf = calloc(1, buf_len * sizeof(char)); - if (!buf) { - TDM_ERR("creating buffer failed"); - goto failed; - } - - grp = calloc(1, sizeof(struct group)); - if (!grp) { - TDM_ERR("creating group failed"); - goto failed; - } - - ret = getgrnam_r(name, grp, buf, buf_len, &grp_res); - if (ret < 0) { - TDM_ERR("getgrnam_r failed errno:%d(%m)", ret); - goto failed; - } - - if (grp_res == NULL) { - TDM_ERR("finding name:%s group failed", name); - goto failed; - } - - id = grp->gr_gid; - free(buf); - free(grp); - - return id; - -failed: - /* LCOV_EXCL_START */ - - if (buf) - free(buf); - if (grp) - free(grp); - - return -1; - - /* LCOV_EXCL_STOP */ -} - -static void -_tdm_socket_init(tdm_private_loop *private_loop) -{ - const char *dir = NULL; - char socket_path[TDM_NAME_LEN * 2]; - int ret = -1, len; - uid_t uid; - gid_t gid; - - dir = getenv("XDG_RUNTIME_DIR"); - if (!dir) { - /* LCOV_EXCL_START */ - - TDM_WRN("getting XDG_RUNTIME_DIR failed"); - return; - - /* LCOV_EXCL_STOP */ - } - - len = strlen(dir); - if (len > TDM_NAME_LEN - 1) { - TDM_ERR("XDG_RUNTIME_DIR is too long\n"); - return; - } - - strncpy(socket_path, dir, TDM_NAME_LEN - 1); - socket_path[TDM_NAME_LEN - 1] = '\0'; - - strncat(socket_path, "/tdm-socket", 11); - socket_path[TDM_NAME_LEN + 10] = '\0'; - - ret = chmod(socket_path, 509); - if (ret < 0) { - /* LCOV_EXCL_START */ - - TDM_WRN("changing modes of socket file failed:%s (%m)", socket_path); - return; - - /* LCOV_EXCL_STOP */ - } - - ret = _tdm_getgrnam_r("root"); - if (ret < 0) { - /* LCOV_EXCL_START */ - - TDM_WRN("getting uid failed"); - return; - - /* LCOV_EXCL_STOP */ - } - uid = ret; - - ret = _tdm_getgrnam_r("display"); - if (ret < 0) { - /* LCOV_EXCL_START */ - - TDM_WRN("getting gid failed"); - return; - - /* LCOV_EXCL_STOP */ - } - gid = ret; - - ret = chown(socket_path, uid, gid); - if (ret < 0) { - /* LCOV_EXCL_START */ - - TDM_WRN("changing owner of socket file failed:%s (%m)", socket_path); - return; - - /* LCOV_EXCL_STOP */ - } -} - INTERN tdm_error tdm_server_init(tdm_private_loop *private_loop) { @@ -958,8 +828,6 @@ tdm_server_init(tdm_private_loop *private_loop) /* LCOV_EXCL_STOP */ } - _tdm_socket_init(private_loop); - private_server = calloc(1, sizeof * private_server); if (!private_server) { TDM_ERR("alloc failed"); -- 2.7.4