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 #ifndef RAW_ADDRESS_H 17 #define RAW_ADDRESS_H 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <string> 22 #include "iosfwd" 23 24 namespace OHOS { 25 namespace bluetooth { 26 class RawAddress { 27 public: 28 // address length 29 const static int BT_ADDRESS_STR_LEN = 17; 30 const static int BT_ADDRESS_BYTE_LEN = 6; 31 const static int BT_COLON_BYTE_SIZE = 1; 32 33 const static int BT_LAP_HIGH_BYTE = 5; 34 const static int BT_LAP_MIDDLE_BYTE = 4; 35 const static int BT_LAP_LOW_BYTE = 3; 36 const static int BT_UAP_BYTE = 2; 37 const static int BT_NAP_HIGH_BYTE = 1; 38 const static int BT_NAP_LOW_BYTE = 0; 39 40 /** 41 * @brief A constructor used to create an <b>RawAddress</b> instance. 42 * 43 * @since 6 44 */ 45 RawAddress() = default; 46 47 /** 48 * @brief A constructor used to create an <b>RawAddress</b> instance. 49 * 50 * @param other Other RawAddress instance. 51 * @since 6 52 */ 53 RawAddress(const RawAddress &other) = default; 54 55 /** 56 * @brief A constructor used to create an <b>RawAddress</b> instance. 57 * 58 * @param address Address string. 59 * @since 6 60 */ RawAddress(const std::string & address)61 explicit RawAddress(const std::string &address) : address_(address) {}; 62 63 /** 64 * @brief A destructor used to delete the <b>RawAddress</b> instance. 65 * 66 * @since 6 67 */ 68 ~RawAddress() = default; 69 70 /** 71 * @brief Get RawAddress address string. 72 * 73 * @return Returns address string. 74 * @since 6 75 */ GetAddress()76 const std::string &GetAddress() const 77 { 78 return address_; 79 }; 80 81 /** 82 * @brief Set RawAddress address string. 83 * 84 * @since 6 85 */ SetAddress(const std::string & address)86 void SetAddress(const std::string &address) 87 { 88 address_ = address; 89 }; 90 91 /** 92 * @brief Convert RawAddress to uint8_t pointer. 93 * 94 * @param dst Out parameter uint8_t pointer. 95 * @since 6 96 */ 97 void ConvertToUint8(uint8_t *dst, const size_t size = BT_ADDRESS_BYTE_LEN) const; 98 99 /** 100 * @brief Convert RawAddress to uint8_t pointer. 101 * 102 * @param src Out parameter uint8_t pointer. 103 * @return Returns address string. 104 * @since 6 105 */ 106 static RawAddress ConvertToString(const uint8_t *src, const size_t size = BT_ADDRESS_BYTE_LEN); 107 108 /** 109 * @brief Compare two RawAddress values. 110 * 111 * @param rhs Compared RawAddress instance. 112 * @return Returns <b>true</b> if this RawAddress is smaller than compared RawAddress; 113 * returns <b>false</b> if this RawAddress is not smaller than compared RawAddress. 114 * @since 6 115 */ 116 bool operator<(const RawAddress &rhs) const; 117 118 /** 119 * @brief Compare two RawAddress whether are same or not. 120 * 121 * @param rhs Compared RawAddress instance. 122 * @return Returns <b>true</b> if this RawAddress is same as compared RawAddress; 123 * returns <b>false</b> if this RawAddress is not same as compared RawAddress. 124 * @since 6 125 */ 126 bool operator==(const RawAddress &rhs) const; 127 128 protected: 129 std::string address_ = ""; 130 }; 131 } // namespace bluetooth 132 } // namespace OHOS 133 #endif // RAW_ADDRESS_H