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 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Defines operate bluetooth data functions. 21 * 22 */ 23 24 /** 25 * @file bluetooth_data.h 26 * 27 * @brief Bluetooth data class. 28 * 29 */ 30 31 #ifndef CLASSIC_BLUETOOTH_DATA_H 32 #define CLASSIC_BLUETOOTH_DATA_H 33 34 #include <cstdlib> 35 #include <vector> 36 #include "base_def.h" 37 #include "classic_data_structure.h" 38 39 namespace OHOS { 40 namespace bluetooth { 41 static constexpr int BLUETOOTH_DATA_MAX_LENGTH = 240; 42 43 /** 44 * @brief Represents bluetooth data. 45 * 46 */ 47 class ClassicBluetoothData { 48 public: 49 /** 50 * @brief A constructor used to create a <b>ClassicBluetoothData</b> instance. 51 * 52 */ 53 ClassicBluetoothData(); 54 55 /** 56 * @brief A destructor used to delete the <b>ClassicBluetoothData</b> instance. 57 * 58 */ 59 ~ClassicBluetoothData(); 60 61 /** 62 * @brief Get bluetooth data. 63 * 64 * @return Returns bluetooth data. 65 */ 66 std::vector<uint8_t> GetClassicBluetoothData() const; 67 68 /** 69 * @brief Set bluetooth data max length. 70 * 71 * @param len Data length. 72 */ 73 void SetDataMaxLength(int len); 74 75 /** 76 * @brief Add bluetooth data structure. 77 * 78 * @param dataStruct Data structure. 79 * @return Returns <b>true</b> if the operation is successful; 80 * returns <b>false</b> if the operation fails. 81 */ 82 bool AddDataStructure(ClassicDataStructure dataStruct); 83 84 /** 85 * @brief Parser bluetooth data. 86 * 87 * @param data Bluetooth data. 88 * @return Returns the parsed data structure list. 89 */ 90 std::vector<ClassicDataStructure> ParserData(const std::vector<uint8_t> &data) const; 91 92 private: 93 std::vector<ClassicDataStructure> dataStructList_ {}; 94 int offset_ {}; 95 int maxLength_ {}; 96 97 BT_DISALLOW_COPY_AND_ASSIGN(ClassicBluetoothData); 98 }; 99 } // namespace bluetooth 100 } // namespace OHOS 101 #endif /// CLASSIC_BLUETOOTH_DATA_H