1 /* 2 * Copyright (c) 2021-2022 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 #ifndef UUID_H 17 #define UUID_H 18 19 #include <array> 20 #include <cstdint> 21 #include <cstring> 22 #include <string> 23 24 /** 25 * @brief The OHOS subsystem. 26 */ 27 namespace OHOS { 28 namespace MMI { 29 /** 30 * @brief This class provides service uuid. 31 * 32 * @since 1.0 33 * @version 1.0 34 */ 35 class Uuid { 36 public: 37 static constexpr int32_t UUID128_BYTES_TYPE = 16; 38 static constexpr int32_t UUID32_BYTES_TYPE = 4; 39 static constexpr int32_t UUID16_BYTES_TYPE = 2; 40 using UUID128Bit = std::array<uint8_t, UUID128_BYTES_TYPE>; 41 /** 42 * @brief A constructor used to create an <b>UUID</b> instance. 43 * 44 * @since 1.0 45 * @version 1.0 46 */ 47 Uuid(); 48 49 /** 50 * @brief A constructor used to create an <b>UUID</b> instance. 51 * 52 * @param other Other uuid to create an <b>UUID</b> instance. 53 * @since 1.0 54 * @version 1.0 55 */ 56 Uuid(const Uuid& other) = default; 57 58 /** 59 * @brief The assignment constructor. 60 * 61 * @param other Other uuid object. 62 * @return Returns the reference of Uuid. 63 * @since 1.0 64 * @version 1.0 65 */ 66 Uuid& operator=(const Uuid& other) = default; 67 68 /** 69 * @brief A destructor used to delete the <b>UUID</b> instance. 70 * 71 * @since 1.0 72 * @version 1.0 73 */ 74 ~Uuid() = default; 75 76 /** 77 * @brief Convert uuid to uint8_t* with little endian. 78 * 79 * @param[in] value : The 128 bits value for a uuid. 80 * @return Returns <b>true</b> if the operation is successful; 81 * returns <b>false</b> if the operation fails. 82 * @since 1.0 83 * @version 1.0 84 */ 85 void ConvertToStdString(std::string& s) const; 86 87 protected: 88 /** 89 * @brief Constructor. 90 */ Uuid(const UUID128Bit uuid)91 Uuid(const UUID128Bit uuid) : uuid_(uuid) {}; 92 93 // base uuid value 94 std::array<uint8_t, UUID128_BYTES_TYPE> BASE_UUID = { 95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 96 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB 97 }; 98 99 std::array<uint8_t, UUID128_BYTES_TYPE> uuid_ = BASE_UUID; 100 }; 101 } // namespace MMI 102 } // namespace OHOS 103 #endif // UUID_H