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