1 /*
2  * Copyright (c) 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 FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_RESOURCE_TYPE_H
17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_RESOURCE_TYPE_H
18 
19 #include <string>
20 #include <memory>
21 
22 #include "parcel.h"
23 namespace OHOS {
24 namespace DevStandbyMgr {
25 struct ReasonCodeEnum {
26     enum : uint32_t {
27         REASON_NATIVE_API = 0,
28         REASON_APP_API = 1,
29     };
30 };
31 class ResourceRequest : public Parcelable {
32 public:
33     ResourceRequest() = default;
ResourceRequest(uint32_t allowType,int32_t uid,const std::string & name,int32_t duration,const std::string & reason,uint32_t reasonCode)34     ResourceRequest(uint32_t allowType, int32_t uid, const std::string& name, int32_t duration,
35         const std::string& reason, uint32_t reasonCode) : allowType_(allowType), uid_(uid), name_(name),
36         duration_(duration), reason_(reason), reasonCode_(reasonCode) {}
37 
38     /**
39      * @brief Unmarshals a purpose from a Parcel.
40      *
41      * @param parcel Indicates the parcel object for unmarshalling.
42      * @return The info of delay suspend.
43      */
44     static sptr<ResourceRequest> Unmarshalling(Parcel& in);
45 
46     /**
47      * @brief Marshals a purpose into a parcel.
48      *
49      * @param parcel Indicates the parcel object for marshalling.
50      * @return True if success, else false.
51      */
52     bool Marshalling(Parcel& out) const override;
53 
54     /**
55      * @brief Get the uid of the resource request.
56      *
57      * @return the allow type.
58      */
GetAllowType()59     inline uint32_t GetAllowType() const
60     {
61         return allowType_;
62     }
63 
64     /**
65      * @brief Set the allow type which represents the resources.
66      *
67      * @param allowType represents allow type.
68      */
SetAllowType(uint32_t allowType)69     inline void SetAllowType(uint32_t allowType)
70     {
71         allowType_ = allowType;
72     }
73 
74     /**
75      * @brief Get the uid of the resource request.
76      *
77      * @return the uid.
78      */
GetUid()79     inline int32_t GetUid() const
80     {
81         return uid_;
82     }
83 
84     /**
85      * @brief Set the uid of the resource request.
86      *
87      * @param uid
88      */
SetUid(int32_t uid)89     inline void SetUid(int32_t uid)
90     {
91         uid_ = uid;
92     }
93 
94     /**
95      * @brief Get the name of the resource request.
96      *
97      * @return name of the resource request.
98      */
GetName()99     inline std::string GetName() const
100     {
101         return name_;
102     }
103 
104     /**
105      * @brief Set the name of the resource request.
106      *
107      * @param name name of the resource request.
108      */
SetName(const std::string & name)109     inline void SetName(const std::string& name)
110     {
111         name_ = name;
112     }
113 
114     /**
115      * @brief Get the duration of the resource request.
116      *
117      * @return the duration of the resource request.
118      */
GetDuration()119     inline int32_t GetDuration() const
120     {
121         return duration_;
122     }
123 
124     /**
125      * @brief Set the Duration of the resource request.
126      *
127      * @param duration timeOut of the resource request.
128      */
SetDuration(int32_t duration)129     inline void SetDuration(int32_t duration)
130     {
131         duration_ = duration;
132     }
133 
134     /**
135      * @brief Get the reason object of the resource request.
136      *
137      * @return reason of the resource request.
138      */
GetReason()139     inline std::string GetReason() const
140     {
141         return reason_;
142     }
143 
144     /**
145      * @brief Set the reason object of the resource request.
146      *
147      * @param reason reason of the resource request.
148      */
SetReason(const std::string & reason)149     inline void SetReason(const std::string& reason)
150     {
151         reason_ = reason;
152     }
153 
154     /**
155      * @brief Get the reason code object of the resource request.
156      *
157      * @param reason reason code of the resource request.
158      */
GetReasonCode()159     inline uint32_t GetReasonCode()
160     {
161         return reasonCode_;
162     }
163 
164     /**
165      * @brief Set the reason code object of the resource request.
166      *
167      * @param reason reason code of the resource request.
168      */
SetReasonCode(uint32_t reasonCode)169     inline void SetReasonCode(uint32_t reasonCode)
170     {
171         reasonCode_ = reasonCode;
172     }
173 
174 private:
175     bool ReadFromParcel(Parcel& in);
176 
177     uint32_t allowType_;
178     int32_t uid_;
179     std::string name_;
180     int32_t duration_;
181     std::string reason_;
182     uint32_t reasonCode_;
183 };
184 }  // namespace DevStandbyMgr
185 }  // namespace OHOS
186 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_RESOURCE_TYPE_H