1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_DRM_LOG_H 17 #define OHOS_DRM_LOG_H 18 19 #include <stdio.h> 20 #include <cinttypes> 21 #include "hilog/log.h" 22 #include "hisysevent.h" 23 24 #undef LOG_DOMAIN 25 #undef LOG_TAG 26 #define LOG_DOMAIN 0xD002B21 27 #define LOG_TAG "DRM" 28 #define MAX_STRING_SIZE 256 29 30 #define DRM_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 31 32 #define POINTER_MASK 0x00FFFFFF 33 #define FAKE_POINTER(addr) (POINTER_MASK & reinterpret_cast<uintptr_t>(addr)) 34 35 #define DECORATOR_HILOG(op, fmt, args...) \ 36 do { \ 37 op(LOG_CORE, "{%{public}s()-%{public}s:%{public}d}" fmt, __FUNCTION__, DRM_FILE_NAME, __LINE__, ##args); \ 38 } while (0) 39 40 #define DRM_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 41 #define DRM_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__) 42 #define DRM_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__) 43 #define DRM_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__) 44 #define DRM_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__) 45 46 #ifndef DRM_CHECK_AND_RETURN_RET_LOG 47 #define DRM_CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 48 do { \ 49 if (!(cond)) { \ 50 DRM_ERR_LOG(fmt, ##__VA_ARGS__); \ 51 return ret; \ 52 } \ 53 } while (0) 54 #endif 55 56 #ifndef DRM_CHECK_AND_RETURN_LOG 57 #define DRM_CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 58 do { \ 59 if (!(cond)) { \ 60 DRM_ERR_LOG(fmt, ##__VA_ARGS__); \ 61 return; \ 62 } \ 63 } while (0) 64 #endif 65 66 #ifndef DRM_CHECK_AND_CONTINUE_LOG 67 #define DRM_CHECK_AND_CONTINUE_LOG(cond, fmt, ...) \ 68 do { \ 69 if (!(cond)) { \ 70 ReleaseHandleAndKeySystemMap(handle); \ 71 DRM_ERR_LOG(fmt, ##__VA_ARGS__); \ 72 continue;; \ 73 } \ 74 } while (0) 75 #endif 76 77 #define POINTER_MASK 0x00FFFFFF 78 #define DATA_MAX_LEN (1 * 1024 * 1024) 79 #define RESPONSE_MAX_LEN (8 * 1024 * 1024) 80 #define REQUEST_MAX_LEN (8 * 1024 * 1024) 81 #define IV_MAX_LEN 128 82 #define KEYID_MAX_LEN 128 83 #define LICENSEID_MAX_LEN 128 84 #define SUBSAMPLE_MAX_NUM 256 85 #define HEXADECIMAL 16 86 #define BASE_CONVERSION_OPERATOR 2 87 #define KEY_SYSTEM_MAX_NUMBER 64 88 #define KEY_SESSION_MAX_NUMBER 64 89 90 #endif // OHOS_DRM_LOG_H