12498b56bSopenharmony_ci/*
22498b56bSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
32498b56bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
42498b56bSopenharmony_ci * you may not use this file except in compliance with the License.
52498b56bSopenharmony_ci * You may obtain a copy of the License at
62498b56bSopenharmony_ci *
72498b56bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
82498b56bSopenharmony_ci *
92498b56bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
102498b56bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
112498b56bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122498b56bSopenharmony_ci * See the License for the specific language governing permissions and
132498b56bSopenharmony_ci * limitations under the License.
142498b56bSopenharmony_ci */
152498b56bSopenharmony_ci
162498b56bSopenharmony_ci#ifndef HILOG_COMMON_H
172498b56bSopenharmony_ci#define HILOG_COMMON_H
182498b56bSopenharmony_ci
192498b56bSopenharmony_ci#include <climits>
202498b56bSopenharmony_ci#include <cstdint>
212498b56bSopenharmony_ci#include <iostream>
222498b56bSopenharmony_ci#include <optional>
232498b56bSopenharmony_ci#include <vector>
242498b56bSopenharmony_ci#include <functional>
252498b56bSopenharmony_ci#include <hilog_base.h>
262498b56bSopenharmony_ci
272498b56bSopenharmony_ci#define OUTPUT_SOCKET_NAME "hilogOutput"
282498b56bSopenharmony_ci#define CONTROL_SOCKET_NAME "hilogControl"
292498b56bSopenharmony_ci#define HILOG_FILE_DIR "/data/log/hilog/"
302498b56bSopenharmony_ci#define MAX_REGEX_STR_LEN (128)
312498b56bSopenharmony_ci#define MAX_FILE_NAME_LEN (64)
322498b56bSopenharmony_ci#define RET_SUCCESS 0
332498b56bSopenharmony_ci#define RET_FAIL (-1)
342498b56bSopenharmony_ci#define MAX_JOBS (10)
352498b56bSopenharmony_ciconstexpr size_t MIN_BUFFER_SIZE = (64 * 1024);
362498b56bSopenharmony_ciconstexpr size_t MAX_BUFFER_SIZE = (16 * 1024 * 1024);
372498b56bSopenharmony_ciconstexpr uint32_t MAX_PERSISTER_BUFFER_SIZE = 64 * 1024;
382498b56bSopenharmony_ciconstexpr uint32_t MIN_LOG_FILE_SIZE = MAX_PERSISTER_BUFFER_SIZE;
392498b56bSopenharmony_ciconstexpr uint32_t MAX_LOG_FILE_SIZE = (512 * 1024 * 1024);
402498b56bSopenharmony_ciconstexpr int MIN_LOG_FILE_NUM = 2;
412498b56bSopenharmony_ciconstexpr int MAX_LOG_FILE_NUM = 1000;
422498b56bSopenharmony_ciconstexpr uint32_t DOMAIN_OS_MIN = 0xD000000;
432498b56bSopenharmony_ciconstexpr uint32_t DOMAIN_OS_MAX = 0xD0FFFFF;
442498b56bSopenharmony_ciconstexpr uint32_t DOMAIN_APP_MIN = 0x0;
452498b56bSopenharmony_ciconstexpr uint32_t DOMAIN_APP_MAX = 0xFFFF;
462498b56bSopenharmony_ciconstexpr uint32_t JOB_ID_MIN = 10;
472498b56bSopenharmony_ciconstexpr uint32_t JOB_ID_MAX = UINT_MAX;
482498b56bSopenharmony_ciconstexpr uint32_t WAITING_DATA_MS = 5000;
492498b56bSopenharmony_ci
502498b56bSopenharmony_citemplate <typename T>
512498b56bSopenharmony_ciusing OptRef = std::optional<std::reference_wrapper<T>>;
522498b56bSopenharmony_ci
532498b56bSopenharmony_citemplate <typename T>
542498b56bSopenharmony_ciusing OptCRef = std::optional<std::reference_wrapper<const T>>;
552498b56bSopenharmony_ci
562498b56bSopenharmony_ci#define CONTENT_LEN(pMsg) ((pMsg)->len - sizeof(HilogMsg) - (pMsg)->tagLen) /* include '\0' */
572498b56bSopenharmony_ci#define CONTENT_PTR(pMsg) ((pMsg)->tag + (pMsg)->tagLen)
582498b56bSopenharmony_ci
592498b56bSopenharmony_ci#define likely(x)      __builtin_expect(!!(x), 1)
602498b56bSopenharmony_ci#define unlikely(x)    __builtin_expect(!!(x), 0)
612498b56bSopenharmony_ci
622498b56bSopenharmony_ci/*
632498b56bSopenharmony_ci * ********************************************
642498b56bSopenharmony_ci *  Error codes list
652498b56bSopenharmony_ci *  Error codes _values_ are pinned down.
662498b56bSopenharmony_ci * ********************************************
672498b56bSopenharmony_ci*/
682498b56bSopenharmony_citypedef enum {
692498b56bSopenharmony_ci    SUCCESS_CONTINUE = 1,
702498b56bSopenharmony_ci    ERR_LOG_LEVEL_INVALID  = -2,
712498b56bSopenharmony_ci    ERR_LOG_TYPE_INVALID = -3,
722498b56bSopenharmony_ci    ERR_INVALID_RQST_CMD = -4,
732498b56bSopenharmony_ci    ERR_INVALID_DOMAIN_STR = -5,
742498b56bSopenharmony_ci    ERR_QUERY_TYPE_INVALID = -8,
752498b56bSopenharmony_ci    ERR_LOG_PERSIST_FILE_SIZE_INVALID = -11,
762498b56bSopenharmony_ci    ERR_LOG_PERSIST_FILE_NAME_INVALID = -12,
772498b56bSopenharmony_ci    ERR_LOG_PERSIST_COMPRESS_BUFFER_EXP = -13,
782498b56bSopenharmony_ci    ERR_LOG_PERSIST_DIR_OPEN_FAIL = -14,
792498b56bSopenharmony_ci    ERR_LOG_PERSIST_COMPRESS_INIT_FAIL = -15,
802498b56bSopenharmony_ci    ERR_LOG_PERSIST_FILE_OPEN_FAIL = -16,
812498b56bSopenharmony_ci    ERR_LOG_PERSIST_JOBID_FAIL = -18,
822498b56bSopenharmony_ci    ERR_DOMAIN_INVALID = -19,
832498b56bSopenharmony_ci    ERR_MSG_LEN_INVALID = -21,
842498b56bSopenharmony_ci    ERR_LOG_PERSIST_FILE_PATH_INVALID = -25,
852498b56bSopenharmony_ci    ERR_LOG_PERSIST_JOBID_INVALID = -28,
862498b56bSopenharmony_ci    ERR_BUFF_SIZE_INVALID = -30,
872498b56bSopenharmony_ci    ERR_COMMAND_INVALID = -31,
882498b56bSopenharmony_ci    ERR_LOG_PERSIST_TASK_EXISTED = -32,
892498b56bSopenharmony_ci    ERR_LOG_FILE_NUM_INVALID = -34,
902498b56bSopenharmony_ci    ERR_NOT_NUMBER_STR = -35,
912498b56bSopenharmony_ci    ERR_TOO_MANY_ARGUMENTS = -36,
922498b56bSopenharmony_ci    ERR_DUPLICATE_OPTION = -37,
932498b56bSopenharmony_ci    ERR_INVALID_ARGUMENT = -38,
942498b56bSopenharmony_ci    ERR_TOO_MANY_DOMAINS = -39,
952498b56bSopenharmony_ci    ERR_INVALID_SIZE_STR = -40,
962498b56bSopenharmony_ci    ERR_TOO_MANY_PIDS = -41,
972498b56bSopenharmony_ci    ERR_TOO_MANY_TAGS = -42,
982498b56bSopenharmony_ci    ERR_TAG_STR_TOO_LONG = -43,
992498b56bSopenharmony_ci    ERR_REGEX_STR_TOO_LONG = -44,
1002498b56bSopenharmony_ci    ERR_FILE_NAME_TOO_LONG = -45,
1012498b56bSopenharmony_ci    ERR_SOCKET_CLIENT_INIT_FAIL = -46,
1022498b56bSopenharmony_ci    ERR_SOCKET_WRITE_MSG_HEADER_FAIL = -47,
1032498b56bSopenharmony_ci    ERR_SOCKET_WRITE_CMD_FAIL = -48,
1042498b56bSopenharmony_ci    ERR_SOCKET_RECEIVE_RSP = -49,
1052498b56bSopenharmony_ci    ERR_PERSIST_TASK_EMPTY = -50,
1062498b56bSopenharmony_ci    ERR_JOBID_NOT_EXSIST = -60,
1072498b56bSopenharmony_ci    ERR_TOO_MANY_JOBS = -61,
1082498b56bSopenharmony_ci    ERR_STATS_NOT_ENABLE = -62,
1092498b56bSopenharmony_ci    ERR_NO_RUNNING_TASK = -63,
1102498b56bSopenharmony_ci    ERR_NO_PID_PERMISSION = -64,
1112498b56bSopenharmony_ci} ErrorCode;
1122498b56bSopenharmony_ci
1132498b56bSopenharmony_ci#endif /* HILOG_COMMON_H */
114