1/* 2 * Copyright (c) 2020 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 HOS_LITE_HIVIEW_EVENT_H 17#define HOS_LITE_HIVIEW_EVENT_H 18 19#include "ohos_types.h" 20 21#ifdef __cplusplus 22#if __cplusplus 23extern "C" { 24#endif 25#endif /* End of #ifdef __cplusplus */ 26 27#ifndef HIEVENT_NONE 28#define HIEVENT_NONE 0 /* none event */ 29#endif 30#ifndef HIEVENT_FAULT 31#define HIEVENT_FAULT 1 /* fault event */ 32#endif 33#ifndef HIEVENT_UE 34#define HIEVENT_UE 2 /* user behavior event */ 35#endif 36#ifndef HIEVENT_STAT 37#define HIEVENT_STAT 4 /* statistics event */ 38#endif 39 40#pragma pack(1) 41typedef struct { 42 uint8 mark; 43 uint8 len; /* payload length */ 44 uint16 eventId; /* 0-65535 */ 45 uint32 time; 46} HiEventCommon; 47 48typedef struct { 49 HiEventCommon common; 50 uint8 type; /* Do not write to file. */ 51 uint8 *payload; /* T-L-V */ 52} HiEvent; 53#pragma pack() 54 55/** 56 * Definitions for function Pointer. 57 * @param data HieventContent pointer. 58 * @return function handle result. If TRUE is returned, the platform does not process, 59 * else the platform continues to process. 60 **/ 61typedef boolean (*HieventProc)(const HiEvent *event); 62 63#ifndef FILE_PROC_DEFINED 64#define FILE_PROC_DEFINED 65/** 66 * Callback function prototype for file processing. 67 * 68 * @param path the path of the file to be processed. 69 * @param type the type of the file to be processed. 70 * @param event the type of event that triggered the function. 0 for file full. 71 **/ 72typedef void (*FileProc)(const char *path, uint8 type, uint8 event); 73#endif 74 75/** 76 * Create and output a event. 77 * Use the macro definition interface instead of directly using this interface. 78 * @param type Event type. 79 * @param eventId Event ID. Event ID is assigned uniformly and globally unique. 80 * @param key The id of the parameter in the XML definition. Valid data range: 0-15. -1 means no parameters. 81 * @param value The Value of the parameter. 82 * @attention This event carry only one parameter. 83 **/ 84void HiEventPrintf(uint8 type, uint16 eventId, int8 key, int32 value); 85 86/** 87 * Create the HivewEvent object. 88 * Use the macro definition interface instead of directly using this interface. 89 * @param type Event type. 90 * @param eventId Event ID. Event ID is assigned uniformly and globally unique. 91 * @param num The number of values carried by the event. Valid data range: 2-16. 92 * @return HiEvent object. 93 * @attention This function is the atomic operation. This method cannot be used when no parameter 94 is carried or only one parameter is carried. 95 **/ 96HiEvent *HiEventCreate(uint8 type, uint16 eventId, uint8 num); 97 98/** 99 * Add parameter's value to event object. 100 * Use the macro definition interface instead of directly using this interface. 101 * @param event Operation object. 102 * @param key The id of the parameter in the XML definition. Valid data range: 0-15. 103 * @param value The Value of the parameter. 104 **/ 105void HiEventPutInteger(HiEvent *event, int8 key, int32 value); 106 107/** 108 * Ouput the event object and release memory. 109 * Use the macro definition interface instead of directly using this interface. 110 * @param event Operation object. 111 * @attention This function will automatically release the event object. 112 **/ 113void HiEventReport(HiEvent *event); 114 115/* 116 * Interface for flush event before the system restarts. 117 * @param syncFlag indicates synchronised flush or asynchronous flush. 118 * @attention Use this interface to flush event to the UART or the files. 119 */ 120void HiEventFlush(boolean syncFlag); 121 122/** 123 * Interface for register the Hievent handle. 124 * @param func Function Pointer. 125 **/ 126void HiEventRegisterProc(HieventProc func); 127 128/** 129 * Interface for deregister the Hievent handle. 130 **/ 131void HiEventUnRegisterProc(HieventProc func); 132 133/** 134 * Add a monitoring function when the specified type of file is full . 135 * 136 * @param type hievent type. 137 * @param func callback function. 138 * @param dest hievent output target file path. 139 **/ 140void HiEventFileAddWatcher(uint8 type, FileProc func, const char *dest); 141 142/** 143 * Remove monitoring of specified types of files. 144 * 145 * @param type hievent type. 146 * @param func callback function. 147 **/ 148void HiEventFileRemoveWatcher(uint8 type, FileProc func); 149 150/** 151 * Process files according to mode. 152 * 153 * @param type hievent type. 154 * @param dest hievent output target file path. 155 * @param mode file processing mode. 0 for copy specified type hievent file to dest and keep the 156 * content in the source file, 1 for rename specified type hievent file to dest. 157 * @return 0 if success, otherwise -1. 158 **/ 159int HiEventFileProc(uint8 type, const char *dest, uint8 mode); 160 161/** 162 * Lock the hievent output target file. 163 * 164 **/ 165void HiEventOutputFileLock(void); 166 167/** 168 * Unlock the hievent output target file. 169 * 170 **/ 171void HiEventOutputFileUnLock(void); 172 173#ifndef HIEVENT_COMPILE_TYPE 174#define HIEVENT_COMPILE_TYPE (HIEVENT_FAULT | HIEVENT_UE | HIEVENT_STAT) 175#endif 176 177#define IS_COMPILE_EVENT(t) (((HIEVENT_COMPILE_TYPE) & (t)) == (t)) 178 179/** 180 * If no parameter is carried or only one parameter is carried, use the following method. 181 * @param id Event ID. Event ID is assigned uniformly and globally unique. The maximum value is 65535. 182 * @param k Index of the parameter carried in the event. Valid data range: 0-15. If the value is -1, 183 * the event does not carry any parameter. 184 * @param v Value of the parameter carried in the event. 185**/ 186#if IS_COMPILE_EVENT(HIEVENT_FAULT) 187#define HIEVENT_FAULT_REPORT(id, k, v) HiEventPrintf(HIEVENT_FAULT, (id), (k), (v)) 188#else 189#define HIEVENT_FAULT_REPORT(id, k, v) 190#endif 191 192#if IS_COMPILE_EVENT(HIEVENT_UE) 193#define HIEVENT_UE_REPORT(id, k, v) HiEventPrintf(HIEVENT_UE, (id), (k), (v)) 194#else 195#define HIEVENT_UE_REPORT(id, k, v) 196#endif 197 198#if IS_COMPILE_EVENT(HIEVENT_STAT) 199#define HIEVENT_STAT_REPORT(id, k, v) HiEventPrintf(HIEVENT_STAT, (id), (k), (v)) 200#else 201#define HIEVENT_STAT_REPORT(id, k, v) 202#endif 203 204/** 205* If multiple parameters need to be carried, use the following method. 206* @param type Event type. 207* @param id Event id. Event ID is assigned uniformly and globally unique. 208* @param num Number of parameters carried in an event. Valid data range: 2-16. 209* @attention The following method cannot be used when no parameter is carried or only one parameter is carried. 210**/ 211#if HIEVENT_COMPILE_TYPE > HIEVENT_NONE 212#define HIEVENT_CREATE(type, id, num) HiEventCreate(type, id, num) 213#define HIEVENT_PUT_INT_VALUE(pEvent, k, v) HiEventPutInteger(pEvent, k, v) 214#define HIEVENT_REPORT(pEvent) HiEventReport(pEvent) 215#else 216#define HIEVENT_CREATE(type, id, num) 217#define HIEVENT_PUT_INT_VALUE(pEvent, k, v) 218#define HIEVENT_REPORT(pEvent) 219#endif 220 221#ifdef __cplusplus 222#if __cplusplus 223} 224#endif 225#endif /* End of #ifdef __cplusplus */ 226 227#endif /* End of #ifndef HOS_LITE_HIVIEW_EVENT_H */ 228