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