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 OHOS_MEMORY_MEMMGR_BUNDLE_PRIORITY_INFO_H
17 #define OHOS_MEMORY_MEMMGR_BUNDLE_PRIORITY_INFO_H
18 
19 #include <string>
20 #include <map>
21 #include <mutex>
22 
23 #include "reclaim_priority_constants.h"
24 #include "process_priority_info.h"
25 
26 namespace OHOS {
27 namespace Memory {
28 class BundlePriorityInfo {
29 public:
30     using ProcessesInfoMap = std::map<pid_t, ProcessPriorityInfo>;
31     explicit BundlePriorityInfo(const std::string &name, int bundleUid);
32     explicit BundlePriorityInfo(const std::string &name, int bundleUid, int priority);
33     explicit BundlePriorityInfo(const std::string &name, int bundleUid, int priority, int accountId, BundleState state);
34     BundlePriorityInfo(const BundlePriorityInfo &copyBundle);
35     inline bool operator<(const BundlePriorityInfo &tmp) const
36     {
37         return priority_ < tmp.priority_;
38     }
39     std::string name_;
40     int uid_;
41     ProcessesInfoMap procs_;
42     int priority_;
43     int accountId_;
44     BundleState state_;
45     std::mutex bundleLock_;
46     int64_t createTime_;
47 
48     bool HasProc(pid_t pid);
49     void AddProc(ProcessPriorityInfo &newProcess);
50     void RemoveProcByPid(pid_t pid);
51     ProcessPriorityInfo& FindProcByPid(pid_t pid);
52     int GetProcsCount();
53     int GetMinProcPriority();
54     void SetPriority(int targetPriority);
55     void UpdatePriority();
56     BundleState GetState();
57     void SetState(BundleState state);
58     int64_t GetCreateTime() const;
59     void SetCreateTime(const int64_t createTime);
60     void IncreaseProcsPriority(int delta);
61 };
62 } // namespace Memory
63 } // namespace OHOS
64 #endif // OHOS_MEMORY_MEMMGR_BUNDLE_PRIORITY_INFO_H
65