1 /* 2 * Copyright (c) 2021 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 HILOG_COMMON_H 17 #define HILOG_COMMON_H 18 19 #include <climits> 20 #include <cstdint> 21 #include <iostream> 22 #include <optional> 23 #include <vector> 24 #include <functional> 25 #include <hilog_base.h> 26 27 #define OUTPUT_SOCKET_NAME "hilogOutput" 28 #define CONTROL_SOCKET_NAME "hilogControl" 29 #define HILOG_FILE_DIR "/data/log/hilog/" 30 #define MAX_REGEX_STR_LEN (128) 31 #define MAX_FILE_NAME_LEN (64) 32 #define RET_SUCCESS 0 33 #define RET_FAIL (-1) 34 #define MAX_JOBS (10) 35 constexpr size_t MIN_BUFFER_SIZE = (64 * 1024); 36 constexpr size_t MAX_BUFFER_SIZE = (512 * 1024 * 1024); 37 constexpr uint32_t MAX_PERSISTER_BUFFER_SIZE = 64 * 1024; 38 constexpr uint32_t MIN_LOG_FILE_SIZE = MAX_PERSISTER_BUFFER_SIZE; 39 constexpr uint32_t MAX_LOG_FILE_SIZE = (512 * 1024 * 1024); 40 constexpr int MIN_LOG_FILE_NUM = 2; 41 constexpr int MAX_LOG_FILE_NUM = 1000; 42 constexpr uint32_t DOMAIN_OS_MIN = 0xD000000; 43 constexpr uint32_t DOMAIN_OS_MAX = 0xD0FFFFF; 44 constexpr uint32_t DOMAIN_APP_MIN = 0x0; 45 constexpr uint32_t DOMAIN_APP_MAX = 0xFFFF; 46 constexpr uint32_t JOB_ID_MIN = 10; 47 constexpr uint32_t JOB_ID_MAX = UINT_MAX; 48 constexpr uint32_t WAITING_DATA_MS = 5000; 49 50 template <typename T> 51 using OptRef = std::optional<std::reference_wrapper<T>>; 52 53 template <typename T> 54 using OptCRef = std::optional<std::reference_wrapper<const T>>; 55 56 #define CONTENT_LEN(pMsg) ((pMsg)->len - sizeof(HilogMsg) - (pMsg)->tagLen) /* include '\0' */ 57 #define CONTENT_PTR(pMsg) ((pMsg)->tag + (pMsg)->tagLen) 58 59 #define likely(x) __builtin_expect(!!(x), 1) 60 #define unlikely(x) __builtin_expect(!!(x), 0) 61 62 /* 63 * ******************************************** 64 * Error codes list 65 * Error codes _values_ are pinned down. 66 * ******************************************** 67 */ 68 typedef enum { 69 SUCCESS_CONTINUE = 1, 70 ERR_LOG_LEVEL_INVALID = -2, 71 ERR_LOG_TYPE_INVALID = -3, 72 ERR_INVALID_RQST_CMD = -4, 73 ERR_INVALID_DOMAIN_STR = -5, 74 ERR_QUERY_TYPE_INVALID = -8, 75 ERR_LOG_PERSIST_FILE_SIZE_INVALID = -11, 76 ERR_LOG_PERSIST_FILE_NAME_INVALID = -12, 77 ERR_LOG_PERSIST_COMPRESS_BUFFER_EXP = -13, 78 ERR_LOG_PERSIST_DIR_OPEN_FAIL = -14, 79 ERR_LOG_PERSIST_COMPRESS_INIT_FAIL = -15, 80 ERR_LOG_PERSIST_FILE_OPEN_FAIL = -16, 81 ERR_LOG_PERSIST_JOBID_FAIL = -18, 82 ERR_DOMAIN_INVALID = -19, 83 ERR_MSG_LEN_INVALID = -21, 84 ERR_LOG_PERSIST_FILE_PATH_INVALID = -25, 85 ERR_LOG_PERSIST_JOBID_INVALID = -28, 86 ERR_BUFF_SIZE_INVALID = -30, 87 ERR_COMMAND_INVALID = -31, 88 ERR_LOG_PERSIST_TASK_EXISTED = -32, 89 ERR_LOG_FILE_NUM_INVALID = -34, 90 ERR_NOT_NUMBER_STR = -35, 91 ERR_TOO_MANY_ARGUMENTS = -36, 92 ERR_DUPLICATE_OPTION = -37, 93 ERR_INVALID_ARGUMENT = -38, 94 ERR_TOO_MANY_DOMAINS = -39, 95 ERR_INVALID_SIZE_STR = -40, 96 ERR_TOO_MANY_PIDS = -41, 97 ERR_TOO_MANY_TAGS = -42, 98 ERR_TAG_STR_TOO_LONG = -43, 99 ERR_REGEX_STR_TOO_LONG = -44, 100 ERR_FILE_NAME_TOO_LONG = -45, 101 ERR_SOCKET_CLIENT_INIT_FAIL = -46, 102 ERR_SOCKET_WRITE_MSG_HEADER_FAIL = -47, 103 ERR_SOCKET_WRITE_CMD_FAIL = -48, 104 ERR_SOCKET_RECEIVE_RSP = -49, 105 ERR_PERSIST_TASK_EMPTY = -50, 106 ERR_JOBID_NOT_EXSIST = -60, 107 ERR_TOO_MANY_JOBS = -61, 108 ERR_STATS_NOT_ENABLE = -62, 109 ERR_NO_RUNNING_TASK = -63, 110 ERR_NO_PID_PERMISSION = -64, 111 } ErrorCode; 112 113 #endif /* HILOG_COMMON_H */ 114