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 <stdint.h>
     20 
     21 #include <vector>
     22 
     23 #include <base/macros.h>
     24 
     25 namespace bluetooth {
     26 
     27 // Represents a data packet for Bluetooth Low Energy advertisements. This is the
     28 // native equivalent of the Android framework class defined in
     29 // frameworks/base/core/j/android/bluetooth/le/AdvertiseData.java
     30 class AdvertiseData final {
     31  public:
     32   // Constructs an AdvertiseData with the given parameters. |data| can only
     33   // contain the "Service UUIDs", "Service Data", and "Manufacturer Data" fields
     34   // as specified in the Core Specification Supplement. |data| must be properly
     35   // formatted according to the supplement and contains the data as it will be
     36   // sent over the wire.
     37   //
     38   // The values for include_device_name() and include_tx_power_level() are
     39   // initialized to false by default. These can be modified using the setters
     40   // declared below.
     41   explicit AdvertiseData(const std::vector<uint8_t>& data);
     42 
     43   // Default constructor initializes all fields to be empty/false.
     44   AdvertiseData();
     45   AdvertiseData(const AdvertiseData& other);
     46   ~AdvertiseData() = default;
     47 
     48   // Returns true if the advertising data is formatted correctly according to
     49   // the TLV format.
     50   bool IsValid() const;
     51 
     52   // data() returns the current advertising data contained by this instance. The
     53   // data is in the TLV format as specified in the Bluetooth Core Specification.
     54   const std::vector<uint8_t>& data() const { return data_; }
     55 
     56   // Whether the device name should be included in the advertisement packet.
     57   bool include_device_name() const { return include_device_name_; }
     58   void set_include_device_name(bool value) { include_device_name_ = value; }
     59 
     60   // Whether the transmission power level should be included in the
     61   // advertisement packet.
     62   bool include_tx_power_level() const { return include_tx_power_level_; }
     63   void set_include_tx_power_level(bool value) {
     64     include_tx_power_level_ = value;
     65   }
     66 
     67   // Comparison operator.
     68   bool operator==(const AdvertiseData& rhs) const;
     69 
     70   // Assignment operator
     71   AdvertiseData& operator=(const AdvertiseData& other);
     72 
     73  private:
     74   std::vector<uint8_t> data_;
     75   bool include_device_name_;
     76   bool include_tx_power_level_;
     77 };
     78 
     79 }  // namespace bluetooth
     80