1 /* 2 * Copyright (c) 2023 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 SECURITY_GUARD_CONFIG_DATA_MANAGER_H 17 #define SECURITY_GUARD_CONFIG_DATA_MANAGER_H 18 19 #include <mutex> 20 #include <set> 21 #include <unordered_map> 22 23 #include "config_define.h" 24 25 namespace OHOS::Security::SecurityGuard { 26 class ConfigDataManager { 27 public: 28 static ConfigDataManager &GetInstance(); 29 void InsertModelMap(uint32_t modelId, const ModelCfg &config); 30 void InsertEventMap(int64_t eventId, const EventCfg &config); 31 void InsertModelToEventMap(uint32_t modelId, std::set<int64_t> eventIds); 32 void InsertEventToTableMap(int64_t eventId, std::string table); 33 void ResetModelMap(); 34 void ResetEventMap(); 35 void ResetModelToEventMap(); 36 void ResetEventToTableMap(); 37 std::vector<int64_t> GetEventIds(uint32_t modelId); 38 std::vector<int64_t> GetAllEventIds(); 39 std::vector<uint32_t> GetAllModelIds(); 40 bool GetModelConfig(uint32_t modelId, ModelCfg &config); 41 bool GetEventConfig(int64_t eventId, EventCfg &config); 42 std::string GetTableFromEventId(int64_t eventId); 43 std::vector<AppInfo> GetAppInfosByName(const std::string &appName); 44 private: 45 std::unordered_map<uint32_t, std::set<int64_t>> modelToEventMap_; 46 std::unordered_map<uint32_t, ModelCfg> modelMap_; 47 std::unordered_map<int64_t, EventCfg> eventMap_; 48 std::unordered_map<int64_t, std::string> eventToTableMap_; 49 std::mutex modelToEventMutex_; 50 std::mutex modelMutex_; 51 std::mutex eventMutex_; 52 std::mutex eventToTableMutex_; 53 }; 54 } // OHOS::Security::SecurityGuard 55 56 #endif // SECURITY_GUARD_CONFIG_DATA_MANAGER_H