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

Commit 662604ce authored by Zach Johnson's avatar Zach Johnson
Browse files

Format gd/neighbor with new clang-format

find neighbor -regex '.*\.\(cc\|h\|tpp\)' -exec clang-format -style=file -i {} \;

Test: cert/run --host
Bug: 156858180
Tag: #gd-refactor
Change-Id: Iac2361e60bc15e2de3496f1e6fb9f253b6c284d7
parent 6490e776
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -15,12 +15,13 @@
 */
#define LOG_TAG "neighbor2"

#include "neighbor/connectability.h"

#include <memory>

#include "hci/hci_layer.h"
#include "hci/hci_packets.h"
#include "module.h"
#include "neighbor/connectability.h"
#include "neighbor/scan.h"
#include "os/handler.h"
#include "os/log.h"
+10 −9
Original line number Diff line number Diff line
@@ -15,13 +15,14 @@
 */
#define LOG_TAG "bt_gd_neigh"

#include "neighbor/discoverability.h"

#include <memory>

#include "common/bind.h"
#include "hci/hci_layer.h"
#include "hci/hci_packets.h"
#include "module.h"
#include "neighbor/discoverability.h"
#include "neighbor/scan.h"
#include "os/handler.h"
#include "os/log.h"
@@ -91,10 +92,10 @@ void neighbor::DiscoverabilityModule::impl::OnCommandComplete(hci::CommandComple

void neighbor::DiscoverabilityModule::impl::StartDiscoverability(std::vector<hci::Lap>& laps) {
  ASSERT(laps.size() <= num_supported_iac_);
  hci_layer_->EnqueueCommand(hci::WriteCurrentIacLapBuilder::Create(laps),
                             handler_->BindOnceOn(this, &impl::OnCommandComplete));
  hci_layer_->EnqueueCommand(hci::ReadCurrentIacLapBuilder::Create(),
                             handler_->BindOnceOn(this, &impl::OnCommandComplete));
  hci_layer_->EnqueueCommand(
      hci::WriteCurrentIacLapBuilder::Create(laps), handler_->BindOnceOn(this, &impl::OnCommandComplete));
  hci_layer_->EnqueueCommand(
      hci::ReadCurrentIacLapBuilder::Create(), handler_->BindOnceOn(this, &impl::OnCommandComplete));
  scan_module_->SetInquiryScan();
}

@@ -115,11 +116,11 @@ void neighbor::DiscoverabilityModule::impl::Start() {
  scan_module_ = module_.GetDependency<neighbor::ScanModule>();
  handler_ = module_.GetHandler();

  hci_layer_->EnqueueCommand(hci::ReadCurrentIacLapBuilder::Create(),
                             handler_->BindOnceOn(this, &impl::OnCommandComplete));
  hci_layer_->EnqueueCommand(
      hci::ReadCurrentIacLapBuilder::Create(), handler_->BindOnceOn(this, &impl::OnCommandComplete));

  hci_layer_->EnqueueCommand(hci::ReadNumberOfSupportedIacBuilder::Create(),
                             handler_->BindOnceOn(this, &impl::OnCommandComplete));
  hci_layer_->EnqueueCommand(
      hci::ReadNumberOfSupportedIacBuilder::Create(), handler_->BindOnceOn(this, &impl::OnCommandComplete));
  LOG_DEBUG("Started discoverability module");
}

+54 −26
Original line number Diff line number Diff line
@@ -33,14 +33,24 @@ namespace facade {

class NeighborFacadeService : public NeighborFacade::Service {
 public:
  NeighborFacadeService(ConnectabilityModule* connectability_module, DiscoverabilityModule* discoverability_module,
                        InquiryModule* inquiry_module, NameModule* name_module, PageModule*, ScanModule* scan_module,
  NeighborFacadeService(
      ConnectabilityModule* connectability_module,
      DiscoverabilityModule* discoverability_module,
      InquiryModule* inquiry_module,
      NameModule* name_module,
      PageModule*,
      ScanModule* scan_module,
      ::bluetooth::os::Handler* facade_handler)
      : connectability_module_(connectability_module), discoverability_module_(discoverability_module),
        inquiry_module_(inquiry_module), name_module_(name_module), scan_module_(scan_module),
      : connectability_module_(connectability_module),
        discoverability_module_(discoverability_module),
        inquiry_module_(inquiry_module),
        name_module_(name_module),
        scan_module_(scan_module),
        facade_handler_(facade_handler) {}

  ::grpc::Status SetConnectability(::grpc::ServerContext* context, const ::bluetooth::neighbor::EnableMsg* request,
  ::grpc::Status SetConnectability(
      ::grpc::ServerContext* context,
      const ::bluetooth::neighbor::EnableMsg* request,
      ::google::protobuf::Empty* response) override {
    if (request->enabled()) {
      connectability_module_->StartConnectability();
@@ -50,7 +60,8 @@ class NeighborFacadeService : public NeighborFacade::Service {
    return ::grpc::Status::OK;
  }

  ::grpc::Status SetDiscoverability(::grpc::ServerContext* context,
  ::grpc::Status SetDiscoverability(
      ::grpc::ServerContext* context,
      const ::bluetooth::neighbor::DiscoverabilitiyMsg* request,
      ::google::protobuf::Empty* response) override {
    switch (request->mode()) {
@@ -69,7 +80,9 @@ class NeighborFacadeService : public NeighborFacade::Service {
    return ::grpc::Status::OK;
  }

  ::grpc::Status SetInquiryMode(::grpc::ServerContext* context, const ::bluetooth::neighbor::InquiryMsg* request,
  ::grpc::Status SetInquiryMode(
      ::grpc::ServerContext* context,
      const ::bluetooth::neighbor::InquiryMsg* request,
      ::grpc::ServerWriter<InquiryResultMsg>* writer) override {
    inquiry_module_->RegisterCallbacks(inquiry_callbacks_);
    switch (request->result_mode()) {
@@ -101,7 +114,8 @@ class NeighborFacadeService : public NeighborFacade::Service {
    return pending_events_.RunLoop(context, writer);
  }

  ::grpc::Status ReadRemoteName(::grpc::ServerContext* context,
  ::grpc::Status ReadRemoteName(
      ::grpc::ServerContext* context,
      const ::bluetooth::neighbor::RemoteNameRequestMsg* request,
      ::google::protobuf::Empty* response) override {
    hci::Address remote;
@@ -121,18 +135,25 @@ class NeighborFacadeService : public NeighborFacade::Service {
        LOG_ALWAYS_FATAL("Unknown PageScanRepetition mode %d", static_cast<int>(request->page_scan_repetition_mode()));
    }
    name_module_->ReadRemoteNameRequest(
        remote, mode, request->clock_offset(),
        remote,
        mode,
        request->clock_offset(),
        (request->clock_offset() != 0 ? hci::ClockOffsetValid::VALID : hci::ClockOffsetValid::INVALID),
        common::Bind(&NeighborFacadeService::on_remote_name, common::Unretained(this)), facade_handler_);
        common::Bind(&NeighborFacadeService::on_remote_name, common::Unretained(this)),
        facade_handler_);
    return ::grpc::Status::OK;
  }

  ::grpc::Status GetRemoteNameEvents(::grpc::ServerContext* context, const ::google::protobuf::Empty* request,
  ::grpc::Status GetRemoteNameEvents(
      ::grpc::ServerContext* context,
      const ::google::protobuf::Empty* request,
      ::grpc::ServerWriter<RemoteNameResponseMsg>* writer) override {
    return pending_remote_names_.RunLoop(context, writer);
  }

  ::grpc::Status EnableInquiryScan(::grpc::ServerContext* context, const ::bluetooth::neighbor::EnableMsg* request,
  ::grpc::Status EnableInquiryScan(
      ::grpc::ServerContext* context,
      const ::bluetooth::neighbor::EnableMsg* request,
      ::google::protobuf::Empty* response) override {
    if (request->enabled()) {
      scan_module_->SetInquiryScan();
@@ -142,7 +163,9 @@ class NeighborFacadeService : public NeighborFacade::Service {
    return ::grpc::Status::OK;
  }

  ::grpc::Status EnablePageScan(::grpc::ServerContext* context, const ::bluetooth::neighbor::EnableMsg* request,
  ::grpc::Status EnablePageScan(
      ::grpc::ServerContext* context,
      const ::bluetooth::neighbor::EnableMsg* request,
      ::google::protobuf::Empty* response) override {
    if (request->enabled()) {
      scan_module_->SetPageScan();
@@ -201,9 +224,14 @@ void NeighborFacadeModule::ListDependencies(ModuleList* list) {

void NeighborFacadeModule::Start() {
  ::bluetooth::grpc::GrpcFacadeModule::Start();
  service_ = new NeighborFacadeService(GetDependency<ConnectabilityModule>(), GetDependency<DiscoverabilityModule>(),
                                       GetDependency<InquiryModule>(), GetDependency<NameModule>(),
                                       GetDependency<PageModule>(), GetDependency<ScanModule>(), GetHandler());
  service_ = new NeighborFacadeService(
      GetDependency<ConnectabilityModule>(),
      GetDependency<DiscoverabilityModule>(),
      GetDependency<InquiryModule>(),
      GetDependency<NameModule>(),
      GetDependency<PageModule>(),
      GetDependency<ScanModule>(),
      GetHandler());
}

void NeighborFacadeModule::Stop() {
+83 −47
Original line number Diff line number Diff line
@@ -39,8 +39,12 @@ struct InquiryModule::impl {
  void StartOneShotInquiry(bool limited, InquiryLength inquiry_length, NumResponses num_responses);
  void StopOneShotInquiry();

  void StartPeriodicInquiry(bool limited, InquiryLength inquiry_length, NumResponses num_responses,
                            PeriodLength max_delay, PeriodLength min_delay);
  void StartPeriodicInquiry(
      bool limited,
      InquiryLength inquiry_length,
      NumResponses num_responses,
      PeriodLength max_delay,
      PeriodLength min_delay);
  void StopPeriodicInquiry();

  void SetScanActivity(ScanParameters params);
@@ -218,10 +222,13 @@ void neighbor::InquiryModule::impl::OnEvent(hci::EventPacketView view) {
    case hci::EventCode::EXTENDED_INQUIRY_RESULT: {
      auto packet = hci::ExtendedInquiryResultView::Create(view);
      ASSERT(packet.IsValid());
      LOG_DEBUG("Extended inquiry result addr:%s repetition_mode:%s cod:%s clock_offset:%d rssi:%hhd",
      LOG_DEBUG(
          "Extended inquiry result addr:%s repetition_mode:%s cod:%s clock_offset:%d rssi:%hhd",
          packet.GetAddress().ToString().c_str(),
          hci::PageScanRepetitionModeText(packet.GetPageScanRepetitionMode()).c_str(),
                packet.GetClassOfDevice().ToString().c_str(), packet.GetClockOffset(), packet.GetRssi());
          packet.GetClassOfDevice().ToString().c_str(),
          packet.GetClockOffset(),
          packet.GetRssi());
      inquiry_callbacks_.extended_result(packet);
    } break;

@@ -237,14 +244,14 @@ void neighbor::InquiryModule::impl::OnEvent(hci::EventPacketView view) {
void neighbor::InquiryModule::impl::RegisterCallbacks(InquiryCallbacks callbacks) {
  inquiry_callbacks_ = callbacks;

  hci_layer_->RegisterEventHandler(hci::EventCode::INQUIRY_RESULT,
                                   handler_->BindOn(this, &InquiryModule::impl::OnEvent));
  hci_layer_->RegisterEventHandler(hci::EventCode::INQUIRY_RESULT_WITH_RSSI,
                                   handler_->BindOn(this, &InquiryModule::impl::OnEvent));
  hci_layer_->RegisterEventHandler(hci::EventCode::EXTENDED_INQUIRY_RESULT,
                                   handler_->BindOn(this, &InquiryModule::impl::OnEvent));
  hci_layer_->RegisterEventHandler(hci::EventCode::INQUIRY_COMPLETE,
                                   handler_->BindOn(this, &InquiryModule::impl::OnEvent));
  hci_layer_->RegisterEventHandler(
      hci::EventCode::INQUIRY_RESULT, handler_->BindOn(this, &InquiryModule::impl::OnEvent));
  hci_layer_->RegisterEventHandler(
      hci::EventCode::INQUIRY_RESULT_WITH_RSSI, handler_->BindOn(this, &InquiryModule::impl::OnEvent));
  hci_layer_->RegisterEventHandler(
      hci::EventCode::EXTENDED_INQUIRY_RESULT, handler_->BindOn(this, &InquiryModule::impl::OnEvent));
  hci_layer_->RegisterEventHandler(
      hci::EventCode::INQUIRY_COMPLETE, handler_->BindOn(this, &InquiryModule::impl::OnEvent));
}

void neighbor::InquiryModule::impl::UnregisterCallbacks() {
@@ -274,8 +281,8 @@ void neighbor::InquiryModule::impl::EnqueueCommandCompleteSync(std::unique_ptr<h
  command_sync_ = nullptr;
}

void neighbor::InquiryModule::impl::StartOneShotInquiry(bool limited, InquiryLength inquiry_length,
                                                        NumResponses num_responses) {
void neighbor::InquiryModule::impl::StartOneShotInquiry(
    bool limited, InquiryLength inquiry_length, NumResponses num_responses) {
  ASSERT(HasCallbacks());
  ASSERT(!IsInquiryActive());
  hci::Lap lap;
@@ -296,8 +303,11 @@ void neighbor::InquiryModule::impl::StopOneShotInquiry() {
  EnqueueCommandComplete(hci::InquiryCancelBuilder::Create());
}

void neighbor::InquiryModule::impl::StartPeriodicInquiry(bool limited, InquiryLength inquiry_length,
                                                         NumResponses num_responses, PeriodLength max_delay,
void neighbor::InquiryModule::impl::StartPeriodicInquiry(
    bool limited,
    InquiryLength inquiry_length,
    NumResponses num_responses,
    PeriodLength max_delay,
    PeriodLength min_delay) {
  ASSERT(HasCallbacks());
  ASSERT(!IsInquiryActive());
@@ -338,7 +348,9 @@ void neighbor::InquiryModule::impl::Start() {

void neighbor::InquiryModule::impl::Stop() {
  LOG_INFO("Inquiry scan interval:%hu window:%hu", inquiry_scan_.interval, inquiry_scan_.window);
  LOG_INFO("Inquiry mode:%s scan_type:%s", hci::InquiryModeText(inquiry_mode_).c_str(),
  LOG_INFO(
      "Inquiry mode:%s scan_type:%s",
      hci::InquiryModeText(inquiry_mode_).c_str(),
      hci::InquiryScanTypeText(inquiry_scan_type_).c_str());
  LOG_INFO("Inquiry response tx power:%hhd", inquiry_response_tx_power_);
  LOG_DEBUG("Stopped inquiry module");
@@ -353,8 +365,12 @@ void neighbor::InquiryModule::impl::SetInquiryMode(hci::InquiryMode mode) {
void neighbor::InquiryModule::impl::SetScanActivity(ScanParameters params) {
  EnqueueCommandComplete(hci::WriteInquiryScanActivityBuilder::Create(params.interval, params.window));
  inquiry_scan_ = params;
  LOG_DEBUG("Set scan activity interval:0x%x/%.02fms window:0x%x/%.02fms", params.interval,
            ScanIntervalTimeMs(params.interval), params.window, ScanWindowTimeMs(params.window));
  LOG_DEBUG(
      "Set scan activity interval:0x%x/%.02fms window:0x%x/%.02fms",
      params.interval,
      ScanIntervalTimeMs(params.interval),
      params.window,
      ScanWindowTimeMs(params.window));
}

void neighbor::InquiryModule::impl::SetScanType(hci::InquiryScanType scan_type) {
@@ -385,13 +401,21 @@ void neighbor::InquiryModule::UnregisterCallbacks() {
}

void neighbor::InquiryModule::StartGeneralInquiry(InquiryLength inquiry_length, NumResponses num_responses) {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::StartOneShotInquiry,
                                      common::Unretained(pimpl_.get()), false, inquiry_length, num_responses));
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::StartOneShotInquiry,
      common::Unretained(pimpl_.get()),
      false,
      inquiry_length,
      num_responses));
}

void neighbor::InquiryModule::StartLimitedInquiry(InquiryLength inquiry_length, NumResponses num_responses) {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::StartOneShotInquiry,
                                      common::Unretained(pimpl_.get()), true, inquiry_length, num_responses));
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::StartOneShotInquiry,
      common::Unretained(pimpl_.get()),
      true,
      inquiry_length,
      num_responses));
}

void neighbor::InquiryModule::StopInquiry() {
@@ -399,17 +423,27 @@ void neighbor::InquiryModule::StopInquiry() {
      common::BindOnce(&neighbor::InquiryModule::impl::StopOneShotInquiry, common::Unretained(pimpl_.get())));
}

void neighbor::InquiryModule::StartGeneralPeriodicInquiry(InquiryLength inquiry_length, NumResponses num_responses,
                                                          PeriodLength max_delay, PeriodLength min_delay) {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::StartPeriodicInquiry,
                                      common::Unretained(pimpl_.get()), false, inquiry_length, num_responses, max_delay,
void neighbor::InquiryModule::StartGeneralPeriodicInquiry(
    InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay, PeriodLength min_delay) {
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::StartPeriodicInquiry,
      common::Unretained(pimpl_.get()),
      false,
      inquiry_length,
      num_responses,
      max_delay,
      min_delay));
}

void neighbor::InquiryModule::StartLimitedPeriodicInquiry(InquiryLength inquiry_length, NumResponses num_responses,
                                                          PeriodLength max_delay, PeriodLength min_delay) {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::StartPeriodicInquiry,
                                      common::Unretained(pimpl_.get()), true, inquiry_length, num_responses, max_delay,
void neighbor::InquiryModule::StartLimitedPeriodicInquiry(
    InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay, PeriodLength min_delay) {
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::StartPeriodicInquiry,
      common::Unretained(pimpl_.get()),
      true,
      inquiry_length,
      num_responses,
      max_delay,
      min_delay));
}

@@ -424,27 +458,29 @@ void neighbor::InquiryModule::SetScanActivity(ScanParameters params) {
}

void neighbor::InquiryModule::SetInterlacedScan() {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::SetScanType, common::Unretained(pimpl_.get()),
                                      hci::InquiryScanType::INTERLACED));
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::SetScanType, common::Unretained(pimpl_.get()), hci::InquiryScanType::INTERLACED));
}

void neighbor::InquiryModule::SetStandardScan() {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::SetScanType, common::Unretained(pimpl_.get()),
                                      hci::InquiryScanType::STANDARD));
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::SetScanType, common::Unretained(pimpl_.get()), hci::InquiryScanType::STANDARD));
}

void neighbor::InquiryModule::SetStandardInquiryResultMode() {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::SetInquiryMode, common::Unretained(pimpl_.get()),
                                      hci::InquiryMode::STANDARD));
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::SetInquiryMode, common::Unretained(pimpl_.get()), hci::InquiryMode::STANDARD));
}

void neighbor::InquiryModule::SetInquiryWithRssiResultMode() {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::SetInquiryMode, common::Unretained(pimpl_.get()),
                                      hci::InquiryMode::RSSI));
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::SetInquiryMode, common::Unretained(pimpl_.get()), hci::InquiryMode::RSSI));
}

void neighbor::InquiryModule::SetExtendedInquiryResultMode() {
  GetHandler()->Post(common::BindOnce(&neighbor::InquiryModule::impl::SetInquiryMode, common::Unretained(pimpl_.get()),
  GetHandler()->Post(common::BindOnce(
      &neighbor::InquiryModule::impl::SetInquiryMode,
      common::Unretained(pimpl_.get()),
      hci::InquiryMode::RSSI_OR_EXTENDED));
}

+4 −4
Original line number Diff line number Diff line
@@ -49,10 +49,10 @@ class InquiryModule : public bluetooth::Module {
  void StartLimitedInquiry(InquiryLength inquiry_length, NumResponses num_responses);
  void StopInquiry();

  void StartGeneralPeriodicInquiry(InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay,
                                   PeriodLength min_delay);
  void StartLimitedPeriodicInquiry(InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay,
                                   PeriodLength min_delay);
  void StartGeneralPeriodicInquiry(
      InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay, PeriodLength min_delay);
  void StartLimitedPeriodicInquiry(
      InquiryLength inquiry_length, NumResponses num_responses, PeriodLength max_delay, PeriodLength min_delay);
  void StopPeriodicInquiry();

  void SetScanActivity(ScanParameters parms);
Loading