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_service_proxy.h"
16 #include "iremote_broker.h"
17 #include "print_constant.h"
18 #include "print_job.h"
19 #include "print_log.h"
20 #include "printer_info.h"
21
22 namespace OHOS::Print {
23 using namespace OHOS::HiviewDFX;
24
PrintServiceProxy(const sptr<IRemoteObject> & object)25 PrintServiceProxy::PrintServiceProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IPrintService>(object) {}
26
GetResult(int retCode,MessageParcel & reply)27 int32_t PrintServiceProxy::GetResult(int retCode, MessageParcel &reply)
28 {
29 if (retCode != ERR_NONE) {
30 PRINT_HILOGE("rpc error code = %{public}d", retCode);
31 return E_PRINT_RPC_FAILURE;
32 }
33
34 retCode = reply.ReadInt32();
35 PRINT_HILOGD("PrintServiceProxy out. ret = [%{public}d]", retCode);
36 return retCode;
37 }
38
StartService()39 int32_t PrintServiceProxy::StartService()
40 {
41 MessageParcel data, reply;
42 MessageOption option;
43 data.WriteInterfaceToken(GetDescriptor());
44 const std::string ndkInfo = "nativePrint";
45 data.WriteString(ndkInfo);
46 PRINT_HILOGI("nativePrint PrintServiceProxy StartService started.");
47 sptr<IRemoteObject> remote = Remote();
48 if (remote == nullptr) {
49 PRINT_HILOGE("PrintServiceProxy StartService remote is null");
50 return E_PRINT_RPC_FAILURE;
51 }
52 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_START_SERVICE, data, reply, option);
53 ret = GetResult(ret, reply);
54 PRINT_HILOGD("PrintServiceProxy CMD_START_SERVICE ret = [%{public}d]", ret);
55 return ret;
56 }
57
StartPrint(const std::vector<std::string> & fileList,const std::vector<uint32_t> & fdList,std::string & taskId)58 int32_t PrintServiceProxy::StartPrint(const std::vector<std::string> &fileList,
59 const std::vector<uint32_t> &fdList, std::string &taskId)
60 {
61 MessageParcel data, reply;
62 MessageOption option;
63 data.WriteInterfaceToken(GetDescriptor());
64 PRINT_HILOGD("Current file is %{public}zd", fileList.size());
65 for (auto file : fileList) {
66 PRINT_HILOGD("file is %{private}s", file.c_str());
67 }
68
69 data.WriteBool(fileList.size() > 0);
70 if (!fileList.empty()) {
71 data.WriteStringVector(fileList);
72 }
73
74 data.WriteBool(fdList.size() > 0);
75 if (!fdList.empty()) {
76 data.WriteInt32(fdList.size());
77 for (auto fd : fdList) {
78 data.WriteFileDescriptor(fd);
79 }
80 }
81
82 data.WriteString(taskId);
83
84 PRINT_HILOGD("PrintServiceProxy StartPrint started.");
85 sptr<IRemoteObject> remote = Remote();
86 if (remote == nullptr) {
87 PRINT_HILOGE("PrintServiceProxy StartPrint remote is null");
88 return E_PRINT_RPC_FAILURE;
89 }
90 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_START_PRINT, data, reply, option);
91 ret = GetResult(ret, reply);
92 taskId = reply.ReadString();
93 PRINT_HILOGD("PrintServiceProxy StartPrint ret = [%{public}d] TaskId = %{public}s", ret, taskId.c_str());
94 return ret;
95 }
96
StopPrint(const std::string & taskId)97 int32_t PrintServiceProxy::StopPrint(const std::string &taskId)
98 {
99 MessageParcel data, reply;
100 MessageOption option;
101 data.WriteInterfaceToken(GetDescriptor());
102 data.WriteString(taskId);
103 PRINT_HILOGD("PrintServiceProxy StopPrint started.");
104 sptr<IRemoteObject> remote = Remote();
105 if (remote == nullptr) {
106 PRINT_HILOGE("PrintServiceProxy StopPrint remote is null");
107 return E_PRINT_RPC_FAILURE;
108 }
109 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_STOP_PRINT, data, reply, option);
110 ret = GetResult(ret, reply);
111 PRINT_HILOGD("PrintServiceProxy StopPrint out. ret = [%{public}d]", ret);
112 return ret;
113 }
114
ConnectPrinter(const std::string & printerId)115 int32_t PrintServiceProxy::ConnectPrinter(const std::string &printerId)
116 {
117 MessageParcel data, reply;
118 MessageOption option;
119 data.WriteInterfaceToken(GetDescriptor());
120 data.WriteString(printerId);
121 PRINT_HILOGD("PrintServiceProxy ConnectPrinter started.");
122 sptr<IRemoteObject> remote = Remote();
123 if (remote == nullptr) {
124 PRINT_HILOGE("PrintServiceProxy ConnectPrinter remote is null");
125 return E_PRINT_RPC_FAILURE;
126 }
127 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_CONNECTPRINTER, data, reply, option);
128 ret = GetResult(ret, reply);
129 PRINT_HILOGD("PrintServiceProxy ConnectPrinter out. ret = [%{public}d]", ret);
130 return ret;
131 }
132
DisconnectPrinter(const std::string & printerId)133 int32_t PrintServiceProxy::DisconnectPrinter(const std::string &printerId)
134 {
135 MessageParcel data, reply;
136 MessageOption option;
137 data.WriteInterfaceToken(GetDescriptor());
138 data.WriteString(printerId);
139 PRINT_HILOGD("PrintServiceProxy DisconnectPrinter started.");
140 sptr<IRemoteObject> remote = Remote();
141 if (remote == nullptr) {
142 PRINT_HILOGE("PrintServiceProxy DisconnectPrinter remote is null");
143 return E_PRINT_RPC_FAILURE;
144 }
145 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_DISCONNECTPRINTER, data, reply, option);
146 ret = GetResult(ret, reply);
147 PRINT_HILOGD("PrintServiceProxy DisconnectPrinter out. ret = [%{public}d]", ret);
148 return ret;
149 }
150
QueryAllExtension(std::vector<PrintExtensionInfo> & extensionInfos)151 int32_t PrintServiceProxy::QueryAllExtension(std::vector<PrintExtensionInfo> &extensionInfos)
152 {
153 MessageParcel data, reply;
154 MessageOption option;
155 data.WriteInterfaceToken(GetDescriptor());
156 PRINT_HILOGD("PrintServiceProxy QueryAllExtension started.");
157 sptr<IRemoteObject> remote = Remote();
158 if (remote == nullptr) {
159 PRINT_HILOGE("PrintServiceProxy QueryAllExtension remote is null");
160 return E_PRINT_RPC_FAILURE;
161 }
162 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYALLEXTENSION, data, reply, option);
163 ret = GetResult(ret, reply);
164 if (ret != E_PRINT_NONE) {
165 PRINT_HILOGD("PrintServiceProxy QueryAllExtension Failed.");
166 return ret;
167 }
168
169 uint32_t len = reply.ReadUint32();
170 if (len > PRINT_MAX_PRINT_COUNT) {
171 PRINT_HILOGE("len is out of range.");
172 return E_PRINT_INVALID_PARAMETER;
173 }
174 for (uint32_t i = 0; i < len; i++) {
175 auto infoPtr = PrintExtensionInfo::Unmarshalling(reply);
176 if (infoPtr == nullptr) {
177 PRINT_HILOGE("wrong information from data");
178 return E_PRINT_GENERIC_FAILURE;
179 }
180 extensionInfos.emplace_back(*infoPtr);
181 }
182 PRINT_HILOGD("PrintServiceProxy QueryAllExtension succeeded.");
183 return E_PRINT_NONE;
184 }
185
StartDiscoverPrinter(const std::vector<std::string> & extensionList)186 int32_t PrintServiceProxy::StartDiscoverPrinter(const std::vector<std::string> &extensionList)
187 {
188 MessageParcel data, reply;
189 MessageOption option;
190 data.WriteInterfaceToken(GetDescriptor());
191 data.WriteStringVector(extensionList);
192 PRINT_HILOGD("PrintServiceProxy StartDiscoverPrinter started.");
193 sptr<IRemoteObject> remote = Remote();
194 if (remote == nullptr) {
195 PRINT_HILOGE("PrintServiceProxy StartDiscoverPrinter remote is null");
196 return E_PRINT_RPC_FAILURE;
197 }
198 int32_t ret = remote->SendRequest(
199 OHOS::Print::IPrintInterfaceCode::CMD_STARTDISCOVERPRINTER, data, reply, option);
200 ret = GetResult(ret, reply);
201 PRINT_HILOGD("PrintServiceProxy StartDiscoverPrinter out. ret = [%{public}d]", ret);
202 return ret;
203 }
204
StopDiscoverPrinter()205 int32_t PrintServiceProxy::StopDiscoverPrinter()
206 {
207 MessageParcel data, reply;
208 MessageOption option;
209 data.WriteInterfaceToken(GetDescriptor());
210 PRINT_HILOGD("PrintServiceProxy StopDiscoverPrinter started.");
211 sptr<IRemoteObject> remote = Remote();
212 if (remote == nullptr) {
213 PRINT_HILOGE("PrintServiceProxy StopDiscoverPrinter remote is null");
214 return E_PRINT_RPC_FAILURE;
215 }
216 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_STOPDISCOVERPRINTER, data, reply, option);
217 ret = GetResult(ret, reply);
218 PRINT_HILOGD("PrintServiceProxy StopDiscoverPrinter out. ret = [%{public}d]", ret);
219 return ret;
220 }
221
StartPrintJob(PrintJob & jobinfo)222 int32_t PrintServiceProxy::StartPrintJob(PrintJob &jobinfo)
223 {
224 MessageParcel data, reply;
225 MessageOption option;
226
227 data.WriteInterfaceToken(GetDescriptor());
228 jobinfo.Marshalling(data);
229 PRINT_HILOGD("PrintServiceProxy StartPrintJob started.");
230 sptr<IRemoteObject> remote = Remote();
231 if (remote == nullptr) {
232 PRINT_HILOGE("PrintServiceProxy StartPrintJob remote is null");
233 return E_PRINT_RPC_FAILURE;
234 }
235 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_STARTPRINTJOB, data, reply, option);
236 ret = GetResult(ret, reply);
237 PRINT_HILOGD("PrintServiceProxy StartPrintJob out. ret = [%{public}d]", ret);
238 return ret;
239 }
240
CancelPrintJob(const std::string & jobId)241 int32_t PrintServiceProxy::CancelPrintJob(const std::string &jobId)
242 {
243 MessageParcel data, reply;
244 MessageOption option;
245
246 data.WriteInterfaceToken(GetDescriptor());
247 data.WriteString(jobId);
248 PRINT_HILOGD("PrintServiceProxy CancelPrintJob started.");
249 sptr<IRemoteObject> remote = Remote();
250 if (remote == nullptr) {
251 PRINT_HILOGE("PrintServiceProxy CancelPrintJob remote is null");
252 return E_PRINT_RPC_FAILURE;
253 }
254 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_CANCELPRINTJOB, data, reply, option);
255 ret = GetResult(ret, reply);
256 PRINT_HILOGD("PrintServiceProxy CancelPrintJob out. ret = [%{public}d]", ret);
257 return ret;
258 }
259
AddPrinters(const std::vector<PrinterInfo> & printerInfos)260 int32_t PrintServiceProxy::AddPrinters(const std::vector<PrinterInfo> &printerInfos)
261 {
262 MessageParcel data, reply;
263 MessageOption option;
264 data.WriteInterfaceToken(GetDescriptor());
265 data.WriteUint32(printerInfos.size());
266 PRINT_HILOGD("AddPrinters printerInfos.size() = %{public}zu", printerInfos.size());
267 for (uint32_t i = 0; i < printerInfos.size(); i++) {
268 printerInfos[i].Marshalling(data);
269 }
270 PRINT_HILOGD("PrintServiceProxy AddPrinters started.");
271 sptr<IRemoteObject> remote = Remote();
272 if (remote == nullptr) {
273 PRINT_HILOGE("PrintServiceProxy AddPrinters remote is null");
274 return E_PRINT_RPC_FAILURE;
275 }
276 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERS, data, reply, option);
277 ret = GetResult(ret, reply);
278 PRINT_HILOGD("PrintServiceProxy AddPrinters out. ret = [%{public}d]", ret);
279 return ret;
280 }
281
RemovePrinters(const std::vector<std::string> & printerIds)282 int32_t PrintServiceProxy::RemovePrinters(const std::vector<std::string> &printerIds)
283 {
284 MessageParcel data, reply;
285 MessageOption option;
286 data.WriteInterfaceToken(GetDescriptor());
287 data.WriteStringVector(printerIds);
288
289 PRINT_HILOGD("PrintServiceProxy RemovePrinters started.");
290 sptr<IRemoteObject> remote = Remote();
291 if (remote == nullptr) {
292 PRINT_HILOGE("PrintServiceProxy RemovePrinters remote is null");
293 return E_PRINT_RPC_FAILURE;
294 }
295 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REMOVEPRINTERS, data, reply, option);
296 ret = GetResult(ret, reply);
297 PRINT_HILOGD("PrintServiceProxy RemovePrinters out. ret = [%{public}d]", ret);
298 return ret;
299 }
300
UpdatePrinters(const std::vector<PrinterInfo> & printerInfos)301 int32_t PrintServiceProxy::UpdatePrinters(const std::vector<PrinterInfo> &printerInfos)
302 {
303 MessageParcel data, reply;
304 MessageOption option;
305 data.WriteInterfaceToken(GetDescriptor());
306 data.WriteUint32(printerInfos.size());
307 PRINT_HILOGD("UpdatePrinters printerInfos.size() = %{public}zu", printerInfos.size());
308 for (uint32_t i = 0; i < printerInfos.size(); i++) {
309 printerInfos[i].Marshalling(data);
310 }
311 PRINT_HILOGD("PrintServiceProxy UpdatePrinters started.");
312 sptr<IRemoteObject> remote = Remote();
313 if (remote == nullptr) {
314 PRINT_HILOGE("PrintServiceProxy UpdatePrinters remote is null");
315 return E_PRINT_RPC_FAILURE;
316 }
317 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERS, data, reply, option);
318 ret = GetResult(ret, reply);
319 PRINT_HILOGD("PrintServiceProxy UpdatePrinters out. ret = [%{public}d]", ret);
320 return ret;
321 }
322
UpdatePrinterState(const std::string & printerId,uint32_t state)323 int32_t PrintServiceProxy::UpdatePrinterState(const std::string &printerId, uint32_t state)
324 {
325 MessageParcel data, reply;
326 MessageOption option;
327 data.WriteInterfaceToken(GetDescriptor());
328 data.WriteString(printerId);
329 data.WriteUint32(state);
330 PRINT_HILOGD("PrintServiceProxy UpdatePrinterState started.");
331 sptr<IRemoteObject> remote = Remote();
332 if (remote == nullptr) {
333 PRINT_HILOGE("PrintServiceProxy UpdatePrinterState remote is null");
334 return E_PRINT_RPC_FAILURE;
335 }
336 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERSTATE, data, reply, option);
337 ret = GetResult(ret, reply);
338 PRINT_HILOGD("PrintServiceProxy UpdatePrinterState out. ret = [%{public}d]", ret);
339 return ret;
340 }
341
UpdatePrintJobStateForNormalApp(const std::string & jobId,uint32_t state,uint32_t subState)342 int32_t PrintServiceProxy::UpdatePrintJobStateForNormalApp(
343 const std::string &jobId, uint32_t state, uint32_t subState)
344 {
345 MessageParcel data, reply;
346 MessageOption option;
347 data.WriteInterfaceToken(GetDescriptor());
348 data.WriteString(jobId);
349 data.WriteUint32(state);
350 data.WriteUint32(subState);
351 PRINT_HILOGI("PrintServiceProxy UpdatePrintJobStateForNormalApp started.");
352 sptr<IRemoteObject> remote = Remote();
353 if (remote == nullptr) {
354 PRINT_HILOGE("PrintServiceProxy UpdatePrintJobStateForNormalApp remote is null");
355 return E_PRINT_RPC_FAILURE;
356 }
357 int32_t ret = remote->SendRequest(
358 OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTJOBSTATE_FORNORMALAPP, data, reply, option);
359 ret = GetResult(ret, reply);
360 PRINT_HILOGI("PrintServiceProxy UpdatePrintJobStateForNormalApp out. ret = [%{public}d]", ret);
361 return ret;
362 }
363
UpdatePrintJobStateOnlyForSystemApp(const std::string & jobId,uint32_t state,uint32_t subState)364 int32_t PrintServiceProxy::UpdatePrintJobStateOnlyForSystemApp(
365 const std::string &jobId, uint32_t state, uint32_t subState)
366 {
367 MessageParcel data, reply;
368 MessageOption option;
369 data.WriteInterfaceToken(GetDescriptor());
370 data.WriteString(jobId);
371 data.WriteUint32(state);
372 data.WriteUint32(subState);
373 PRINT_HILOGD("PrintServiceProxy UpdatePrintJobStateOnlyForSystemApp started.");
374 sptr<IRemoteObject> remote = Remote();
375 if (remote == nullptr) {
376 PRINT_HILOGE("PrintServiceProxy UpdatePrintJobStateOnlyForSystemApp remote is null");
377 return E_PRINT_RPC_FAILURE;
378 }
379 int32_t ret = remote->SendRequest(
380 OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTJOBSTATE_FORSYSTEMAPP, data, reply, option);
381 ret = GetResult(ret, reply);
382 PRINT_HILOGD("PrintServiceProxy UpdatePrintJobStateOnlyForSystemApp out. ret = [%{public}d]", ret);
383 return ret;
384 }
385
UpdateExtensionInfo(const std::string & extInfo)386 int32_t PrintServiceProxy::UpdateExtensionInfo(const std::string &extInfo)
387 {
388 MessageParcel data, reply;
389 MessageOption option;
390 data.WriteInterfaceToken(GetDescriptor());
391 data.WriteString(extInfo);
392 PRINT_HILOGD("PrintServiceProxy UpdateExtensionInfo started.");
393 sptr<IRemoteObject> remote = Remote();
394 if (remote == nullptr) {
395 PRINT_HILOGE("PrintServiceProxy UpdateExtensionInfo remote is null");
396 return E_PRINT_RPC_FAILURE;
397 }
398 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UPDATEEXTENSIONINFO, data, reply, option);
399 ret = GetResult(ret, reply);
400 PRINT_HILOGD("PrintServiceProxy UpdateExtensionInfo out. ret = [%{public}d]", ret);
401 return ret;
402 }
403
RequestPreview(const PrintJob & jobinfo,std::string & previewResult)404 int32_t PrintServiceProxy::RequestPreview(const PrintJob &jobinfo, std::string &previewResult)
405 {
406 MessageParcel data, reply;
407 MessageOption option;
408 data.WriteInterfaceToken(GetDescriptor());
409 jobinfo.Marshalling(data);
410 PRINT_HILOGD("PrintServiceProxy RequestPreview started.");
411 sptr<IRemoteObject> remote = Remote();
412 if (remote == nullptr) {
413 PRINT_HILOGE("PrintServiceProxy RequestPreview remote is null");
414 return E_PRINT_RPC_FAILURE;
415 }
416 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REQUESTPREVIEW, data, reply, option);
417 ret = GetResult(ret, reply);
418 previewResult = reply.ReadString();
419 PRINT_HILOGD("PrintServiceProxy RequestPreview ret = [%{public}d] previewResult = %{public}s",
420 ret, previewResult.c_str());
421 return ret;
422 }
423
QueryPrinterCapability(const std::string & printerId)424 int32_t PrintServiceProxy::QueryPrinterCapability(const std::string &printerId)
425 {
426 MessageParcel data, reply;
427 MessageOption option;
428 data.WriteInterfaceToken(GetDescriptor());
429 data.WriteString(printerId);
430 PRINT_HILOGD("PrintServiceProxy QueryPrinterCapability started.");
431 sptr<IRemoteObject> remote = Remote();
432 if (remote == nullptr) {
433 PRINT_HILOGE("PrintServiceProxy QueryPrinterCapability remote is null");
434 return E_PRINT_RPC_FAILURE;
435 }
436 int32_t ret = remote->SendRequest(
437 OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERCAPABILITY, data, reply, option);
438 ret = GetResult(ret, reply);
439 PRINT_HILOGD("PrintServiceProxy QueryPrinterCapability out. ret = [%{public}d]", ret);
440 return ret;
441 }
442
QueryPrinterInfoByPrinterId(const std::string & printerId,PrinterInfo & info)443 int32_t PrintServiceProxy::QueryPrinterInfoByPrinterId(const std::string &printerId, PrinterInfo &info)
444 {
445 MessageParcel data, reply;
446 MessageOption option;
447 data.WriteInterfaceToken(GetDescriptor());
448 data.WriteString(printerId);
449 info.Marshalling(data);
450 PRINT_HILOGD("PrintServiceProxy QueryPrinterInfoByPrinterId started.");
451 sptr<IRemoteObject> remote = Remote();
452 if (remote == nullptr) {
453 PRINT_HILOGE("PrintServiceProxy QueryPrinterInfoByPrinterId remote is null");
454 return E_PRINT_RPC_FAILURE;
455 }
456 int32_t ret = remote->SendRequest(
457 OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERINFOBYPRINTERID, data, reply, option);
458 ret = GetResult(ret, reply);
459 auto printerInfoPtr = PrinterInfo::Unmarshalling(reply);
460 if (printerInfoPtr == nullptr) {
461 PRINT_HILOGE("wrong printJob from data");
462 return E_PRINT_GENERIC_FAILURE;
463 }
464 info = *printerInfoPtr;
465 PRINT_HILOGD("PrintServiceProxy QueryPrinterInfoByPrinterId out. ret = [%{public}d]", ret);
466 return ret;
467 }
468
QueryAddedPrinter(std::vector<std::string> & printerNameList)469 int32_t PrintServiceProxy::QueryAddedPrinter(std::vector<std::string> &printerNameList)
470 {
471 MessageParcel data, reply;
472 MessageOption option;
473 data.WriteInterfaceToken(GetDescriptor());
474 PRINT_HILOGD("PrintServiceProxy QueryAddedPrinter started.");
475 sptr<IRemoteObject> remote = Remote();
476 if (remote == nullptr) {
477 PRINT_HILOGE("PrintServiceProxy QueryAddedPrinter remote is null");
478 return E_PRINT_RPC_FAILURE;
479 }
480 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYADDEDPRINTER, data, reply, option);
481 ret = GetResult(ret, reply);
482 PRINT_HILOGD("PrintServiceProxy QueryAddedPrinter out. ret = [%{public}d]", ret);
483 reply.ReadStringVector(&printerNameList);
484 PRINT_HILOGD("PrintServiceProxy QueryAddedPrinter printerNameList size %{public}zu.", printerNameList.size());
485 return ret;
486 }
487
QueryPrinterProperties(const std::string & printerId,const std::vector<std::string> & keyList,std::vector<std::string> & valueList)488 int32_t PrintServiceProxy::QueryPrinterProperties(const std::string &printerId,
489 const std::vector<std::string> &keyList, std::vector<std::string> &valueList)
490 {
491 MessageParcel data, reply;
492 MessageOption option;
493 data.WriteInterfaceToken(GetDescriptor());
494 data.WriteString(printerId);
495 data.WriteStringVector(keyList);
496 PRINT_HILOGD("PrintServiceProxy QueryPrinterProperties started.");
497 sptr<IRemoteObject> remote = Remote();
498 if (remote == nullptr) {
499 PRINT_HILOGE("PrintServiceProxy QueryPrinterProperties remote is null");
500 return E_PRINT_RPC_FAILURE;
501 }
502 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERPROPERTIES, data, reply,
503 option);
504 ret = GetResult(ret, reply);
505 reply.ReadStringVector(&valueList);
506 PRINT_HILOGD("PrintServiceProxy QueryPrinterProperties out. ret = [%{public}d]", ret);
507 return ret;
508 }
509
StartNativePrintJob(PrintJob & printJob)510 int32_t PrintServiceProxy::StartNativePrintJob(PrintJob &printJob)
511 {
512 MessageParcel data, reply;
513 MessageOption option;
514 data.WriteInterfaceToken(GetDescriptor());
515 printJob.Marshalling(data);
516 PRINT_HILOGD("PrintServiceProxy StartNativePrintJob started.");
517 sptr<IRemoteObject> remote = Remote();
518 if (remote == nullptr) {
519 PRINT_HILOGE("PrintServiceProxy StartNativePrintJob remote is null");
520 return E_PRINT_RPC_FAILURE;
521 }
522 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_STARTNATIVEPRINTJOB, data, reply,
523 option);
524 ret = GetResult(ret, reply);
525 PRINT_HILOGD("PrintServiceProxy StartNativePrintJob out. ret = [%{public}d]", ret);
526 return ret;
527 }
528
GetPrinterPreference(const std::string & printerId,std::string & printerPreference)529 int32_t PrintServiceProxy::GetPrinterPreference(const std::string &printerId, std::string &printerPreference)
530 {
531 MessageParcel data, reply;
532 MessageOption option;
533 data.WriteInterfaceToken(GetDescriptor());
534 data.WriteString(printerId);
535 PRINT_HILOGD("PrintServiceProxy GetPrinterPreference started.");
536 sptr<IRemoteObject> remote = Remote();
537 if (remote == nullptr) {
538 PRINT_HILOGE("PrintServiceProxy GetPrinterPreference remote is null");
539 return E_PRINT_RPC_FAILURE;
540 }
541 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_GET_PRINTER_PREFERENCE,
542 data, reply, option);
543 ret = GetResult(ret, reply);
544 printerPreference = reply.ReadString();
545 PRINT_HILOGI("PrintServiceProxy GetPrinterPreference ret = [%{public}d] GetPrinterPreference = %{public}s",
546 ret, printerPreference.c_str());
547 return ret;
548 }
549
SetPrinterPreference(const std::string & printerId,const std::string & printerPreference)550 int32_t PrintServiceProxy::SetPrinterPreference(const std::string &printerId, const std::string &printerPreference)
551 {
552 MessageParcel data, reply;
553 MessageOption option;
554 data.WriteInterfaceToken(GetDescriptor());
555 data.WriteString(printerId);
556 data.WriteString(printerPreference);
557 PRINT_HILOGI("PrintServiceProxy SetPrinterPreference started.");
558 sptr<IRemoteObject> remote = Remote();
559 if (remote == nullptr) {
560 PRINT_HILOGE("PrintServiceProxy SetPrinterPreference remote is null");
561 return E_PRINT_RPC_FAILURE;
562 }
563 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_SET_PRINTER_PREFERENCE,
564 data, reply, option);
565 ret = GetResult(ret, reply);
566 PRINT_HILOGI("PrintServiceProxy SetPrinterPreference ret = [%{public}d]", ret);
567 return ret;
568 }
569
QueryAllPrintJob(std::vector<PrintJob> & printJobs)570 int32_t PrintServiceProxy::QueryAllPrintJob(std::vector<PrintJob> &printJobs)
571 {
572 MessageParcel data, reply;
573 MessageOption option;
574 data.WriteInterfaceToken(GetDescriptor());
575 PRINT_HILOGD("PrintServiceProxy QueryAllPrintJob started.");
576 sptr<IRemoteObject> remote = Remote();
577 if (remote == nullptr) {
578 PRINT_HILOGE("PrintServiceProxy QueryAllPrintJob remote is null");
579 return E_PRINT_RPC_FAILURE;
580 }
581 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYALLPRINTJOB, data, reply, option);
582 ret = GetResult(ret, reply);
583 if (ret != E_PRINT_NONE) {
584 PRINT_HILOGD("PrintServiceProxy QueryAllPrintJob Failed.");
585 return ret;
586 }
587
588 uint32_t len = reply.ReadUint32();
589 if (len > PRINT_MAX_PRINT_COUNT) {
590 PRINT_HILOGE("len is out of range.");
591 return E_PRINT_INVALID_PARAMETER;
592 }
593 for (uint32_t i = 0; i < len; i++) {
594 auto jobPtr = PrintJob::Unmarshalling(reply);
595 if (jobPtr == nullptr) {
596 PRINT_HILOGE("wrong printJob from data");
597 return E_PRINT_GENERIC_FAILURE;
598 }
599 printJobs.emplace_back(*jobPtr);
600 }
601 PRINT_HILOGD("PrintServiceProxy QueryAllPrintJob succeeded.");
602 return E_PRINT_NONE;
603 }
604
QueryPrintJobById(std::string & printJobId,PrintJob & printJob)605 int32_t PrintServiceProxy::QueryPrintJobById(std::string &printJobId, PrintJob &printJob)
606 {
607 MessageParcel data, reply;
608 MessageOption option;
609 data.WriteInterfaceToken(GetDescriptor());
610 data.WriteString(printJobId);
611 PRINT_HILOGD("PrintServiceProxy QueryPrintJobById started.");
612 sptr<IRemoteObject> remote = Remote();
613 if (remote == nullptr) {
614 PRINT_HILOGE("PrintServiceProxy QueryPrintJobById remote is null");
615 return E_PRINT_RPC_FAILURE;
616 }
617 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTJOBBYID, data, reply, option);
618 ret = GetResult(ret, reply);
619 auto printJobPtr = PrintJob::Unmarshalling(reply);
620 if (printJobPtr == nullptr) {
621 PRINT_HILOGE("wrong printJob from data");
622 return E_PRINT_GENERIC_FAILURE;
623 }
624 printJob = *printJobPtr;
625 PRINT_HILOGD("[QueryPrintJobById] printerId : %{public}s", printJob.GetJobId().c_str());
626 PRINT_HILOGD("PrintServiceProxy QueryPrintJobById succeeded.");
627 return ret;
628 }
629
AddPrinterToCups(const std::string & printerUri,const std::string & printerName,const std::string & printerMake)630 int32_t PrintServiceProxy::AddPrinterToCups(const std::string &printerUri, const std::string &printerName,
631 const std::string &printerMake)
632 {
633 MessageParcel data, reply;
634 MessageOption option;
635 data.WriteInterfaceToken(GetDescriptor());
636 data.WriteString(printerUri);
637 data.WriteString(printerName);
638 data.WriteString(printerMake);
639 PRINT_HILOGD("PrintServiceProxy AddPrinterToCups started.");
640 sptr<IRemoteObject> remote = Remote();
641 if (remote == nullptr) {
642 PRINT_HILOGE("PrintServiceProxy AddPrinterToCups remote is null");
643 return E_PRINT_RPC_FAILURE;
644 }
645 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERTOCUPS, data, reply, option);
646 ret = GetResult(ret, reply);
647 PRINT_HILOGD("PrintServiceProxy AddPrinterToCups succeeded.");
648 return ret;
649 }
650
QueryPrinterCapabilityByUri(const std::string & printerUri,const std::string & printerId,PrinterCapability & printerCaps)651 int32_t PrintServiceProxy::QueryPrinterCapabilityByUri(const std::string &printerUri, const std::string &printerId,
652 PrinterCapability &printerCaps)
653 {
654 MessageParcel data, reply;
655 MessageOption option;
656 data.WriteInterfaceToken(GetDescriptor());
657 data.WriteString(printerUri);
658 data.WriteString(printerId);
659 PRINT_HILOGD("PrintServiceProxy QueryPrinterCapabilityByUri started.");
660 sptr<IRemoteObject> remote = Remote();
661 if (remote == nullptr) {
662 PRINT_HILOGE("PrintServiceProxy QueryPrinterCapabilityByUri remote is null");
663 return E_PRINT_RPC_FAILURE;
664 }
665 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERCAPABILITYBYURI,
666 data, reply, option);
667 ret = GetResult(ret, reply);
668 auto printerCapsPtr = PrinterCapability::Unmarshalling(reply);
669 printerCaps = *printerCapsPtr;
670 PRINT_HILOGD("PrintServiceProxy QueryPrinterCapabilityByUri succeeded.");
671 return ret;
672 }
673
NotifyPrintServiceEvent(std::string & jobId,uint32_t event)674 int32_t PrintServiceProxy::NotifyPrintServiceEvent(std::string &jobId, uint32_t event)
675 {
676 MessageParcel data, reply;
677 MessageOption option;
678 data.WriteInterfaceToken(GetDescriptor());
679 data.WriteString(jobId);
680 data.WriteUint32(event);
681 PRINT_HILOGD("PrintServiceProxy NotifyPrintServiceEvent started.");
682 sptr<IRemoteObject> remote = Remote();
683 if (remote == nullptr) {
684 PRINT_HILOGE("PrintServiceProxy NotifyPrintServiceEvent remote is null");
685 return E_PRINT_RPC_FAILURE;
686 }
687 int32_t ret = remote->SendRequest(
688 OHOS::Print::IPrintInterfaceCode::CMD_NOTIFY_PRINT_SERVICE_EVENT, data, reply, option);
689 ret = GetResult(ret, reply);
690 PRINT_HILOGD("PrintServiceProxy NotifyPrintServiceEvent out. ret = [%{public}d]", ret);
691 return ret;
692 }
693
SetDefaultPrinter(const std::string & printerId,uint32_t type)694 int32_t PrintServiceProxy::SetDefaultPrinter(const std::string &printerId, uint32_t type)
695 {
696 MessageParcel data, reply;
697 MessageOption option;
698 data.WriteInterfaceToken(GetDescriptor());
699 data.WriteString(printerId);
700 data.WriteUint32(type);
701 PRINT_HILOGD("PrintServiceProxy SetDefaultPrinter started.");
702 sptr<IRemoteObject> remote = Remote();
703 if (remote == nullptr) {
704 PRINT_HILOGE("PrintServiceProxy SetDefaultPrinter remote is null");
705 return E_PRINT_RPC_FAILURE;
706 }
707 int32_t ret = remote->SendRequest(
708 OHOS::Print::IPrintInterfaceCode::CMD_SET_DEFAULT_PRINTERID, data, reply, option);
709 ret = GetResult(ret, reply);
710 PRINT_HILOGD("PrintServiceProxy SetDefaultPrinter out. ret = [%{public}d]", ret);
711 return ret;
712 }
713
DeletePrinterFromCups(const std::string & printerName)714 int32_t PrintServiceProxy::DeletePrinterFromCups(const std::string &printerName)
715 {
716 MessageParcel data, reply;
717 MessageOption option;
718 data.WriteInterfaceToken(GetDescriptor());
719 data.WriteString(printerName);
720 PRINT_HILOGD("PrintServiceProxy DeletePrinterFromCups started.");
721 sptr<IRemoteObject> remote = Remote();
722 if (remote == nullptr) {
723 PRINT_HILOGE("PrintServiceProxy DeletePrinterFromCups remote is null");
724 return E_PRINT_RPC_FAILURE;
725 }
726 int32_t ret = remote->SendRequest(
727 OHOS::Print::IPrintInterfaceCode::CMD_DELETE_PRINTER_FROM_CUPS, data, reply, option);
728 ret = GetResult(ret, reply);
729 PRINT_HILOGD("PrintServiceProxy DeletePrinterFromCups out. ret = [%{public}d]", ret);
730 return ret;
731 }
732
DiscoverUsbPrinters(std::vector<PrinterInfo> & printers)733 int32_t PrintServiceProxy::DiscoverUsbPrinters(std::vector<PrinterInfo> &printers)
734 {
735 MessageParcel data, reply;
736 MessageOption option;
737 data.WriteInterfaceToken(GetDescriptor());
738 PRINT_HILOGD("PrintServiceProxy DiscoverUsbPrinters started.");
739 sptr<IRemoteObject> remote = Remote();
740 if (remote == nullptr) {
741 PRINT_HILOGE("PrintServiceProxy DiscoverUsbPrinters remote is null");
742 return E_PRINT_RPC_FAILURE;
743 }
744 int32_t ret = remote->
745 SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_DISCOVER_USB_PRINTERS, data, reply, option);
746 ret = GetResult(ret, reply);
747 if (ret != E_PRINT_NONE) {
748 PRINT_HILOGD("PrintServiceProxy DiscoverUsbPrinters Failed.");
749 return ret;
750 }
751
752 uint32_t len = reply.ReadUint32();
753 if (len > PRINT_MAX_PRINT_COUNT) {
754 PRINT_HILOGE("len is out of range.");
755 return E_PRINT_INVALID_PARAMETER;
756 }
757 for (uint32_t i = 0; i < len; i++) {
758 auto infoPtr = PrinterInfo::Unmarshalling(reply);
759 if (infoPtr == nullptr) {
760 PRINT_HILOGE("wrong printerInfo from data");
761 return E_PRINT_GENERIC_FAILURE;
762 }
763 printers.emplace_back(*infoPtr);
764 }
765 PRINT_HILOGD("PrintServiceProxy DiscoverUsbPrinters succeeded.");
766 return E_PRINT_NONE;
767 }
768
On(const std::string taskId,const std::string & type,const sptr<IPrintCallback> & listener)769 int32_t PrintServiceProxy::On(const std::string taskId, const std::string &type, const sptr<IPrintCallback> &listener)
770 {
771 if (listener == nullptr) {
772 PRINT_HILOGE("listener is nullptr");
773 return E_PRINT_INVALID_PARAMETER;
774 }
775
776 if (type.empty()) {
777 PRINT_HILOGE("PrintServiceProxy::On type is null.");
778 return E_PRINT_INVALID_PARAMETER;
779 }
780
781 MessageParcel data, reply;
782 MessageOption option;
783
784 data.WriteInterfaceToken(GetDescriptor());
785 data.WriteString(taskId);
786 data.WriteString(type);
787 data.WriteRemoteObject(listener->AsObject().GetRefPtr());
788 sptr<IRemoteObject> remote = Remote();
789 if (remote == nullptr) {
790 PRINT_HILOGE("PrintServiceProxy On remote is null");
791 return E_PRINT_RPC_FAILURE;
792 }
793 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_ON, data, reply, option);
794 ret = GetResult(ret, reply);
795 PRINT_HILOGD("PrintServiceProxy On out. ret = [%{public}d]", ret);
796 return ret;
797 }
798
Off(const std::string taskId,const std::string & type)799 int32_t PrintServiceProxy::Off(const std::string taskId, const std::string &type)
800 {
801 PRINT_HILOGD("PrintServiceProxy::Off in");
802 if (type.empty()) {
803 PRINT_HILOGE("PrintServiceProxy::On type is null.");
804 return E_PRINT_INVALID_PARAMETER;
805 }
806
807 MessageParcel data, reply;
808 MessageOption option;
809
810 data.WriteInterfaceToken(GetDescriptor());
811 data.WriteString(taskId);
812 data.WriteString(type);
813 sptr<IRemoteObject> remote = Remote();
814 if (remote == nullptr) {
815 PRINT_HILOGE("PrintServiceProxy Off remote is null");
816 return E_PRINT_RPC_FAILURE;
817 }
818 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_OFF, data, reply, option);
819 ret = GetResult(ret, reply);
820 PRINT_HILOGD("PrintServiceProxy Off out. ret = [%{public}d]", ret);
821 return ret;
822 }
823
RegisterPrinterCallback(const std::string & type,const sptr<IPrintCallback> & listener)824 int32_t PrintServiceProxy::RegisterPrinterCallback(const std::string &type, const sptr<IPrintCallback> &listener)
825 {
826 if (listener == nullptr) {
827 PRINT_HILOGE("listener is nullptr");
828 return E_PRINT_INVALID_PARAMETER;
829 }
830
831 if (type.empty()) {
832 PRINT_HILOGE("PrintServiceProxy:: type is empty.");
833 return E_PRINT_INVALID_PARAMETER;
834 }
835
836 MessageParcel data, reply;
837 MessageOption option;
838
839 data.WriteInterfaceToken(GetDescriptor());
840 data.WriteString(type);
841 data.WriteRemoteObject(listener->AsObject().GetRefPtr());
842 sptr<IRemoteObject> remote = Remote();
843 if (remote == nullptr) {
844 PRINT_HILOGE("PrintServiceProxy RegisterPrinterCallback remote is null");
845 return E_PRINT_RPC_FAILURE;
846 }
847 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REG_PRINTER_CB, data, reply, option);
848 ret = GetResult(ret, reply);
849 PRINT_HILOGD("PrintServiceProxy RegisterPrinterCallback out. ret = [%{public}d]", ret);
850 return ret;
851 }
852
UnregisterPrinterCallback(const std::string & type)853 int32_t PrintServiceProxy::UnregisterPrinterCallback(const std::string &type)
854 {
855 PRINT_HILOGD("PrintServiceProxy::UnregisterPrinterCallback in");
856 if (type.empty()) {
857 PRINT_HILOGE("PrintServiceProxy::type is empty.");
858 return E_PRINT_INVALID_PARAMETER;
859 }
860
861 MessageParcel data, reply;
862 MessageOption option;
863
864 data.WriteInterfaceToken(GetDescriptor());
865 data.WriteString(type);
866 sptr<IRemoteObject> remote = Remote();
867 if (remote == nullptr) {
868 PRINT_HILOGE("PrintServiceProxy UnregisterPrinterCallback remote is null");
869 return E_PRINT_RPC_FAILURE;
870 }
871 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UNREG_PRINTER_CB, data, reply, option);
872 ret = GetResult(ret, reply);
873 PRINT_HILOGD("PrintServiceProxy UnregisterPrinterCallback out. ret = [%{public}d]", ret);
874 return ret;
875 }
876
RegisterExtCallback(const std::string & extensionCID,const sptr<IPrintExtensionCallback> & listener)877 int32_t PrintServiceProxy::RegisterExtCallback(const std::string &extensionCID,
878 const sptr<IPrintExtensionCallback> &listener)
879 {
880 if (listener == nullptr) {
881 PRINT_HILOGE("listener is nullptr");
882 return E_PRINT_INVALID_PARAMETER;
883 }
884
885 PRINT_HILOGD("PrintServiceProxy::RegisterExtCallback in: %{public}s", extensionCID.c_str());
886 MessageParcel data, reply;
887 MessageOption option;
888
889 data.WriteInterfaceToken(GetDescriptor());
890 data.WriteString(extensionCID);
891 data.WriteRemoteObject(listener->AsObject().GetRefPtr());
892
893 sptr<IRemoteObject> remote = Remote();
894 if (remote == nullptr) {
895 PRINT_HILOGE("PrintServiceProxy RegisterExtCallback remote is null");
896 return E_PRINT_RPC_FAILURE;
897 }
898 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REG_EXT_CB, data, reply, option);
899 ret = GetResult(ret, reply);
900 PRINT_HILOGD("PrintServiceProxy RegisterExtCallback out. ret = [%{public}d]", ret);
901 return ret;
902 }
903
PrintByAdapter(const std::string printJobName,const PrintAttributes & printAttributes,std::string & taskId)904 int32_t PrintServiceProxy::PrintByAdapter(const std::string printJobName, const PrintAttributes &printAttributes,
905 std::string &taskId)
906 {
907 PRINT_HILOGI("PrintServiceProxy PrintByAdapter start.");
908 MessageParcel data, reply;
909 MessageOption option;
910
911 data.WriteInterfaceToken(GetDescriptor());
912 data.WriteString(printJobName);
913 printAttributes.Marshalling(data);
914 data.WriteString(taskId);
915 PRINT_HILOGD("PrintServiceProxy PrintByAdapter started.");
916 sptr<IRemoteObject> remote = Remote();
917 if (remote == nullptr) {
918 PRINT_HILOGE("PrintServiceProxy PrintByAdapter remote is null");
919 return E_PRINT_RPC_FAILURE;
920 }
921 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_STARTPRINTJOB_BY_ADAPTER,
922 data, reply, option);
923 if (ret != ERR_NONE) {
924 PRINT_HILOGE("PrintByAdapter, rpc error code = %{public}d", ret);
925 return E_PRINT_RPC_FAILURE;
926 }
927 ret = GetResult(ret, reply);
928 PRINT_HILOGD("PrintServiceProxy PrintByAdapter out. ret = [%{public}d]", ret);
929 return ret;
930 }
931
StartGetPrintFile(const std::string & jobId,const PrintAttributes & printAttributes,const uint32_t fd)932 int32_t PrintServiceProxy::StartGetPrintFile(const std::string &jobId, const PrintAttributes &printAttributes,
933 const uint32_t fd)
934 {
935 MessageParcel data, reply;
936 MessageOption option;
937
938 data.WriteInterfaceToken(GetDescriptor());
939 data.WriteString(jobId);
940 printAttributes.Marshalling(data);
941 data.WriteFileDescriptor(fd);
942 PRINT_HILOGI("PrintServiceProxy StartGetPrintFile started.");
943 sptr<IRemoteObject> remote = Remote();
944 if (remote == nullptr) {
945 PRINT_HILOGE("PrintServiceProxy StartGetPrintFile remote is null");
946 return E_PRINT_RPC_FAILURE;
947 }
948 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_START_GET_FILE, data, reply, option);
949 if (ret != ERR_NONE) {
950 PRINT_HILOGE("StartGetPrintFile, rpc error code = %{public}d", ret);
951 return E_PRINT_RPC_FAILURE;
952 }
953
954 ret = GetResult(ret, reply);
955 PRINT_HILOGD("PrintServiceProxy StartGetPrintFile out. ret = [%{public}d]", ret);
956 return ret;
957 }
958
NotifyPrintService(const std::string & jobId,const std::string & type)959 int32_t PrintServiceProxy::NotifyPrintService(const std::string &jobId, const std::string &type)
960 {
961 PRINT_HILOGD("PrintServiceProxy::NotifyPrintService in");
962 MessageParcel data, reply;
963 MessageOption option;
964
965 data.WriteInterfaceToken(GetDescriptor());
966 data.WriteString(jobId);
967 data.WriteString(type);
968 sptr<IRemoteObject> remote = Remote();
969 if (remote == nullptr) {
970 PRINT_HILOGE("PrintServiceProxy NotifyPrintService remote is null");
971 return E_PRINT_RPC_FAILURE;
972 }
973 int32_t ret = remote->SendRequest(
974 OHOS::Print::IPrintInterfaceCode::CMD_NOTIFY_PRINT_SERVICE, data, reply, option);
975 ret = GetResult(ret, reply);
976 PRINT_HILOGD("PrintServiceProxy NotifyPrintService out. ret = [%{public}d]", ret);
977 return ret;
978 }
979
AddPrinterToDiscovery(const PrinterInfo & printerInfo)980 int32_t PrintServiceProxy::AddPrinterToDiscovery(const PrinterInfo &printerInfo)
981 {
982 MessageParcel data, reply;
983 MessageOption option;
984 data.WriteInterfaceToken(GetDescriptor());
985 printerInfo.Marshalling(data);
986 PRINT_HILOGD("PrintServiceProxy AddPrinterToDiscovery started.");
987 sptr<IRemoteObject> remote = Remote();
988 if (remote == nullptr) {
989 PRINT_HILOGE("PrintServiceProxy AddPrinterToDiscovery remote is null");
990 return E_PRINT_RPC_FAILURE;
991 }
992 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERTODISCOVERY,
993 data, reply, option);
994 ret = GetResult(ret, reply);
995 PRINT_HILOGD("PrintServiceProxy AddPrinterToDiscovery out. ret = [%{public}d]", ret);
996 return ret;
997 }
998
UpdatePrinterInDiscovery(const PrinterInfo & printerInfo)999 int32_t PrintServiceProxy::UpdatePrinterInDiscovery(const PrinterInfo& printerInfo)
1000 {
1001 MessageParcel data, reply;
1002 MessageOption option;
1003 data.WriteInterfaceToken(GetDescriptor());
1004 printerInfo.Marshalling(data);
1005 PRINT_HILOGD("PrintServiceProxy UpdatePrinterInDiscovery started.");
1006 sptr<IRemoteObject> remote = Remote();
1007 if (remote == nullptr) {
1008 PRINT_HILOGE("PrintServiceProxy UpdatePrinterInDiscovery remote is null");
1009 return E_PRINT_RPC_FAILURE;
1010 }
1011 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERINDISCOVERY,
1012 data, reply, option);
1013 ret = GetResult(ret, reply);
1014 PRINT_HILOGD("PrintServiceProxy UpdatePrinterInDiscovery out. ret = [%{public}d]", ret);
1015 return ret;
1016 }
1017
RemovePrinterFromDiscovery(const std::string & printerId)1018 int32_t PrintServiceProxy::RemovePrinterFromDiscovery(const std::string &printerId)
1019 {
1020 MessageParcel data, reply;
1021 MessageOption option;
1022 data.WriteInterfaceToken(GetDescriptor());
1023 data.WriteString(printerId);
1024 PRINT_HILOGD("PrintServiceProxy RemovePrinterFromDiscovery started.");
1025 sptr<IRemoteObject> remote = Remote();
1026 if (remote == nullptr) {
1027 PRINT_HILOGE("PrintServiceProxy RemovePrinterFromDiscovery remote is null");
1028 return E_PRINT_RPC_FAILURE;
1029 }
1030 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REMOVEPRINTERFROMDISCOVERY,
1031 data, reply, option);
1032 ret = GetResult(ret, reply);
1033 PRINT_HILOGD("PrintServiceProxy RemovePrinterFromDiscovery out. ret = [%{public}d]", ret);
1034 return ret;
1035 }
1036
UpdatePrinterInSystem(const PrinterInfo & printerInfo)1037 int32_t PrintServiceProxy::UpdatePrinterInSystem(const PrinterInfo& printerInfo)
1038 {
1039 MessageParcel data, reply;
1040 MessageOption option;
1041 data.WriteInterfaceToken(GetDescriptor());
1042 printerInfo.Marshalling(data);
1043 PRINT_HILOGD("PrintServiceProxy UpdatePrinterInSystem started.");
1044 sptr<IRemoteObject> remote = Remote();
1045 if (remote == nullptr) {
1046 PRINT_HILOGE("PrintServiceProxy UpdatePrinterInSystem remote is null");
1047 return E_PRINT_RPC_FAILURE;
1048 }
1049 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERINSYSTEM,
1050 data, reply, option);
1051 ret = GetResult(ret, reply);
1052 PRINT_HILOGD("PrintServiceProxy UpdatePrinterInSystem out. ret = [%{public}d]", ret);
1053 return ret;
1054 }
1055
UnregisterAllExtCallback(const std::string & extensionId)1056 int32_t PrintServiceProxy::UnregisterAllExtCallback(const std::string &extensionId)
1057 {
1058 PRINT_HILOGD("PrintServiceProxy::UnregisterAllExtCallback in");
1059 MessageParcel data, reply;
1060 MessageOption option;
1061 data.WriteInterfaceToken(GetDescriptor());
1062 data.WriteString(extensionId);
1063 sptr<IRemoteObject> remote = Remote();
1064 if (remote == nullptr) {
1065 PRINT_HILOGE("PrintServiceProxy UnregisterAllExtCallback remote is null");
1066 return E_PRINT_RPC_FAILURE;
1067 }
1068 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UNREG_EXT_CB, data, reply, option);
1069 ret = GetResult(ret, reply);
1070 PRINT_HILOGD("PrintServiceProxy UnregisterAllExtCallback out. ret = [%{public}d]", ret);
1071 return ret;
1072 }
1073
LoadExtSuccess(const std::string & extensionId)1074 int32_t PrintServiceProxy::LoadExtSuccess(const std::string &extensionId)
1075 {
1076 PRINT_HILOGD("PrintServiceProxy::LoadExtSuccess in");
1077 MessageParcel data, reply;
1078 MessageOption option;
1079 data.WriteInterfaceToken(GetDescriptor());
1080 data.WriteString(extensionId);
1081 sptr<IRemoteObject> remote = Remote();
1082 if (remote == nullptr) {
1083 PRINT_HILOGE("PrintServiceProxy LoadExtSuccess remote is null");
1084 return E_PRINT_RPC_FAILURE;
1085 }
1086 int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_LOAD_EXT, data, reply, option);
1087 ret = GetResult(ret, reply);
1088 PRINT_HILOGD("PrintServiceProxy LoadExtSuccess out. ret = [%{public}d]", ret);
1089 return ret;
1090 }
1091 } // namespace OHOS::Print
1092