• 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 DispatchAbilityMultiApp(std::shared_ptr<KITS::TagInfo> tagInfo);
41     void DispatchAbilitySingleApp(ElementName &element, std::shared_ptr<KITS::TagInfo> tagInfo);
42 protected:
43     std::shared_ptr<NCI::ITagHost> FindAndRemoveTagHost(int rfDiscId);
44     void RegisterTagHost(std::shared_ptr<NCI::ITagHost> tag);
45     void UnregisterTagHost(int rfDiscId);
46 
47 private:
48     std::shared_ptr<KITS::TagInfo> GetTagInfoFromTag(std::shared_ptr<NCI::ITagHost> tag);
49     KITS::TagInfoParcelable GetTagInfoParcelableFromTag(std::shared_ptr<NCI::ITagHost> tag);
50     void DispatchTag(std::shared_ptr<NCI::ITagHost> tag);
51     void TagDisconnectedCallback(int tagRfDiscId);
52     std::shared_ptr<NFC::INfcService> nfcService_ {};
53     // Lock
54     std::mutex mutex_ {};
55     std::map<int, std::shared_ptr<NCI::ITagHost>> tagHostMap_ {};
56     // tag field on checking
57     const static int DEFAULT_FIELD_ON_CHECK_DURATION = 125; // ms
58     const static int DEFAULT_ISO_DEP_FIELD_ON_CHECK_DURATION = 500; // ms
59     const static int DEFAULT_MOTOR_VIBRATOR_ONCE = 500; // ms
60 
61     // there is only single tag application matched to be dispatched.
62     const static int TAG_APP_MATCHED_SIZE_SINGLE = 1;
63 
64     // ndef message
65     std::string lastNdefMsg_;
66 };
67 }  // namespace TAG
68 }  // namespace NFC
69 }  // namespace OHOS
70 #endif  // TAG_DISPATCH_H
71