• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 OHOS_CAMERA_DPS_EVENTS_MONITOR_H
17 #define OHOS_CAMERA_DPS_EVENTS_MONITOR_H
18 
19 #include "events_subscriber.h"
20 #include "ievents_listener.h"
21 #include "singleton.h"
22 #include "system_ability_status_change_stub.h"
23 
24 namespace OHOS {
25 namespace CameraStandard {
26 namespace DeferredProcessing {
27 class CommonEventListener : public SystemAbilityStatusChangeStub {
28 public:
29     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
30     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
31 
32 private:
33     std::shared_ptr<EventSubscriber> eventSubscriber_ {nullptr};
34 };
35 
36 class EventsMonitor : public Singleton<EventsMonitor> {
37     DECLARE_SINGLETON(EventsMonitor)
38 
39 public:
40     void Initialize();
41     void NotifyCameraSessionStatus(const int32_t userId,
42         const std::string& cameraId, bool running, bool isSystemCamera);
43     void NotifyMediaLibraryStatus(bool available);
44     void NotifyImageEnhanceStatus(int32_t status);
45     void NotifyScreenStatus(int32_t status);
46     void NotifyChargingStatus(int32_t status);
47     void NotifyBatteryStatus(int32_t status);
48     void NotifyBatteryLevel(int32_t level);
49     void NotifySystemPressureLevel(SystemPressureLevel level);
50     void NotifyThermalLevel(int level);
51     void NotifyPhotoProcessSize(int32_t size);
52     void NotifyEventToObervers(int userId, EventType event, int value);
53     void RegisterEventsListener(int userId, const std::vector<EventType>& events,
54         const std::weak_ptr<IEventsListener>& listener);
55     void NotifyObservers(EventType event, int value, int userId = 0);
56 
57 private:
58     void NotifyObserversUnlocked(int userId, EventType event, int value);
59     int32_t SubscribeSystemAbility();
60     int32_t UnSubscribeSystemAbility();
61 
62     std::mutex mutex_;
63     std::atomic_bool initialized_ {false};
64     std::atomic<int> numActiveSessions_ {0};
65     std::map<int32_t, std::map<EventType, std::vector<std::weak_ptr<IEventsListener>>>> userIdToeventListeners_ {};
66     sptr<CommonEventListener> ceListener_ {nullptr};
67 };
68 } // namespace DeferredProcessing
69 } // namespace CameraStandard
70 } // namespace OHOS
71 #endif // OHOS_CAMERA_DPS_EVENTS_MONITOR_H
72