• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 EVENT_CONFIG_H
17 #define EVENT_CONFIG_H
18 
19 #include <fstream>
20 #include <mutex>
21 #include <optional>
22 #include <sstream>
23 #include <string>
24 #include <unordered_map>
25 
26 #include <cJSON.h>
27 #include <unistd.h>
28 
29 namespace OHOS {
30 namespace ExternalDeviceManager {
31 struct FaultInfo {
32     std::string faultName;
33     std::string type;
34     std::string title;
35     std::string msg;
36     std::string uri;
GetInfoFaultInfo37     std::string GetInfo() const
38     {
39         return "faultName: " + faultName + ", type: " + type + ", title: " + title + ", msg: " + msg +
40             ", uri: " + uri;
41     }
42 };
43 using DomainFaultsMap  = std::unordered_map<std::string, std::vector<FaultInfo>>;
44 class EventConfig {
45 public:
46     static EventConfig &GetInstance();
47     FaultInfo ExtractFaultInfo(const cJSON *faultItem);
48     std::vector<FaultInfo> GetFaultsInfoByDomain(const std::string &domain);
49     bool ParseJsonFile();
50     FaultInfo GetFaultInfo(const std::string &domain, const std::string &faultName) const;
51 
52 private:
53     DomainFaultsMap FillFaultsMap(const DomainFaultsMap &ccmMap, const DomainFaultsMap &localMap);
54     void DeleteJsonObj(cJSON *obj);
55     bool ParseJsonFile(const std::string &targetPath, DomainFaultsMap &peripheralFaultNap);
56     DomainFaultsMap peripheralFaultsMap_;
57     static std::mutex mutex_;
58     static std::shared_ptr<EventConfig> instance_;
59 };
60 } // namespace ExternalDeviceManager
61 } // namespace OHOS
62 #endif // EVENT_CONFIG_H
63