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 "nfc_service.h" 25 #include "taginfo.h" 26 #include "taginfo_parcelable.h" 27 28 namespace OHOS { 29 namespace NFC { 30 class NfcService; 31 namespace TAG { 32 class TagDispatcher final { 33 public: 34 explicit TagDispatcher(std::shared_ptr<NfcService> nfcService); 35 ~TagDispatcher(); 36 TagDispatcher(const TagDispatcher&) = delete; 37 TagDispatcher& operator=(const TagDispatcher&) = delete; 38 39 void HandleTagFound(uint32_t rfDiscId); 40 void HandleTagDebounce(); 41 void HandleTagLost(uint32_t rfDiscId); 42 void RegNdefMsgCb(const sptr<INdefMsgCallback> &callback); 43 void OnNotificationButtonClicked(int notificationId); 44 45 private: 46 std::shared_ptr<KITS::TagInfo> GetTagInfoFromTag(uint32_t rfDiscId); 47 KITS::TagInfoParcelable* GetTagInfoParcelableFromTag(uint32_t rfDiscId); 48 void DispatchTag(uint32_t rfDiscId); 49 bool HandleNdefDispatch(uint32_t tagDiscId, std::string &msg); 50 void PublishTagNotification(uint32_t tagDiscId, bool isIsoDep); 51 void StartVibratorOnce(bool isNtfPublished = false); 52 53 private: 54 std::shared_ptr<NfcService> nfcService_ {}; 55 std::weak_ptr<NCI::INciTagInterface> nciTagProxy_ {}; 56 std::weak_ptr<NCI::INciNfccInterface> nciNfccProxy_ {}; 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 68 std::shared_ptr<KITS::TagInfo> tagInfo_ {}; 69 bool ndefCbRes_ = false; 70 }; 71 } // namespace TAG 72 } // namespace NFC 73 } // namespace OHOS 74 #endif // TAG_DISPATCH_H 75