199552fe9Sopenharmony_ci/* 299552fe9Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 399552fe9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 499552fe9Sopenharmony_ci * you may not use this file except in compliance with the License. 599552fe9Sopenharmony_ci * You may obtain a copy of the License at 699552fe9Sopenharmony_ci * 799552fe9Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 899552fe9Sopenharmony_ci * 999552fe9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1099552fe9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1199552fe9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1299552fe9Sopenharmony_ci * See the License for the specific language governing permissions and 1399552fe9Sopenharmony_ci * limitations under the License. 1499552fe9Sopenharmony_ci */ 1599552fe9Sopenharmony_ci 1699552fe9Sopenharmony_ci#ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_RESOURCE_TYPE_H 1799552fe9Sopenharmony_ci#define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_RESOURCE_TYPE_H 1899552fe9Sopenharmony_ci 1999552fe9Sopenharmony_ci#include <string> 2099552fe9Sopenharmony_ci#include <memory> 2199552fe9Sopenharmony_ci 2299552fe9Sopenharmony_ci#include "parcel.h" 2399552fe9Sopenharmony_cinamespace OHOS { 2499552fe9Sopenharmony_cinamespace DevStandbyMgr { 2599552fe9Sopenharmony_cistruct ReasonCodeEnum { 2699552fe9Sopenharmony_ci enum : uint32_t { 2799552fe9Sopenharmony_ci REASON_NATIVE_API = 0, 2899552fe9Sopenharmony_ci REASON_APP_API = 1, 2999552fe9Sopenharmony_ci }; 3099552fe9Sopenharmony_ci}; 3199552fe9Sopenharmony_ciclass ResourceRequest : public Parcelable { 3299552fe9Sopenharmony_cipublic: 3399552fe9Sopenharmony_ci ResourceRequest() = default; 3499552fe9Sopenharmony_ci ResourceRequest(uint32_t allowType, int32_t uid, const std::string& name, int32_t duration, 3599552fe9Sopenharmony_ci const std::string& reason, uint32_t reasonCode) : allowType_(allowType), uid_(uid), name_(name), 3699552fe9Sopenharmony_ci duration_(duration), reason_(reason), reasonCode_(reasonCode) {} 3799552fe9Sopenharmony_ci 3899552fe9Sopenharmony_ci /** 3999552fe9Sopenharmony_ci * @brief Unmarshals a purpose from a Parcel. 4099552fe9Sopenharmony_ci * 4199552fe9Sopenharmony_ci * @param parcel Indicates the parcel object for unmarshalling. 4299552fe9Sopenharmony_ci * @return The info of delay suspend. 4399552fe9Sopenharmony_ci */ 4499552fe9Sopenharmony_ci static sptr<ResourceRequest> Unmarshalling(Parcel& in); 4599552fe9Sopenharmony_ci 4699552fe9Sopenharmony_ci /** 4799552fe9Sopenharmony_ci * @brief Marshals a purpose into a parcel. 4899552fe9Sopenharmony_ci * 4999552fe9Sopenharmony_ci * @param parcel Indicates the parcel object for marshalling. 5099552fe9Sopenharmony_ci * @return True if success, else false. 5199552fe9Sopenharmony_ci */ 5299552fe9Sopenharmony_ci bool Marshalling(Parcel& out) const override; 5399552fe9Sopenharmony_ci 5499552fe9Sopenharmony_ci /** 5599552fe9Sopenharmony_ci * @brief Get the uid of the resource request. 5699552fe9Sopenharmony_ci * 5799552fe9Sopenharmony_ci * @return the allow type. 5899552fe9Sopenharmony_ci */ 5999552fe9Sopenharmony_ci inline uint32_t GetAllowType() const 6099552fe9Sopenharmony_ci { 6199552fe9Sopenharmony_ci return allowType_; 6299552fe9Sopenharmony_ci } 6399552fe9Sopenharmony_ci 6499552fe9Sopenharmony_ci /** 6599552fe9Sopenharmony_ci * @brief Set the allow type which represents the resources. 6699552fe9Sopenharmony_ci * 6799552fe9Sopenharmony_ci * @param allowType represents allow type. 6899552fe9Sopenharmony_ci */ 6999552fe9Sopenharmony_ci inline void SetAllowType(uint32_t allowType) 7099552fe9Sopenharmony_ci { 7199552fe9Sopenharmony_ci allowType_ = allowType; 7299552fe9Sopenharmony_ci } 7399552fe9Sopenharmony_ci 7499552fe9Sopenharmony_ci /** 7599552fe9Sopenharmony_ci * @brief Get the uid of the resource request. 7699552fe9Sopenharmony_ci * 7799552fe9Sopenharmony_ci * @return the uid. 7899552fe9Sopenharmony_ci */ 7999552fe9Sopenharmony_ci inline int32_t GetUid() const 8099552fe9Sopenharmony_ci { 8199552fe9Sopenharmony_ci return uid_; 8299552fe9Sopenharmony_ci } 8399552fe9Sopenharmony_ci 8499552fe9Sopenharmony_ci /** 8599552fe9Sopenharmony_ci * @brief Set the uid of the resource request. 8699552fe9Sopenharmony_ci * 8799552fe9Sopenharmony_ci * @param uid 8899552fe9Sopenharmony_ci */ 8999552fe9Sopenharmony_ci inline void SetUid(int32_t uid) 9099552fe9Sopenharmony_ci { 9199552fe9Sopenharmony_ci uid_ = uid; 9299552fe9Sopenharmony_ci } 9399552fe9Sopenharmony_ci 9499552fe9Sopenharmony_ci /** 9599552fe9Sopenharmony_ci * @brief Get the name of the resource request. 9699552fe9Sopenharmony_ci * 9799552fe9Sopenharmony_ci * @return name of the resource request. 9899552fe9Sopenharmony_ci */ 9999552fe9Sopenharmony_ci inline std::string GetName() const 10099552fe9Sopenharmony_ci { 10199552fe9Sopenharmony_ci return name_; 10299552fe9Sopenharmony_ci } 10399552fe9Sopenharmony_ci 10499552fe9Sopenharmony_ci /** 10599552fe9Sopenharmony_ci * @brief Set the name of the resource request. 10699552fe9Sopenharmony_ci * 10799552fe9Sopenharmony_ci * @param name name of the resource request. 10899552fe9Sopenharmony_ci */ 10999552fe9Sopenharmony_ci inline void SetName(const std::string& name) 11099552fe9Sopenharmony_ci { 11199552fe9Sopenharmony_ci name_ = name; 11299552fe9Sopenharmony_ci } 11399552fe9Sopenharmony_ci 11499552fe9Sopenharmony_ci /** 11599552fe9Sopenharmony_ci * @brief Get the duration of the resource request. 11699552fe9Sopenharmony_ci * 11799552fe9Sopenharmony_ci * @return the duration of the resource request. 11899552fe9Sopenharmony_ci */ 11999552fe9Sopenharmony_ci inline int32_t GetDuration() const 12099552fe9Sopenharmony_ci { 12199552fe9Sopenharmony_ci return duration_; 12299552fe9Sopenharmony_ci } 12399552fe9Sopenharmony_ci 12499552fe9Sopenharmony_ci /** 12599552fe9Sopenharmony_ci * @brief Set the Duration of the resource request. 12699552fe9Sopenharmony_ci * 12799552fe9Sopenharmony_ci * @param duration timeOut of the resource request. 12899552fe9Sopenharmony_ci */ 12999552fe9Sopenharmony_ci inline void SetDuration(int32_t duration) 13099552fe9Sopenharmony_ci { 13199552fe9Sopenharmony_ci duration_ = duration; 13299552fe9Sopenharmony_ci } 13399552fe9Sopenharmony_ci 13499552fe9Sopenharmony_ci /** 13599552fe9Sopenharmony_ci * @brief Get the reason object of the resource request. 13699552fe9Sopenharmony_ci * 13799552fe9Sopenharmony_ci * @return reason of the resource request. 13899552fe9Sopenharmony_ci */ 13999552fe9Sopenharmony_ci inline std::string GetReason() const 14099552fe9Sopenharmony_ci { 14199552fe9Sopenharmony_ci return reason_; 14299552fe9Sopenharmony_ci } 14399552fe9Sopenharmony_ci 14499552fe9Sopenharmony_ci /** 14599552fe9Sopenharmony_ci * @brief Set the reason object of the resource request. 14699552fe9Sopenharmony_ci * 14799552fe9Sopenharmony_ci * @param reason reason of the resource request. 14899552fe9Sopenharmony_ci */ 14999552fe9Sopenharmony_ci inline void SetReason(const std::string& reason) 15099552fe9Sopenharmony_ci { 15199552fe9Sopenharmony_ci reason_ = reason; 15299552fe9Sopenharmony_ci } 15399552fe9Sopenharmony_ci 15499552fe9Sopenharmony_ci /** 15599552fe9Sopenharmony_ci * @brief Get the reason code object of the resource request. 15699552fe9Sopenharmony_ci * 15799552fe9Sopenharmony_ci * @param reason reason code of the resource request. 15899552fe9Sopenharmony_ci */ 15999552fe9Sopenharmony_ci inline uint32_t GetReasonCode() 16099552fe9Sopenharmony_ci { 16199552fe9Sopenharmony_ci return reasonCode_; 16299552fe9Sopenharmony_ci } 16399552fe9Sopenharmony_ci 16499552fe9Sopenharmony_ci /** 16599552fe9Sopenharmony_ci * @brief Set the reason code object of the resource request. 16699552fe9Sopenharmony_ci * 16799552fe9Sopenharmony_ci * @param reason reason code of the resource request. 16899552fe9Sopenharmony_ci */ 16999552fe9Sopenharmony_ci inline void SetReasonCode(uint32_t reasonCode) 17099552fe9Sopenharmony_ci { 17199552fe9Sopenharmony_ci reasonCode_ = reasonCode; 17299552fe9Sopenharmony_ci } 17399552fe9Sopenharmony_ci 17499552fe9Sopenharmony_ciprivate: 17599552fe9Sopenharmony_ci bool ReadFromParcel(Parcel& in); 17699552fe9Sopenharmony_ci 17799552fe9Sopenharmony_ci uint32_t allowType_; 17899552fe9Sopenharmony_ci int32_t uid_; 17999552fe9Sopenharmony_ci std::string name_; 18099552fe9Sopenharmony_ci int32_t duration_; 18199552fe9Sopenharmony_ci std::string reason_; 18299552fe9Sopenharmony_ci uint32_t reasonCode_; 18399552fe9Sopenharmony_ci}; 18499552fe9Sopenharmony_ci} // namespace DevStandbyMgr 18599552fe9Sopenharmony_ci} // namespace OHOS 18699552fe9Sopenharmony_ci#endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_RESOURCE_TYPE_H