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 #ifndef HFP_HF_COMMAND_PARSER_H 16 #define HFP_HF_COMMAND_PARSER_H 17 18 #include <cstdint> 19 #include <string> 20 #include <unordered_map> 21 22 #include "base_def.h" 23 #include "hfp_hf_command_processor.h" 24 #include "hfp_hf_data_connection.h" 25 26 namespace OHOS { 27 namespace bluetooth { 28 /** 29 * @brief Class for parse AT command from remote AG device. 30 */ 31 class HfpHfCommandParser { 32 public: 33 /** 34 * @brief Get the HfpHfCommandParser instance. 35 * 36 * @return Returns HfpHfCommandParser instance. 37 */ 38 static HfpHfCommandParser &GetInstance(); 39 40 /** 41 * @brief Read data from data link. 42 * 43 * @param dataConn Data connection. 44 * @param commandProcessor Command processor pointer. 45 */ 46 void Read(HfpHfDataConnection &dataConn, HfpHfCommandProcessor &commandProcessor); 47 48 /** 49 * @brief Parse data bufffer. 50 * 51 * @param dataConn Data connection. 52 * @param commandProcessor Command processor pointer. 53 * @param data Data buffer pointer. 54 * @param len Data buffer length. 55 */ 56 void Parse(HfpHfDataConnection &dataConn, HfpHfCommandProcessor &commandProcessor, 57 std::vector<uint8_t> &data, size_t len); 58 59 private: 60 inline static constexpr int AT_HEAD_SIZE = 2; 61 void ParseBody(HfpHfDataConnection &dataConn, 62 HfpHfCommandProcessor &commandProcessor, std::vector<uint8_t> &data, size_t &pos, const size_t len); 63 HfpHfCommandParser() = default; 64 ~HfpHfCommandParser() = default; 65 BT_DISALLOW_COPY_AND_ASSIGN(HfpHfCommandParser); 66 67 std::unordered_map<std::string, HfpHfCommandProcessor::HfpHfAtHandler> &g_atCmdMap { 68 HfpHfCommandProcessor::GetAtCmdMap() 69 }; 70 }; 71 } // namespace bluetooth 72 } // namespace OHOS 73 #endif // HFP_HF_COMMAND_PARSER_H