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