1 /* 2 * Copyright (c) 2024-2024 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 #ifndef CAMERA_COMMON_EVENT_MANAGER_H 16 #define CAMERA_COMMON_EVENT_MANAGER_H 17 18 #include "refbase.h" 19 #include "camera_log.h" 20 #include "camera_util.h" 21 #include "common_event_data.h" 22 #include "common_event_manager.h" 23 #include "common_event_subscriber.h" 24 #include "common_event_support.h" 25 #include "matching_skills.h" 26 27 #include <functional> 28 #include <mutex> 29 30 namespace OHOS { 31 namespace CameraStandard { 32 33 using EventReceiver = std::function<void(const EventFwk::CommonEventData&)>; 34 class CameraCommonEventManager : public RefBase { 35 public: 36 CameraCommonEventManager(); 37 ~CameraCommonEventManager(); 38 static sptr<CameraCommonEventManager> GetInstance(); 39 void SubscribeCommonEvent(const std::string &eventName, EventReceiver receiver); 40 void UnSubscribeCommonEvent(const std::string &eventName); 41 bool IsScreenLocked(); 42 void SetScreenLocked(bool status); 43 44 class CameraCommonEventSubscriber : public EventFwk::CommonEventSubscriber { 45 public: 46 CameraCommonEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, EventReceiver receiver); 47 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 48 49 private: 50 EventReceiver eventReceiver_; 51 }; 52 53 private: 54 static sptr<CameraCommonEventManager> instance_; 55 std::map<std::string, std::shared_ptr<CameraCommonEventSubscriber>> commonEventSubscriberMap_; 56 static std::mutex instanceMutex_; 57 static std::mutex mapMutex_; 58 bool isScreenLocked_ = false; 59 }; 60 } // namespace CameraStandard 61 } // namespace OHOS 62 #endif // CAMERA_COMMON_EVENT_MANAGER_H