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 #include "power_policy.h"
17
18 #include "edm_log.h"
19 #include "parcel_macro.h"
20
21 namespace OHOS {
22 namespace EDM {
Marshalling(MessageParcel & parcel) const23 bool PowerPolicy::Marshalling(MessageParcel &parcel) const
24 {
25 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, static_cast<uint32_t>(powerPolicyAction_));
26 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, delayTime_);
27 return true;
28 }
29
Unmarshalling(MessageParcel & parcel,PowerPolicy & powerPolicy)30 bool PowerPolicy::Unmarshalling(MessageParcel &parcel, PowerPolicy &powerPolicy)
31 {
32 uint32_t action = parcel.ReadUint32();
33 uint32_t delayTime = parcel.ReadUint32();
34 if (!powerPolicy.SetPowerPolicyAction(action)) {
35 return false;
36 }
37 powerPolicy.SetDelayTime(delayTime);
38 return true;
39 }
40
SetDelayTime(uint32_t delayTime)41 void PowerPolicy::SetDelayTime(uint32_t delayTime)
42 {
43 delayTime_ = delayTime;
44 }
45
SetPowerPolicyAction(uint32_t action)46 bool PowerPolicy::SetPowerPolicyAction(uint32_t action)
47 {
48 if (action >= static_cast<uint32_t>(PowerPolicyAction::NONE) &&
49 action <= static_cast<uint32_t>(PowerPolicyAction::SHUTDOWN)) {
50 powerPolicyAction_ = PowerPolicyAction(action);
51 return true;
52 }
53 return false;
54 }
55
GetPowerPolicyAction() const56 PowerPolicyAction PowerPolicy::GetPowerPolicyAction() const
57 {
58 return powerPolicyAction_;
59 }
60
GetDealyTime() const61 uint32_t PowerPolicy::GetDealyTime() const
62 {
63 return delayTime_;
64 }
65 } // namespace EDM
66 } // namespace OHOS
67