• 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     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 
QueryAllActivePrintJob(std::vector<PrintJob> & printJobs)609 int32_t PrintServiceProxy::QueryAllActivePrintJob(std::vector<PrintJob> &printJobs)
610 {
611     MessageParcel data;
612     MessageParcel reply;
613     MessageOption option;
614     data.WriteInterfaceToken(GetDescriptor());
615     PRINT_HILOGD("PrintServiceProxy QueryAllActivePrintJob started.");
616     sptr<IRemoteObject> remote = Remote();
617     if (remote == nullptr) {
618         PRINT_HILOGE("PrintServiceProxy QueryAllActivePrintJob remote is null");
619         return E_PRINT_RPC_FAILURE;
620     }
621     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYALLACTIVEPRINTJOB,
622         data, reply, option);
623     ret = GetResult(ret, reply);
624     if (ret != E_PRINT_NONE) {
625         PRINT_HILOGD("PrintServiceProxy QueryAllActivePrintJob Failed.");
626         return ret;
627     }
628 
629     uint32_t len = reply.ReadUint32();
630     if (len > PRINT_MAX_PRINT_COUNT) {
631         PRINT_HILOGE("len is out of range.");
632         return E_PRINT_INVALID_PARAMETER;
633     }
634     for (uint32_t i = 0; i < len; i++) {
635         auto jobPtr = PrintJob::Unmarshalling(reply);
636         if (jobPtr == nullptr) {
637             PRINT_HILOGE("wrong printJob from data");
638             return E_PRINT_GENERIC_FAILURE;
639         }
640         printJobs.emplace_back(*jobPtr);
641     }
642     PRINT_HILOGD("PrintServiceProxy QueryAllActivePrintJob succeeded.");
643     return E_PRINT_NONE;
644 }
645 
QueryPrintJobById(std::string & printJobId,PrintJob & printJob)646 int32_t PrintServiceProxy::QueryPrintJobById(std::string &printJobId, PrintJob &printJob)
647 {
648     MessageParcel data;
649     MessageParcel reply;
650     MessageOption option;
651     data.WriteInterfaceToken(GetDescriptor());
652     data.WriteString(printJobId);
653     PRINT_HILOGD("PrintServiceProxy QueryPrintJobById started.");
654     sptr<IRemoteObject> remote = Remote();
655     if (remote == nullptr) {
656         PRINT_HILOGE("PrintServiceProxy QueryPrintJobById remote is null");
657         return E_PRINT_RPC_FAILURE;
658     }
659     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTJOBBYID, data, reply, option);
660     ret = GetResult(ret, reply);
661     auto printJobPtr = PrintJob::Unmarshalling(reply);
662     if (printJobPtr == nullptr) {
663         PRINT_HILOGE("wrong printJob from data");
664         return E_PRINT_GENERIC_FAILURE;
665     }
666     printJob = *printJobPtr;
667     PRINT_HILOGD("[QueryPrintJobById] printerId : %{public}s", printJob.GetJobId().c_str());
668     PRINT_HILOGD("PrintServiceProxy QueryPrintJobById succeeded.");
669     return ret;
670 }
671 
AddPrinterToCups(const std::string & printerUri,const std::string & printerName,const std::string & printerMake)672 int32_t PrintServiceProxy::AddPrinterToCups(const std::string &printerUri, const std::string &printerName,
673     const std::string &printerMake)
674 {
675     MessageParcel data;
676     MessageParcel reply;
677     MessageOption option;
678     data.WriteInterfaceToken(GetDescriptor());
679     data.WriteString(printerUri);
680     data.WriteString(printerName);
681     data.WriteString(printerMake);
682     PRINT_HILOGD("PrintServiceProxy AddPrinterToCups started.");
683     sptr<IRemoteObject> remote = Remote();
684     if (remote == nullptr) {
685         PRINT_HILOGE("PrintServiceProxy AddPrinterToCups remote is null");
686         return E_PRINT_RPC_FAILURE;
687     }
688     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERTOCUPS, data, reply, option);
689     ret = GetResult(ret, reply);
690     PRINT_HILOGD("PrintServiceProxy AddPrinterToCups succeeded.");
691     return ret;
692 }
693 
QueryPrinterCapabilityByUri(const std::string & printerUri,const std::string & printerId,PrinterCapability & printerCaps)694 int32_t PrintServiceProxy::QueryPrinterCapabilityByUri(const std::string &printerUri, const std::string &printerId,
695     PrinterCapability &printerCaps)
696 {
697     MessageParcel data;
698     MessageParcel reply;
699     MessageOption option;
700     data.WriteInterfaceToken(GetDescriptor());
701     data.WriteString(printerUri);
702     data.WriteString(printerId);
703     PRINT_HILOGD("PrintServiceProxy QueryPrinterCapabilityByUri started.");
704     sptr<IRemoteObject> remote = Remote();
705     if (remote == nullptr) {
706         PRINT_HILOGE("PrintServiceProxy QueryPrinterCapabilityByUri remote is null");
707         return E_PRINT_RPC_FAILURE;
708     }
709     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERCAPABILITYBYURI,
710         data, reply, option);
711     ret = GetResult(ret, reply);
712     auto printerCapsPtr = PrinterCapability::Unmarshalling(reply);
713     printerCaps = *printerCapsPtr;
714     PRINT_HILOGD("PrintServiceProxy QueryPrinterCapabilityByUri succeeded.");
715     return ret;
716 }
717 
NotifyPrintServiceEvent(std::string & jobId,uint32_t event)718 int32_t PrintServiceProxy::NotifyPrintServiceEvent(std::string &jobId, uint32_t event)
719 {
720     MessageParcel data;
721     MessageParcel reply;
722     MessageOption option;
723     data.WriteInterfaceToken(GetDescriptor());
724     data.WriteString(jobId);
725     data.WriteUint32(event);
726     PRINT_HILOGD("PrintServiceProxy NotifyPrintServiceEvent started.");
727     sptr<IRemoteObject> remote = Remote();
728     if (remote == nullptr) {
729         PRINT_HILOGE("PrintServiceProxy NotifyPrintServiceEvent remote is null");
730         return E_PRINT_RPC_FAILURE;
731     }
732     int32_t ret = remote->SendRequest(
733         OHOS::Print::IPrintInterfaceCode::CMD_NOTIFY_PRINT_SERVICE_EVENT, data, reply, option);
734     ret = GetResult(ret, reply);
735     PRINT_HILOGD("PrintServiceProxy NotifyPrintServiceEvent out. ret = [%{public}d]", ret);
736     return ret;
737 }
738 
SetDefaultPrinter(const std::string & printerId,uint32_t type)739 int32_t PrintServiceProxy::SetDefaultPrinter(const std::string &printerId, uint32_t type)
740 {
741     MessageParcel data;
742     MessageParcel reply;
743     MessageOption option;
744     data.WriteInterfaceToken(GetDescriptor());
745     data.WriteString(printerId);
746     data.WriteUint32(type);
747     PRINT_HILOGD("PrintServiceProxy SetDefaultPrinter started.");
748     sptr<IRemoteObject> remote = Remote();
749     if (remote == nullptr) {
750         PRINT_HILOGE("PrintServiceProxy SetDefaultPrinter remote is null");
751         return E_PRINT_RPC_FAILURE;
752     }
753     int32_t ret = remote->SendRequest(
754         OHOS::Print::IPrintInterfaceCode::CMD_SET_DEFAULT_PRINTERID, data, reply, option);
755     ret = GetResult(ret, reply);
756     PRINT_HILOGD("PrintServiceProxy SetDefaultPrinter out. ret = [%{public}d]", ret);
757     return ret;
758 }
759 
DeletePrinterFromCups(const std::string & printerName)760 int32_t PrintServiceProxy::DeletePrinterFromCups(const std::string &printerName)
761 {
762     MessageParcel data;
763     MessageParcel reply;
764     MessageOption option;
765     data.WriteInterfaceToken(GetDescriptor());
766     data.WriteString(printerName);
767     PRINT_HILOGD("PrintServiceProxy DeletePrinterFromCups started.");
768     sptr<IRemoteObject> remote = Remote();
769     if (remote == nullptr) {
770         PRINT_HILOGE("PrintServiceProxy DeletePrinterFromCups remote is null");
771         return E_PRINT_RPC_FAILURE;
772     }
773     int32_t ret = remote->SendRequest(
774         OHOS::Print::IPrintInterfaceCode::CMD_DELETE_PRINTER_FROM_CUPS, data, reply, option);
775     ret = GetResult(ret, reply);
776     PRINT_HILOGD("PrintServiceProxy DeletePrinterFromCups out. ret = [%{public}d]", ret);
777     return ret;
778 }
779 
DiscoverUsbPrinters(std::vector<PrinterInfo> & printers)780 int32_t PrintServiceProxy::DiscoverUsbPrinters(std::vector<PrinterInfo> &printers)
781 {
782     MessageParcel data;
783     MessageParcel reply;
784     MessageOption option;
785     data.WriteInterfaceToken(GetDescriptor());
786     PRINT_HILOGD("PrintServiceProxy DiscoverUsbPrinters started.");
787     sptr<IRemoteObject> remote = Remote();
788     if (remote == nullptr) {
789         PRINT_HILOGE("PrintServiceProxy DiscoverUsbPrinters remote is null");
790         return E_PRINT_RPC_FAILURE;
791     }
792     int32_t ret = remote->
793         SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_DISCOVER_USB_PRINTERS, data, reply, option);
794     ret = GetResult(ret, reply);
795     if (ret != E_PRINT_NONE) {
796         PRINT_HILOGD("PrintServiceProxy DiscoverUsbPrinters Failed.");
797         return ret;
798     }
799 
800     uint32_t len = reply.ReadUint32();
801     if (len > PRINT_MAX_PRINT_COUNT) {
802         PRINT_HILOGE("len is out of range.");
803         return E_PRINT_INVALID_PARAMETER;
804     }
805     for (uint32_t i = 0; i < len; i++) {
806         auto infoPtr = PrinterInfo::Unmarshalling(reply);
807         if (infoPtr == nullptr) {
808             PRINT_HILOGE("wrong printerInfo from data");
809             return E_PRINT_GENERIC_FAILURE;
810         }
811         printers.emplace_back(*infoPtr);
812     }
813     PRINT_HILOGD("PrintServiceProxy DiscoverUsbPrinters succeeded.");
814     return E_PRINT_NONE;
815 }
816 
On(const std::string taskId,const std::string & type,const sptr<IPrintCallback> & listener)817 int32_t PrintServiceProxy::On(const std::string taskId, const std::string &type, const sptr<IPrintCallback> &listener)
818 {
819     if (listener == nullptr) {
820         PRINT_HILOGE("listener is nullptr");
821         return E_PRINT_INVALID_PARAMETER;
822     }
823 
824     if (type.empty()) {
825         PRINT_HILOGE("PrintServiceProxy::On type is null.");
826         return E_PRINT_INVALID_PARAMETER;
827     }
828 
829     MessageParcel data;
830     MessageParcel reply;
831     MessageOption option;
832 
833     data.WriteInterfaceToken(GetDescriptor());
834     data.WriteString(taskId);
835     data.WriteString(type);
836     data.WriteRemoteObject(listener->AsObject().GetRefPtr());
837     sptr<IRemoteObject> remote = Remote();
838     if (remote == nullptr) {
839         PRINT_HILOGE("PrintServiceProxy On remote is null");
840         return E_PRINT_RPC_FAILURE;
841     }
842     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_ON, data, reply, option);
843     ret = GetResult(ret, reply);
844     PRINT_HILOGD("PrintServiceProxy On out. ret = [%{public}d]", ret);
845     return ret;
846 }
847 
Off(const std::string taskId,const std::string & type)848 int32_t PrintServiceProxy::Off(const std::string taskId, const std::string &type)
849 {
850     PRINT_HILOGD("PrintServiceProxy::Off in");
851     if (type.empty()) {
852         PRINT_HILOGE("PrintServiceProxy::On type is null.");
853         return E_PRINT_INVALID_PARAMETER;
854     }
855 
856     MessageParcel data;
857     MessageParcel reply;
858     MessageOption option;
859 
860     data.WriteInterfaceToken(GetDescriptor());
861     data.WriteString(taskId);
862     data.WriteString(type);
863     sptr<IRemoteObject> remote = Remote();
864     if (remote == nullptr) {
865         PRINT_HILOGE("PrintServiceProxy Off remote is null");
866         return E_PRINT_RPC_FAILURE;
867     }
868     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_OFF, data, reply, option);
869     ret = GetResult(ret, reply);
870     PRINT_HILOGD("PrintServiceProxy Off out. ret = [%{public}d]", ret);
871     return ret;
872 }
873 
RegisterPrinterCallback(const std::string & type,const sptr<IPrintCallback> & listener)874 int32_t PrintServiceProxy::RegisterPrinterCallback(const std::string &type, const sptr<IPrintCallback> &listener)
875 {
876     if (listener == nullptr) {
877         PRINT_HILOGE("listener is nullptr");
878         return E_PRINT_INVALID_PARAMETER;
879     }
880 
881     if (type.empty()) {
882         PRINT_HILOGE("PrintServiceProxy:: type is empty.");
883         return E_PRINT_INVALID_PARAMETER;
884     }
885 
886     MessageParcel data;
887     MessageParcel reply;
888     MessageOption option;
889 
890     data.WriteInterfaceToken(GetDescriptor());
891     data.WriteString(type);
892     data.WriteRemoteObject(listener->AsObject().GetRefPtr());
893     sptr<IRemoteObject> remote = Remote();
894     if (remote == nullptr) {
895         PRINT_HILOGE("PrintServiceProxy RegisterPrinterCallback remote is null");
896         return E_PRINT_RPC_FAILURE;
897     }
898     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REG_PRINTER_CB, data, reply, option);
899     ret = GetResult(ret, reply);
900     PRINT_HILOGD("PrintServiceProxy RegisterPrinterCallback out. ret = [%{public}d]", ret);
901     return ret;
902 }
903 
UnregisterPrinterCallback(const std::string & type)904 int32_t PrintServiceProxy::UnregisterPrinterCallback(const std::string &type)
905 {
906     PRINT_HILOGD("PrintServiceProxy::UnregisterPrinterCallback in");
907     if (type.empty()) {
908         PRINT_HILOGE("PrintServiceProxy::type is empty.");
909         return E_PRINT_INVALID_PARAMETER;
910     }
911 
912     MessageParcel data;
913     MessageParcel reply;
914     MessageOption option;
915 
916     data.WriteInterfaceToken(GetDescriptor());
917     data.WriteString(type);
918     sptr<IRemoteObject> remote = Remote();
919     if (remote == nullptr) {
920         PRINT_HILOGE("PrintServiceProxy UnregisterPrinterCallback remote is null");
921         return E_PRINT_RPC_FAILURE;
922     }
923     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UNREG_PRINTER_CB, data, reply, option);
924     ret = GetResult(ret, reply);
925     PRINT_HILOGD("PrintServiceProxy UnregisterPrinterCallback out. ret = [%{public}d]", ret);
926     return ret;
927 }
928 
RegisterExtCallback(const std::string & extensionCID,const sptr<IPrintExtensionCallback> & listener)929 int32_t PrintServiceProxy::RegisterExtCallback(const std::string &extensionCID,
930     const sptr<IPrintExtensionCallback> &listener)
931 {
932     if (listener == nullptr) {
933         PRINT_HILOGE("listener is nullptr");
934         return E_PRINT_INVALID_PARAMETER;
935     }
936 
937     PRINT_HILOGD("PrintServiceProxy::RegisterExtCallback in: %{public}s", extensionCID.c_str());
938     MessageParcel data;
939     MessageParcel reply;
940     MessageOption option;
941 
942     data.WriteInterfaceToken(GetDescriptor());
943     data.WriteString(extensionCID);
944     data.WriteRemoteObject(listener->AsObject().GetRefPtr());
945 
946     sptr<IRemoteObject> remote = Remote();
947     if (remote == nullptr) {
948         PRINT_HILOGE("PrintServiceProxy RegisterExtCallback remote is null");
949         return E_PRINT_RPC_FAILURE;
950     }
951     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REG_EXT_CB, data, reply, option);
952     ret = GetResult(ret, reply);
953     PRINT_HILOGD("PrintServiceProxy RegisterExtCallback out. ret = [%{public}d]", ret);
954     return ret;
955 }
956 
PrintByAdapter(const std::string printJobName,const PrintAttributes & printAttributes,std::string & taskId)957 int32_t PrintServiceProxy::PrintByAdapter(const std::string printJobName, const PrintAttributes &printAttributes,
958     std::string &taskId)
959 {
960     PRINT_HILOGI("PrintServiceProxy PrintByAdapter start.");
961     MessageParcel data;
962     MessageParcel reply;
963     MessageOption option;
964 
965     data.WriteInterfaceToken(GetDescriptor());
966     data.WriteString(printJobName);
967     printAttributes.Marshalling(data);
968     data.WriteString(taskId);
969     PRINT_HILOGD("PrintServiceProxy PrintByAdapter started.");
970     sptr<IRemoteObject> remote = Remote();
971     if (remote == nullptr) {
972         PRINT_HILOGE("PrintServiceProxy PrintByAdapter remote is null");
973         return E_PRINT_RPC_FAILURE;
974     }
975     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_STARTPRINTJOB_BY_ADAPTER,
976         data, reply, option);
977     if (ret != ERR_NONE) {
978         PRINT_HILOGE("PrintByAdapter, rpc error code = %{public}d", ret);
979         return E_PRINT_RPC_FAILURE;
980     }
981     ret = GetResult(ret, reply);
982     PRINT_HILOGD("PrintServiceProxy PrintByAdapter out. ret = [%{public}d]", ret);
983     return ret;
984 }
985 
StartGetPrintFile(const std::string & jobId,const PrintAttributes & printAttributes,const uint32_t fd)986 int32_t PrintServiceProxy::StartGetPrintFile(const std::string &jobId, const PrintAttributes &printAttributes,
987     const uint32_t fd)
988 {
989     MessageParcel data;
990     MessageParcel reply;
991     MessageOption option;
992 
993     data.WriteInterfaceToken(GetDescriptor());
994     data.WriteString(jobId);
995     printAttributes.Marshalling(data);
996     data.WriteFileDescriptor(fd);
997     PRINT_HILOGI("PrintServiceProxy StartGetPrintFile started.");
998     sptr<IRemoteObject> remote = Remote();
999     if (remote == nullptr) {
1000         PRINT_HILOGE("PrintServiceProxy StartGetPrintFile remote is null");
1001         return E_PRINT_RPC_FAILURE;
1002     }
1003     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_START_GET_FILE, data, reply, option);
1004     if (ret != ERR_NONE) {
1005         PRINT_HILOGE("StartGetPrintFile, rpc error code = %{public}d", ret);
1006         return E_PRINT_RPC_FAILURE;
1007     }
1008 
1009     ret = GetResult(ret, reply);
1010     PRINT_HILOGD("PrintServiceProxy StartGetPrintFile out. ret = [%{public}d]", ret);
1011     return ret;
1012 }
1013 
NotifyPrintService(const std::string & jobId,const std::string & type)1014 int32_t PrintServiceProxy::NotifyPrintService(const std::string &jobId, const std::string &type)
1015 {
1016     PRINT_HILOGD("PrintServiceProxy::NotifyPrintService in");
1017     MessageParcel data;
1018     MessageParcel reply;
1019     MessageOption option;
1020 
1021     data.WriteInterfaceToken(GetDescriptor());
1022     data.WriteString(jobId);
1023     data.WriteString(type);
1024     sptr<IRemoteObject> remote = Remote();
1025     if (remote == nullptr) {
1026         PRINT_HILOGE("PrintServiceProxy NotifyPrintService remote is null");
1027         return E_PRINT_RPC_FAILURE;
1028     }
1029     int32_t ret = remote->SendRequest(
1030         OHOS::Print::IPrintInterfaceCode::CMD_NOTIFY_PRINT_SERVICE, data, reply, option);
1031     ret = GetResult(ret, reply);
1032     PRINT_HILOGD("PrintServiceProxy NotifyPrintService out. ret = [%{public}d]", ret);
1033     return ret;
1034 }
1035 
AddPrinterToDiscovery(const PrinterInfo & printerInfo)1036 int32_t PrintServiceProxy::AddPrinterToDiscovery(const PrinterInfo &printerInfo)
1037 {
1038     MessageParcel data;
1039     MessageParcel reply;
1040     MessageOption option;
1041     data.WriteInterfaceToken(GetDescriptor());
1042     printerInfo.Marshalling(data);
1043     PRINT_HILOGD("PrintServiceProxy AddPrinterToDiscovery started.");
1044     sptr<IRemoteObject> remote = Remote();
1045     if (remote == nullptr) {
1046         PRINT_HILOGE("PrintServiceProxy AddPrinterToDiscovery remote is null");
1047         return E_PRINT_RPC_FAILURE;
1048     }
1049     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERTODISCOVERY,
1050         data, reply, option);
1051     ret = GetResult(ret, reply);
1052     PRINT_HILOGD("PrintServiceProxy AddPrinterToDiscovery out. ret = [%{public}d]", ret);
1053     return ret;
1054 }
1055 
UpdatePrinterInDiscovery(const PrinterInfo & printerInfo)1056 int32_t PrintServiceProxy::UpdatePrinterInDiscovery(const PrinterInfo& printerInfo)
1057 {
1058     MessageParcel data;
1059     MessageParcel reply;
1060     MessageOption option;
1061     data.WriteInterfaceToken(GetDescriptor());
1062     printerInfo.Marshalling(data);
1063     PRINT_HILOGD("PrintServiceProxy UpdatePrinterInDiscovery started.");
1064     sptr<IRemoteObject> remote = Remote();
1065     if (remote == nullptr) {
1066         PRINT_HILOGE("PrintServiceProxy UpdatePrinterInDiscovery remote is null");
1067         return E_PRINT_RPC_FAILURE;
1068     }
1069     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERINDISCOVERY,
1070         data, reply, option);
1071     ret = GetResult(ret, reply);
1072     PRINT_HILOGD("PrintServiceProxy UpdatePrinterInDiscovery out. ret = [%{public}d]", ret);
1073     return ret;
1074 }
1075 
RemovePrinterFromDiscovery(const std::string & printerId)1076 int32_t PrintServiceProxy::RemovePrinterFromDiscovery(const std::string &printerId)
1077 {
1078     MessageParcel data;
1079     MessageParcel reply;
1080     MessageOption option;
1081     data.WriteInterfaceToken(GetDescriptor());
1082     data.WriteString(printerId);
1083     PRINT_HILOGD("PrintServiceProxy RemovePrinterFromDiscovery started.");
1084     sptr<IRemoteObject> remote = Remote();
1085     if (remote == nullptr) {
1086         PRINT_HILOGE("PrintServiceProxy RemovePrinterFromDiscovery remote is null");
1087         return E_PRINT_RPC_FAILURE;
1088     }
1089     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_REMOVEPRINTERFROMDISCOVERY,
1090         data, reply, option);
1091     ret = GetResult(ret, reply);
1092     PRINT_HILOGD("PrintServiceProxy RemovePrinterFromDiscovery out. ret = [%{public}d]", ret);
1093     return ret;
1094 }
1095 
UpdatePrinterInSystem(const PrinterInfo & printerInfo)1096 int32_t PrintServiceProxy::UpdatePrinterInSystem(const PrinterInfo& printerInfo)
1097 {
1098     MessageParcel data;
1099     MessageParcel reply;
1100     MessageOption option;
1101     data.WriteInterfaceToken(GetDescriptor());
1102     printerInfo.Marshalling(data);
1103     PRINT_HILOGD("PrintServiceProxy UpdatePrinterInSystem started.");
1104     sptr<IRemoteObject> remote = Remote();
1105     if (remote == nullptr) {
1106         PRINT_HILOGE("PrintServiceProxy UpdatePrinterInSystem remote is null");
1107         return E_PRINT_RPC_FAILURE;
1108     }
1109     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERINSYSTEM,
1110         data, reply, option);
1111     ret = GetResult(ret, reply);
1112     PRINT_HILOGD("PrintServiceProxy UpdatePrinterInSystem out. ret = [%{public}d]", ret);
1113     return ret;
1114 }
1115 
UnregisterAllExtCallback(const std::string & extensionId)1116 int32_t PrintServiceProxy::UnregisterAllExtCallback(const std::string &extensionId)
1117 {
1118     PRINT_HILOGD("PrintServiceProxy::UnregisterAllExtCallback in");
1119     MessageParcel data;
1120     MessageParcel reply;
1121     MessageOption option;
1122     data.WriteInterfaceToken(GetDescriptor());
1123     data.WriteString(extensionId);
1124     sptr<IRemoteObject> remote = Remote();
1125     if (remote == nullptr) {
1126         PRINT_HILOGE("PrintServiceProxy UnregisterAllExtCallback remote is null");
1127         return E_PRINT_RPC_FAILURE;
1128     }
1129     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_UNREG_EXT_CB, data, reply, option);
1130     ret = GetResult(ret, reply);
1131     PRINT_HILOGD("PrintServiceProxy UnregisterAllExtCallback out. ret = [%{public}d]", ret);
1132     return ret;
1133 }
1134 
LoadExtSuccess(const std::string & extensionId)1135 int32_t PrintServiceProxy::LoadExtSuccess(const std::string &extensionId)
1136 {
1137     PRINT_HILOGD("PrintServiceProxy::LoadExtSuccess in");
1138     MessageParcel data;
1139     MessageParcel reply;
1140     MessageOption option;
1141     data.WriteInterfaceToken(GetDescriptor());
1142     data.WriteString(extensionId);
1143     sptr<IRemoteObject> remote = Remote();
1144     if (remote == nullptr) {
1145         PRINT_HILOGE("PrintServiceProxy LoadExtSuccess remote is null");
1146         return E_PRINT_RPC_FAILURE;
1147     }
1148     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_LOAD_EXT, data, reply, option);
1149     ret = GetResult(ret, reply);
1150     PRINT_HILOGD("PrintServiceProxy LoadExtSuccess out. ret = [%{public}d]", ret);
1151     return ret;
1152 }
1153 
RestartPrintJob(const std::string & jobId)1154 int32_t PrintServiceProxy::RestartPrintJob(const std::string &jobId)
1155 {
1156     MessageParcel data;
1157     MessageParcel reply;
1158     MessageOption option;
1159 
1160     data.WriteInterfaceToken(GetDescriptor());
1161     data.WriteString(jobId);
1162     PRINT_HILOGD("PrintServiceProxy RestartPrintJob started.");
1163     sptr<IRemoteObject> remote = Remote();
1164     if (remote == nullptr) {
1165         PRINT_HILOGE("PrintServiceProxy RestartPrintJob remote is null");
1166         return E_PRINT_RPC_FAILURE;
1167     }
1168     int32_t ret = remote->SendRequest(OHOS::Print::IPrintInterfaceCode::CMD_RESTARTPRINTJOB, data, reply, option);
1169     ret = GetResult(ret, reply);
1170     PRINT_HILOGD("PrintServiceProxy RestartPrintJob out. ret = [%{public}d]", ret);
1171     return ret;
1172 }
1173 } // namespace OHOS::Print
1174