1 /*
2  * Copyright (C) 2023 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 "reader_mode_callback_proxy.h"
16 #include "loghelper.h"
17 #include "nfc_service_ipc_interface_code.h"
18 
19 namespace OHOS {
20 namespace NFC {
21 namespace TAG {
ReaderModeCallbackProxy(const sptr<IRemoteObject> & remote)22 ReaderModeCallbackProxy::ReaderModeCallbackProxy(const sptr<IRemoteObject> &remote)
23     : IRemoteProxy<KITS::IReaderModeCallback>(remote)
24 {}
25 
OnTagDiscovered(KITS::TagInfoParcelable * tagInfo)26 void ReaderModeCallbackProxy::OnTagDiscovered(KITS::TagInfoParcelable* tagInfo)
27 {
28     DebugLog("ReaderModeCallbackProxy::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     tagInfo->Marshalling(data);
38 
39     int error = Remote()->SendRequest(static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_TAG_FOUND_READER_MODE),
40         data, reply, option);
41     if (error != ERR_NONE) {
42         InfoLog("Set Attr %{public}d failed,error code is %{public}d",
43             NfcServiceIpcInterfaceCode::COMMAND_TAG_FOUND_READER_MODE, error);
44         return;
45     }
46     int exception = reply.ReadInt32();
47     if (exception) {
48         DebugLog("notify COMMAND_TAG_FOUND_READER_MODE failed!");
49     }
50     return;
51 }
52 }  // namespace TAG
53 }  // namespace NFC
54 }  // namespace OHOS