diff options
Diffstat (limited to 'common/aitt_internal.h')
-rw-r--r-- | common/aitt_internal.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/common/aitt_internal.h b/common/aitt_internal.h new file mode 100644 index 0000000..feef42b --- /dev/null +++ b/common/aitt_internal.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2021-2022 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include <libgen.h> +#include <sys/syscall.h> +#include <unistd.h> + +#include <cassert> +#include <cerrno> +#include <cstring> + +#include "aitt_internal_definitions.h" +#include "aitt_platform.h" + +#if defined(SYS_gettid) +#define GETTID() syscall(SYS_gettid) +#else // SYS_gettid +#define GETTID() 0lu +#endif // SYS_gettid + +#define AITT_ERRMSG_LEN 80 + +#if (_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE +#define AITT_STRERROR_R(errno, buf, buflen) \ + do { \ + int ret = strerror_r(errno, buf, buflen); \ + if (ret != 0) { \ + assert(ret == 0 && "strerror_r failed"); \ + } \ + } while (0) +#else +#define AITT_STRERROR_R(errno, buf, buflen) \ + do { \ + const char *errstr = strerror_r(errno, buf, buflen); \ + if (errstr == nullptr) { \ + assert(errstr != nullptr && "strerror_r failed"); \ + } \ + } while (0) +#endif + +#ifdef _LOG_WITH_TIMESTAMP +#include "aitt_internal_profiling.h" +#else +#define DBG(fmt, ...) PLATFORM_LOGD("[%lu] " fmt, GETTID(), ##__VA_ARGS__) + +#define INFO(fmt, ...) PLATFORM_LOGI("[%lu] " fmt, GETTID(), ##__VA_ARGS__) +#define ERR(fmt, ...) PLATFORM_LOGE("[%lu] \033[31m" fmt "\033[0m", GETTID(), ##__VA_ARGS__) +#define ERR_CODE(_aitt_errno, fmt, ...) \ + do { \ + char errMsg[AITT_ERRMSG_LEN] = {'\0'}; \ + int _errno = (_aitt_errno); \ + AITT_STRERROR_R(_errno, errMsg, sizeof(errMsg)); \ + PLATFORM_LOGE("[%lu] (%d:%s) \033[31m" fmt "\033[0m", GETTID(), _errno, errMsg, \ + ##__VA_ARGS__); \ + } while (0) +#endif + +#define RET_IF(expr) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + return; \ + } \ + } while (0) + +#define RETV_IF(expr, val) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + return (val); \ + } \ + } while (0) + +#define RETVM_IF(expr, val, fmt, arg...) \ + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return (val); \ + } \ + } while (0) |