1 /* 2 * Copyright 2020 The Android Open Source Project 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 #pragma once 17 18 #include <string> 19 20 #include "common/byte_array.h" 21 #include "hci/address.h" 22 #include "storage/config_cache.h" 23 #include "storage/device.h" 24 25 namespace bluetooth { 26 namespace storage { 27 28 class AdapterConfig { 29 public: 30 AdapterConfig(ConfigCache* config, ConfigCache* memory_only_config, std::string section); 31 32 // for move 33 AdapterConfig(AdapterConfig&& other) noexcept = default; 34 AdapterConfig& operator=(AdapterConfig&& other) noexcept = default; 35 36 // for copy 37 AdapterConfig(const AdapterConfig& other) noexcept = default; 38 AdapterConfig& operator=(const AdapterConfig& other) noexcept = default; 39 40 // operators 41 bool operator==(const AdapterConfig& other) const { 42 return config_ == other.config_ && memory_only_config_ == other.memory_only_config_ && section_ == other.section_; 43 } 44 bool operator!=(const AdapterConfig& other) const { 45 return !(*this == other); 46 } 47 bool operator<(const AdapterConfig& other) const { 48 if (config_ != other.config_) { 49 return config_ < other.config_; 50 } 51 if (memory_only_config_ != other.memory_only_config_) { 52 return memory_only_config_ < other.memory_only_config_; 53 } 54 return section_ < other.section_; 55 } 56 bool operator>(const AdapterConfig& rhs) const { 57 return (rhs < *this); 58 } 59 bool operator<=(const AdapterConfig& rhs) const { 60 return !(*this > rhs); 61 } 62 bool operator>=(const AdapterConfig& rhs) const { 63 return !(*this < rhs); 64 } 65 66 private: 67 ConfigCache* config_; 68 ConfigCache* memory_only_config_; 69 std::string section_; 70 71 public: 72 GENERATE_PROPERTY_GETTER_SETTER_REMOVER(Address, hci::Address, "Address"); 73 GENERATE_PROPERTY_GETTER_SETTER_REMOVER(LeIdentityResolvingKey, common::ByteArray<16>, "LE_LOCAL_KEY_IRK"); 74 GENERATE_PROPERTY_GETTER_SETTER_REMOVER(LegacyScanMode, hci::LegacyScanMode, "ScanMode"); 75 GENERATE_PROPERTY_GETTER_SETTER_REMOVER(DiscoveryTimeoutSeconds, int, "DiscoveryTimeout"); 76 }; 77 78 } // namespace storage 79 } // namespace bluetooth