1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <memory> // for shared_ptr, make_... 20 21 #include "model/hci/h4_data_channel_packetizer.h" // for H4DataChannelP... 22 #include "model/hci/hci_transport.h" // for HciTransport 23 #include "net/async_data_channel.h" // for AsyncDataChannel 24 25 namespace rootcanal { 26 27 using android::net::AsyncDataChannel; 28 29 class HciSocketTransport : public HciTransport { 30 public: 31 HciSocketTransport(std::shared_ptr<AsyncDataChannel> socket); 32 ~HciSocketTransport() = default; 33 Create(std::shared_ptr<AsyncDataChannel> socket)34 static std::shared_ptr<HciTransport> Create( 35 std::shared_ptr<AsyncDataChannel> socket) { 36 return std::make_shared<HciSocketTransport>(socket); 37 } 38 39 void Send(PacketType packet_type, 40 const std::vector<uint8_t>& packet) override; 41 42 void RegisterCallbacks(PacketCallback packet_callback, 43 CloseCallback close_callback) override; 44 45 void Tick() override; 46 void Close() override; 47 48 private: 49 std::shared_ptr<AsyncDataChannel> socket_; 50 H4DataChannelPacketizer h4_{socket_, 51 [](const std::vector<uint8_t>&) {}, 52 [](const std::vector<uint8_t>&) {}, 53 [](const std::vector<uint8_t>&) {}, 54 [](const std::vector<uint8_t>&) {}, 55 [](const std::vector<uint8_t>&) {}, 56 [] {}}; 57 }; 58 59 } // namespace rootcanal 60