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 HILOGTOOL_MSG_H 17 #define HILOGTOOL_MSG_H 18 19 #include <cstdint> 20 #include <string> 21 #include <stdint.h> 22 #include <time.h> 23 #include "hilog_common.h" 24 25 #define FILE_PATH_MAX_LEN 100 26 #define JOB_ID_ALL 0xffffffff 27 typedef enum { 28 LOG_QUERY_REQUEST = 0x01, 29 LOG_QUERY_RESPONSE, 30 NEXT_REQUEST, 31 NEXT_RESPONSE, 32 NEW_DATA_NOTIFY, 33 MC_REQ_LOG_PERSIST_START, 34 MC_RSP_LOG_PERSIST_START, 35 MC_REQ_LOG_PERSIST_STOP, 36 MC_RSP_LOG_PERSIST_STOP, 37 MC_REQ_LOG_PERSIST_QUERY, 38 MC_RSP_LOG_PERSIST_QUERY, 39 MC_REQ_BUFFER_RESIZE, // set buffer request 40 MC_RSP_BUFFER_RESIZE, // set buffer response 41 MC_REQ_BUFFER_SIZE, // query buffer size 42 MC_RSP_BUFFER_SIZE, // query buffer size 43 MC_REQ_STATISTIC_INFO_QUERY, // statistic info query request 44 MC_RSP_STATISTIC_INFO_QUERY, // statistic info query response 45 MC_REQ_STATISTIC_INFO_CLEAR, // statistic info clear request 46 MC_RSP_STATISTIC_INFO_CLEAR, // statistic info clear response 47 MC_REQ_FLOW_CONTROL, // set flow control request 48 MC_RSP_FLOW_CONTROL, // set flow control response 49 MC_REQ_LOG_CLEAR, // clear log request 50 MC_RSP_LOG_CLEAR // clear log response 51 } OperationCmd; 52 53 /* 54 * property operation, such as private switch ,log level, flow switch 55 */ 56 typedef enum { 57 OT_PRIVATE_SWITCH = 0x01, 58 OT_KMSG_SWITCH, 59 OT_LOG_LEVEL, 60 OT_FLOW_SWITCH, 61 } OperateType; 62 63 64 typedef enum { 65 CREATE_SUCCESS = 1, 66 CREATE_DUPLICATE = 2, 67 CREATE_DENIED = 3, 68 QUERY_SUCCESS = 4, 69 QUERY_NOT_EXIST = 5, 70 DELETE_SUCCESS = 6, 71 DELETE_DENIED = 7, 72 } PersisterResponse; 73 74 typedef enum { 75 COMPRESS_TYPE_NONE = 0, 76 COMPRESS_TYPE_ZSTD, 77 COMPRESS_TYPE_ZLIB, 78 } CompressAlg; 79 80 typedef enum { 81 OFF_SHOWFORMAT = 0, 82 COLOR_SHOWFORMAT, 83 TIME_SHOWFORMAT, 84 TIME_USEC_SHOWFORMAT, 85 YEAR_SHOWFORMAT, 86 ZONE_SHOWFORMAT, 87 EPOCH_SHOWFORMAT, 88 MONOTONIC_SHOWFORMAT, 89 TIME_NSEC_SHOWFORMAT, 90 } HilogShowFormat; 91 92 typedef struct { 93 uint8_t version; 94 uint8_t msgType; // hilogtool-hilogd message type 95 uint16_t msgLen; // message length 96 } MessageHeader; 97 98 typedef struct { 99 MessageHeader header; 100 uint8_t nPid; 101 uint8_t nNoPid; 102 uint8_t nDomain; 103 uint8_t nNoDomain; 104 uint8_t nTag; 105 uint8_t nNoTag; 106 uint8_t levels; 107 uint16_t types; 108 uint32_t pids[MAX_PIDS]; 109 uint32_t domains[MAX_DOMAINS]; 110 char tags[MAX_TAGS][MAX_TAG_LEN]; 111 uint16_t logCount; 112 uint8_t noLevels; 113 uint16_t noTypes; 114 uint32_t noPids[MAX_PIDS]; 115 uint32_t noDomains[MAX_DOMAINS]; 116 char noTags[MAX_TAGS][MAX_TAG_LEN]; 117 } LogQueryRequest; 118 119 typedef struct { 120 uint16_t sendId; 121 uint16_t length; /* data len, equals tag_len plus content length, include '\0' */ 122 uint16_t level; 123 uint16_t type; 124 uint16_t tag_len; /* include '\0' */ 125 uint32_t pid; 126 uint32_t tid; 127 uint32_t domain; 128 uint32_t tv_sec; 129 uint32_t tv_nsec; 130 char data[]; /* tag and content, include '\0' */ 131 } HilogDataMessage; 132 133 typedef struct { 134 MessageHeader header; 135 HilogDataMessage data; 136 } LogQueryResponse; 137 138 typedef struct { 139 MessageHeader header; 140 } NewDataNotify; 141 142 typedef struct { 143 MessageHeader header; 144 uint16_t sendId; 145 } NextRequest; 146 147 typedef struct { 148 MessageHeader header; 149 uint16_t sendId; 150 char data[]; 151 } NextResponce; 152 153 typedef struct { 154 uint16_t logType; 155 } BuffSizeMsg; 156 157 typedef struct { 158 MessageHeader msgHeader; 159 BuffSizeMsg buffSizeMsg[]; 160 } BufferSizeRequest; 161 162 typedef struct { 163 uint16_t logType; 164 uint64_t buffSize; 165 int32_t result; 166 } BuffSizeResult; 167 168 typedef struct { 169 MessageHeader msgHeader; 170 BuffSizeResult buffSizeRst[]; 171 } BufferSizeResponse; 172 173 typedef struct { 174 uint16_t logType; 175 uint64_t buffSize; 176 } BuffResizeMsg; 177 178 typedef struct { 179 MessageHeader msgHeader; 180 BuffResizeMsg buffResizeMsg[]; 181 } BufferResizeRequest; 182 183 typedef struct { 184 uint16_t logType; 185 uint64_t buffSize; 186 int32_t result; 187 } BuffResizeResult; 188 189 typedef struct { 190 MessageHeader msgHeader; 191 BuffResizeResult buffResizeRst[]; 192 } BufferResizeResponse; 193 194 typedef struct { 195 MessageHeader msgHeader; 196 uint16_t logType; 197 uint32_t domain; 198 } StatisticInfoQueryRequest; 199 200 typedef struct { 201 MessageHeader msgHeader; 202 int32_t result; 203 uint16_t logType; 204 uint32_t domain; 205 uint64_t printLen; 206 uint64_t cacheLen; 207 int32_t dropped; 208 } StatisticInfoQueryResponse; 209 210 typedef struct { 211 MessageHeader msgHeader; 212 uint16_t logType; 213 uint32_t domain; 214 } StatisticInfoClearRequest; 215 216 typedef struct { 217 MessageHeader msgHeader; 218 int32_t result; 219 uint16_t logType; 220 uint32_t domain; 221 } StatisticInfoClearResponse; 222 223 typedef struct { 224 uint16_t logType; 225 } LogClearMsg; 226 227 typedef struct { 228 MessageHeader msgHeader; 229 LogClearMsg logClearMsg[]; 230 } LogClearRequest; 231 232 typedef struct { 233 uint16_t logType; 234 int32_t result; 235 } LogClearResult; 236 237 typedef struct { 238 MessageHeader msgHeader; 239 LogClearResult logClearRst[]; 240 } LogClearResponse; 241 242 typedef struct { 243 std::string logTypeStr; 244 std::string compressAlgStr; 245 std::string fileSizeStr; 246 std::string fileNumStr; 247 std::string fileNameStr; 248 std::string jobIdStr; 249 } LogPersistParam; 250 typedef struct { 251 uint16_t logType; // union logType 252 uint16_t compressAlg; 253 char filePath[FILE_PATH_MAX_LEN]; 254 uint32_t fileSize; 255 uint32_t fileNum; 256 uint32_t jobId; 257 } LogPersistStartMsg; 258 typedef struct { 259 MessageHeader msgHeader; 260 LogPersistStartMsg logPersistStartMsg; 261 } LogPersistStartRequest; 262 263 typedef struct { 264 int32_t result; 265 uint32_t jobId; 266 } LogPersistStartResult; 267 268 typedef struct { 269 MessageHeader msgHeader; 270 LogPersistStartResult logPersistStartRst; 271 } LogPersistStartResponse; 272 273 typedef struct { 274 uint32_t jobId; 275 } LogPersistStopMsg; 276 typedef struct { 277 MessageHeader msgHeader; 278 LogPersistStopMsg logPersistStopMsg[]; 279 } LogPersistStopRequest; 280 281 typedef struct { 282 int32_t result; 283 uint32_t jobId; 284 } LogPersistStopResult; 285 typedef struct { 286 MessageHeader msgHeader; 287 LogPersistStopResult logPersistStopRst[]; 288 } LogPersistStopResponse; 289 290 typedef struct { 291 uint16_t logType; 292 } LogPersistQueryMsg; 293 typedef struct { 294 MessageHeader msgHeader; 295 LogPersistQueryMsg logPersistQueryMsg; 296 } LogPersistQueryRequest; 297 298 typedef struct { 299 int32_t result; 300 uint32_t jobId; 301 uint16_t logType; 302 uint16_t compressAlg; 303 char filePath[FILE_PATH_MAX_LEN]; 304 uint32_t fileSize; 305 uint32_t fileNum; 306 } LogPersistQueryResult; 307 typedef struct { 308 MessageHeader msgHeader; 309 LogPersistQueryResult logPersistQueryRst[]; 310 } LogPersistQueryResponse; 311 312 typedef struct { 313 std::string privateSwitchStr; 314 std::string kmsgSwitchStr; 315 std::string flowSwitchStr; 316 std::string logLevelStr; 317 std::string domainStr; 318 std::string tagStr; 319 std::string pidStr; 320 } SetPropertyParam; 321 322 #endif /* HILOGTOOL_MSG_H */ 323