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_SERVICES_EFFICIENCY_RESOURCES_INCLUDE_REC_APPLY_RECORD_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_EFFICIENCY_RESOURCES_INCLUDE_REC_APPLY_RECORD_H
18 
19 #include <list>
20 #include <sstream>
21 
22 #include "iremote_object.h"
23 #include "parcel.h"
24 #include "nlohmann/json.hpp"
25 
26 namespace OHOS {
27 namespace BackgroundTaskMgr {
28 class BgEfficiencyResourcesMgr;
29 
30 struct PersistTime {
31     uint32_t resourceIndex_ {0};
32     bool isPersist_ {false};
33     int64_t endTime_ {0};
34     std::string reason_ {""};
35     PersistTime() = default;
36     PersistTime(const uint32_t resourceIndex, const bool isPersist, const int64_t endTime,
37         const std::string &reason);
38     bool operator < (const PersistTime& rhs) const;
39 };
40 
41 class ResourceApplicationRecord {
42 public:
43     ResourceApplicationRecord() = default;
ResourceApplicationRecord(int32_t uid,int32_t pid,uint32_t resourceNumber,std::string bundleName)44     ResourceApplicationRecord(int32_t uid, int32_t pid, uint32_t resourceNumber, std::string bundleName)
45         : uid_(uid), pid_(pid), resourceNumber_(resourceNumber), bundleName_(bundleName) {}
46     ~ResourceApplicationRecord() = default;
47     int32_t GetUid() const;
48     int32_t GetPid() const;
49     std::string GetBundleName() const;
50     uint32_t GetResourceNumber() const;
51     std::list<PersistTime>& GetResourceUnitList();
52     void SetResourceNumber();
53     void ParseToJson(nlohmann::json &root);
54     std::string ParseToJsonStr();
55     bool ParseFromJson(const nlohmann::json& value);
56 
57 private:
58     int32_t uid_ {0};
59     int32_t pid_ {0};
60     uint32_t resourceNumber_ {0};
61     std::string bundleName_ {""};
62     std::list<PersistTime> resourceUnitList_ {};
63 
64     friend class BgEfficiencyResourcesMgr;
65 };
66 }  // namespace BackgroundTaskMgr
67 }  // namespace OHOS
68 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_EFFICIENCY_RESOURCES_INCLUDE_REC_APPLY_RECORD_H