• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
42     class CameraCommonEventSubscriber : public EventFwk::CommonEventSubscriber {
43     public:
44     CameraCommonEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, EventReceiver receiver);
45     void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
46 
47     private:
48         EventReceiver eventReceiver_;
49     };
50 
51 private:
52     static sptr<CameraCommonEventManager> instance_;
53     std::map<std::string, std::shared_ptr<CameraCommonEventSubscriber>> commonEventSubscriberMap_;
54     static std::mutex instanceMutex_;
55     static std::mutex mapMutex_;
56 };
57 } // namespace CameraStandard
58 } // namespace OHOS
59 #endif // CAMERA_COMMON_EVENT_MANAGER_H
60