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 FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EVENT_CONFIG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EVENT_CONFIG_H 18 19 #include <string> 20 #include <list> 21 #include <memory> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "base/json/json_util.h" 26 27 namespace OHOS::Ace::Recorder { 28 struct ExposureCfg { 29 std::string id; 30 double ratio = 0.0; 31 int duration = 0; 32 33 bool operator==(const ExposureCfg& exposureCfg) const 34 { 35 return id == exposureCfg.id; 36 } 37 }; 38 39 struct ExposureCfgHash { operatorExposureCfgHash40 size_t operator()(const ExposureCfg& exposureCfg) const 41 { 42 return std::hash<std::string>()(exposureCfg.id); 43 } 44 }; 45 46 struct PageCfg { 47 std::list<std::string> shareNodes; 48 std::list<ExposureCfg> exposureCfgs; 49 }; 50 51 using Config = std::unordered_map<std::string, PageCfg>; 52 53 class EventConfig final { 54 public: 55 EventConfig(); 56 ~EventConfig() = default; 57 58 void Init(const std::string& config); 59 bool IsEnable() const; 60 bool IsCategoryEnable(int32_t index) const; 61 const std::shared_ptr<Config>& GetConfig() const; GetWebCategory()62 std::string GetWebCategory() const 63 { 64 return webCategory_; 65 } 66 GetWebIdentifier()67 std::string GetWebIdentifier() const 68 { 69 return webIdentifier_; 70 } 71 GetWebJsCode()72 const std::string& GetWebJsCode() const 73 { 74 return webJsCode_; 75 } 76 77 private: 78 inline void ParseSwitch(const std::unique_ptr<JsonValue>& jsonObj); 79 inline void ParseJsCode(const std::unique_ptr<JsonValue>& jsonObj); 80 inline void ParseShareNode(const std::unique_ptr<JsonValue>& shareNodeArray, PageCfg& pageCfg); 81 inline void ParseExposureCfg(const std::unique_ptr<JsonValue>& exposureCfgArray, PageCfg& pageCfg); 82 bool enable_ = false; 83 std::vector<bool> switches_; 84 85 std::shared_ptr<Config> config_; 86 std::string webCategory_; 87 std::string webIdentifier_; 88 std::string webJsCode_; 89 }; 90 } // namespace OHOS::Ace::Recorder 91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EVENT_CONFIG_H 92