• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CACHE_H
17 #define HOS_LITE_HIVIEW_CACHE_H
18 
19 #include "ohos_types.h"
20 #include "hiview_util.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif /* End of #ifdef __cplusplus */
27 
28 typedef enum {
29     CORE_CACHE = 0,
30     LOG_CACHE,
31     JS_LOG_CACHE,
32     DUMP_CACHE,
33     FAULT_EVENT_CACHE,
34     UE_EVENT_CACHE,
35     STAT_EVENT_CACHE,
36 } HiviewCacheType;
37 
38 #pragma pack(1)
39 typedef struct {
40     uint16 wCursor;    // 0-65535
41     uint16 usedSize;   // 0-65535
42     uint16 size;       // cache size 0-65535
43     HiviewCacheType type;
44     uint8 *buffer;     // Circular buffer
45 } HiviewCache;
46 #pragma pack()
47 
48 /**
49  * Initialize the cache object using static memory.
50  * @param cache Operation object.
51  * @param type cache type.
52  * @param buffer External static memory.
53  * @param size Static memory size.
54  * @return TRUE/FALSE.
55  **/
56 boolean InitHiviewStaticCache(HiviewCache *cache, HiviewCacheType type, uint8 *buffer, uint16 size);
57 
58 /**
59  * Initialize the cache object.
60  * @param cache Operation object.
61  * @param type cache type.
62  * @param size cache size.
63  * @return TRUE/FALSE.
64  **/
65 boolean InitHiviewCache(HiviewCache *cache, HiviewCacheType type, uint16 size);
66 
67 /**
68  * Write data to cache.
69  * @param cache Operation object.
70  * @param data Data to be written to the cache.
71  * @param wLen The length of the data to be written.
72  * @return Length write.
73  **/
74 int32 WriteToCache(HiviewCache *cache, const uint8 *data, uint16 wLen);
75 
76 /**
77  * Read data form cache.
78  * @param cache Operation object.
79  * @param data Read buffer.
80  * @param rLen The length of the data to be read.
81  * @return Length read.
82  **/
83 int32 ReadFromCache(HiviewCache *cache, uint8 *data, uint16 rLen);
84 
85 /**
86  * Preread data form cache.
87  * Use this method when you don't want to modify the read status of the cache.
88  * @param cache Operation object.
89  * @param data Read buffer.
90  * @param rLen The length of the data to be read.
91  * @return Length read.
92  * @attention The value of rCursor will not be changed.
93  **/
94 int32 PrereadFromCache(HiviewCache *cache, uint8 *data, uint16 rLen);
95 
96 /**
97  * Discard all cache data.
98  * Use this method when an unrecoverable data exception is detected.
99  * @param cache Operation object.
100  **/
101 void DiscardCacheData(HiviewCache *cache);
102 
103 /**
104  * Destroy the cache and release the memory.
105  * @param cache Operation object.
106  **/
107 void DestroyCache(HiviewCache *cache);
108 
109 #ifdef __cplusplus
110 #if __cplusplus
111 }
112 #endif
113 #endif /* End of #ifdef __cplusplus */
114 
115 #endif /* End of #ifndef HOS_LITE_HIVIEW_CACHE_H */
116