From: SooChan Lim Date: Mon, 23 Apr 2018 06:14:08 +0000 (+0900) Subject: type_common: add tbm_##res##_str and tbm_error_str X-Git-Tag: submit/tizen/20180426.070622~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=feb8f8d40314c2c6e3f381a00cfe6fc8919465c0;p=platform%2Fcore%2Fuifw%2Flibtbm.git type_common: add tbm_##res##_str and tbm_error_str These macros makes integer values assigned string values. Change-Id: I7bb4596b59cef7c1ac5ed49f94e23d162519daa0 --- diff --git a/src/tbm_type_common.h b/src/tbm_type_common.h index 26facf7..1b8ab30 100644 --- a/src/tbm_type_common.h +++ b/src/tbm_type_common.h @@ -233,4 +233,38 @@ typedef enum { TBM_BUFGMR_DEBUG_TRACE_SURFACE_QUEUE = (1 << 3), } tbm_bufmgr_debug_trace_mask; +/* type to string ***********************************************************/ +struct tbm_type_name { + int type; + const char *name; +}; + +#define TBM_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#define TBM_TYPE_NAME_FN(res) \ +static inline const char * tbm_##res##_str(int type) \ +{ \ + unsigned int i; \ + for (i = 0; i < TBM_ARRAY_SIZE(tbm_##res##_names); i++) { \ + if (tbm_##res##_names[i].type == type) \ + return tbm_##res##_names[i].name; \ + } \ + return "(invalid)"; \ +} + +static struct tbm_type_name tbm_error_names[] = { + { TBM_ERROR_NONE, "TBM_ERROR_NONE" }, + { TBM_ERROR_OUT_OF_MEMORY, "TBM_ERROR_OUT_OF_MEMORY" }, + { TBM_ERROR_INVALID_PARAMETER, "TBM_ERROR_INVALID_PARAMETER" }, + { TBM_ERROR_INVALID_OPERATION, "TBM_ERROR_INVALID_OPERATION" }, + { TBM_ERROR_NOT_SUPPORTED, "TBM_ERROR_NOT_SUPPORTED" }, + { TBM_SURFACE_QUEUE_ERROR_EMPTY, "TBM_SURFACE_QUEUE_ERROR_EMPTY" }, + { TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE, "TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE" }, + { TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE, "TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE" }, + { TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED, "TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED" }, + { TBM_SURFACE_QUEUE_ERROR_ALREADY_EXIST, "TBM_SURFACE_QUEUE_ERROR_ALREADY_EXIST" }, + { TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE, "TBM_SURFACE_QUEUE_ERROR_UNKNOWN_SURFACE" }, +}; +TBM_TYPE_NAME_FN(error) + #endif /* _TBM_TYPE_COMMON_H_ */