• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *PhotoSchedulerInfo
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_I_STATE_H
17 #define OHOS_CAMERA_DPS_I_STATE_H
18 
19 #include "basic_definitions.h"
20 #include "dp_log.h"
21 
22 namespace OHOS {
23 namespace CameraStandard {
24 namespace DeferredProcessing {
25 const std::string IGNORE_BATTERY_LEVEL = "ohos.dps.ignore_battery_level";
26 const std::string IGNORE_BATTERY = "ohos.dps.ignore_battery";
27 const std::string IGNORE_SCREEN = "ohos.dps.ignore_screen";
28 const std::string IGNORE_TEMPERATURE = "ohos.dps.ignore_temperature";
29 
30 struct SchedulerInfo {
31     bool isNeedStop {true};
32     bool isNeedInterrupt {false};
33     bool isCharging {false};
34 
35     bool operator==(const SchedulerInfo& info) const
36     {
37         return isNeedStop == info.isNeedStop &&
38             isNeedInterrupt == info.isNeedInterrupt &&
39             isCharging == info.isCharging;
40     }
41 };
42 
43 class IState {
44 public:
IState(SchedulerType type,int32_t initValue)45     explicit IState(SchedulerType type, int32_t initValue) : type_(type), stateValue_(initValue)
46     {
47         DP_DEBUG_LOG("entered.");
48     }
49     virtual ~IState() = default;
50 
Initialize()51     int32_t Initialize()
52     {
53         currentInfo_ = ReevaluateSchedulerInfo();
54         return DoInitialize();
55     }
56 
GetSchedulerInfo()57     virtual SchedulerInfo GetSchedulerInfo()
58     {
59         return currentInfo_;
60     }
61 
UpdateSchedulerInfo(int32_t newValue)62     bool UpdateSchedulerInfo(int32_t newValue)
63     {
64         DP_CHECK_RETURN_RET_LOG(stateValue_ == newValue, false,
65             "DPS_EVENT: SchedulerInfo[%{public}d] is not change, state: %{public}d", type_, stateValue_);
66 
67         stateValue_ = newValue;
68         currentInfo_ = ReevaluateSchedulerInfo();
69         DP_INFO_LOG("DPS_EVENT: SchedulerInfo[%{public}d] state set: %{public}d", type_, stateValue_);
70         return true;
71     }
72 
GetSchedulerType()73     inline SchedulerType GetSchedulerType() const
74     {
75         return type_;
76     }
77 
GetState()78     inline int32_t GetState() const
79     {
80         return stateValue_;
81     }
82 
83 protected:
84     virtual SchedulerInfo ReevaluateSchedulerInfo() = 0;
DoInitialize()85     virtual int32_t DoInitialize()
86     {
87         return DP_OK;
88     }
89 
90     const SchedulerType type_;
91     int32_t stateValue_;
92     SchedulerInfo currentInfo_ {true, false, false};
93 };
94 } // namespace DeferredProcessing
95 } // namespace CameraStandard
96 } // namespace OHOS
97 #endif // OHOS_CAMERA_DPS_I_STATE_H