• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 - 2023 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_parcelable.h"
16 #include "loghelper.h"
17 #include "nfc_controller.h"
18 #include "nfc_sdk_common.h"
19 #include "parcel.h"
20 #include "refbase.h"
21 
22 namespace OHOS {
23 namespace NFC {
24 namespace KITS {
TagInfoParcelable(std::vector<int> tagTechList,std::vector<AppExecFwk::PacMap> tagTechExtrasData,std::string & tagUid,int tagRfDiscId,OHOS::sptr<IRemoteObject> tagServiceIface)25 TagInfoParcelable::TagInfoParcelable(std::vector<int> tagTechList,
26                                      std::vector<AppExecFwk::PacMap> tagTechExtrasData,
27                                      std::string& tagUid,
28                                      int tagRfDiscId,
29                                      OHOS::sptr<IRemoteObject> tagServiceIface)
30 {
31     tagRfDiscId_ = tagRfDiscId;
32     tagUid_ = tagUid;
33     tagTechList_ = std::move(tagTechList);
34     tagServiceIface_ = tagServiceIface;
35     tagTechExtrasData_ = std::move(tagTechExtrasData);
36 }
37 
~TagInfoParcelable()38 TagInfoParcelable::~TagInfoParcelable()
39 {
40     tagUid_.clear();
41     tagTechList_.clear();
42     tagTechExtrasData_.clear();
43     tagRfDiscId_ = 0;
44     tagServiceIface_ = nullptr;
45 }
46 
Marshalling(Parcel & parcel) const47 bool TagInfoParcelable::Marshalling(Parcel &parcel) const
48 {
49     const std::vector<int> tagTechList = std::move(tagTechList_);
50     parcel.WriteInt32Vector(tagTechList);
51     parcel.WriteInt32(tagTechExtrasData_.size());
52     for (unsigned int i = 0; i < tagTechExtrasData_.size(); i++) {
53         tagTechExtrasData_[i].Marshalling(parcel);
54     }
55     parcel.WriteString(tagUid_);
56     parcel.WriteInt32(tagRfDiscId_);
57     return true;
58 }
59 
Unmarshalling(Parcel & parcel)60 TagInfoParcelable *TagInfoParcelable::Unmarshalling(Parcel &parcel)
61 {
62     std::vector<int> tagTechList;
63     parcel.ReadInt32Vector(&tagTechList);
64 
65     int32_t extraLen = 0;
66     parcel.ReadInt32(extraLen);
67     std::vector<AppExecFwk::PacMap> tagTechExtrasData;
68     for (int i = 0; i < extraLen; i++) {
69         AppExecFwk::PacMap* pacMap = AppExecFwk::PacMap::Unmarshalling(parcel);
70         tagTechExtrasData.push_back(*(pacMap));
71     }
72     std::string tagUid;
73     parcel.ReadString(tagUid);
74 
75     int tagRfDiscId;
76     parcel.ReadInt32(tagRfDiscId);
77     TagInfoParcelable *taginfo = new (std::nothrow) TagInfoParcelable(tagTechList, tagTechExtrasData,
78         tagUid, tagRfDiscId, nullptr);
79     return taginfo;
80 }
81 
GetUid()82 std::string TagInfoParcelable::GetUid()
83 {
84     return tagUid_;
85 }
86 
GetTechList()87 std::vector<int> TagInfoParcelable::GetTechList()
88 {
89     return tagTechList_;
90 }
91 
GetDiscId()92 int TagInfoParcelable::GetDiscId()
93 {
94     return tagRfDiscId_;
95 }
96 
GetTechExtrasDataList()97 std::vector<AppExecFwk::PacMap> TagInfoParcelable::GetTechExtrasDataList()
98 {
99     return tagTechExtrasData_;
100 }
101 
ToString()102 std::string TagInfoParcelable::ToString()
103 {
104     std::string res = "tagTechList: [";
105     if (tagTechList_.size() <= 0) {
106         res += "]";
107         return res;
108     }
109     for (uint32_t i = 0; i < tagTechList_.size() - 1; i++) {
110         res += std::to_string(tagTechList_[i]);
111         res += ", ";
112     }
113     res += std::to_string(tagTechList_[tagTechList_.size() - 1]);
114     res += "]";
115     return res;
116 }
117 }  // namespace KITS
118 }  // namespace NFC
119 }  // namespace OHOS