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