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 "concurrent_task_service_proxy.h"
17 #include "concurrent_task_log.h"
18 #include "concurrent_task_errors.h"
19
20 namespace OHOS {
21 namespace ConcurrentTask {
ReportData(uint32_t resType,int64_t value,const Json::Value & payload)22 void ConcurrentTaskServiceProxy::ReportData(uint32_t resType, int64_t value, const Json::Value& payload)
23 {
24 int32_t error;
25 MessageParcel data;
26 MessageParcel reply;
27 MessageOption option = { MessageOption::TF_ASYNC };
28 if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
29 CONCUR_LOGE("Write interface token failed in ReportData Proxy");
30 return;
31 }
32 if (!data.WriteUint32(resType) || !data.WriteInt64(value) || !data.WriteString(payload.toStyledString())) {
33 CONCUR_LOGE("Write info failed in ReportData Proxy");
34 return;
35 }
36 uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::REPORT_DATA);
37 error = Remote()->SendRequest(code, data, reply, option);
38 if (error != NO_ERROR) {
39 CONCUR_LOGE("Send request error: %{public}d", error);
40 return;
41 }
42 CONCUR_LOGD("ConcurrentTaskServiceProxy::ReportData success.");
43 }
44
ReportSceneInfo(uint32_t type,const Json::Value & payload)45 void ConcurrentTaskServiceProxy::ReportSceneInfo(uint32_t type, const Json::Value& payload)
46 {
47 int32_t error;
48 MessageParcel data;
49 MessageParcel reply;
50 MessageOption option = { MessageOption::TF_ASYNC };
51 if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
52 CONCUR_LOGE("Write interface token failed in ReportSceneInfo Proxy");
53 return;
54 }
55 if (!data.WriteUint32(type) || !data.WriteString(payload.toStyledString())) {
56 CONCUR_LOGE("Write info failed in ReportSceneInfo Proxy");
57 return;
58 }
59 uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::REPORT_SCENE_INFO);
60 error = Remote()->SendRequest(code, data, reply, option);
61 if (error != NO_ERROR) {
62 CONCUR_LOGE("Send request error: %{public}d", error);
63 return;
64 }
65 CONCUR_LOGD("ConcurrentTaskServiceProxy::ReportSceneInfo success.");
66 }
67
QueryInterval(int queryItem,IntervalReply & queryRs)68 void ConcurrentTaskServiceProxy::QueryInterval(int queryItem, IntervalReply& queryRs)
69 {
70 int32_t error;
71 MessageParcel data;
72 MessageParcel reply;
73 MessageOption option = { MessageOption::TF_SYNC };
74
75 if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
76 CONCUR_LOGE("Write interface token failed in QueryInterval Proxy");
77 return;
78 }
79 if (!data.WriteInt32(queryItem) || !data.WriteInt32(queryRs.tid) || !data.WriteInt32(queryRs.paramA)) {
80 CONCUR_LOGE("Write info failed in QueryInterval Proxy");
81 return;
82 }
83
84 uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::QUERY_INTERVAL);
85 error = Remote()->SendRequest(code, data, reply, option);
86 if (error != NO_ERROR) {
87 CONCUR_LOGE("QueryInterval error: %{public}d", error);
88 return;
89 }
90 queryRs.rtgId = -1;
91 queryRs.tid = -1;
92 queryRs.paramA = -1;
93 queryRs.paramB = -1;
94 queryRs.bundleName = "";
95
96 if (!reply.ReadInt32(queryRs.rtgId) || !reply.ReadInt32(queryRs.tid)
97 || !reply.ReadInt32(queryRs.paramA) || !reply.ReadInt32(queryRs.paramB)
98 || !reply.ReadString(queryRs.bundleName)) {
99 CONCUR_LOGE("Read info failed in QueryInterval Proxy");
100 return;
101 }
102 return;
103 }
104
QueryDeadline(int queryItem,DeadlineReply & ddlReply,const Json::Value & payload)105 void ConcurrentTaskServiceProxy::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload)
106 {
107 int32_t error;
108 MessageParcel data;
109 MessageParcel reply;
110 MessageOption option = { MessageOption::TF_ASYNC };
111
112 if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
113 CONCUR_LOGE("Write interface token failed in QueryDeadline Proxy");
114 return;
115 }
116 if (!data.WriteInt32(queryItem) || !data.WriteString(payload.toStyledString())) {
117 CONCUR_LOGE("Write info failed in QueryDeadline Proxy");
118 return;
119 }
120 uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::QUERY_DEADLINE);
121 error = Remote()->SendRequest(code, data, reply, option);
122 if (error != NO_ERROR) {
123 CONCUR_LOGE("QueryDeadline error: %{public}d", error);
124 return;
125 }
126 CONCUR_LOGD("ConcurrentTaskServiceProxy::QueryDeadline success.");
127 }
128
RequestAuth(const Json::Value & payload)129 void ConcurrentTaskServiceProxy::RequestAuth(const Json::Value& payload)
130 {
131 int32_t error;
132 MessageParcel data;
133 MessageParcel reply;
134 MessageOption option = { MessageOption::TF_SYNC };
135 if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
136 CONCUR_LOGE("Write interface token failed in RequestAuth Proxy");
137 return;
138 }
139 if (!data.WriteString(payload.toStyledString())) {
140 CONCUR_LOGE("Write info failed in RequestAuth Proxy");
141 return;
142 }
143 uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::REQUEST_AUTH);
144 error = Remote()->SendRequest(code, data, reply, option);
145 if (error != NO_ERROR) {
146 CONCUR_LOGE("Send request error: %{public}d", error);
147 return;
148 }
149 CONCUR_LOGD("ConcurrentTaskServiceProxy::RequestAuth success.");
150 }
151 } // namespace ConcurrentTask
152 } // namespace OHOS
153