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 <cstring> 20 #include <vector> 21 #include <iremote_object.h> 22 #include "socperf_action_type.h" 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 set socperf server status, enable or disable 81 * 82 * @param status true means enable socperfserver, false means disable socperfserver 83 * @param msg the reason why we need change socperfserver status 84 */ 85 void SetRequestStatus(bool status, const std::string& msg); 86 87 /** 88 * @brief set thermal level intermal for perfquest 89 * 90 * @param level thermal level 91 */ 92 void SetThermalLevel(int32_t level); 93 94 /** 95 * @brief send the device mode, enable or disable 96 * 97 * @param mode the mode which will to be changed 98 * @param status true means socperfserver enter the device mode, false quit the device mode 99 */ 100 void RequestDeviceMode(const std::string& mode, bool status); 101 102 /** 103 * @brief get cmd Id count, cmdID is trigger, its count++ 104 * @param msg the reason 105 * @return cmdId count, as 10000:xx,10001:xx 106 */ 107 std::string RequestCmdIdCount(const std::string& msg); 108 109 /** 110 * @brief Reset SocperfClient 111 * 112 */ 113 void ResetClient(); 114 115 private: 116 SocPerfClient(); 117 ~SocPerfClient(); 118 119 private: 120 bool CheckClientValid(); 121 std::string AddPidAndTidInfo(const std::string& msg); 122 123 private: 124 class SocPerfDeathRecipient : public IRemoteObject::DeathRecipient { 125 public: 126 explicit SocPerfDeathRecipient(SocPerfClient &socPerfClient); 127 128 ~SocPerfDeathRecipient(); 129 130 void OnRemoteDied(const wptr<IRemoteObject> &object) override; 131 132 private: 133 SocPerfClient &socPerfClient_; 134 }; 135 136 private: 137 std::mutex mutex_; 138 sptr<SocPerfDeathRecipient> recipient_; 139 }; 140 } // namespace SOCPERF 141 } // namespace OHOS 142 143 #endif // SOC_PERF_INTERFACES_INNER_API_SOCPERF_CLIENT_INCLUDE_SOCPERF_CLIENT_H 144