1 /* 2 * Copyright (c) 2022 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 #ifndef HIAPPEVENT_FRAMEWORKS_NATIVE_LIB_HIAPPEVENT_CACHE_APP_EVENT_CACHE_H 16 #define HIAPPEVENT_FRAMEWORKS_NATIVE_LIB_HIAPPEVENT_CACHE_APP_EVENT_CACHE_H 17 18 #include <map> 19 #include <memory> 20 #include <mutex> 21 #include <string> 22 #include <utility> 23 24 #include "app_event_block.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 class AppEventStore; 29 30 class AppEventCache { 31 public: 32 static std::shared_ptr<AppEventCache> GetInstance(); 33 bool IsOpen(); 34 int Open(const std::string& dir); 35 int Close(); 36 int CreateBlock(const std::string& name); 37 int DestroyBlock(const std::string& name); 38 std::shared_ptr<AppEventBlock> GetBlock(const std::string& name); 39 int GetBlocksStat(std::map<std::string, std::pair<int, int64_t>>& blocksStat); 40 41 private: 42 static std::mutex cacheMutex_; 43 static std::shared_ptr<AppEventCache> instance_; 44 std::shared_ptr<AppEventStore> store_; 45 std::map<std::string, std::shared_ptr<AppEventBlock>> blocks_; 46 }; 47 } // namespace HiviewDFX 48 } // namespace OHOS 49 #endif // HIAPPEVENT_FRAMEWORKS_NATIVE_LIB_HIAPPEVENT_CACHE_APP_EVENT_CACHE_H 50