• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "net/async_data_channel.h"
23 
24 namespace rootcanal {
25 
26 using PacketReadCallback = std::function<void(const std::vector<uint8_t>&)>;
27 using android::net::AsyncDataChannel;
28 
29 // Implementation of HCI protocol bits common to different transports
30 class HciProtocol {
31  public:
32   HciProtocol() = default;
~HciProtocol()33   virtual ~HciProtocol(){};
34 
35   // Protocol-specific implementation of sending packets.
36   virtual size_t Send(uint8_t type, const uint8_t* data, size_t length) = 0;
37 
38  protected:
39   static size_t WriteSafely(AsyncDataChannel* socket, const uint8_t* data,
40                             size_t length);
41 };
42 
43 }  // namespace rootcanal
44