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 {
     31  public:
     32   // Constructs an AdvertiseData with the given parameters. |data| can only
     33   // contain the "Service UUIDs", "Service Data", "Manufacturer Data",
     34   // "Tx Power" and "Device name" fields as specified in the Core Specification
     35   //  Supplement. |data| must be properly formatted according to the supplement
     36   // and contains the data as it will be sent over the wire.
     37   //
     38   // Tx Power field value will be filled with proper value.
     39   explicit AdvertiseData(const std::vector<uint8_t>& data);
     40 
     41   // Default constructor initializes all fields to be empty/false.
     42   AdvertiseData();
     43   AdvertiseData(const AdvertiseData& other);
     44   virtual ~AdvertiseData() = default;
     45 
     46   // Returns true if the advertising data is formatted correctly according to
     47   // the TLV format.
     48   bool IsValid() const;
     49 
     50   // data() returns the current advertising data contained by this instance. The
     51   // data is in the TLV format as specified in the Bluetooth Core Specification.
     52   const std::vector<uint8_t>& data() const { return data_; }
     53 
     54   // Comparison operator.
     55   bool operator==(const AdvertiseData& rhs) const;
     56 
     57   // Assignment operator
     58   AdvertiseData& operator=(const AdvertiseData& other);
     59 
     60  protected:
     61   std::vector<uint8_t> data_;
     62 };
     63 
     64 }  // namespace bluetooth
     65