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 TAG_DISPATCH_H 16 #define TAG_DISPATCH_H 17 18 #include <map> 19 #include <mutex> 20 21 #include "indef_msg_callback.h" 22 #include "inci_tag_interface.h" 23 #include "isodep_card_handler.h" 24 #include "ndef_har_data_parser.h" 25 #include "nfc_service.h" 26 #include "taginfo.h" 27 #include "taginfo_parcelable.h" 28 29 namespace OHOS { 30 namespace NFC { 31 class NfcService; 32 namespace TAG { 33 class TagDispatcher final { 34 public: 35 explicit TagDispatcher(std::shared_ptr<NfcService> nfcService); 36 ~TagDispatcher(); 37 TagDispatcher(const TagDispatcher&) = delete; 38 TagDispatcher& operator=(const TagDispatcher&) = delete; 39 40 void HandleTagFound(uint32_t rfDiscId); 41 void HandleTagDebounce(); 42 void HandleTagLost(uint32_t rfDiscId); 43 void RegNdefMsgCb(const sptr<INdefMsgCallback> &callback); 44 void OnNotificationButtonClicked(int notificationId); 45 46 private: 47 std::shared_ptr<KITS::TagInfo> GetTagInfoFromTag(uint32_t rfDiscId); 48 KITS::TagInfoParcelable* GetTagInfoParcelableFromTag(uint32_t rfDiscId); 49 void DispatchTag(uint32_t rfDiscId); 50 bool HandleNdefDispatch(uint32_t tagDiscId, std::string &msg); 51 void PublishTagNotification(uint32_t tagDiscId, bool isIsoDep); 52 void StartVibratorOnce(); 53 54 private: 55 std::shared_ptr<NfcService> nfcService_ {}; 56 std::weak_ptr<NCI::INciTagInterface> nciTagProxy_ {}; 57 58 // tag field on checking 59 const static int DEFAULT_FIELD_ON_CHECK_DURATION = 150; // ms 60 const static int DEFAULT_ISO_DEP_FIELD_ON_CHECK_DURATION = 500; // ms 61 62 // ndef message 63 std::string lastNdefMsg_ {}; 64 sptr<INdefMsgCallback> ndefCb_; 65 66 std::shared_ptr<IsodepCardHandler> isodepCardHandler_ {}; 67 std::shared_ptr<NdefHarDataParser> ndefHarDataParser_ {nullptr}; 68 69 std::shared_ptr<KITS::TagInfo> tagInfo_ {}; 70 bool ndefCbRes_ = false; 71 }; 72 } // namespace TAG 73 } // namespace NFC 74 } // namespace OHOS 75 #endif // TAG_DISPATCH_H 76