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, 36 PacketReadCallback command_cb, 37 PacketReadCallback event_cb, 38 PacketReadCallback acl_cb, PacketReadCallback sco_cb, 39 PacketReadCallback iso_cb, 40 ClientDisconnectCallback disconnect_cb); 41 42 size_t Send(uint8_t type, const uint8_t* data, size_t length); 43 44 void OnDataReady(std::shared_ptr<AsyncDataChannel> socket); 45 46 private: 47 std::shared_ptr<AsyncDataChannel> uart_socket_; 48 H4Parser h4_parser_; 49 50 ClientDisconnectCallback disconnect_cb_; 51 bool disconnected_{false}; 52 }; 53 54 } // namespace rootcanal 55