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 <functional>
20 #include <vector>
21 
22 #include "h4_parser.h"
23 
24 namespace rootcanal {
25 
26 // A socket based H4Packetizer. Call OnDataReady whenever
27 // data can be read from file descriptor fd.
28 //
29 // This is only supported on unix.
30 class H4Packetizer {
31  public:
32   H4Packetizer(int fd, PacketReadCallback command_cb,
33                PacketReadCallback event_cb, PacketReadCallback acl_cb,
34                PacketReadCallback sco_cb, PacketReadCallback iso_cb,
35                ClientDisconnectCallback disconnect_cb);
36 
37   size_t Send(uint8_t type, const uint8_t* data, size_t length);
38 
39   void OnDataReady(int fd);
40 
41  private:
42   int uart_fd_;
43   H4Parser h4_parser_;
44 
45   ClientDisconnectCallback disconnect_cb_;
46   bool disconnected_{false};
47 };
48 
49 }  // namespace rootcanal
50