Home | History | Annotate | Download | only in bluetooth
      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 #pragma once
     18 
     19 #include <base/macros.h>
     20 #include <base/time/time.h>
     21 
     22 namespace bluetooth {
     23 
     24 // AdvertiseSettings provides a way to adjust advertising preferences for each
     25 // Bluetooth LE advertisement instance. This is the native equivalent of the
     26 // Android framework class defined in
     27 // frameworks/base/core/java/android/bluetooth/le/AdvertiseSettings.java
     28 class AdvertiseSettings {
     29  public:
     30   // Advertising mode describes power consumption mode used for advertising.
     31   enum Mode {
     32     // Perform Bluetooth LE advertising in low power mode. This is the default
     33     // and preferred advertising mode as it consumes the least power.
     34     MODE_LOW_POWER = 0x00,
     35 
     36     // Perform Bluetooth LE advertising in balanced power mode. This is balanced
     37     // between advertising frequency and power consumption.
     38     MODE_BALANCED = 0x01,
     39 
     40     // Perform Bluetooth LE advertising in low latency, high power mode. This
     41     // has the highest power consumption and should not be used for continuous
     42     // background advertising.
     43     MODE_LOW_LATENCY = 0x02,
     44   };
     45 
     46   // Levels that can be set for advertising transmission power.
     47   enum TxPowerLevel {
     48     // Advertise using the lowest transmission (TX) power level. Low
     49     // transmission power can be used to restrict the visibility range of
     50     // advertising packets.
     51     TX_POWER_LEVEL_ULTRA_LOW = 0x00,
     52 
     53     // Advertise using low TX power level.
     54     TX_POWER_LEVEL_LOW = 0x01,
     55 
     56     // Advertise using medium TX power level.
     57     TX_POWER_LEVEL_MEDIUM = 0x02,
     58 
     59     // Advertise using high TX power level. This corresponds to largest
     60     // visibility range of the advertising packet.
     61     TX_POWER_LEVEL_HIGH = 0x03,
     62   };
     63 
     64   AdvertiseSettings(Mode mode,
     65                     base::TimeDelta timeout,
     66                     TxPowerLevel tx_power_level,
     67                     bool connectable);
     68 
     69   // The default constructor sets all fields to defaults:
     70   //   mode: MODE_LOW_POWER
     71   //   TX power level: TX_POWER_LEVEL_MEDIUM
     72   //   connectable: true
     73   AdvertiseSettings();
     74   ~AdvertiseSettings() = default;
     75 
     76   // Returns the advertise mode.
     77   Mode mode() const { return mode_; }
     78 
     79   // Returns the advertising time limit in milliseconds.
     80   const base::TimeDelta& timeout() const { return timeout_; }
     81 
     82   // Returns the TX power level for advertising.
     83   TxPowerLevel tx_power_level() const { return tx_power_level_; }
     84 
     85   // Returns whether the advertisement will indicate connectable.
     86   bool connectable() const { return connectable_; }
     87 
     88   // Comparison operator.
     89   bool operator==(const AdvertiseSettings& rhs) const;
     90 
     91  private:
     92   Mode mode_;
     93   base::TimeDelta timeout_;
     94   TxPowerLevel tx_power_level_;
     95   bool connectable_;
     96 };
     97 
     98 }  // namespace bluetooth
     99