1 /* 2 * Copyright 2018 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 <memory> 20 #include <vector> 21 22 #include "include/phy.h" 23 #include "packets/link_layer/link_layer_packet_builder.h" 24 #include "packets/link_layer/link_layer_packet_view.h" 25 #include "phy_layer.h" 26 27 namespace test_vendor_lib { 28 29 class PhyLayerFactory { 30 friend class PhyLayerImpl; 31 32 public: 33 PhyLayerFactory(Phy::Type phy_type); 34 35 virtual ~PhyLayerFactory() = default; 36 37 Phy::Type GetType(); 38 39 std::shared_ptr<PhyLayer> GetPhyLayer(const std::function<void(packets::LinkLayerPacketView)>& device_receive); 40 41 void UnregisterPhyLayer(uint32_t id); 42 43 virtual void TimerTick(); 44 45 virtual std::string ToString() const; 46 47 protected: 48 virtual void Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet, uint32_t id); 49 50 private: 51 Phy::Type phy_type_; 52 std::vector<std::shared_ptr<PhyLayer>> phy_layers_; 53 uint32_t next_id_{1}; 54 }; 55 56 class PhyLayerImpl : public PhyLayer { 57 public: 58 PhyLayerImpl(Phy::Type phy_type, uint32_t id, const std::function<void(packets::LinkLayerPacketView)>& device_receive, 59 const std::shared_ptr<PhyLayerFactory>& factory); 60 virtual ~PhyLayerImpl() override; 61 62 virtual void Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) override; 63 virtual void Receive(packets::LinkLayerPacketView packet) override; 64 virtual void TimerTick() override; 65 66 private: 67 std::shared_ptr<PhyLayerFactory> factory_; 68 }; 69 } // namespace test_vendor_lib 70