uuid.h revision 611fcf98316e28425abe28dbcc07b8d037653cee
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#pragma once
17
18#include <array>
19#include <string>
20
21#include "hardware/bluetooth.h"
22
23namespace bluetooth {
24
25class Uuid {
26 public:
27  enum Type {
28    kUuid128Octets = 16,
29    kUuid32Octets = 4,
30    kUuid16Octets = 2,
31  };
32
33  typedef std::array<uint8_t, Uuid::kUuid16Octets> Uuid16Bit;
34  typedef std::array<uint8_t, Uuid::kUuid32Octets> Uuid32Bit;
35  typedef std::array<uint8_t, Uuid::kUuid128Octets> Uuid128Bit;
36
37  // Construct a Bluetooth 'base' UUID.
38  Uuid();
39
40  // BlueDroid constructor.
41  explicit Uuid(const bt_uuid_t& uuid);
42
43  // String constructor. Only hex ASCII accepted.
44  explicit Uuid(const std::string& uuid);
45
46  // std::array variants constructors.
47  explicit Uuid(const Uuid::Uuid16Bit& uuid);
48  explicit Uuid(const Uuid::Uuid32Bit& uuid);
49  explicit Uuid(const Uuid::Uuid128Bit& uuid);
50
51  // Provide the full network-byte-ordered blob.
52  const Uuid128Bit GetFullBigEndian() const;
53
54  // Provide blob in Little endian (BlueDroid expects this).
55  const Uuid128Bit GetFullLittleEndian() const;
56
57  // Helper for bluedroid LE type.
58  const bt_uuid_t GetBlueDroid() const;
59
60  bool operator<(const Uuid& rhs) const;
61  bool operator==(const Uuid& rhs) const;
62
63 private:
64  void InitializeDefault();
65  // Network-byte-ordered ID.
66  Uuid128Bit id_;
67};
68
69}  // namespace bluetooth
70