• 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_extension_callback_proxy.h"
16 
17 #include "message_parcel.h"
18 #include "print_log.h"
19 
20 namespace OHOS::Print {
PrintExtensionCallbackProxy(const sptr<IRemoteObject> & impl)21 PrintExtensionCallbackProxy::PrintExtensionCallbackProxy(const sptr<IRemoteObject> &impl)
22     : IRemoteProxy<IPrintExtensionCallback>(impl) {
23 }
24 
OnCallback()25 bool PrintExtensionCallbackProxy::OnCallback()
26 {
27     PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack Start");
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option;
31     data.WriteInterfaceToken(GetDescriptor());
32 
33     int error = Remote()->SendRequest(PRINT_EXTCB, data, reply, option);
34     if (error != 0) {
35         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
36         return false;
37     }
38     bool ret = reply.ReadBool();
39     PRINT_HILOGD("PrintExtcbProxy::OnCallBack End, ret = %{public}d", ret);
40     return ret;
41 }
42 
OnCallback(const std::string & printerId)43 bool PrintExtensionCallbackProxy::OnCallback(const std::string &printerId)
44 {
45     PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack Start");
46     MessageParcel data;
47     MessageParcel reply;
48     MessageOption option;
49     data.WriteInterfaceToken(GetDescriptor());
50     data.WriteString(printerId);
51 
52     int error = Remote()->SendRequest(PRINT_EXTCB_PRINTER, data, reply, option);
53     if (error != 0) {
54         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
55         return false;
56     }
57     bool ret = reply.ReadBool();
58     PRINT_HILOGD("PrintExtcbProxy::OnCallBack End, ret = %{public}d", ret);
59     return ret;
60 }
61 
OnCallback(const PrintJob & job)62 bool PrintExtensionCallbackProxy::OnCallback(const PrintJob &job)
63 {
64     PRINT_HILOGD("PrintExtensionCallbackProxy::OnCallBack Start");
65     MessageParcel data;
66     MessageParcel reply;
67     MessageOption option;
68     data.WriteInterfaceToken(GetDescriptor());
69     job.Marshalling(data);
70     int error = Remote()->SendRequest(PRINT_EXTCB_PRINTJOB, data, reply, option);
71     if (error != 0) {
72         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
73         return false;
74     }
75     bool ret = reply.ReadBool();
76     PRINT_HILOGD("PrintExtcbProxy::OnCallBack End, ret = %{public}d", ret);
77     return ret;
78 }
79 
OnCallback(const std::string & printerId,PrinterCapability & cap)80 bool PrintExtensionCallbackProxy::OnCallback(const std::string &printerId, PrinterCapability &cap)
81 {
82     PRINT_HILOGD("PrintExtcbProxy::OnCallBack Start");
83     MessageParcel data;
84     MessageParcel reply;
85     MessageOption option;
86     data.WriteInterfaceToken(GetDescriptor());
87     data.WriteString(printerId);
88     int error = Remote()->SendRequest(PRINT_EXTCB_PRINTCAPABILITY, data, reply, option);
89     if (error != 0) {
90         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
91         return false;
92     }
93     bool ret = reply.ReadBool();
94     if (ret) {
95         auto capPtr = PrinterCapability::Unmarshalling(reply);
96         if (capPtr == nullptr) {
97             PRINT_HILOGE("Failed to create printer capability object");
98             return false;
99         }
100         cap = *capPtr;
101     }
102 
103     PRINT_HILOGD("PrintExtcbProxy::OnCallBack End, ret = %{public}d", ret);
104     return ret;
105 }
106 } // namespace OHOS::Print
107