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