2 // Copyright 2015 The Android Open Source Project
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include "command_packet.h"
24 #include "event_packet.h"
27 namespace test_vendor_lib {
29 // Provides abstractions for IO with Packet objects. Used to receive commands
30 // and data from the HCI and to send controller events back to the host.
33 PacketStream() = default;
35 virtual ~PacketStream() = default;
37 // Reads a command packet from the file descriptor at |fd| and returns the
38 // packet back to the caller, along with the responsibility of managing the
40 std::unique_ptr<CommandPacket> ReceiveCommand(int fd) const;
42 // Reads a single octet from |fd| and interprets it as a packet type octet.
43 // Validates the type octet for correctness.
44 serial_data_type_t ReceivePacketType(int fd) const;
46 // Sends an event to file descriptor |fd|. The ownership of the event is left
48 bool SendEvent(std::unique_ptr<EventPacket> event, int fd) const;
51 // Checks if |type| is in the valid range from DATA_TYPE_COMMAND to
53 bool ValidateTypeOctet(serial_data_type_t type) const;
55 // Attempts to receive |num_octets_to_receive| into |destination| from |fd|,
56 // returning false if an error occurs.
57 bool ReceiveAll(std::vector<uint8_t>& destination,
58 size_t num_octets_to_receive, int fd) const;
60 // Attempts to send |num_octets_to_send| from |source| to |fd|, returning
61 // false if an error occurs.
62 bool SendAll(const std::vector<uint8_t>& source, size_t num_octets_to_send,
66 } // namespace test_vendor_lib