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(std::shared_ptr<AsyncDataChannel> socket) { 35 return std::make_shared<HciSocketTransport>(socket); 36 } 37 38 void Send(PacketType packet_type, const std::vector<uint8_t>& packet) override; 39 40 void RegisterCallbacks(PacketCallback packet_callback, CloseCallback close_callback) override; 41 42 void Tick() override; 43 void Close() override; 44 45 private: 46 std::shared_ptr<AsyncDataChannel> socket_; 47 H4DataChannelPacketizer h4_{socket_, 48 [](const std::vector<uint8_t>&) {}, 49 [](const std::vector<uint8_t>&) {}, 50 [](const std::vector<uint8_t>&) {}, 51 [](const std::vector<uint8_t>&) {}, 52 [](const std::vector<uint8_t>&) {}, 53 [] {}}; 54 }; 55 56 } // namespace rootcanal 57