Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41570575 authored by Myles Watson's avatar Myles Watson Committed by android-build-merger
Browse files

RootCanal: Remove unregistered devices from Phys am: 60bb4272 am: 3f1d3ef0

am: 42b72b1a

Change-Id: Id261e5d81f42adaa4bc907d4c0994c74f6bdd204
parents 6bdf62d8 42b72b1a
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -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 {
+3 −1
Original line number Diff line number Diff line
@@ -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){};

+4 −0
Original line number Diff line number Diff line
@@ -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_;
  }
+15 −3
Original line number Diff line number Diff line
@@ -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 =
@@ -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);
}
+6 −1
Original line number Diff line number Diff line
@@ -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);
@@ -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 {
@@ -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