Loading system/vendor_libs/test_vendor_lib/model/devices/device.cc +12 −5 Original line number Diff line number Diff line Loading @@ -34,15 +34,22 @@ void Device::RegisterPhyLayer(std::shared_ptr<PhyLayer> phy) { phy_layers_[phy->GetType()].push_back(phy); } void Device::UnregisterPhyLayer(std::shared_ptr<PhyLayer> phy) { void Device::UnregisterPhyLayers() { for (auto phy_pair : phy_layers_) { auto phy_list = std::get<1>(phy_pair); for (size_t i = 0; i < phy_list.size(); i++) { if (phy == phy_list[i]) { phy_list.erase(phy_list.begin() + i); for (auto phy : phy_list) { phy->Unregister(); } } } void Device::UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id) { for (size_t i = 0; i < phy_layers_[phy_type].size(); i++) { if (phy_layers_[phy_type][i]->IsFactoryId(factory_id)) { phy_layers_[phy_type][i]->Unregister(); phy_layers_[phy_type].erase(phy_layers_[phy_type].begin() + i); } } } bool Device::IsAdvertisementAvailable(std::chrono::milliseconds scan_time) const { Loading system/vendor_libs/test_vendor_lib/model/devices/device.h +3 −1 Original line number Diff line number Diff line Loading @@ -69,7 +69,9 @@ class Device { void RegisterPhyLayer(std::shared_ptr<PhyLayer> phy); void UnregisterPhyLayer(std::shared_ptr<PhyLayer> phy); void UnregisterPhyLayers(); void UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id); virtual void IncomingPacket(packets::LinkLayerPacketView){}; Loading system/vendor_libs/test_vendor_lib/model/setup/phy_layer.h +4 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,10 @@ class PhyLayer { virtual void TimerTick() = 0; virtual bool IsFactoryId(uint32_t factory_id) = 0; virtual void Unregister() = 0; Phy::Type GetType() { return phy_type_; } Loading system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc +15 −3 Original line number Diff line number Diff line Loading @@ -24,12 +24,17 @@ namespace test_vendor_lib { PhyLayerFactory::PhyLayerFactory(Phy::Type phy_type) : phy_type_(phy_type) {} PhyLayerFactory::PhyLayerFactory(Phy::Type phy_type, uint32_t factory_id) : phy_type_(phy_type), factory_id_(factory_id) {} Phy::Type PhyLayerFactory::GetType() { return phy_type_; } uint32_t PhyLayerFactory::GetFactoryId() { return factory_id_; } std::shared_ptr<PhyLayer> PhyLayerFactory::GetPhyLayer( const std::function<void(packets::LinkLayerPacketView)>& device_receive) { std::shared_ptr<PhyLayer> new_phy = Loading Loading @@ -89,14 +94,21 @@ PhyLayerImpl::PhyLayerImpl(Phy::Type phy_type, uint32_t id, : PhyLayer(phy_type, id, device_receive), factory_(factory) {} PhyLayerImpl::~PhyLayerImpl() { factory_->UnregisterPhyLayer(GetId()); PhyLayer::~PhyLayer(); Unregister(); } void PhyLayerImpl::Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) { factory_->Send(packet, GetId()); } void PhyLayerImpl::Unregister() { factory_->UnregisterPhyLayer(GetId()); } bool PhyLayerImpl::IsFactoryId(uint32_t id) { return factory_->GetFactoryId() == id; } void PhyLayerImpl::Receive(packets::LinkLayerPacketView packet) { transmit_to_device_(packet); } Loading system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h +6 −1 Original line number Diff line number Diff line Loading @@ -30,12 +30,14 @@ class PhyLayerFactory { friend class PhyLayerImpl; public: PhyLayerFactory(Phy::Type phy_type); PhyLayerFactory(Phy::Type phy_type, uint32_t factory_id); virtual ~PhyLayerFactory() = default; Phy::Type GetType(); uint32_t GetFactoryId(); std::shared_ptr<PhyLayer> GetPhyLayer(const std::function<void(packets::LinkLayerPacketView)>& device_receive); void UnregisterPhyLayer(uint32_t id); Loading @@ -51,6 +53,7 @@ class PhyLayerFactory { Phy::Type phy_type_; std::vector<std::shared_ptr<PhyLayer>> phy_layers_; uint32_t next_id_{1}; const uint32_t factory_id_; }; class PhyLayerImpl : public PhyLayer { Loading @@ -61,6 +64,8 @@ class PhyLayerImpl : public PhyLayer { virtual void Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) override; virtual void Receive(packets::LinkLayerPacketView packet) override; virtual void Unregister() override; virtual bool IsFactoryId(uint32_t factory_id) override; virtual void TimerTick() override; private: Loading Loading
system/vendor_libs/test_vendor_lib/model/devices/device.cc +12 −5 Original line number Diff line number Diff line Loading @@ -34,15 +34,22 @@ void Device::RegisterPhyLayer(std::shared_ptr<PhyLayer> phy) { phy_layers_[phy->GetType()].push_back(phy); } void Device::UnregisterPhyLayer(std::shared_ptr<PhyLayer> phy) { void Device::UnregisterPhyLayers() { for (auto phy_pair : phy_layers_) { auto phy_list = std::get<1>(phy_pair); for (size_t i = 0; i < phy_list.size(); i++) { if (phy == phy_list[i]) { phy_list.erase(phy_list.begin() + i); for (auto phy : phy_list) { phy->Unregister(); } } } void Device::UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id) { for (size_t i = 0; i < phy_layers_[phy_type].size(); i++) { if (phy_layers_[phy_type][i]->IsFactoryId(factory_id)) { phy_layers_[phy_type][i]->Unregister(); phy_layers_[phy_type].erase(phy_layers_[phy_type].begin() + i); } } } bool Device::IsAdvertisementAvailable(std::chrono::milliseconds scan_time) const { Loading
system/vendor_libs/test_vendor_lib/model/devices/device.h +3 −1 Original line number Diff line number Diff line Loading @@ -69,7 +69,9 @@ class Device { void RegisterPhyLayer(std::shared_ptr<PhyLayer> phy); void UnregisterPhyLayer(std::shared_ptr<PhyLayer> phy); void UnregisterPhyLayers(); void UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id); virtual void IncomingPacket(packets::LinkLayerPacketView){}; Loading
system/vendor_libs/test_vendor_lib/model/setup/phy_layer.h +4 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,10 @@ class PhyLayer { virtual void TimerTick() = 0; virtual bool IsFactoryId(uint32_t factory_id) = 0; virtual void Unregister() = 0; Phy::Type GetType() { return phy_type_; } Loading
system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc +15 −3 Original line number Diff line number Diff line Loading @@ -24,12 +24,17 @@ namespace test_vendor_lib { PhyLayerFactory::PhyLayerFactory(Phy::Type phy_type) : phy_type_(phy_type) {} PhyLayerFactory::PhyLayerFactory(Phy::Type phy_type, uint32_t factory_id) : phy_type_(phy_type), factory_id_(factory_id) {} Phy::Type PhyLayerFactory::GetType() { return phy_type_; } uint32_t PhyLayerFactory::GetFactoryId() { return factory_id_; } std::shared_ptr<PhyLayer> PhyLayerFactory::GetPhyLayer( const std::function<void(packets::LinkLayerPacketView)>& device_receive) { std::shared_ptr<PhyLayer> new_phy = Loading Loading @@ -89,14 +94,21 @@ PhyLayerImpl::PhyLayerImpl(Phy::Type phy_type, uint32_t id, : PhyLayer(phy_type, id, device_receive), factory_(factory) {} PhyLayerImpl::~PhyLayerImpl() { factory_->UnregisterPhyLayer(GetId()); PhyLayer::~PhyLayer(); Unregister(); } void PhyLayerImpl::Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) { factory_->Send(packet, GetId()); } void PhyLayerImpl::Unregister() { factory_->UnregisterPhyLayer(GetId()); } bool PhyLayerImpl::IsFactoryId(uint32_t id) { return factory_->GetFactoryId() == id; } void PhyLayerImpl::Receive(packets::LinkLayerPacketView packet) { transmit_to_device_(packet); } Loading
system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h +6 −1 Original line number Diff line number Diff line Loading @@ -30,12 +30,14 @@ class PhyLayerFactory { friend class PhyLayerImpl; public: PhyLayerFactory(Phy::Type phy_type); PhyLayerFactory(Phy::Type phy_type, uint32_t factory_id); virtual ~PhyLayerFactory() = default; Phy::Type GetType(); uint32_t GetFactoryId(); std::shared_ptr<PhyLayer> GetPhyLayer(const std::function<void(packets::LinkLayerPacketView)>& device_receive); void UnregisterPhyLayer(uint32_t id); Loading @@ -51,6 +53,7 @@ class PhyLayerFactory { Phy::Type phy_type_; std::vector<std::shared_ptr<PhyLayer>> phy_layers_; uint32_t next_id_{1}; const uint32_t factory_id_; }; class PhyLayerImpl : public PhyLayer { Loading @@ -61,6 +64,8 @@ class PhyLayerImpl : public PhyLayer { virtual void Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) override; virtual void Receive(packets::LinkLayerPacketView packet) override; virtual void Unregister() override; virtual bool IsFactoryId(uint32_t factory_id) override; virtual void TimerTick() override; private: Loading