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

Commit b91254ac authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge "HCI: Remove indirection for Complete and Status"

parents 88759898 ee317c11
Loading
Loading
Loading
Loading
+21 −25
Original line number Diff line number Diff line
@@ -303,19 +303,6 @@ struct HciLayer::impl {
    event_handlers_.erase(event);
  }

  void register_le_meta_event(ContextualCallback<void(EventView)> handler) {
    ASSERT_LOG(
        event_handlers_.count(EventCode::LE_META_EVENT) == 0,
        "Can not register a second handler for %02hhx (%s)",
        EventCode::LE_META_EVENT,
        EventCodeText(EventCode::LE_META_EVENT).c_str());
    event_handlers_[EventCode::LE_META_EVENT] = handler;
  }

  void unregister_le_meta_event() {
    unregister_event(EventCode::LE_META_EVENT);
  }

  void register_le_event(SubeventCode event, ContextualCallback<void(LeMetaEventView)> handler) {
    ASSERT_LOG(
        subevent_handlers_.count(event) == 0,
@@ -400,12 +387,27 @@ struct HciLayer::impl {
        }
      }
    }
    switch (event_code) {
      case EventCode::COMMAND_COMPLETE:
        on_command_complete(event);
        break;
      case EventCode::COMMAND_STATUS:
        on_command_status(event);
        break;
      case EventCode::LE_META_EVENT:
        on_le_meta_event(event);
        break;
      default:
        if (event_handlers_.find(event_code) == event_handlers_.end()) {
      LOG_WARN("Unhandled event of type 0x%02hhx (%s)", event_code, EventCodeText(event_code).c_str());
      return;
    }
          LOG_WARN(
              "Unhandled event of type 0x%02hhx (%s)",
              event_code,
              EventCodeText(event_code).c_str());
        } else {
          event_handlers_[event_code].Invoke(event);
        }
    }
  }

  void on_le_meta_event(EventView event) {
    LeMetaEventView meta_event_view = LeMetaEventView::Create(event);
@@ -513,10 +515,6 @@ void HciLayer::RegisterEventHandler(EventCode event, ContextualCallback<void(Eve
  CallOn(impl_, &impl::register_event, event, handler);
}

void HciLayer::RegisterLeMetaEventHandler(ContextualCallback<void(EventView)> handler) {
  CallOn(impl_, &impl::register_le_meta_event, handler);
}

void HciLayer::UnregisterEventHandler(EventCode event) {
  CallOn(impl_, &impl::unregister_event, event);
}
@@ -673,10 +671,8 @@ void HciLayer::Start() {
  Handler* handler = GetHandler();
  impl_->acl_queue_.GetDownEnd()->RegisterDequeue(handler, BindOn(impl_, &impl::on_outbound_acl_ready));
  impl_->sco_queue_.GetDownEnd()->RegisterDequeue(handler, BindOn(impl_, &impl::on_outbound_sco_ready));
  impl_->iso_queue_.GetDownEnd()->RegisterDequeue(handler, BindOn(impl_, &impl::on_outbound_iso_ready));
  RegisterEventHandler(EventCode::COMMAND_COMPLETE, handler->BindOn(impl_, &impl::on_command_complete));
  RegisterEventHandler(EventCode::COMMAND_STATUS, handler->BindOn(impl_, &impl::on_command_status));
  RegisterLeMetaEventHandler(handler->BindOn(impl_, &impl::on_le_meta_event));
  impl_->iso_queue_.GetDownEnd()->RegisterDequeue(
      handler, BindOn(impl_, &impl::on_outbound_iso_ready));
  RegisterEventHandler(EventCode::DISCONNECTION_COMPLETE, handler->BindOn(this, &HciLayer::on_disconnection_complete));
  RegisterEventHandler(
      EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE,
+5 −2
Original line number Diff line number Diff line
@@ -119,8 +119,11 @@ class HciLayer : public Module, public CommandInterface<CommandBuilder> {

  virtual void Disconnect(uint16_t handle, ErrorCode reason);
  virtual void ReadRemoteVersion(
      hci::ErrorCode hci_status, uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version);
  virtual void RegisterLeMetaEventHandler(common::ContextualCallback<void(EventView)> event_handler);
      hci::ErrorCode hci_status,
      uint16_t handle,
      uint8_t version,
      uint16_t manufacturer_name,
      uint16_t sub_version);

  std::list<common::ContextualCallback<void(uint16_t, ErrorCode)>> disconnect_handlers_;
  std::list<common::ContextualCallback<void(hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t)>>
+39 −0
Original line number Diff line number Diff line
@@ -458,6 +458,45 @@ TEST_F(HciTest, leMetaEvent) {
  ASSERT_TRUE(LeConnectionCompleteView::Create(LeMetaEventView::Create(EventView::Create(event))).IsValid());
}

TEST_F(HciTest, postEventsOnceOnHciHandler) {
  auto event_future = upper->GetReceivedEventFuture();
  auto command_future = hal->GetSentCommandFuture();

  // Send a CreateConnection command.
  Address addr;
  Address::FromString("01:02:03:04:05:06", addr);
  upper->SendHciCommandExpectingStatus(CreateConnectionBuilder::Create(
      addr,
      0,
      PageScanRepetitionMode::R0,
      0,
      ClockOffsetValid::INVALID,
      CreateConnectionRoleSwitch::ALLOW_ROLE_SWITCH));
  auto sent_status = command_future.wait_for(kTimeout);
  ASSERT_EQ(sent_status, std::future_status::ready);

  // Validate the received command.
  auto command = CreateConnectionView::Create(
      ConnectionManagementCommandView::Create(AclCommandView::Create(hal->GetSentCommand())));
  ASSERT_TRUE(command.IsValid());

  // Send a status and a connection complete at the same time.
  uint8_t num_packets = 1;
  hal->callbacks->hciEventReceived(
      GetPacketBytes(CreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, num_packets)));
  hal->callbacks->hciEventReceived(GetPacketBytes(ConnectionCompleteBuilder::Create(
      ErrorCode::SUCCESS, 0x123, addr, LinkType::ACL, Enable::DISABLED)));

  auto event_status = event_future.wait_for(kTimeout);
  ASSERT_EQ(event_status, std::future_status::ready);

  // Make sure the status comes first.
  auto event = upper->GetReceivedEvent();
  ASSERT_TRUE(
      CreateConnectionStatusView::Create(CommandStatusView::Create(EventView::Create(event)))
          .IsValid());
}

TEST_F(HciTest, DISABLED_hciTimeOut) {
  auto event_future = upper->GetReceivedEventFuture();
  auto reset_command_future = hal->GetSentCommandFuture();