• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
QueryInterval(int queryItem,IntervalReply & queryRs)45 void ConcurrentTaskServiceProxy::QueryInterval(int queryItem, IntervalReply& queryRs)
46 {
47     int32_t error;
48     MessageParcel data;
49     MessageParcel reply;
50     MessageOption option = { MessageOption::TF_SYNC };
51 
52     if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
53         CONCUR_LOGE("Write interface token failed in QueryInterval Proxy");
54         return;
55     }
56     if (!data.WriteInt32(queryItem) || !data.WriteInt32(queryRs.tid)) {
57         CONCUR_LOGE("Write info failed in QueryInterval Proxy");
58         return;
59     }
60 
61     uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::QUERY_INTERVAL);
62     error = Remote()->SendRequest(code, data, reply, option);
63     if (error != NO_ERROR) {
64         CONCUR_LOGE("QueryInterval error: %{public}d", error);
65         return;
66     }
67     queryRs.rtgId = -1;
68     queryRs.tid = -1;
69     queryRs.paramA = -1;
70     queryRs.paramB = -1;
71     queryRs.bundleName = "";
72 
73     if (!reply.ReadInt32(queryRs.rtgId) || !reply.ReadInt32(queryRs.tid)
74         || !reply.ReadInt32(queryRs.paramA) || !reply.ReadInt32(queryRs.paramB)
75         || !reply.ReadString(queryRs.bundleName)) {
76         CONCUR_LOGE("Read info failed in QueryInterval Proxy");
77         return;
78     }
79     return;
80 }
81 
QueryDeadline(int queryItem,DeadlineReply & ddlReply,const Json::Value & payload)82 void ConcurrentTaskServiceProxy::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload)
83 {
84     int32_t error;
85     MessageParcel data;
86     MessageParcel reply;
87     MessageOption option = { MessageOption::TF_ASYNC };
88 
89     if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
90         CONCUR_LOGE("Write interface token failed in QueryDeadline Proxy");
91         return;
92     }
93     if (!data.WriteInt32(queryItem) || !data.WriteString(payload.toStyledString())) {
94         CONCUR_LOGE("Write info failed in QueryDeadline Proxy");
95         return;
96     }
97     uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::QUERY_DEADLINE);
98     error = Remote()->SendRequest(code, data, reply, option);
99     if (error != NO_ERROR) {
100         CONCUR_LOGE("QueryDeadline error: %{public}d", error);
101         return;
102     }
103     CONCUR_LOGD("ConcurrentTaskServiceProxy::QueryDeadline success.");
104 }
105 
RequestAuth(const Json::Value & payload)106 void ConcurrentTaskServiceProxy::RequestAuth(const Json::Value& payload)
107 {
108     int32_t error;
109     MessageParcel data;
110     MessageParcel reply;
111     MessageOption option = { MessageOption::TF_SYNC };
112     if (!data.WriteInterfaceToken(ConcurrentTaskServiceProxy::GetDescriptor())) {
113         CONCUR_LOGE("Write interface token failed in RequestAuth Proxy");
114         return;
115     }
116     if (!data.WriteString(payload.toStyledString())) {
117         CONCUR_LOGE("Write info failed in RequestAuth Proxy");
118         return;
119     }
120     uint32_t code = static_cast<uint32_t>(ConcurrentTaskInterfaceCode::REQUEST_AUTH);
121     error = Remote()->SendRequest(code, data, reply, option);
122     if (error != NO_ERROR) {
123         CONCUR_LOGE("Send request error: %{public}d", error);
124         return;
125     }
126     CONCUR_LOGD("ConcurrentTaskServiceProxy::RequestAuth success.");
127 }
128 } // namespace ConcurrentTask
129 } // namespace OHOS
130