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 BLACKBOX_H 17 #define BLACKBOX_H 18 19 #include "hiview_log.h" 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif /* End of #if __cplusplus */ 25 #endif /* End of #ifdef __cplusplus */ 26 27 #define ERROR_INFO_HEADER "#### error info ####\r\n" 28 #define ERROR_INFO_HEADER_FORMAT "event: %s\r\nmodule: %s\r\nerrorDesc: %s\r\n" 29 #define ERROR_INFO_MAX_LEN 768 30 #define Min(a, b) (((a) > (b)) ? (b) : (a)) 31 #define BBOX_PRINT_ERR(format, ...) HILOG_DEBUG(HILOG_MODULE_HIVIEW, "bbox: func: %s line: %d, Err: " \ 32 format, __func__, __LINE__, ##__VA_ARGS__) 33 #define BBOX_PRINT_INFO(format, ...) HILOG_DEBUG(HILOG_MODULE_HIVIEW, "bbox: Info: " format, ##__VA_ARGS__) 34 35 #define PATH_MAX_LEN 256 36 #define EVENT_MAX_LEN 32 37 #define MODULE_MAX_LEN 32 38 #define ERROR_DESC_MAX_LEN 512 39 #define MODULE_SYSTEM "SYSTEM" 40 #define EVENT_SYSREBOOT "SYSREBOOT" 41 #define EVENT_LONGPRESS "LONGPRESS" 42 #define EVENT_COMBINATIONKEY "COMBINATIONKEY" 43 #define EVENT_SUBSYSREBOOT "SUBSYSREBOOT" 44 #define EVENT_POWEROFF "POWEROFF" 45 #define EVENT_PANIC "PANIC" 46 #define EVENT_SYS_WATCHDOG "SYSWATCHDOG" 47 #define EVENT_HUNGTASK "HUNGTASK" 48 #define EVENT_BOOTFAIL "BOOTFAIL" 49 50 struct ErrorInfo { 51 char event[EVENT_MAX_LEN]; 52 char module[MODULE_MAX_LEN]; 53 char errorDesc[ERROR_DESC_MAX_LEN]; 54 }; 55 56 struct ModuleOps { 57 char module[MODULE_MAX_LEN]; 58 void (*Dump)(const char *logDir, struct ErrorInfo *info); 59 void (*Reset)(struct ErrorInfo *info); 60 int (*GetLastLogInfo)(struct ErrorInfo *info); 61 int (*SaveLastLog)(const char *logDir, struct ErrorInfo *info); 62 }; 63 64 int BBoxRegisterModuleOps(struct ModuleOps *ops); 65 int BBoxNotifyError(const char event[EVENT_MAX_LEN], 66 const char module[MODULE_MAX_LEN], 67 const char errorDesc[ERROR_DESC_MAX_LEN], 68 int needSysReset); 69 int BBoxDriverInit(void); 70 71 #ifdef __cplusplus 72 #if __cplusplus 73 } 74 #endif /* End of #if __cplusplus */ 75 #endif /* End of #ifdef __cplusplus */ 76 77 #endif /* End of #ifndef BLACKBOX_H */