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

Commit f0d27c71 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I1685fabd,Ia789132e,I4b0ed942,I9607c58f,Ie9efd0e2

* changes:
  RootCanal: Add Reset command to handler
  Track phys in Device in a list
  RootCanal: Schedule device and phy deletions
  RootCanal: Use CancelAsyncTask in test_environment
  RootCanal: Use Device::Send in devices
parents db83183d 0ec73036
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -71,14 +71,14 @@ class TestEnvironment {
                                                    task);
      },

      [this](test_vendor_lib::AsyncTaskId task) {
        async_manager_.CancelAsyncTask(task);
      },

      [this](test_vendor_lib::AsyncUserId user) {
        async_manager_.CancelAsyncTasksFromUser(user);
      },

      [this](test_vendor_lib::AsyncTaskId task) {
        async_manager_.CancelAsyncTask(task);
      },

      [this](const std::string& server, int port) {
        return ConnectToRemoteServer(server, port);
      }};
+2 −6
Original line number Diff line number Diff line
@@ -70,9 +70,7 @@ void Beacon::TimerTick() {
    std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
        std::move(ad);

    for (const auto& phy : phy_layers_[Phy::Type::LOW_ENERGY]) {
      phy->Send(to_send);
    }
    SendLinkLayerPacket(to_send, Phy::Type::LOW_ENERGY);
  }
}

@@ -87,9 +85,7 @@ void Beacon::IncomingPacket(model::packets::LinkLayerPacketView packet) {
    std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
        std::move(scan_response);

    for (const auto& phy : phy_layers_[Phy::Type::LOW_ENERGY]) {
      phy->Send(to_send);
    }
    SendLinkLayerPacket(to_send, Phy::Type::LOW_ENERGY);
  }
}

+18 −12
Original line number Diff line number Diff line
@@ -29,23 +29,25 @@ std::string Device::ToString() const {
}

void Device::RegisterPhyLayer(std::shared_ptr<PhyLayer> phy) {
  phy_layers_[phy->GetType()].push_back(phy);
  phy_layers_.push_back(phy);
}

void Device::UnregisterPhyLayers() {
  for (auto phy_pair : phy_layers_) {
    auto phy_list = std::get<1>(phy_pair);
    for (auto phy : phy_list) {
  for (auto phy : phy_layers_) {
    if (phy != nullptr) {
      phy->Unregister();
    }
  }
  phy_layers_.clear();
}

void Device::UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id) {
  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);
  for (auto& phy : phy_layers_) {
    if (phy != nullptr && phy->IsFactoryId(factory_id) &&
        phy->GetType() == phy_type) {
      phy->Unregister();
      phy.reset();
      return;
    }
  }
}
@@ -58,17 +60,21 @@ bool Device::IsAdvertisementAvailable() const {
void Device::SendLinkLayerPacket(
    std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send,
    Phy::Type phy_type) {
  for (const auto& phy : phy_layers_[phy_type]) {
  for (auto phy : phy_layers_) {
    if (phy != nullptr && phy->GetType() == phy_type) {
      phy->Send(to_send);
    }
  }
}

void Device::SendLinkLayerPacket(model::packets::LinkLayerPacketView to_send,
                                 Phy::Type phy_type) {
  for (const auto& phy : phy_layers_[phy_type]) {
  for (auto phy : phy_layers_) {
    if (phy != nullptr && phy->GetType() == phy_type) {
      phy->Send(to_send);
    }
  }
}

void Device::SetAddress(Address) {
  LOG_INFO("%s does not implement %s", GetTypeString().c_str(), __func__);
+1 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@

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

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

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

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

    for (const auto& phy : phy_layers_[Phy::Type::LOW_ENERGY]) {
      LOG_INFO("Sending a Scan Response on a Phy");
      phy->Send(to_send);
    }
    SendLinkLayerPacket(to_send, Phy::Type::LOW_ENERGY);
  }
}

Loading