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 #include "print_callback_proxy.h"
16
17 #include "message_parcel.h"
18 #include "print_log.h"
19
20 namespace OHOS::Print {
PrintCallbackProxy(const sptr<IRemoteObject> & impl)21 PrintCallbackProxy::PrintCallbackProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IPrintCallback>(impl) {}
22
OnCallback()23 bool PrintCallbackProxy::OnCallback()
24 {
25 PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
26 MessageParcel data;
27 MessageParcel reply;
28 MessageOption option;
29
30 data.WriteInterfaceToken(GetDescriptor());
31 int error = Remote()->SendRequest(PRINT_CALLBACK_TASK, data, reply, option);
32 if (error != 0) {
33 PRINT_HILOGE("SendRequest failed, error %{public}d", error);
34 return false;
35 }
36 PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
37 return true;
38 }
39
OnCallback(uint32_t state,const PrinterInfo & info)40 bool PrintCallbackProxy::OnCallback(uint32_t state, const PrinterInfo &info)
41 {
42 PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
43 MessageParcel data;
44 MessageParcel reply;
45 MessageOption option;
46
47 PRINT_HILOGD("Printer Event argument:[%{public}d], printerId [%{private}s]", state, info.GetPrinterId().c_str());
48 data.WriteInterfaceToken(GetDescriptor());
49 data.WriteUint32(state);
50 info.Marshalling(data);
51
52 int error = Remote()->SendRequest(PRINT_CALLBACK_PRINTER, data, reply, option);
53 if (error != 0) {
54 PRINT_HILOGE("SendRequest failed, error %{public}d", error);
55 return false;
56 }
57 PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
58 return true;
59 }
60
OnCallback(uint32_t state,const PrintJob & info)61 bool PrintCallbackProxy::OnCallback(uint32_t state, const PrintJob &info)
62 {
63 PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
64 MessageParcel data;
65 MessageParcel reply;
66 MessageOption option;
67
68 PRINT_HILOGD("PrintJob Event state:[%{public}d], subState [%{public}d]", state, info.GetSubState());
69 data.WriteInterfaceToken(GetDescriptor());
70 data.WriteUint32(state);
71 info.Marshalling(data);
72
73 int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_JOB, data, reply, option);
74 if (error != 0) {
75 PRINT_HILOGE("SendRequest failed, error %{public}d", error);
76 return false;
77 }
78 PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
79 return true;
80 }
81
OnCallback(const std::string & extensionId,const std::string & info)82 bool PrintCallbackProxy::OnCallback(const std::string &extensionId, const std::string &info)
83 {
84 PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
85 MessageParcel data;
86 MessageParcel reply;
87 MessageOption option;
88
89 data.WriteInterfaceToken(GetDescriptor());
90 data.WriteString(extensionId);
91 data.WriteString(info);
92
93 int error = Remote()->SendRequest(PRINT_CALLBACK_EXTINFO, data, reply, option);
94 if (error != 0) {
95 PRINT_HILOGE("SendRequest failed, error %{public}d", error);
96 return false;
97 }
98 PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
99 return true;
100 }
101
OnCallbackAdapterLayout(const std::string & jobId,const PrintAttributes & oldAttrs,const PrintAttributes & newAttrs,uint32_t fd)102 bool PrintCallbackProxy::OnCallbackAdapterLayout(const std::string &jobId, const PrintAttributes &oldAttrs,
103 const PrintAttributes &newAttrs, uint32_t fd)
104 {
105 PRINT_HILOGI("PrintCallbackProxy::OnCallbackAdapterLayout Start");
106 MessageParcel data;
107 MessageParcel reply;
108 MessageOption option;
109
110 if (!data.WriteInterfaceToken(GetDescriptor())) {
111 PRINT_HILOGE("write descriptor failed");
112 return false;
113 }
114
115 data.WriteString(jobId);
116 oldAttrs.Marshalling(data);
117 newAttrs.Marshalling(data);
118 data.WriteFileDescriptor(fd);
119
120 int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_JOB_ADAPTER, data, reply, option);
121 if (error != 0) {
122 PRINT_HILOGE("SendRequest failed, error %{public}d", error);
123 return false;
124 }
125 PRINT_HILOGI("PrintCallbackProxy::OnCallbackAdapterLayout End");
126 return true;
127 }
128
onCallbackAdapterJobStateChanged(const std::string jobId,const uint32_t state,const uint32_t subState)129 bool PrintCallbackProxy::onCallbackAdapterJobStateChanged(const std::string jobId, const uint32_t state,
130 const uint32_t subState)
131 {
132 PRINT_HILOGI("PrintCallbackProxy::onCallbackAdapterJobStateChanged Start");
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option;
136
137 if (!data.WriteInterfaceToken(GetDescriptor())) {
138 PRINT_HILOGE("write descriptor failed");
139 return false;
140 }
141
142 data.WriteString(jobId);
143 data.WriteUint32(state);
144 data.WriteUint32(subState);
145
146 int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_JOB_CHANGED_ADAPTER, data, reply, option);
147 if (error != 0) {
148 PRINT_HILOGE("SendRequest failed, error %{public}d", error);
149 return false;
150 }
151 PRINT_HILOGI("PrintCallbackProxy::onCallbackAdapterJobStateChanged End");
152 return true;
153 }
154
OnCallbackAdapterGetFile(uint32_t state)155 bool PrintCallbackProxy::OnCallbackAdapterGetFile(uint32_t state)
156 {
157 PRINT_HILOGI("PrintCallbackProxy::OnCallbackAdapterGetFile Start");
158 MessageParcel data;
159 MessageParcel reply;
160 MessageOption option;
161
162 if (!data.WriteInterfaceToken(GetDescriptor())) {
163 PRINT_HILOGE("write descriptor failed");
164 return false;
165 }
166
167 data.WriteUint32(state);
168
169 int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_GET_FILE_ADAPTER, data, reply, option);
170 if (error != 0) {
171 PRINT_HILOGE("SendRequest failed, error %{public}d", error);
172 return false;
173 }
174 PRINT_HILOGI("PrintCallbackProxy::OnCallbackAdapterGetFile End");
175 return true;
176 }
177 } // namespace OHOS::Print
178