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