1 /*
2  * Copyright (c) 2022 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_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_RESOURCE_CALLBACK_INFO_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_RESOURCE_CALLBACK_INFO_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 
23 #include "parcel.h"
24 
25 namespace OHOS {
26 namespace BackgroundTaskMgr {
27 class ResourceCallbackInfo : public Parcelable  {
28 public:
29     ResourceCallbackInfo() = default;
ResourceCallbackInfo(int32_t uid,int32_t pid,uint32_t resourceNumber,std::string bundleName)30     ResourceCallbackInfo(int32_t uid, int32_t pid, uint32_t resourceNumber, std::string bundleName)
31         : uid_(uid), pid_(pid), resourceNumber_(resourceNumber), bundleName_(bundleName) {}
32 
33     /**
34      * @brief Marshals a purpose into a parcel.
35      *
36      * @param parcel Indicates the parcel object for marshalling.
37      * @return True if success, else false.
38      */
39     bool Marshalling(Parcel& out) const override;
40 
41     /**
42      * @brief Unmarshals a purpose from a Parcel.
43      *
44      * @param parcel Indicates the Parcel object for unmarshalling.
45      * @return App info of transient task.
46      */
47     static ResourceCallbackInfo* Unmarshalling(Parcel& in);
48 
49     /**
50      * @brief read date from a parcel, transform json to data
51      *
52      * @param in
53      * @return true read data from parcel seccessed
54      * @return false failed
55      */
56     bool ReadFromParcel(Parcel& in);
57 
58     /**
59      * @brief Get the uid.
60      *
61      * @return The uid of app.
62      */
GetUid()63     inline int32_t GetUid()
64     {
65         return uid_;
66     }
67 
68     /**
69      * @brief Get the uid.
70      *
71      * @return The pid of app.
72      */
GetPid()73     inline int32_t GetPid()
74     {
75         return pid_;
76     }
77 
78     /**
79      * @brief Get the resourceNumber.
80      *
81      * @return The type of the resources.
82      */
GetResourceNumber()83     inline uint32_t GetResourceNumber()
84     {
85         return resourceNumber_;
86     }
87 
88     /**
89      * @brief Get the bundleName_.
90      *
91      * @return The bundle name of the app.
92      */
GetBundleName()93     inline std::string GetBundleName()
94     {
95         return bundleName_;
96     }
97 
98     /**
99      * @brief Set the Resource Number object
100      *
101      * @param resourceNumber represents resource types.
102      */
SetResourceNumber(uint32_t resourceNumber)103     inline void SetResourceNumber(uint32_t resourceNumber)
104     {
105         resourceNumber_ = resourceNumber;
106     }
107 private:
108     int32_t uid_ {0};
109     int32_t pid_ {0};
110     uint32_t resourceNumber_ {0};
111     std::string bundleName_ {""};
112 };
113 }  // namespace BackgroundTaskMgr
114 }  // namespace OHOS
115 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_RESOURCE_CALLBACK_INFO_H