16f2c2defSopenharmony_ci/*
26f2c2defSopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd.
36f2c2defSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
46f2c2defSopenharmony_ci * you may not use this file except in compliance with the License.
56f2c2defSopenharmony_ci * You may obtain a copy of the License at
66f2c2defSopenharmony_ci *
76f2c2defSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
86f2c2defSopenharmony_ci *
96f2c2defSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
106f2c2defSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
116f2c2defSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126f2c2defSopenharmony_ci * See the License for the specific language governing permissions and
136f2c2defSopenharmony_ci * limitations under the License.
146f2c2defSopenharmony_ci */
156f2c2defSopenharmony_ci
166f2c2defSopenharmony_ci#ifndef HOS_LITE_HIVIEW_CACHE_H
176f2c2defSopenharmony_ci#define HOS_LITE_HIVIEW_CACHE_H
186f2c2defSopenharmony_ci
196f2c2defSopenharmony_ci#include "ohos_types.h"
206f2c2defSopenharmony_ci#include "hiview_util.h"
216f2c2defSopenharmony_ci
226f2c2defSopenharmony_ci#ifdef __cplusplus
236f2c2defSopenharmony_ci#if __cplusplus
246f2c2defSopenharmony_ciextern "C" {
256f2c2defSopenharmony_ci#endif
266f2c2defSopenharmony_ci#endif /* End of #ifdef __cplusplus */
276f2c2defSopenharmony_ci
286f2c2defSopenharmony_citypedef enum {
296f2c2defSopenharmony_ci    CORE_CACHE = 0,
306f2c2defSopenharmony_ci    LOG_CACHE,
316f2c2defSopenharmony_ci    JS_LOG_CACHE,
326f2c2defSopenharmony_ci    DUMP_CACHE,
336f2c2defSopenharmony_ci    FAULT_EVENT_CACHE,
346f2c2defSopenharmony_ci    UE_EVENT_CACHE,
356f2c2defSopenharmony_ci    STAT_EVENT_CACHE,
366f2c2defSopenharmony_ci} HiviewCacheType;
376f2c2defSopenharmony_ci
386f2c2defSopenharmony_ci#pragma pack(1)
396f2c2defSopenharmony_citypedef struct {
406f2c2defSopenharmony_ci    uint16 wCursor;    // 0-65535
416f2c2defSopenharmony_ci    uint16 usedSize;   // 0-65535
426f2c2defSopenharmony_ci    uint16 size;       // cache size 0-65535
436f2c2defSopenharmony_ci    HiviewCacheType type;
446f2c2defSopenharmony_ci    uint8 *buffer;     // Circular buffer
456f2c2defSopenharmony_ci} HiviewCache;
466f2c2defSopenharmony_ci#pragma pack()
476f2c2defSopenharmony_ci
486f2c2defSopenharmony_ci/**
496f2c2defSopenharmony_ci * Initialize the cache object using static memory.
506f2c2defSopenharmony_ci * @param cache Operation object.
516f2c2defSopenharmony_ci * @param type cache type.
526f2c2defSopenharmony_ci * @param buffer External static memory.
536f2c2defSopenharmony_ci * @param size Static memory size.
546f2c2defSopenharmony_ci * @return TRUE/FALSE.
556f2c2defSopenharmony_ci **/
566f2c2defSopenharmony_ciboolean InitHiviewStaticCache(HiviewCache *cache, HiviewCacheType type, uint8 *buffer, uint16 size);
576f2c2defSopenharmony_ci
586f2c2defSopenharmony_ci/**
596f2c2defSopenharmony_ci * Initialize the cache object.
606f2c2defSopenharmony_ci * @param cache Operation object.
616f2c2defSopenharmony_ci * @param type cache type.
626f2c2defSopenharmony_ci * @param size cache size.
636f2c2defSopenharmony_ci * @return TRUE/FALSE.
646f2c2defSopenharmony_ci **/
656f2c2defSopenharmony_ciboolean InitHiviewCache(HiviewCache *cache, HiviewCacheType type, uint16 size);
666f2c2defSopenharmony_ci
676f2c2defSopenharmony_ci/**
686f2c2defSopenharmony_ci * Write data to cache.
696f2c2defSopenharmony_ci * @param cache Operation object.
706f2c2defSopenharmony_ci * @param data Data to be written to the cache.
716f2c2defSopenharmony_ci * @param wLen The length of the data to be written.
726f2c2defSopenharmony_ci * @return Length write.
736f2c2defSopenharmony_ci **/
746f2c2defSopenharmony_ciint32 WriteToCache(HiviewCache *cache, const uint8 *data, uint16 wLen);
756f2c2defSopenharmony_ci
766f2c2defSopenharmony_ci/**
776f2c2defSopenharmony_ci * Read data form cache.
786f2c2defSopenharmony_ci * @param cache Operation object.
796f2c2defSopenharmony_ci * @param data Read buffer.
806f2c2defSopenharmony_ci * @param rLen The length of the data to be read.
816f2c2defSopenharmony_ci * @return Length read.
826f2c2defSopenharmony_ci **/
836f2c2defSopenharmony_ciint32 ReadFromCache(HiviewCache *cache, uint8 *data, uint16 rLen);
846f2c2defSopenharmony_ci
856f2c2defSopenharmony_ci/**
866f2c2defSopenharmony_ci * Preread data form cache.
876f2c2defSopenharmony_ci * Use this method when you don't want to modify the read status of the cache.
886f2c2defSopenharmony_ci * @param cache Operation object.
896f2c2defSopenharmony_ci * @param data Read buffer.
906f2c2defSopenharmony_ci * @param rLen The length of the data to be read.
916f2c2defSopenharmony_ci * @return Length read.
926f2c2defSopenharmony_ci * @attention The value of rCursor will not be changed.
936f2c2defSopenharmony_ci **/
946f2c2defSopenharmony_ciint32 PrereadFromCache(HiviewCache *cache, uint8 *data, uint16 rLen);
956f2c2defSopenharmony_ci
966f2c2defSopenharmony_ci/**
976f2c2defSopenharmony_ci * Discard all cache data.
986f2c2defSopenharmony_ci * Use this method when an unrecoverable data exception is detected.
996f2c2defSopenharmony_ci * @param cache Operation object.
1006f2c2defSopenharmony_ci **/
1016f2c2defSopenharmony_civoid DiscardCacheData(HiviewCache *cache);
1026f2c2defSopenharmony_ci
1036f2c2defSopenharmony_ci/**
1046f2c2defSopenharmony_ci * Destroy the cache and release the memory.
1056f2c2defSopenharmony_ci * @param cache Operation object.
1066f2c2defSopenharmony_ci **/
1076f2c2defSopenharmony_civoid DestroyCache(HiviewCache *cache);
1086f2c2defSopenharmony_ci
1096f2c2defSopenharmony_ci#ifdef __cplusplus
1106f2c2defSopenharmony_ci#if __cplusplus
1116f2c2defSopenharmony_ci}
1126f2c2defSopenharmony_ci#endif
1136f2c2defSopenharmony_ci#endif /* End of #ifdef __cplusplus */
1146f2c2defSopenharmony_ci
1156f2c2defSopenharmony_ci#endif /* End of #ifndef HOS_LITE_HIVIEW_CACHE_H */
116