• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 
16 #include "beacon_fence.h"
17 
18 namespace OHOS {
19 namespace Location {
BeaconFence()20 BeaconFence::BeaconFence()
21 {
22     identifier_ = "";
23     type_ = BEACON_MANUFACTURE_DATA;
24     manufactureData_.manufactureId = 0;
25 }
26 
BeaconFence(BeaconFence & beaconFence)27 BeaconFence::BeaconFence(BeaconFence& beaconFence)
28 {
29     identifier_ = beaconFence.GetIdentifier();
30     type_ = beaconFence.GetBeaconFenceInfoType();
31     manufactureData_ = beaconFence.GetBeaconManufactureData();
32 }
33 
~BeaconFence()34 BeaconFence::~BeaconFence() {}
35 
ReadFromParcel(Parcel & parcel)36 void BeaconFence::ReadFromParcel(Parcel& parcel)
37 {
38     std::unique_lock<std::mutex> lock(beaconFenceMutex_);
39     identifier_ = Str16ToStr8(parcel.ReadString16());
40     type_ = static_cast<BeaconFenceInfoType>(parcel.ReadInt32());
41     manufactureData_.manufactureId = parcel.ReadInt32();
42     parcel.ReadUInt8Vector(&manufactureData_.manufactureData);
43     parcel.ReadUInt8Vector(&manufactureData_.manufactureDataMask);
44 }
45 
UnmarshallingShared(Parcel & parcel)46 std::shared_ptr<BeaconFence> BeaconFence::UnmarshallingShared(Parcel& parcel)
47 {
48     std::unique_ptr<BeaconFence> beaconFence = std::make_unique<BeaconFence>();
49     beaconFence->ReadFromParcel(parcel);
50     return beaconFence;
51 }
52 
Unmarshalling(Parcel & parcel)53 BeaconFence* BeaconFence::Unmarshalling(Parcel& parcel)
54 {
55     auto beaconFence = new BeaconFence();
56     beaconFence->ReadFromParcel(parcel);
57     return beaconFence;
58 }
59 
Marshalling(Parcel & parcel) const60 bool BeaconFence::Marshalling(Parcel& parcel) const
61 {
62     std::unique_lock<std::mutex> lock(beaconFenceMutex_);
63     return parcel.WriteString16(Str8ToStr16(identifier_)) &&
64         parcel.WriteInt32(static_cast<int>(type_)) &&
65         parcel.WriteInt32(manufactureData_.manufactureId) &&
66         parcel.WriteUInt8Vector(manufactureData_.manufactureData) &&
67         parcel.WriteUInt8Vector(manufactureData_.manufactureDataMask);
68 }
69 } // namespace Location
70 } // namespace OHOS