1 /******************************************************************************
2  *
3  *  Copyright 2020 NXP
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef _WEAVER_UTILS_H_
20 #define _WEAVER_UTILS_H_
21 
22 #include <log/log.h>
23 #include <string.h>
24 
25 #define __FILENAME__                                                           \
26   (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
27 #define TAG "Weaver-1.0"
28 #define UNUSED(x) (void)(x)
29 #define IS_NULL(value)                                                         \
30   if (value == NULL)                                                           \
31     ;
32 static bool is_weaver_debug =
33     true; // configurable to enable disable debug logs.
34 
35 #define LOG_D(tag, fmt, ...)                                                   \
36   ALOGD_IF(is_weaver_debug, "%s::%d %s " fmt "\n", __FILENAME__, __LINE__,     \
37            __FUNCTION__, ##__VA_ARGS__)
38 #define LOG_E(tag, fmt, ...)                                                   \
39   ALOGE("%s::%d %s " fmt "\n", __FILENAME__, __LINE__, __FUNCTION__,           \
40         ##__VA_ARGS__)
41 
42 #define RETURN_IF_NULL(ptr, ret_value, msg)                                    \
43   if (ptr == NULL) {                                                           \
44     ALOGE(msg);                                                                \
45     return ret_value;                                                          \
46   }
47 
48 #endif /* _WEAVER_UTILS_H__ */
49