1 // 2 // Copyright 2017 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 <stddef.h> // for size_t 20 #include <stdint.h> // for uint8_t 21 22 #include <memory> // for shared_ptr 23 24 #include "h4_parser.h" // for ClientDisconnectCallback, H4Parser 25 #include "net/async_data_channel.h" // for AsyncDataChannel 26 27 namespace rootcanal { 28 29 using android::net::AsyncDataChannel; 30 31 // A socket based H4DataChannelPacketizer. Call OnDataReady whenever 32 // data can be read from the socket. 33 class H4DataChannelPacketizer { 34 public: 35 H4DataChannelPacketizer(std::shared_ptr<AsyncDataChannel> socket, PacketReadCallback command_cb, 36 PacketReadCallback event_cb, PacketReadCallback acl_cb, 37 PacketReadCallback sco_cb, PacketReadCallback iso_cb, 38 ClientDisconnectCallback disconnect_cb); 39 40 size_t Send(uint8_t type, const uint8_t* data, size_t length); 41 42 void OnDataReady(std::shared_ptr<AsyncDataChannel> socket); 43 44 private: 45 std::shared_ptr<AsyncDataChannel> uart_socket_; 46 H4Parser h4_parser_; 47 48 ClientDisconnectCallback disconnect_cb_; 49 bool disconnected_{false}; 50 }; 51 52 } // namespace rootcanal 53