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

Commit 08dffa70 authored by Myles Watson's avatar Myles Watson
Browse files

Rootcanal: Use a list of Phys in Device

Bug: 138260499
Test: start a device with Rootcanal, add_device_to_phy
Change-Id: If4b292472c1dce5e4a14dec92eaea9ff2bcca301
parent abfd6408
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -70,8 +70,7 @@ void Beacon::TimerTick() {
    std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
        std::move(ad);

    std::vector<std::shared_ptr<PhyLayer>> le_phys = phy_layers_[Phy::Type::LOW_ENERGY];
    for (std::shared_ptr<PhyLayer> phy : le_phys) {
    for (auto phy : phy_layers_[Phy::Type::LOW_ENERGY]) {
      phy->Send(to_send);
    }
  }
@@ -88,8 +87,7 @@ void Beacon::IncomingPacket(model::packets::LinkLayerPacketView packet) {
    std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
        std::move(scan_response);

    std::vector<std::shared_ptr<PhyLayer>> le_phys = phy_layers_[Phy::Type::LOW_ENERGY];
    for (auto phy : le_phys) {
    for (auto phy : phy_layers_[Phy::Type::LOW_ENERGY]) {
      phy->Send(to_send);
    }
  }
+4 −4
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ void Device::UnregisterPhyLayers() {
}

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);
  for (const auto phy_layer : phy_layers_[phy_type]) {
    if (phy_layer->IsFactoryId(factory_id)) {
      phy_layer->Unregister();
      phy_layers_[phy_type].remove(phy_layer);
    }
  }
}
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <chrono>
#include <cstdint>
#include <list>
#include <map>
#include <string>
#include <vector>
@@ -86,7 +87,7 @@ class Device {
                                   Phy::Type phy_type);

 protected:
  std::map<Phy::Type, std::vector<std::shared_ptr<PhyLayer>>> phy_layers_;
  std::map<Phy::Type, std::list<std::shared_ptr<PhyLayer>>> phy_layers_;

  std::chrono::steady_clock::time_point last_advertisement_;

+1 −2
Original line number Diff line number Diff line
@@ -80,8 +80,7 @@ void Loopback::IncomingPacket(model::packets::LinkLayerPacketView packet) {
    std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
        std::move(scan_response);

    std::vector<std::shared_ptr<PhyLayer>> le_phys = phy_layers_[Phy::Type::LOW_ENERGY];
    for (auto phy : le_phys) {
    for (auto phy : phy_layers_[Phy::Type::LOW_ENERGY]) {
      LOG_INFO("Sending a Scan Response on a Phy");
      phy->Send(to_send);
    }
+9 −2
Original line number Diff line number Diff line
@@ -25,8 +25,12 @@ class PhyLayer {
 public:
  PhyLayer(Phy::Type phy_type, uint32_t id,
           const std::function<void(model::packets::LinkLayerPacketView)>&
               device_receive)
      : phy_type_(phy_type), id_(id), transmit_to_device_(device_receive) {}
               device_receive,
           uint32_t device_id)
      : phy_type_(phy_type),
        id_(id),
        device_id_(device_id),
        transmit_to_device_(device_receive) {}

  virtual void Send(
      const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet) = 0;
@@ -48,11 +52,14 @@ class PhyLayer {
    return id_;
  }

  uint32_t GetDeviceId() { return device_id_; }

  virtual ~PhyLayer() = default;

 private:
  Phy::Type phy_type_;
  uint32_t id_;
  uint32_t device_id_;

 protected:
  const std::function<void(model::packets::LinkLayerPacketView)>
Loading