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