Myles Watson | 761dc49 | 2017-03-03 13:50:49 -0800 | [diff] [blame] | 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 <hidl/HidlSupport.h> |
| 20 | |
| 21 | #include "hci_internals.h" |
| 22 | #include "hci_packetizer.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace bluetooth { |
| 27 | namespace hci { |
| 28 | |
| 29 | using ::android::hardware::hidl_vec; |
| 30 | using PacketReadCallback = std::function<void(const hidl_vec<uint8_t>&)>; |
| 31 | |
| 32 | // Implementation of HCI protocol bits common to different transports |
| 33 | class HciProtocol { |
| 34 | public: |
| 35 | HciProtocol() = default; |
| 36 | virtual ~HciProtocol(){}; |
| 37 | |
| 38 | // Protocol-specific implementation of sending packets. |
| 39 | virtual size_t Send(uint8_t type, const uint8_t* data, size_t length) = 0; |
| 40 | |
| 41 | protected: |
| 42 | static size_t WriteSafely(int fd, const uint8_t* data, size_t length); |
| 43 | }; |
| 44 | |
| 45 | } // namespace hci |
| 46 | } // namespace bluetooth |
| 47 | } // namespace hardware |
| 48 | } // namespace android |