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 <cstdint> // for int32_t 20 #include <iosfwd> // for string 21 #include <vector> // for vector 22 #include "i_socperf_service.h" // for ISocPerfService 23 24 namespace OHOS { 25 namespace SOCPERF { 26 class SocPerfClient { 27 public: 28 /** 29 * @brief Get the Instance object 30 * 31 * @return SocPerfClient& 32 */ 33 static SocPerfClient& GetInstance(); 34 35 /** 36 * @brief Sending a performance request. 37 * 38 * @param cmdId Scene id defined in config file. 39 * @param msg Additional string info, which is used for other extensions. 40 */ 41 void PerfRequest(int32_t cmdId, const std::string& msg); 42 43 /** 44 * @brief Sending a performance request. 45 * 46 * @param cmdId Scene id defined in config file. 47 * @param onOffTag Indicates the start of end of a long-term frequency increase event. 48 * @param msg Additional string info, which is used for other extensions. 49 */ 50 void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg); 51 52 /** 53 * @brief Sending a power limit boost request. 54 * 55 * @param onOffTag Indicates the start of end of a power limit boost event. 56 * @param msg Additional string info, which is used for other extensions. 57 */ 58 void PowerLimitBoost(bool onOffTag, const std::string& msg); 59 60 /** 61 * @brief Sending a thermal limit boost request. 62 * 63 * @param onOffTag Indicates the start of end of a thermal limit boost event. 64 * @param msg Additional string info, which is used for other extensions. 65 */ 66 void ThermalLimitBoost(bool onOffTag, const std::string& msg); 67 68 /** 69 * @brief Sending a limit request. 70 * 71 * @param clientId Used to indentify the caller of frequency limiting, such as 72 * the thermal module or power consumption module. 73 * @param configs Indicates the specific value to be limited. 74 * @param msg Additional string info, which is used for other extensions. 75 */ 76 void LimitRequest(int32_t clientId, 77 const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg); 78 79 /** 80 * @brief Reset SocperfClient 81 * 82 */ 83 void ResetClient(); 84 85 private: SocPerfClient()86 SocPerfClient() {} ~SocPerfClient()87 ~SocPerfClient() {} 88 89 private: 90 bool CheckClientValid(); 91 std::string AddPidAndTidInfo(const std::string& msg); 92 93 private: 94 class SocPerfDeathRecipient : public IRemoteObject::DeathRecipient { 95 public: 96 explicit SocPerfDeathRecipient(SocPerfClient &socPerfClient); 97 98 ~SocPerfDeathRecipient(); 99 100 void OnRemoteDied(const wptr<IRemoteObject> &object) override; 101 102 private: 103 SocPerfClient &socPerfClient_; 104 }; 105 106 private: 107 std::mutex mutex_; 108 sptr<ISocPerfService> client; 109 sptr<SocPerfDeathRecipient> recipient_; 110 }; 111 } // namespace SOCPERF 112 } // namespace OHOS 113 114 #endif // SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H 115