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/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, base::TimeDelta timeout,
65                     TxPowerLevel tx_power_level, bool connectable);
66 
67   // The default constructor sets all fields to defaults:
68   //   mode: MODE_LOW_POWER
69   //   TX power level: TX_POWER_LEVEL_MEDIUM
70   //   connectable: true
71   AdvertiseSettings();
72   virtual ~AdvertiseSettings() = default;
73 
74   // Returns the advertise mode.
mode()75   Mode mode() const { return mode_; }
76 
77   // Returns the advertising time limit in milliseconds.
timeout()78   const base::TimeDelta& timeout() const { return timeout_; }
79 
80   // Returns the TX power level for advertising.
tx_power_level()81   TxPowerLevel tx_power_level() const { return tx_power_level_; }
82 
83   // Returns whether the advertisement will indicate connectable.
connectable()84   bool connectable() const { return connectable_; }
85 
86   // Comparison operator.
87   bool operator==(const AdvertiseSettings& rhs) const;
88 
89  protected:
90   Mode mode_;
91   base::TimeDelta timeout_;
92   TxPowerLevel tx_power_level_;
93   bool connectable_;
94 };
95 
96 }  // namespace bluetooth
97