1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Defines uuid for framework. 21 * 22 * @since 6 23 */ 24 25 /** 26 * @file uuid.h 27 * 28 * @brief framework uuid interface. 29 * 30 * @since 6 31 */ 32 33 #ifndef DUMMY_UUID_H 34 #define DUMMY_UUID_H 35 36 #include "sys/time.h" 37 #include <string> 38 #include <array> 39 #include <ctime> 40 #include <regex> 41 42 namespace OHOS { 43 namespace Bluetooth { 44 45 /** 46 * @brief This class provides framework uuid. 47 * 48 * @since 6 49 */ 50 class UUID { 51 public: 52 //128 bits uuid length 53 const static int UUID128_BYTES_LEN = 16; 54 55 /** 56 * @brief A constructor used to create an <b>UUID</b> instance. 57 * 58 * @since 6 59 */ UUID()60 UUID(){}; 61 62 /** 63 * @brief A destructor used to delete the <b>UUID</b> instance. 64 * 65 * @since 6 66 */ ~UUID()67 ~UUID(){}; 68 69 /** 70 * @brief A constructor used to create an <b>UUID</b> instance. Constructor a new UUID using most significant 64 71 * bits and least significant 64 bits. 72 * 73 * @param[in] mostSigBits : The most significant 64 bits of UUID. 74 * @param[in] leastSigBits : The least significant 64 bits of UUID. 75 * @since 6 76 */ 77 UUID(const long mostSigBits, const long leastSigBits); 78 79 /** 80 * @brief A constructor used to create an <b>UUID</b> instance. Constructor a new UUID from string. 81 * 82 * @param[in] name : The value of string to create UUID. 83 * for example : "00000000-0000-1000-8000-00805F9B34FB" 84 * @return Returns a specified UUID. 85 * @since 6 86 */ 87 static UUID FromString(const std::string &name); 88 89 /** 90 * @brief A constructor used to create an <b>UUID</b> instance. Constructor a new random UUID. 91 * 92 * @return Returns a random UUID. 93 * @since 6 94 */ 95 static UUID RandomUUID(); 96 97 /** 98 * @brief Convert UUID to string. 99 * 100 * @return Returns a String object representing this UUID. 101 * @since 6 102 */ 103 std::string ToString() const; 104 105 /** 106 * @brief Compares this UUID with the specified UUID. 107 * 108 * @param[in] val : UUID which this UUID is to be compared. 109 * @return Returns <b> <0 </b> if this UUID is less than compared UUID; 110 * returns <b> =0 </b> if this UUID is equal to compared UUID; 111 * returns <b> >0 </b> if this UUID is greater than compared UUID. 112 * @since 6 113 */ 114 int CompareTo(const UUID &val) const; 115 116 /** 117 * @brief Compares this object to the specified object. 118 * 119 * @param[in] val : UUID which this UUID is to be compared. 120 * @return Returns <b>true</b> if this UUID is the same as compared UUID; 121 * returns <b>false</b> if this UUID is not the same as compared UUID. 122 * @since 6 123 */ 124 bool Equals(const UUID &val) const; 125 126 /** 127 * @brief Returns the least significant 64 bits of this UUID's 128 bit value. 128 * 129 * @return Retruns the least significant 64 bits of this UUID's 128 bit value. 130 * @since 6 131 */ 132 uint64_t GetLeastSignificantBits() const; 133 134 /** 135 * @brief Returns the most significant 64 bits of this UUID's 128 bit value. 136 * 137 * @return Returns the most significant 64 bits of this UUID's 128 bit value. 138 * @since 6 139 */ 140 uint64_t GetMostSignificantBits() const; 141 142 /** 143 * @brief Constructor a new UUID from uint8_t array. 144 * 145 * @param[in] name : The 128 bits value for a UUID. 146 * @return Returns a specified UUID. 147 * @since 6 148 */ 149 static UUID ConvertFrom128Bits(const std::array<uint8_t, UUID128_BYTES_LEN> &name); 150 151 /** 152 * @brief Returns uint8_t array from UUID. 153 * 154 * @return returns a specified array. 155 * @since 6 156 */ 157 std::array<uint8_t, UUID128_BYTES_LEN> ConvertTo128Bits() const; 158 159 /** 160 * @brief Compare two UUID whether are same or not. 161 * 162 * @param rhs Compared UUID instance. 163 * @return Returns <b>true</b> if this UUID is the same as compared UUID; 164 * returns <b>false</b> if this UUID is not the same as compared UUID. 165 */ 166 bool operator==(const UUID &rhs) const; 167 168 /** 169 * @brief In order to use the object key in the map object, overload the operator <. 170 * @param[in] uuid : UUID object. 171 * @return @c bool : If the object uuid is the same, return true, otherwise return false. 172 */ 173 bool operator<(const UUID &uuid) const; 174 175 private: 176 std::array<uint8_t, UUID128_BYTES_LEN> uuid_ = {0x00}; 177 }; 178 179 /** 180 * @brief This class provides framework ParcelUuid. 181 * 182 * @since 6 183 */ 184 using ParcelUuid = UUID; 185 186 bool IsValidUuid(std::string uuid); 187 188 } // namespace Bluetooth 189 } // namespace OHOS 190 191 #endif //DUMMY_UUID_H