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 #ifndef NFC_CONTROLLER_STUB_H 16 #define NFC_CONTROLLER_STUB_H 17 18 #include "indef_msg_callback.h" 19 #include "infc_controller_callback.h" 20 #include "infc_controller_service.h" 21 #ifdef VENDOR_APPLICATIONS_ENABLED 22 #include "iquery_app_info_callback.h" 23 #endif 24 #include "iremote_stub.h" 25 #include "nfc_controller_callback_proxy.h" 26 #include "nfc_sdk_common.h" 27 #include "message_parcel.h" 28 #include "access_token.h" 29 30 namespace OHOS { 31 namespace NFC { 32 class NfcControllerStub : public OHOS::IRemoteStub<OHOS::NFC::INfcControllerService> { 33 public: 34 int OnRemoteRequest(uint32_t code, /* [in] */ 35 OHOS::MessageParcel& data, /* [in] */ 36 OHOS::MessageParcel& reply, /* [out] */ 37 OHOS::MessageOption& option) override; /* [in] */ 38 NfcControllerStub()39 NfcControllerStub() {} ~NfcControllerStub()40 virtual ~NfcControllerStub() {} 41 virtual KITS::ErrorCode RegisterCallBack(const sptr<INfcControllerCallback> &callback, 42 const std::string& type, Security::AccessToken::AccessTokenID callerToken) = 0; 43 virtual KITS::ErrorCode UnRegisterCallBack(const std::string& type, 44 Security::AccessToken::AccessTokenID callerToken) = 0; 45 virtual KITS::ErrorCode UnRegisterAllCallBack(Security::AccessToken::AccessTokenID callerToken) = 0; 46 virtual KITS::ErrorCode RegNdefMsgCallback(const sptr<INdefMsgCallback> &callback) = 0; 47 void RemoveNfcDeathRecipient(const wptr<IRemoteObject> &remote); 48 49 private: 50 int HandleGetState(OHOS::MessageParcel& data, OHOS::MessageParcel& reply); 51 int HandleTurnOn(OHOS::MessageParcel& data, OHOS::MessageParcel& reply); 52 int HandleTurnOff(OHOS::MessageParcel& data, OHOS::MessageParcel& reply); 53 int HandleIsNfcOpen(OHOS::MessageParcel& data, OHOS::MessageParcel& reply); 54 int HandleRegisterCallBack(OHOS::MessageParcel& data, OHOS::MessageParcel& reply); 55 int HandleUnRegisterCallBack(OHOS::MessageParcel& data, OHOS::MessageParcel& reply); 56 int HandleGetNfcTagInterface(MessageParcel& data, MessageParcel& reply); 57 int HandleRegNdefMsgCb(MessageParcel& data, MessageParcel& reply); 58 #ifdef VENDOR_APPLICATIONS_ENABLED 59 int HandleRegQueryApplicationCb(MessageParcel& data, MessageParcel& reply); 60 int HandleRegCardEmulationNotifyCb(MessageParcel& data, MessageParcel& reply); 61 int HandleNotifyEventStatus(MessageParcel& data, MessageParcel& reply); 62 #endif 63 int HandleGetNfcHceInterface(MessageParcel &data, MessageParcel &reply); 64 65 private: 66 KITS::ErrorCode RegisterCallBack(const sptr<INfcControllerCallback> &callback, 67 const std::string& type) override; 68 KITS::ErrorCode UnRegisterCallBack(const std::string& type) override; 69 KITS::ErrorCode RegNdefMsgCb(const sptr<INdefMsgCallback> &callback) override; 70 71 private: 72 std::mutex mutex_ {}; 73 sptr<INfcControllerCallback> callback_; 74 sptr<INdefMsgCallback> ndefCallback_; 75 #ifdef VENDOR_APPLICATIONS_ENABLED 76 sptr<IQueryAppInfoCallback> queryAppInfoCallback_ {nullptr}; 77 sptr<IOnCardEmulationNotifyCb> onCardEmulationNotifyCb_ {nullptr}; 78 #endif 79 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 80 }; 81 } // namespace NFC 82 } // namespace OHOS 83 #endif // NFC_CONTROLLER_STUB_H 84