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 CLASSIC_UTILS_H
17 #define CLASSIC_UTILS_H
18 
19 #include <vector>
20 #include <string>
21 
22 #include "bt_uuid.h"
23 #include "log.h"
24 
25 /*
26  * @brief The bluetooth system.
27  */
28 namespace OHOS {
29 namespace bluetooth {
30 /**
31  * @brief Classic Utils.
32  */
33 class ClassicUtils {
34 public:
35     /**
36      * @brief Convert int to hex string
37      *
38      * @param  value: std::vector<uint8_t>
39      * @return Returns string.
40      */
41     static std::string ConvertIntToHexString(const std::vector<uint8_t> &value);
42 
43     /**
44      * @brief Convert hex string to int
45      *
46      * @param  str: string
47      * @return Returns std::vector<uint8_t> value.
48      */
49     static void ConvertHexStringToInt(const std::string &str, std::vector<uint8_t> &value);
50 
51     /**
52      * @brief Convert Uuid list to string
53      *
54      * @param  uuids: the Uuid list
55      * @return Returns string value.
56      */
57     static std::string ConvertUuidToString(const std::vector<Uuid> &uuids);
58 
59     /**
60      * @brief Convert string to Uuid list
61      *
62      * @param  value: string
63      * @return Returns std::vector<Uuid> value.
64      */
65     static std::vector<Uuid> ConvertStringToUuid(const std::string &value);
66 
67     /**
68      * @brief Check the return value.
69      *        If the ret is false, output the error log.
70      *
71      * @param  fileName: file name
72      * @param  funcName: function name
73      * @param  ret: the return value need to check
74      */
CheckReturnValue(const std::string & fileName,const std::string & funcName,bool ret)75     static inline void CheckReturnValue(const std::string &fileName, const std::string &funcName, bool ret)
76     {
77         if (!ret) {
78             LOG_ERROR("[%{public}s]:%{public}s(), ret[%{public}d]", fileName.c_str(), funcName.c_str(), ret);
79         }
80     }
81 private:
82     /**
83      * @brief Convert int to hex string
84      *
85      * @param  value: uint8_t
86      * @return Returns hex string.
87      */
88     static std::string IntToHexString(uint8_t value);
89 };
90 }  // namespace bluetooth
91 }  // namespace OHOS
92 #endif // CLASSIC_UTILS_H