Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon Cooksey 0:fb7af294d5d9 1 /* mbed Microcontroller Library
Simon Cooksey 0:fb7af294d5d9 2 * Copyright (c) 2006-2013 ARM Limited
Simon Cooksey 0:fb7af294d5d9 3 *
Simon Cooksey 0:fb7af294d5d9 4 * Licensed under the Apache License, Version 2.0 (the "License");
Simon Cooksey 0:fb7af294d5d9 5 * you may not use this file except in compliance with the License.
Simon Cooksey 0:fb7af294d5d9 6 * You may obtain a copy of the License at
Simon Cooksey 0:fb7af294d5d9 7 *
Simon Cooksey 0:fb7af294d5d9 8 * http://www.apache.org/licenses/LICENSE-2.0
Simon Cooksey 0:fb7af294d5d9 9 *
Simon Cooksey 0:fb7af294d5d9 10 * Unless required by applicable law or agreed to in writing, software
Simon Cooksey 0:fb7af294d5d9 11 * distributed under the License is distributed on an "AS IS" BASIS,
Simon Cooksey 0:fb7af294d5d9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Simon Cooksey 0:fb7af294d5d9 13 * See the License for the specific language governing permissions and
Simon Cooksey 0:fb7af294d5d9 14 * limitations under the License.
Simon Cooksey 0:fb7af294d5d9 15 */
Simon Cooksey 0:fb7af294d5d9 16
Simon Cooksey 0:fb7af294d5d9 17 #ifndef __UUID_H__
Simon Cooksey 0:fb7af294d5d9 18 #define __UUID_H__
Simon Cooksey 0:fb7af294d5d9 19
Simon Cooksey 0:fb7af294d5d9 20 #include <stdint.h>
Simon Cooksey 0:fb7af294d5d9 21 #include <string.h>
Simon Cooksey 0:fb7af294d5d9 22 #include <algorithm>
Simon Cooksey 0:fb7af294d5d9 23
Simon Cooksey 0:fb7af294d5d9 24 #include "blecommon.h"
Simon Cooksey 0:fb7af294d5d9 25
Simon Cooksey 0:fb7af294d5d9 26 /**
Simon Cooksey 0:fb7af294d5d9 27 * A trivial converter for single hexadecimal character to an unsigned integer.
Simon Cooksey 0:fb7af294d5d9 28 *
Simon Cooksey 0:fb7af294d5d9 29 * @param c
Simon Cooksey 0:fb7af294d5d9 30 * Hexadecimal character.
Simon Cooksey 0:fb7af294d5d9 31 *
Simon Cooksey 0:fb7af294d5d9 32 * @return The corresponding value as unsigned integer.
Simon Cooksey 0:fb7af294d5d9 33 */
Simon Cooksey 0:fb7af294d5d9 34 static uint8_t char2int(char c) {
Simon Cooksey 0:fb7af294d5d9 35 if ((c >= '0') && (c <= '9')) {
Simon Cooksey 0:fb7af294d5d9 36 return c - '0';
Simon Cooksey 0:fb7af294d5d9 37 } else if ((c >= 'a') && (c <= 'f')) {
Simon Cooksey 0:fb7af294d5d9 38 return c - 'a' + 10;
Simon Cooksey 0:fb7af294d5d9 39 } else if ((c >= 'A') && (c <= 'F')) {
Simon Cooksey 0:fb7af294d5d9 40 return c - 'A' + 10;
Simon Cooksey 0:fb7af294d5d9 41 } else {
Simon Cooksey 0:fb7af294d5d9 42 return 0;
Simon Cooksey 0:fb7af294d5d9 43 }
Simon Cooksey 0:fb7af294d5d9 44 }
Simon Cooksey 0:fb7af294d5d9 45
Simon Cooksey 0:fb7af294d5d9 46 /**
Simon Cooksey 0:fb7af294d5d9 47 * An instance of this class represents a Universally Unique Identifier (UUID)
Simon Cooksey 0:fb7af294d5d9 48 * in the BLE API.
Simon Cooksey 0:fb7af294d5d9 49 */
Simon Cooksey 0:fb7af294d5d9 50 class UUID {
Simon Cooksey 0:fb7af294d5d9 51 public:
Simon Cooksey 0:fb7af294d5d9 52 /**
Simon Cooksey 0:fb7af294d5d9 53 * Enumeration of the possible types of UUIDs in BLE with regards to length.
Simon Cooksey 0:fb7af294d5d9 54 */
Simon Cooksey 0:fb7af294d5d9 55 enum UUID_Type_t {
Simon Cooksey 0:fb7af294d5d9 56 UUID_TYPE_SHORT = 0, /**< Short 16-bit UUID. */
Simon Cooksey 0:fb7af294d5d9 57 UUID_TYPE_LONG = 1 /**< Full 128-bit UUID. */
Simon Cooksey 0:fb7af294d5d9 58 };
Simon Cooksey 0:fb7af294d5d9 59
Simon Cooksey 0:fb7af294d5d9 60 /**
Simon Cooksey 0:fb7af294d5d9 61 * Enumeration to specify byte ordering of the long version of the UUID.
Simon Cooksey 0:fb7af294d5d9 62 */
Simon Cooksey 0:fb7af294d5d9 63 typedef enum {
Simon Cooksey 0:fb7af294d5d9 64 MSB, /**< Most-significant byte first (at the smallest address) */
Simon Cooksey 0:fb7af294d5d9 65 LSB /**< least-significant byte first (at the smallest address) */
Simon Cooksey 0:fb7af294d5d9 66 } ByteOrder_t;
Simon Cooksey 0:fb7af294d5d9 67
Simon Cooksey 0:fb7af294d5d9 68 /**
Simon Cooksey 0:fb7af294d5d9 69 * Type for a 16-bit UUID.
Simon Cooksey 0:fb7af294d5d9 70 */
Simon Cooksey 0:fb7af294d5d9 71 typedef uint16_t ShortUUIDBytes_t;
Simon Cooksey 0:fb7af294d5d9 72
Simon Cooksey 0:fb7af294d5d9 73 /**
Simon Cooksey 0:fb7af294d5d9 74 * Length of a long UUID in bytes.
Simon Cooksey 0:fb7af294d5d9 75 */
Simon Cooksey 0:fb7af294d5d9 76 static const unsigned LENGTH_OF_LONG_UUID = 16;
Simon Cooksey 0:fb7af294d5d9 77 /**
Simon Cooksey 0:fb7af294d5d9 78 * Type for a 128-bit UUID.
Simon Cooksey 0:fb7af294d5d9 79 */
Simon Cooksey 0:fb7af294d5d9 80 typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
Simon Cooksey 0:fb7af294d5d9 81
Simon Cooksey 0:fb7af294d5d9 82 /**
Simon Cooksey 0:fb7af294d5d9 83 * Maximum length of a string representation of a UUID not including the
Simon Cooksey 0:fb7af294d5d9 84 * null termination ('\0'): two characters per
Simon Cooksey 0:fb7af294d5d9 85 * byte plus four '-' characters.
Simon Cooksey 0:fb7af294d5d9 86 */
Simon Cooksey 0:fb7af294d5d9 87 static const unsigned MAX_UUID_STRING_LENGTH = LENGTH_OF_LONG_UUID * 2 + 4;
Simon Cooksey 0:fb7af294d5d9 88
Simon Cooksey 0:fb7af294d5d9 89 public:
Simon Cooksey 0:fb7af294d5d9 90
Simon Cooksey 0:fb7af294d5d9 91 /**
Simon Cooksey 0:fb7af294d5d9 92 * Creates a new 128-bit UUID.
Simon Cooksey 0:fb7af294d5d9 93 *
Simon Cooksey 0:fb7af294d5d9 94 * @note The UUID is a unique 128-bit (16 byte) ID used to identify
Simon Cooksey 0:fb7af294d5d9 95 * different service or characteristics on the BLE device.
Simon Cooksey 0:fb7af294d5d9 96 *
Simon Cooksey 0:fb7af294d5d9 97 * @param stringUUID
Simon Cooksey 0:fb7af294d5d9 98 * The 128-bit (16-byte) UUID as a human readable const-string.
Simon Cooksey 0:fb7af294d5d9 99 * Format: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Simon Cooksey 0:fb7af294d5d9 100 * Upper and lower case supported. Hyphens are optional, but only
Simon Cooksey 0:fb7af294d5d9 101 * upto four of them. The UUID is stored internally as a 16 byte
Simon Cooksey 0:fb7af294d5d9 102 * array, LSB (little endian), which is opposite from the string.
Simon Cooksey 0:fb7af294d5d9 103 */
Simon Cooksey 0:fb7af294d5d9 104 UUID(const char* stringUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
Simon Cooksey 0:fb7af294d5d9 105 bool nibble = false;
Simon Cooksey 0:fb7af294d5d9 106 uint8_t byte = 0;
Simon Cooksey 0:fb7af294d5d9 107 size_t baseIndex = 0;
Simon Cooksey 0:fb7af294d5d9 108 uint8_t tempUUID[LENGTH_OF_LONG_UUID];
Simon Cooksey 0:fb7af294d5d9 109
Simon Cooksey 0:fb7af294d5d9 110 /*
Simon Cooksey 0:fb7af294d5d9 111 * Iterate through string, abort if NULL is encountered prematurely.
Simon Cooksey 0:fb7af294d5d9 112 * Ignore upto four hyphens.
Simon Cooksey 0:fb7af294d5d9 113 */
Simon Cooksey 0:fb7af294d5d9 114 for (size_t index = 0; (index < MAX_UUID_STRING_LENGTH) && (baseIndex < LENGTH_OF_LONG_UUID); index++) {
Simon Cooksey 0:fb7af294d5d9 115 if (stringUUID[index] == '\0') {
Simon Cooksey 0:fb7af294d5d9 116 /* Error abort */
Simon Cooksey 0:fb7af294d5d9 117 break;
Simon Cooksey 0:fb7af294d5d9 118 } else if (stringUUID[index] == '-') {
Simon Cooksey 0:fb7af294d5d9 119 /* Ignore hyphen */
Simon Cooksey 0:fb7af294d5d9 120 continue;
Simon Cooksey 0:fb7af294d5d9 121 } else if (nibble) {
Simon Cooksey 0:fb7af294d5d9 122 /* Got second nibble */
Simon Cooksey 0:fb7af294d5d9 123 byte |= char2int(stringUUID[index]);
Simon Cooksey 0:fb7af294d5d9 124 nibble = false;
Simon Cooksey 0:fb7af294d5d9 125
Simon Cooksey 0:fb7af294d5d9 126 /* Store copy */
Simon Cooksey 0:fb7af294d5d9 127 tempUUID[baseIndex++] = byte;
Simon Cooksey 0:fb7af294d5d9 128 } else {
Simon Cooksey 0:fb7af294d5d9 129 /* Got first nibble */
Simon Cooksey 0:fb7af294d5d9 130 byte = char2int(stringUUID[index]) << 4;
Simon Cooksey 0:fb7af294d5d9 131 nibble = true;
Simon Cooksey 0:fb7af294d5d9 132 }
Simon Cooksey 0:fb7af294d5d9 133 }
Simon Cooksey 0:fb7af294d5d9 134
Simon Cooksey 0:fb7af294d5d9 135 /* Populate internal variables if string was successfully parsed */
Simon Cooksey 0:fb7af294d5d9 136 if (baseIndex == LENGTH_OF_LONG_UUID) {
Simon Cooksey 0:fb7af294d5d9 137 setupLong(tempUUID, UUID::MSB);
Simon Cooksey 0:fb7af294d5d9 138 } else {
Simon Cooksey 0:fb7af294d5d9 139 const uint8_t sig[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
Simon Cooksey 0:fb7af294d5d9 140 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
Simon Cooksey 0:fb7af294d5d9 141 setupLong(sig, UUID::MSB);
Simon Cooksey 0:fb7af294d5d9 142 }
Simon Cooksey 0:fb7af294d5d9 143 }
Simon Cooksey 0:fb7af294d5d9 144
Simon Cooksey 0:fb7af294d5d9 145 /**
Simon Cooksey 0:fb7af294d5d9 146 * Creates a new 128-bit UUID.
Simon Cooksey 0:fb7af294d5d9 147 *
Simon Cooksey 0:fb7af294d5d9 148 * @param[in] longUUID
Simon Cooksey 0:fb7af294d5d9 149 * The 128-bit (16-byte) UUID value.
Simon Cooksey 0:fb7af294d5d9 150 * @param[in] order
Simon Cooksey 0:fb7af294d5d9 151 * The bit order of the UUID, MSB by default.
Simon Cooksey 0:fb7af294d5d9 152 *
Simon Cooksey 0:fb7af294d5d9 153 * @note The UUID is a unique 128-bit (16 byte) ID used to identify
Simon Cooksey 0:fb7af294d5d9 154 * different service or characteristics on the BLE device.
Simon Cooksey 0:fb7af294d5d9 155 */
Simon Cooksey 0:fb7af294d5d9 156 UUID(const LongUUIDBytes_t longUUID, ByteOrder_t order = UUID::MSB) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
Simon Cooksey 0:fb7af294d5d9 157 setupLong(longUUID, order);
Simon Cooksey 0:fb7af294d5d9 158 }
Simon Cooksey 0:fb7af294d5d9 159
Simon Cooksey 0:fb7af294d5d9 160 /**
Simon Cooksey 0:fb7af294d5d9 161 * Creates a new 16-bit UUID.
Simon Cooksey 0:fb7af294d5d9 162 *
Simon Cooksey 0:fb7af294d5d9 163 * For efficiency, and because 16 bytes would take a large chunk of the
Simon Cooksey 0:fb7af294d5d9 164 * 27-byte data payload length of the Link Layer, the BLE specification adds
Simon Cooksey 0:fb7af294d5d9 165 * two additional UUID formats: 16-bit and 32-bit UUIDs. These shortened
Simon Cooksey 0:fb7af294d5d9 166 * formats can be used only with UUIDs that are defined in the Bluetooth
Simon Cooksey 0:fb7af294d5d9 167 * specification (listed by the Bluetooth SIG as standard
Simon Cooksey 0:fb7af294d5d9 168 * Bluetooth UUIDs).
Simon Cooksey 0:fb7af294d5d9 169 *
Simon Cooksey 0:fb7af294d5d9 170 * To reconstruct the full 128-bit UUID from the shortened version, insert
Simon Cooksey 0:fb7af294d5d9 171 * the 16-bit short value (indicated by xxxx, including leading zeros) into
Simon Cooksey 0:fb7af294d5d9 172 * the Bluetooth Base UUID:
Simon Cooksey 0:fb7af294d5d9 173 *
Simon Cooksey 0:fb7af294d5d9 174 * 0000xxxx-0000-1000-8000-00805F9B34FB
Simon Cooksey 0:fb7af294d5d9 175 *
Simon Cooksey 0:fb7af294d5d9 176 * @param[in] _shortUUID
Simon Cooksey 0:fb7af294d5d9 177 * The short UUID value.
Simon Cooksey 0:fb7af294d5d9 178 *
Simon Cooksey 0:fb7af294d5d9 179 * @note Shortening is not available for UUIDs that are not derived from the
Simon Cooksey 0:fb7af294d5d9 180 * Bluetooth Base UUID. Such non-standard UUIDs are commonly called
Simon Cooksey 0:fb7af294d5d9 181 * vendor-specific UUIDs. In these cases, you’ll need to use the full
Simon Cooksey 0:fb7af294d5d9 182 * 128-bit UUID value at all times.
Simon Cooksey 0:fb7af294d5d9 183 *
Simon Cooksey 0:fb7af294d5d9 184 * @note The UUID is a unique 16-bit (2 byte) ID used to identify
Simon Cooksey 0:fb7af294d5d9 185 * different service or characteristics on the BLE device.
Simon Cooksey 0:fb7af294d5d9 186 *
Simon Cooksey 0:fb7af294d5d9 187 * @note We do not yet support 32-bit shortened UUIDs.
Simon Cooksey 0:fb7af294d5d9 188 */
Simon Cooksey 0:fb7af294d5d9 189 UUID(ShortUUIDBytes_t _shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(_shortUUID) {
Simon Cooksey 0:fb7af294d5d9 190 /* Empty */
Simon Cooksey 0:fb7af294d5d9 191 }
Simon Cooksey 0:fb7af294d5d9 192
Simon Cooksey 0:fb7af294d5d9 193 /**
Simon Cooksey 0:fb7af294d5d9 194 * Copy constructor.
Simon Cooksey 0:fb7af294d5d9 195 *
Simon Cooksey 0:fb7af294d5d9 196 * @param[in] source
Simon Cooksey 0:fb7af294d5d9 197 * The UUID to copy.
Simon Cooksey 0:fb7af294d5d9 198 */
Simon Cooksey 0:fb7af294d5d9 199 UUID(const UUID &source) {
Simon Cooksey 0:fb7af294d5d9 200 type = source.type;
Simon Cooksey 0:fb7af294d5d9 201 shortUUID = source.shortUUID;
Simon Cooksey 0:fb7af294d5d9 202 memcpy(baseUUID, source.baseUUID, LENGTH_OF_LONG_UUID);
Simon Cooksey 0:fb7af294d5d9 203 }
Simon Cooksey 0:fb7af294d5d9 204
Simon Cooksey 0:fb7af294d5d9 205 /**
Simon Cooksey 0:fb7af294d5d9 206 * The empty constructor.
Simon Cooksey 0:fb7af294d5d9 207 *
Simon Cooksey 0:fb7af294d5d9 208 * @note The type of the resulting UUID instance is UUID_TYPE_SHORT and the
Simon Cooksey 0:fb7af294d5d9 209 * value BLE_UUID_UNKNOWN.
Simon Cooksey 0:fb7af294d5d9 210 */
Simon Cooksey 0:fb7af294d5d9 211 UUID(void) : type(UUID_TYPE_SHORT), shortUUID(BLE_UUID_UNKNOWN) {
Simon Cooksey 0:fb7af294d5d9 212 /* empty */
Simon Cooksey 0:fb7af294d5d9 213 }
Simon Cooksey 0:fb7af294d5d9 214
Simon Cooksey 0:fb7af294d5d9 215 /**
Simon Cooksey 0:fb7af294d5d9 216 * Fill in a 128-bit UUID; this is useful when the UUID is not known at the
Simon Cooksey 0:fb7af294d5d9 217 * time of the object construction.
Simon Cooksey 0:fb7af294d5d9 218 *
Simon Cooksey 0:fb7af294d5d9 219 * @param[in] longUUID
Simon Cooksey 0:fb7af294d5d9 220 * The UUID value to copy.
Simon Cooksey 0:fb7af294d5d9 221 * @param[in] order
Simon Cooksey 0:fb7af294d5d9 222 * The byte ordering of the UUID at @p longUUID.
Simon Cooksey 0:fb7af294d5d9 223 */
Simon Cooksey 0:fb7af294d5d9 224 void setupLong(const LongUUIDBytes_t longUUID, ByteOrder_t order = UUID::MSB) {
Simon Cooksey 0:fb7af294d5d9 225 type = UUID_TYPE_LONG;
Simon Cooksey 0:fb7af294d5d9 226 if (order == UUID::MSB) {
Simon Cooksey 0:fb7af294d5d9 227 /*
Simon Cooksey 0:fb7af294d5d9 228 * Switch endian. Input is big-endian, internal representation
Simon Cooksey 0:fb7af294d5d9 229 * is little endian.
Simon Cooksey 0:fb7af294d5d9 230 */
Simon Cooksey 0:fb7af294d5d9 231 std::reverse_copy(longUUID, longUUID + LENGTH_OF_LONG_UUID, baseUUID);
Simon Cooksey 0:fb7af294d5d9 232 } else {
Simon Cooksey 0:fb7af294d5d9 233 std::copy(longUUID, longUUID + LENGTH_OF_LONG_UUID, baseUUID);
Simon Cooksey 0:fb7af294d5d9 234 }
Simon Cooksey 0:fb7af294d5d9 235 shortUUID = (uint16_t)((baseUUID[13] << 8) | (baseUUID[12]));
Simon Cooksey 0:fb7af294d5d9 236 }
Simon Cooksey 0:fb7af294d5d9 237
Simon Cooksey 0:fb7af294d5d9 238 public:
Simon Cooksey 0:fb7af294d5d9 239 /**
Simon Cooksey 0:fb7af294d5d9 240 * Check whether this UUID is short or long.
Simon Cooksey 0:fb7af294d5d9 241 *
Simon Cooksey 0:fb7af294d5d9 242 * @return UUID_TYPE_SHORT if the UUID is short, UUID_TYPE_LONG otherwise.
Simon Cooksey 0:fb7af294d5d9 243 */
Simon Cooksey 0:fb7af294d5d9 244 UUID_Type_t shortOrLong(void) const {
Simon Cooksey 0:fb7af294d5d9 245 return type;
Simon Cooksey 0:fb7af294d5d9 246 }
Simon Cooksey 0:fb7af294d5d9 247
Simon Cooksey 0:fb7af294d5d9 248 /**
Simon Cooksey 0:fb7af294d5d9 249 * Get a pointer to the UUID value based on the current UUID type.
Simon Cooksey 0:fb7af294d5d9 250 *
Simon Cooksey 0:fb7af294d5d9 251 * @return A pointer to the short UUID if the type is set to
Simon Cooksey 0:fb7af294d5d9 252 * UUID_TYPE_SHORT. Otherwise, a pointer to the long UUID if the
Simon Cooksey 0:fb7af294d5d9 253 * type is set to UUID_TYPE_LONG.
Simon Cooksey 0:fb7af294d5d9 254 */
Simon Cooksey 0:fb7af294d5d9 255 const uint8_t *getBaseUUID(void) const {
Simon Cooksey 0:fb7af294d5d9 256 if (type == UUID_TYPE_SHORT) {
Simon Cooksey 0:fb7af294d5d9 257 return (const uint8_t*)&shortUUID;
Simon Cooksey 0:fb7af294d5d9 258 } else {
Simon Cooksey 0:fb7af294d5d9 259 return baseUUID;
Simon Cooksey 0:fb7af294d5d9 260 }
Simon Cooksey 0:fb7af294d5d9 261 }
Simon Cooksey 0:fb7af294d5d9 262
Simon Cooksey 0:fb7af294d5d9 263 /**
Simon Cooksey 0:fb7af294d5d9 264 * Get the short UUID.
Simon Cooksey 0:fb7af294d5d9 265 *
Simon Cooksey 0:fb7af294d5d9 266 * @return The short UUID.
Simon Cooksey 0:fb7af294d5d9 267 */
Simon Cooksey 0:fb7af294d5d9 268 ShortUUIDBytes_t getShortUUID(void) const {
Simon Cooksey 0:fb7af294d5d9 269 return shortUUID;
Simon Cooksey 0:fb7af294d5d9 270 }
Simon Cooksey 0:fb7af294d5d9 271
Simon Cooksey 0:fb7af294d5d9 272 /**
Simon Cooksey 0:fb7af294d5d9 273 * Get the length (in bytes) of the UUID based on its type.
Simon Cooksey 0:fb7af294d5d9 274 *
Simon Cooksey 0:fb7af294d5d9 275 * @retval sizeof(ShortUUIDBytes_t) if the UUID type is UUID_TYPE_SHORT.
Simon Cooksey 0:fb7af294d5d9 276 * @retval LENGTH_OF_LONG_UUID if the UUID type is UUID_TYPE_LONG.
Simon Cooksey 0:fb7af294d5d9 277 */
Simon Cooksey 0:fb7af294d5d9 278 uint8_t getLen(void) const {
Simon Cooksey 0:fb7af294d5d9 279 return ((type == UUID_TYPE_SHORT) ? sizeof(ShortUUIDBytes_t) : LENGTH_OF_LONG_UUID);
Simon Cooksey 0:fb7af294d5d9 280 }
Simon Cooksey 0:fb7af294d5d9 281
Simon Cooksey 0:fb7af294d5d9 282 /**
Simon Cooksey 0:fb7af294d5d9 283 * Overload == operator to enable UUID comparisons.
Simon Cooksey 0:fb7af294d5d9 284 *
Simon Cooksey 0:fb7af294d5d9 285 * @param[in] other
Simon Cooksey 0:fb7af294d5d9 286 * The other UUID in the comparison.
Simon Cooksey 0:fb7af294d5d9 287 *
Simon Cooksey 0:fb7af294d5d9 288 * @return true if this == @p other, false otherwise.
Simon Cooksey 0:fb7af294d5d9 289 */
Simon Cooksey 0:fb7af294d5d9 290 bool operator== (const UUID &other) const {
Simon Cooksey 0:fb7af294d5d9 291 if ((this->type == UUID_TYPE_SHORT) && (other.type == UUID_TYPE_SHORT) &&
Simon Cooksey 0:fb7af294d5d9 292 (this->shortUUID == other.shortUUID)) {
Simon Cooksey 0:fb7af294d5d9 293 return true;
Simon Cooksey 0:fb7af294d5d9 294 }
Simon Cooksey 0:fb7af294d5d9 295
Simon Cooksey 0:fb7af294d5d9 296 if ((this->type == UUID_TYPE_LONG) && (other.type == UUID_TYPE_LONG) &&
Simon Cooksey 0:fb7af294d5d9 297 (memcmp(this->baseUUID, other.baseUUID, LENGTH_OF_LONG_UUID) == 0)) {
Simon Cooksey 0:fb7af294d5d9 298 return true;
Simon Cooksey 0:fb7af294d5d9 299 }
Simon Cooksey 0:fb7af294d5d9 300
Simon Cooksey 0:fb7af294d5d9 301 return false;
Simon Cooksey 0:fb7af294d5d9 302 }
Simon Cooksey 0:fb7af294d5d9 303
Simon Cooksey 0:fb7af294d5d9 304 /**
Simon Cooksey 0:fb7af294d5d9 305 * Overload != operator to enable UUID comparisons.
Simon Cooksey 0:fb7af294d5d9 306 *
Simon Cooksey 0:fb7af294d5d9 307 * @param[in] other
Simon Cooksey 0:fb7af294d5d9 308 * The other UUID in the comparison.
Simon Cooksey 0:fb7af294d5d9 309 *
Simon Cooksey 0:fb7af294d5d9 310 * @return true if this != @p other, false otherwise.
Simon Cooksey 0:fb7af294d5d9 311 */
Simon Cooksey 0:fb7af294d5d9 312 bool operator!= (const UUID &other) const {
Simon Cooksey 0:fb7af294d5d9 313 return !(*this == other);
Simon Cooksey 0:fb7af294d5d9 314 }
Simon Cooksey 0:fb7af294d5d9 315
Simon Cooksey 0:fb7af294d5d9 316 private:
Simon Cooksey 0:fb7af294d5d9 317 /**
Simon Cooksey 0:fb7af294d5d9 318 * The UUID type. Refer to UUID_Type_t.
Simon Cooksey 0:fb7af294d5d9 319 */
Simon Cooksey 0:fb7af294d5d9 320 UUID_Type_t type;
Simon Cooksey 0:fb7af294d5d9 321 /**
Simon Cooksey 0:fb7af294d5d9 322 * The long UUID value.
Simon Cooksey 0:fb7af294d5d9 323 */
Simon Cooksey 0:fb7af294d5d9 324 LongUUIDBytes_t baseUUID;
Simon Cooksey 0:fb7af294d5d9 325 /**
Simon Cooksey 0:fb7af294d5d9 326 * The short UUID value.
Simon Cooksey 0:fb7af294d5d9 327 */
Simon Cooksey 0:fb7af294d5d9 328 ShortUUIDBytes_t shortUUID;
Simon Cooksey 0:fb7af294d5d9 329 };
Simon Cooksey 0:fb7af294d5d9 330
Simon Cooksey 0:fb7af294d5d9 331 #endif // ifndef __UUID_H__