• 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 #include "taginfo.h"
16 #include "loghelper.h"
17 #include "nfc_sdk_common.h"
18 #include "parcel.h"
19 #include "refbase.h"
20 
21 namespace OHOS {
22 namespace NFC {
23 namespace KITS {
TagInfo(std::vector<int> tagTechList,std::vector<AppExecFwk::PacMap> tagTechExtrasData,std::string & tagUid,int tagRfDiscId,OHOS::sptr<IRemoteObject> tagServiceIface)24 TagInfo::TagInfo(std::vector<int> tagTechList,
25                  std::vector<AppExecFwk::PacMap> tagTechExtrasData,
26                  std::string& tagUid,
27                  int tagRfDiscId,
28                  OHOS::sptr<IRemoteObject> tagServiceIface)
29 {
30     tagRfDiscId_ = tagRfDiscId;
31     tagUid_ = tagUid;
32     tagTechList_ = std::move(tagTechList);
33     tagTechExtrasData_ = std::move(tagTechExtrasData);
34     connectedTagTech_ = KITS::TagTechnology::NFC_INVALID_TECH;
35 }
36 
~TagInfo()37 TagInfo::~TagInfo()
38 {
39     tagUid_.clear();
40     tagTechList_.clear();
41     connectedTagTech_ = KITS::TagTechnology::NFC_INVALID_TECH;
42     tagRfDiscId_ = 0;
43 }
44 
IsTechSupported(KITS::TagTechnology tech)45 bool TagInfo::IsTechSupported(KITS::TagTechnology tech)
46 {
47     for (auto n : tagTechList_) {
48         if (n == static_cast<int>(tech)) {
49             return true;
50         }
51     }
52     return false;
53 }
54 
GetTagTechList() const55 std::vector<int> TagInfo::GetTagTechList() const
56 {
57     return std::move(tagTechList_);
58 }
59 
GetStringTech(int tech)60 std::string TagInfo::GetStringTech(int tech)
61 {
62     switch (tech) {
63         case static_cast<int>(TagTechnology::NFC_A_TECH):
64             return "NfcA";
65         case static_cast<int>(TagTechnology::NFC_B_TECH):
66             return "NfcB";
67         case static_cast<int>(TagTechnology::NFC_F_TECH):
68             return "NfcF";
69         case static_cast<int>(TagTechnology::NFC_V_TECH):
70             return "NfcV";
71         case static_cast<int>(TagTechnology::NFC_ISODEP_TECH):
72             return "IsoDep";
73         case static_cast<int>(TagTechnology::NFC_MIFARE_CLASSIC_TECH):
74             return "MifareClassic";
75         case static_cast<int>(TagTechnology::NFC_MIFARE_ULTRALIGHT_TECH):
76             return "MifareUL";
77         case static_cast<int>(TagTechnology::NFC_NDEF_TECH):
78             return "Ndef";
79         case static_cast<int>(TagTechnology::NFC_NDEF_FORMATABLE_TECH):
80             return "NdefFormatable";
81         case static_cast<int>(TagTechnology::NFC_BARCODE):
82             return "BarcodeTag";
83         default:
84             break;
85     }
86     return "";
87 }
88 
GetTechExtrasByIndex(size_t techIndex)89 AppExecFwk::PacMap TagInfo::GetTechExtrasByIndex(size_t techIndex)
90 {
91     AppExecFwk::PacMap pacmap;
92     if (tagTechList_.size() == 0 || tagTechList_.size() != tagTechExtrasData_.size()) {
93         ErrorLog("Taginfo:: tagTechList_lenth != tagTechExtrasData_length.");
94         return pacmap;
95     }
96     if (techIndex < 0 || techIndex >= tagTechExtrasData_.size()) {
97         return pacmap;
98     }
99     return tagTechExtrasData_[techIndex];
100 }
101 
GetTechExtrasByTech(KITS::TagTechnology tech)102 AppExecFwk::PacMap TagInfo::GetTechExtrasByTech(KITS::TagTechnology tech)
103 {
104     AppExecFwk::PacMap pacmap;
105     if (tagTechList_.size() == 0 || tagTechList_.size() != tagTechExtrasData_.size()) {
106         return pacmap;
107     }
108 
109     for (size_t i = 0; i < tagTechList_.size(); i++) {
110         if (static_cast<int>(tech) == tagTechList_[i]) {
111             pacmap = tagTechExtrasData_[i];
112             break;
113         }
114     }
115     return pacmap;
116 }
117 
GetStringExtrasData(AppExecFwk::PacMap & extrasData,const std::string & extrasName)118 std::string TagInfo::GetStringExtrasData(AppExecFwk::PacMap& extrasData, const std::string& extrasName)
119 {
120     if (extrasData.IsEmpty() || extrasName.empty()) {
121         return "";
122     }
123     return extrasData.GetStringValue(extrasName, "");
124 }
125 
GetIntExtrasData(AppExecFwk::PacMap & extrasData,const std::string & extrasName)126 int TagInfo::GetIntExtrasData(AppExecFwk::PacMap& extrasData, const std::string& extrasName)
127 {
128     if (extrasData.IsEmpty() || extrasName.empty()) {
129         return ErrorCode::ERR_TAG_PARAMETERS;
130     }
131     return extrasData.GetIntValue(extrasName, 0);
132 }
133 
GetBoolExtrasData(AppExecFwk::PacMap & extrasData,const std::string & extrasName)134 bool TagInfo::GetBoolExtrasData(AppExecFwk::PacMap& extrasData, const std::string& extrasName)
135 {
136     if (extrasData.IsEmpty() || extrasName.empty()) {
137         return false;
138     }
139     return extrasData.GetBooleanValue(extrasName, false);
140 }
141 
SetConnectedTagTech(KITS::TagTechnology connectedTagTech)142 void TagInfo::SetConnectedTagTech(KITS::TagTechnology connectedTagTech)
143 {
144     connectedTagTech_ = connectedTagTech;
145 }
146 
GetConnectedTagTech() const147 KITS::TagTechnology TagInfo::GetConnectedTagTech() const
148 {
149     return connectedTagTech_;
150 }
151 
GetTagUid() const152 std::string TagInfo::GetTagUid() const
153 {
154     return tagUid_;
155 }
156 
GetTagRfDiscId() const157 int TagInfo::GetTagRfDiscId() const
158 {
159     return tagRfDiscId_;
160 }
161 
162 }  // namespace KITS
163 }  // namespace NFC
164 }  // namespace OHOS