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 #include "security_event_info.h" 23 #include "i_model_info.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 InsertEventGroupMap(const std::unordered_map<std::string, EventGroupCfg> &eventGroupMap); 34 bool GetIsBatchUpload(const std::string &groupName); 35 bool GetEventGroupConfig(const std::string &groupName, EventGroupCfg &config); 36 void ResetModelMap(); 37 void ResetEventMap(); 38 void ResetModelToEventMap(); 39 void ResetEventToTableMap(); 40 std::vector<int64_t> GetEventIds(uint32_t modelId); 41 std::vector<int64_t> GetAllEventIds(); 42 std::vector<uint32_t> GetAllModelIds(); 43 std::vector<EventCfg> GetAllEventConfigs(); 44 bool GetModelConfig(uint32_t modelId, ModelCfg &config); 45 bool GetEventConfig(int64_t eventId, EventCfg &config); 46 std::string GetTableFromEventId(int64_t eventId); 47 private: 48 std::unordered_map<uint32_t, std::set<int64_t>> modelToEventMap_; 49 std::unordered_map<uint32_t, ModelCfg> modelMap_; 50 std::unordered_map<int64_t, EventCfg> eventMap_; 51 std::unordered_map<int64_t, std::string> eventToTableMap_; 52 std::unordered_map<std::string, EventGroupCfg> eventGroupMap_; 53 std::mutex modelToEventMutex_; 54 std::mutex modelMutex_; 55 std::mutex eventMutex_; 56 std::mutex eventGroupMutex_; 57 std::mutex eventToTableMutex_; 58 }; 59 } // OHOS::Security::SecurityGuard 60 61 #endif // SECURITY_GUARD_CONFIG_DATA_MANAGER_H