uuid.h revision 611fcf98316e28425abe28dbcc07b8d037653cee
1611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// 2611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// Copyright (C) 2015 Google, Inc. 3611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// 4611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// Licensed under the Apache License, Version 2.0 (the "License"); 5611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// you may not use this file except in compliance with the License. 6611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// You may obtain a copy of the License at: 7611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// 8611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// http://www.apache.org/licenses/LICENSE-2.0 9611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// 10611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// Unless required by applicable law or agreed to in writing, software 11611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// distributed under the License is distributed on an "AS IS" BASIS, 12611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// See the License for the specific language governing permissions and 14611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// limitations under the License. 15611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge// 16611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge#pragma once 17611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 18611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge#include <array> 19611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge#include <string> 20611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 21611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge#include "hardware/bluetooth.h" 22611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 23611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidgenamespace bluetooth { 24611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 25611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidgeclass Uuid { 26611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge public: 27611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge enum Type { 28611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge kUuid128Octets = 16, 29611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge kUuid32Octets = 4, 30611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge kUuid16Octets = 2, 31611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge }; 32611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 33611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge typedef std::array<uint8_t, Uuid::kUuid16Octets> Uuid16Bit; 34611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge typedef std::array<uint8_t, Uuid::kUuid32Octets> Uuid32Bit; 35611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge typedef std::array<uint8_t, Uuid::kUuid128Octets> Uuid128Bit; 36611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 37611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // Construct a Bluetooth 'base' UUID. 38611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge Uuid(); 39611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 40611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // BlueDroid constructor. 41611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge explicit Uuid(const bt_uuid_t& uuid); 42611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 43611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // String constructor. Only hex ASCII accepted. 44611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge explicit Uuid(const std::string& uuid); 45611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 46611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // std::array variants constructors. 47611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge explicit Uuid(const Uuid::Uuid16Bit& uuid); 48611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge explicit Uuid(const Uuid::Uuid32Bit& uuid); 49611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge explicit Uuid(const Uuid::Uuid128Bit& uuid); 50611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 51611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // Provide the full network-byte-ordered blob. 52611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge const Uuid128Bit GetFullBigEndian() const; 53611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 54611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // Provide blob in Little endian (BlueDroid expects this). 55611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge const Uuid128Bit GetFullLittleEndian() const; 56611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 57611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // Helper for bluedroid LE type. 58611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge const bt_uuid_t GetBlueDroid() const; 59611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 60611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge bool operator<(const Uuid& rhs) const; 61611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge bool operator==(const Uuid& rhs) const; 62611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 63611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge private: 64611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge void InitializeDefault(); 65611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge // Network-byte-ordered ID. 66611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge Uuid128Bit id_; 67611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge}; 68611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge 69611fcf98316e28425abe28dbcc07b8d037653ceeIan Coolidge} // namespace bluetooth 70