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