• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <map>
18 #include <mutex>
19 #include "ability_info.h"
20 #include "element_name.h"
21 #include "itag_host.h"
22 #include "taginfo.h"
23 
24 namespace OHOS {
25 namespace NFC {
26 class INfcService;
27 namespace TAG {
28 using AppExecFwk::AbilityInfo;
29 using OHOS::AppExecFwk::ElementName;
30 class TagDispatcher final {
31 public:
32     explicit TagDispatcher(std::shared_ptr<NFC::INfcService> nfcService);
33     ~TagDispatcher();
34     TagDispatcher(const TagDispatcher&) = delete;
35     TagDispatcher& operator=(const TagDispatcher&) = delete;
36 
37     int HandleTagFound(std::shared_ptr<NCI::ITagHost> tag);
38     void HandleTagDebounce();
39     std::weak_ptr<NCI::ITagHost> FindTagHost(int rfDiscId);
40     void DispatchAbility(ElementName &element, std::shared_ptr<KITS::TagInfo> tagInfo);
41 protected:
42     std::shared_ptr<NCI::ITagHost> FindAndRemoveTagHost(int rfDiscId);
43     void RegisterTagHost(std::shared_ptr<NCI::ITagHost> tag);
44     void UnregisterTagHost(int rfDiscId);
45 
46 private:
47     void TagDisconnectedCallback(int tagRfDiscId);
48     std::shared_ptr<NFC::INfcService> nfcService_ {};
49     // Lock
50     std::mutex mutex_ {};
51     std::map<int, std::shared_ptr<NCI::ITagHost>> tagHostMap_ {};
52     // tag field on checking
53     const static int DEFAULT_FIELD_ON_CHECK_DURATION = 125; // ms
54     const static int DEFAULT_ISO_DEP_FIELD_ON_CHECK_DURATION = 500; // ms
55     // ndef message
56     std::string lastNdefMsg_;
57 };
58 }  // namespace TAG
59 }  // namespace NFC
60 }  // namespace OHOS
61 #endif  // TAG_DISPATCH_H
62