1 // 2 // Copyright (C) 2015 Google, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at: 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #include "bluetooth/scan_filter.h" 18 19 namespace bluetooth { 20 21 ScanFilter::ScanFilter(const ScanFilter& other) { 22 device_name_ = other.device_name_; 23 device_address_ = other.device_address_; 24 25 if (other.service_uuid_) service_uuid_.reset(new UUID(*other.service_uuid_)); 26 27 if (other.service_uuid_mask_) 28 service_uuid_mask_.reset(new UUID(*other.service_uuid_mask_)); 29 } 30 31 ScanFilter& ScanFilter::operator=(const ScanFilter& other) { 32 device_name_ = other.device_name_; 33 device_address_ = other.device_address_; 34 35 if (other.service_uuid_) 36 service_uuid_.reset(new UUID(*other.service_uuid_)); 37 else 38 service_uuid_ = nullptr; 39 40 if (other.service_uuid_mask_) 41 service_uuid_mask_.reset(new UUID(*other.service_uuid_mask_)); 42 else 43 service_uuid_mask_ = nullptr; 44 45 return *this; 46 } 47 48 bool ScanFilter::SetDeviceAddress(const std::string& device_address) { 49 if (!RawAddress::IsValidAddress(device_address)) return false; 50 51 device_address_ = device_address; 52 return true; 53 } 54 55 void ScanFilter::SetServiceUuid(const UUID& service_uuid) { 56 service_uuid_.reset(new UUID(service_uuid)); 57 service_uuid_mask_.reset(); 58 } 59 60 void ScanFilter::SetServiceUuidWithMask(const UUID& service_uuid, 61 const UUID& mask) { 62 service_uuid_.reset(new UUID(service_uuid)); 63 service_uuid_mask_.reset(new UUID(mask)); 64 } 65 66 bool ScanFilter::operator==(const ScanFilter& rhs) const { 67 if (device_name_ != rhs.device_name_) return false; 68 69 if (device_address_ != rhs.device_address_) return false; 70 71 // Both must be either NULL or non-NULL. If only one of them is NULL, then 72 // return false. 73 if (!!service_uuid_ != !!rhs.service_uuid_) return false; 74 75 if (service_uuid_ && rhs.service_uuid_ && 76 *service_uuid_ != *rhs.service_uuid_) 77 return false; 78 79 // Both must be either NULL or non-NULL. If only one of them is NULL, then 80 // return false. 81 if (!!service_uuid_mask_ != !!rhs.service_uuid_mask_) return false; 82 83 if (service_uuid_mask_ && rhs.service_uuid_mask_ && 84 *service_uuid_mask_ != *rhs.service_uuid_mask_) 85 return false; 86 87 return true; 88 } 89 90 } // namespace bluetooth 91