• 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_callback_proxy.h"
16 
17 #include "message_parcel.h"
18 #include "print_log.h"
19 
20 namespace OHOS::Print {
PrintCallbackProxy(const sptr<IRemoteObject> & impl)21 PrintCallbackProxy::PrintCallbackProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IPrintCallback>(impl) {}
22 
OnCallback()23 bool PrintCallbackProxy::OnCallback()
24 {
25     PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
26     MessageParcel data;
27     MessageParcel reply;
28     MessageOption option;
29 
30     data.WriteInterfaceToken(GetDescriptor());
31     int error = Remote()->SendRequest(PRINT_CALLBACK_TASK, data, reply, option);
32     if (error != 0) {
33         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
34         return false;
35     }
36     PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
37     return true;
38 }
39 
OnCallback(uint32_t state,const PrinterInfo & info)40 bool PrintCallbackProxy::OnCallback(uint32_t state, const PrinterInfo &info)
41 {
42     PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
43     MessageParcel data;
44     MessageParcel reply;
45     MessageOption option;
46 
47     PRINT_HILOGD("Printer Event argument:[%{public}d], printerId [%{private}s]", state, info.GetPrinterId().c_str());
48     data.WriteInterfaceToken(GetDescriptor());
49     data.WriteUint32(state);
50     info.Marshalling(data);
51 
52     int error = Remote()->SendRequest(PRINT_CALLBACK_PRINTER, data, reply, option);
53     if (error != 0) {
54         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
55         return false;
56     }
57     PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
58     return true;
59 }
60 
OnCallback(uint32_t state,const PrintJob & info)61 bool PrintCallbackProxy::OnCallback(uint32_t state, const PrintJob &info)
62 {
63     PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
64     MessageParcel data;
65     MessageParcel reply;
66     MessageOption option;
67 
68     PRINT_HILOGD("PrintJob Event argument:[%{public}d], subState [%{public}d]", state, info.GetSubState());
69     data.WriteInterfaceToken(GetDescriptor());
70     data.WriteUint32(state);
71     info.Marshalling(data);
72 
73     int error = Remote()->SendRequest(PRINT_CALLBACK_PRINT_JOB, data, reply, option);
74     if (error != 0) {
75         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
76         return false;
77     }
78     PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
79     return true;
80 }
81 
OnCallback(const std::string & extensionId,const std::string & info)82 bool PrintCallbackProxy::OnCallback(const std::string &extensionId, const std::string &info)
83 {
84     PRINT_HILOGD("PrintCallbackProxy::OnCallback Start");
85     MessageParcel data;
86     MessageParcel reply;
87     MessageOption option;
88 
89     data.WriteInterfaceToken(GetDescriptor());
90     data.WriteString(extensionId);
91     data.WriteString(info);
92 
93     int error = Remote()->SendRequest(PRINT_CALLBACK_EXTINFO, data, reply, option);
94     if (error != 0) {
95         PRINT_HILOGE("SendRequest failed, error %{public}d", error);
96         return false;
97     }
98     PRINT_HILOGD("PrintCallbackProxy::OnCallback End");
99     return true;
100 }
101 } // namespace OHOS::Print
102