/* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include "common/blocking_queue.h" #include "hal/hci_hal.h" #include "hci/hci_packets.h" #include "packet/packet_view.h" namespace bluetooth { namespace hal { class TestHciHal : public hal::HciHal { public: TestHciHal() : hal::HciHal() {} ~TestHciHal() { if (callbacks != nullptr) { log::fatal("unregisterIncomingPacketCallback() must be called"); } } void registerIncomingPacketCallback(hal::HciHalCallbacks* callback) override { callbacks = callback; } void unregisterIncomingPacketCallback() override { callbacks = nullptr; } void sendHciCommand(hal::HciPacket command) override; void sendAclData(hal::HciPacket data) override; void sendScoData(hal::HciPacket data) override; void sendIsoData(hal::HciPacket data) override; hal::HciHalCallbacks* callbacks = nullptr; packet::PacketView GetPacketView(hal::HciPacket data); std::optional GetSentCommand( std::chrono::milliseconds timeout = std::chrono::seconds(1)); std::optional GetSentAcl( std::chrono::milliseconds timeout = std::chrono::seconds(1)); std::optional GetSentSco( std::chrono::milliseconds timeout = std::chrono::seconds(1)); std::optional GetSentIso( std::chrono::milliseconds timeout = std::chrono::seconds(1)); void InjectEvent(std::unique_ptr event); void Start() {} void Stop() {} void ListDependencies(ModuleList* /* list */) const {} std::string ToString() const override { return std::string("TestHciHal"); } static const ModuleFactory Factory; private: common::BlockingQueue outgoing_commands_; common::BlockingQueue outgoing_acl_; common::BlockingQueue outgoing_sco_; common::BlockingQueue outgoing_iso_; }; } // namespace hal } // namespace bluetooth