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 OHOS_CAMERA_ROTATE_SERVICE_SERVICES_INCLUDE_CAMERA_ROTATE_PARAM_MANAGER_H 17 #define OHOS_CAMERA_ROTATE_SERVICE_SERVICES_INCLUDE_CAMERA_ROTATE_PARAM_MANAGER_H 18 19 #include <string> 20 #include <mutex> 21 #include <map> 22 #include <functional> 23 #include <memory> 24 25 #include "camera_rotate_param_reader.h" 26 #include "common_event_subscriber.h" 27 #include "parser.h" 28 #include "camera_xml_parser.h" 29 #include "want.h" 30 31 namespace OHOS { 32 namespace CameraStandard { 33 34 class CameraRoateParamManager { 35 public: 36 static CameraRoateParamManager& GetInstance(); 37 void InitParam(); 38 int GetFeatureSwitchConfig(); 39 void SubscriberEvent(); 40 void UnSubscriberEvent(); 41 void OnReceiveEvent(const AAFwk::Want &want); 42 std::vector<CameraRotateStrategyInfo> GetCameraRotateStrategyInfos(); 43 44 private: 45 class ParamCommonEventSubscriber : public EventFwk::CommonEventSubscriber { 46 public: ParamCommonEventSubscriber(const EventFwk::CommonEventSubscribeInfo & subscriberInfo,CameraRoateParamManager & registry)47 explicit ParamCommonEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, 48 CameraRoateParamManager ®istry) 49 : CommonEventSubscriber(subscriberInfo), registry_(registry) 50 {} 51 ~ParamCommonEventSubscriber() = default; 52 OnReceiveEvent(const EventFwk::CommonEventData & data)53 void OnReceiveEvent(const EventFwk::CommonEventData &data) override 54 { 55 registry_.OnReceiveEvent(data.GetWant()); 56 } 57 58 private: 59 CameraRoateParamManager ®istry_; 60 }; 61 CameraRoateParamManager() = default; 62 ~CameraRoateParamManager() = default; 63 void ReloadParam(); 64 std::string LoadVersion(); 65 void LoadParamStr(); 66 std::string GetVersion(); 67 bool LoadConfiguration(const std::string &filepath); 68 void Destroy(); 69 void InitDefaultConfig(); 70 void CopyFileToLocal(); 71 bool DoCopy(const std::string& src, const std::string& des); 72 void VerifyCloudFile(const std::string& prePath); 73 void HandleParamUpdate(const AAFwk::Want &want)const; 74 bool ParseInternal(std::shared_ptr<CameraXmlNode> curNode); 75 void ParserStrategyInfo(std::shared_ptr<CameraXmlNode> curNode); 76 77 std::mutex strategyInfosMutex_; 78 std::shared_ptr<CameraXmlNode> curNode_ = nullptr; 79 std::vector<CameraRotateStrategyInfo> cameraRotateStrategyInfos_ = {}; 80 std::mutex mutxVerify; 81 std::shared_ptr<CameraRoateParamReader> paramReader = nullptr; 82 int totalFeatureSwitch = 0; 83 using EventHandle = std::function<void(const OHOS::AAFwk::Want &)>; 84 typedef void (CameraRoateParamManager::*HandleEventFunc)(const AAFwk::Want &) const; 85 std::map<std::string, EventHandle> eventHandles_; 86 std::map<std::string, HandleEventFunc> handleEventFunc_; 87 std::shared_ptr<ParamCommonEventSubscriber> subscriber_ = nullptr; 88 }; 89 90 } // namespace CameraStandard 91 } // namespace OHOS 92 #endif // OHOS_CAMERA_ROTATE_SERVICE_SERVICES_INCLUDE_CAMERA_ROTATE_PARAM_MANAGER_H 93