1 /*
2 * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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
16 #include "nfc_controller_callback_proxy.h"
17
18 #include "nfc_service_ipc_interface_code.h"
19 #include "loghelper.h"
20
21 namespace OHOS {
22 namespace NFC {
NfcControllerCallBackProxy(const sptr<IRemoteObject> & remote)23 NfcControllerCallBackProxy::NfcControllerCallBackProxy(const sptr<IRemoteObject> &remote)
24 : IRemoteProxy<INfcControllerCallback>(remote)
25 {}
26
OnNfcStateChanged(int nfcRfState)27 void NfcControllerCallBackProxy::OnNfcStateChanged(int nfcRfState)
28 {
29 DebugLog("NfcControllerCallBackProxy::OnNotify");
30 MessageOption option = {MessageOption::TF_ASYNC};
31 MessageParcel data;
32 MessageParcel reply;
33 if (!data.WriteInterfaceToken(GetDescriptor())) {
34 DebugLog("Write interface token error: %{public}s", __func__);
35 return;
36 }
37 data.WriteInt32(0);
38 data.WriteInt32(nfcRfState);
39
40 int error = Remote()->SendRequest(static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_ON_NOTIFY),
41 data, reply, option);
42 if (error != ERR_NONE) {
43 InfoLog("Set Attr %{public}d failed,error code is %{public}d",
44 NfcServiceIpcInterfaceCode::COMMAND_ON_NOTIFY, error);
45 return;
46 }
47 int exception = reply.ReadInt32();
48 if (exception) {
49 DebugLog("notify COMMAND_ON_NOTIFY state change failed!");
50 }
51 return;
52 }
53 } // namespace NFC
54 } // namespace OHOS