1 // 2 // Copyright 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 #pragma once 18 19 #include <memory> 20 21 #include <bluetooth/uuid.h> 22 23 namespace bluetooth { 24 25 // Used for filtering scan results by allowing clients to restrict scan results 26 // to only those that are of interest to them. 27 class ScanFilter { 28 public: 29 ScanFilter() = default; 30 virtual ~ScanFilter() = default; 31 32 // Copy constructor and assignment operator. 33 ScanFilter(const ScanFilter& other); 34 ScanFilter& operator=(const ScanFilter& other); 35 36 // The device name used while filtering scan results. device_name()37 const std::string& device_name() const { return device_name_; } set_device_name(const std::string & name)38 void set_device_name(const std::string& name) { device_name_ = name; } 39 40 // The device address used while filtering scan results. Address should be in 41 // the XX:XX:XX:XX:XX:XX where X is a hexadecimal digit. device_address()42 const std::string& device_address() const { return device_address_; } 43 44 // Sets the device address used for filtering. Returns false if 45 // |device_address| is in an illegal format. 46 bool SetDeviceAddress(const std::string& device_address); 47 48 // The service Uuid and its mask used while filtering scan results. See 49 // SetServiceUuidWithMask for what this mask does. The raw pointer returned 50 // from these getters belongs to the ScanFilter object. nullptr will be 51 // returned if these fields have not been set on this filter. service_uuid()52 const Uuid* service_uuid() const { return service_uuid_.get(); } service_uuid_mask()53 const Uuid* service_uuid_mask() const { return service_uuid_mask_.get(); } 54 55 // Sets the service Uuid for this filter. 56 void SetServiceUuid(const Uuid& service_uuid); 57 58 // Sets the service Uuid for this filter with a 128-bit mask. The mask allows 59 // the caller to partially filter scanned service Uuids. For any of the 60 // 128-bits of a Uuid, set the corresponding bit in the mask to 1 to match the 61 // advertised value, and 0 to ignore that bit. 62 void SetServiceUuidWithMask(const Uuid& service_uuid, const Uuid& mask); 63 64 // Comparison operator. 65 bool operator==(const ScanFilter& rhs) const; 66 67 protected: 68 std::string device_name_; 69 std::string device_address_; 70 71 std::unique_ptr<Uuid> service_uuid_; 72 std::unique_ptr<Uuid> service_uuid_mask_; 73 74 // TODO(armansito): Add service and manufacturer data filter fields. 75 }; 76 77 } // namespace bluetooth 78