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 
16 #include "ndef_msg_callback_proxy.h"
17 
18 #include "nfc_service_ipc_interface_code.h"
19 #include "loghelper.h"
20 
21 namespace OHOS {
22 namespace NFC {
NdefMsgCallbackProxy(const sptr<IRemoteObject> & remote)23 NdefMsgCallbackProxy::NdefMsgCallbackProxy(const sptr<IRemoteObject> &remote)
24     : IRemoteProxy<INdefMsgCallback>(remote)
25 {}
26 
OnNdefMsgDiscovered(const std::string & tagUid,const std::string & ndef,int ndefMsgType)27 bool NdefMsgCallbackProxy::OnNdefMsgDiscovered(const std::string &tagUid, const std::string &ndef, int ndefMsgType)
28 {
29     DebugLog("NdefMsgCallbackProxy::OnNdefMsgDiscovered");
30     MessageOption option = {MessageOption::TF_ASYNC};
31     MessageParcel data;
32     MessageParcel reply;
33     if (!data.WriteInterfaceToken(GetDescriptor())) {
34         DebugLog("NdefMsgCallbackProxy::OnNdefMsgDiscovered, Write interface token error");
35         return false;
36     }
37     data.WriteInt32(0);
38     data.WriteString(tagUid);
39     data.WriteString(ndef);
40     data.WriteInt32(ndefMsgType);
41 
42     int error = Remote()->SendRequest(static_cast<uint32_t>(NfcServiceIpcInterfaceCode::COMMAND_ON_NDEF_MSG_NOTIFY),
43         data, reply, option);
44     if (error != ERR_NONE) {
45         ErrorLog("NdefMsgCallbackProxy::OnNdefMsgDiscovered, Set Attr %{public}d error: %{public}d",
46             NfcServiceIpcInterfaceCode::COMMAND_ON_NDEF_MSG_NOTIFY, error);
47         return false;
48     }
49     bool res = reply.ReadBool();
50     if (!res) {
51         InfoLog("NdefMsgCallbackProxy::OnNdefMsgDiscovered, COMMAND_ON_NDEF_MSG_NOTIFY reply false");
52         return false;
53     }
54     return true;
55 }
56 }  // namespace NFC
57 }  // namespace OHOS