1 /*
2  * Copyright (c) 2022-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 SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H
17 #define SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H
18 
19 #include "i_socperf_service.h"  // for ISocPerfService
20 
21 namespace OHOS {
22 namespace SOCPERF {
23 class SocPerfClient {
24 public:
25     /**
26      * @brief Get the Instance object
27      *
28      * @return SocPerfClient&
29      */
30     static SocPerfClient& GetInstance();
31 
32     /**
33      * @brief Sending a performance request.
34      *
35      * @param cmdId Scene id defined in config file.
36      * @param msg Additional string info, which is used for other extensions.
37      */
38     void PerfRequest(int32_t cmdId, const std::string& msg);
39 
40     /**
41      * @brief Sending a performance request.
42      *
43      * @param cmdId Scene id defined in config file.
44      * @param onOffTag Indicates the start of end of a long-term frequency increase event.
45      * @param msg Additional string info, which is used for other extensions.
46      */
47     void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg);
48 
49     /**
50      * @brief Sending a power limit boost request.
51      *
52      * @param onOffTag Indicates the start of end of a power limit boost event.
53      * @param msg Additional string info, which is used for other extensions.
54      */
55     void PowerLimitBoost(bool onOffTag, const std::string& msg);
56 
57     /**
58      * @brief Sending a thermal limit boost request.
59      *
60      * @param onOffTag Indicates the start of end of a thermal limit boost event.
61      * @param msg Additional string info, which is used for other extensions.
62      */
63     void ThermalLimitBoost(bool onOffTag, const std::string& msg);
64 
65     /**
66      * @brief Sending a limit request.
67      *
68      * @param clientId Used to indentify the caller of frequency limiting, such as
69      * the thermal module or power consumption module.
70      * @param configs Indicates the specific value to be limited.
71      * @param msg Additional string info, which is used for other extensions.
72      */
73     void LimitRequest(int32_t clientId,
74         const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg);
75 
76     /**
77      * @brief set socperf server status, enable or disable
78      *
79      * @param status true means enable socperfserver, false means disable socperfserver
80      * @param msg the reason why we need change socperfserver status
81      */
82     void SetRequestStatus(bool status, const std::string& msg);
83 
84     /**
85      * @brief set thermal level intermal for perfquest
86      *
87      * @param level thermal level
88      */
89     void SetThermalLevel(int32_t level);
90 
91     /**
92      * @brief send the device mode, enable or disable
93      *
94      * @param mode the mode which will to be changed
95      * @param status true means socperfserver enter the device mode, false quit the device mode
96      */
97     void RequestDeviceMode(const std::string& mode, bool status);
98 
99     /**
100      * @brief get cmd Id count, cmdID is trigger, its count++
101      * @param msg the reason
102      * @return cmdId count, as 10000:xx,10001:xx
103      */
104     std::string RequestCmdIdCount(const std::string& msg);
105 
106     /**
107      * @brief Reset SocperfClient
108      *
109      */
110     void ResetClient();
111 
112 private:
SocPerfClient()113     SocPerfClient() {}
~SocPerfClient()114     ~SocPerfClient() {}
115 
116 private:
117     bool CheckClientValid();
118     std::string AddPidAndTidInfo(const std::string& msg);
119 
120 private:
121     class SocPerfDeathRecipient : public IRemoteObject::DeathRecipient {
122     public:
123         explicit SocPerfDeathRecipient(SocPerfClient &socPerfClient);
124 
125         ~SocPerfDeathRecipient();
126 
127         void OnRemoteDied(const wptr<IRemoteObject> &object) override;
128 
129     private:
130         SocPerfClient &socPerfClient_;
131     };
132 
133 private:
134     std::mutex mutex_;
135     sptr<ISocPerfService> client;
136     sptr<SocPerfDeathRecipient> recipient_;
137 };
138 } // namespace SOCPERF
139 } // namespace OHOS
140 
141 #endif // SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H
142