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 #include "socperf_ipc_interface_code.h"
17 #include "socperf_proxy.h"
18 #include "socperf_log.h"
19
20 namespace OHOS {
21 namespace SOCPERF {
PerfRequest(int32_t cmdId,const std::string & msg)22 void SocPerfProxy::PerfRequest(int32_t cmdId, const std::string& msg)
23 {
24 MessageParcel data;
25 MessageParcel reply;
26 MessageOption option = { MessageOption::TF_ASYNC };
27 if (!data.WriteInterfaceToken(GetDescriptor())) {
28 return;
29 }
30 data.WriteInt32(cmdId);
31 data.WriteString(msg);
32 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_PERF_REQUEST),
33 data, reply, option);
34 }
35
PerfRequestEx(int32_t cmdId,bool onOffTag,const std::string & msg)36 void SocPerfProxy::PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg)
37 {
38 MessageParcel data;
39 MessageParcel reply;
40 MessageOption option = { MessageOption::TF_ASYNC };
41 if (!data.WriteInterfaceToken(GetDescriptor())) {
42 return;
43 }
44 data.WriteInt32(cmdId);
45 data.WriteBool(onOffTag);
46 data.WriteString(msg);
47 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_PERF_REQUEST_EX),
48 data, reply, option);
49 }
50
PowerLimitBoost(bool onOffTag,const std::string & msg)51 void SocPerfProxy::PowerLimitBoost(bool onOffTag, const std::string& msg)
52 {
53 MessageParcel data;
54 MessageParcel reply;
55 MessageOption option = { MessageOption::TF_ASYNC };
56 if (!data.WriteInterfaceToken(GetDescriptor())) {
57 return;
58 }
59 data.WriteBool(onOffTag);
60 data.WriteString(msg);
61 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_POWER_LIMIT_BOOST_FREQ),
62 data, reply, option);
63 }
64
ThermalLimitBoost(bool onOffTag,const std::string & msg)65 void SocPerfProxy::ThermalLimitBoost(bool onOffTag, const std::string& msg)
66 {
67 MessageParcel data;
68 MessageParcel reply;
69 MessageOption option = { MessageOption::TF_ASYNC };
70 if (!data.WriteInterfaceToken(GetDescriptor())) {
71 return;
72 }
73 data.WriteBool(onOffTag);
74 data.WriteString(msg);
75 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_THERMAL_LIMIT_BOOST_FREQ),
76 data, reply, option);
77 }
78
LimitRequest(int32_t clientId,const std::vector<int32_t> & tags,const std::vector<int64_t> & configs,const std::string & msg)79 void SocPerfProxy::LimitRequest(int32_t clientId,
80 const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg)
81 {
82 MessageParcel data;
83 MessageParcel reply;
84 MessageOption option = { MessageOption::TF_ASYNC };
85 if (!data.WriteInterfaceToken(GetDescriptor())) {
86 return;
87 }
88 data.WriteInt32(clientId);
89 data.WriteInt32Vector(tags);
90 data.WriteInt64Vector(configs);
91 data.WriteString(msg);
92 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_LIMIT_REQUEST),
93 data, reply, option);
94 }
95
SetRequestStatus(bool status,const std::string & msg)96 void SocPerfProxy::SetRequestStatus(bool status, const std::string &msg)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option = { MessageOption::TF_ASYNC };
101 if (!data.WriteInterfaceToken(GetDescriptor())) {
102 return;
103 }
104 if (!data.WriteBool(status)) {
105 SOC_PERF_LOGE("Failed to write status: %{public}d", status);
106 return;
107 }
108 if (!data.WriteString(msg)) {
109 SOC_PERF_LOGE("Failed to write msg: %{public}s", msg.c_str());
110 return;
111 }
112 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_SET_STATUS), data, reply, option);
113 }
114
SetThermalLevel(int32_t level)115 void SocPerfProxy::SetThermalLevel(int32_t level)
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option = { MessageOption::TF_ASYNC };
120 if (!data.WriteInterfaceToken(GetDescriptor())) {
121 SOC_PERF_LOGE("Failed to write descriptor");
122 return;
123 }
124 if (!data.WriteInt32(level)) {
125 SOC_PERF_LOGE("Failed to write level: %{public}d", level);
126 return;
127 }
128 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_SET_THERMAL_LEVEL),
129 data, reply, option);
130 }
131
RequestDeviceMode(const std::string & mode,bool status)132 void SocPerfProxy::RequestDeviceMode(const std::string& mode, bool status)
133 {
134 MessageParcel data;
135 MessageParcel reply;
136 MessageOption option = { MessageOption::TF_ASYNC };
137 if (!data.WriteInterfaceToken(GetDescriptor())) {
138 return;
139 }
140 if (!data.WriteString(mode)) {
141 SOC_PERF_LOGE("Failed to write mode: %{public}s", mode.c_str());
142 return;
143 }
144 if (!data.WriteBool(status)) {
145 SOC_PERF_LOGE("Failed to write status: %{public}d", status);
146 return;
147 }
148 Remote()->SendRequest(static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_SET_DEVICE_MODE),
149 data, reply, option);
150 }
151
RequestCmdIdCount(const std::string & msg)152 std::string SocPerfProxy::RequestCmdIdCount(const std::string& msg)
153 {
154 MessageParcel data;
155 MessageParcel reply;
156 MessageOption option = { MessageOption::TF_SYNC };
157 if (!data.WriteInterfaceToken(GetDescriptor())) {
158 SOC_PERF_LOGE("Failed to write descriptor");
159 return "";
160 }
161 if (!data.WriteString(msg)) {
162 SOC_PERF_LOGE("Failed to write msg: %{public}s", msg.c_str());
163 return "";
164 }
165 Remote()->SendRequest(static_cast<uint32_t>(
166 SocPerfInterfaceCode::TRANS_IPC_ID_REQUEST_CMDID_COUNT), data, reply, option);
167 std::string ret;
168 if (!reply.ReadString(ret)) {
169 SOC_PERF_LOGE("read RequestCmdIdCount ret failed");
170 return "";
171 }
172 return ret;
173 }
174 } // namespace SOCPERF
175 } // namespace OHOS
176