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 16 #include "ble_parcel_data.h" 17 18 namespace OHOS { 19 namespace bluetooth { 20 ScanResult(const BleScanResultImpl & other)21ScanResult::ScanResult(const BleScanResultImpl &other) 22 { 23 const auto &device = other.GetPeripheralDevice(); 24 if (device.IsRSSI()) { 25 this->SetRssi(device.GetRSSI()); 26 } 27 this->SetAdvertiseFlag(device.GetAdFlag()); 28 29 if (device.IsManufacturerData()) { 30 auto manuData = device.GetManufacturerData(); 31 for (auto it = manuData.begin(); it != manuData.end(); it++) { 32 this->AddManufacturerData(it->first, it->second); 33 } 34 } 35 this->SetConnectable(device.IsConnectable()); 36 37 if (device.IsServiceUUID()) { 38 auto uuids = device.GetServiceUUID(); 39 for (auto iter = uuids.begin(); iter != uuids.end(); iter++) { 40 this->AddServiceUuid(*iter); 41 } 42 } 43 44 if (device.IsServiceData()) { 45 auto uuids = device.GetServiceDataUUID(); 46 int index = 0; 47 for (auto iter = uuids.begin(); iter != uuids.end(); iter++) { 48 this->AddServiceData(*iter, device.GetServiceData(index)); 49 ++index; 50 } 51 } 52 53 if (device.IsName()) { 54 this->SetName(device.GetName()); 55 } 56 57 if (device.IsEventType()) { 58 this->SetEventType(device.GetEventType()); 59 } 60 61 this->SetPeripheralDevice(device.GetRawAddress()); 62 this->SetPayload(std::string(device.GetPayload(), device.GetPayload() + device.GetPayloadLen())); 63 } 64 65 } // namespace bluetooth 66 } // namespace OHOS