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

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

Merge "Get rid of NameDB shim"

parents 9494ab49 6c4c134a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ filegroup {
            "inquiry.cc",
            "l2cap.cc",
            "name.cc",
            "name_db.cc",
            "stack.cc",
    ]
}

system/gd/shim/name_db.cc

deleted100644 → 0
+0 −106
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define LOG_TAG "bt_gd_shim"

#include <functional>
#include <memory>
#include <string>
#include <unordered_map>

#include "hci/address.h"
#include "module.h"
#include "neighbor/name_db.h"
#include "os/handler.h"
#include "shim/name_db.h"

namespace bluetooth {
namespace shim {

namespace {
constexpr char kModuleName[] = "shim::NameDb";
}  // namespace

struct NameDb::impl {
  impl(neighbor::NameDbModule* module, os::Handler* handler);
  ~impl() = default;

  void OnReadRemoteName(hci::Address address, bool success);
  void ReadRemoteNameDbRequest(hci::Address address, ReadRemoteNameDbCallback callback);

  std::unordered_map<hci::Address, ReadRemoteNameDbCallback> address_to_read_remote_callback_map_;
  neighbor::NameDbModule* module_{nullptr};
  os::Handler* handler_;
};

const ModuleFactory NameDb::Factory = ModuleFactory([]() { return new NameDb(); });

NameDb::impl::impl(neighbor::NameDbModule* module, os::Handler* handler) : module_(module), handler_(handler) {}

void NameDb::impl::OnReadRemoteName(hci::Address address, bool success) {
  LOG_DEBUG("%s from %s status:%s", __func__, address.ToString().c_str(), success ? "true" : "false");
  ASSERT(address_to_read_remote_callback_map_.find(address) != address_to_read_remote_callback_map_.end());
  ReadRemoteNameDbCallback callback = std::move(address_to_read_remote_callback_map_.at(address));
  address_to_read_remote_callback_map_.erase(address);
  callback(address.ToString(), success);
}

void NameDb::impl::ReadRemoteNameDbRequest(hci::Address address, ReadRemoteNameDbCallback callback) {
  ASSERT(address_to_read_remote_callback_map_.find(address) == address_to_read_remote_callback_map_.end());
  address_to_read_remote_callback_map_[address] = std::move(callback);

  module_->ReadRemoteNameRequest(address, common::BindOnce(&NameDb::impl::OnReadRemoteName, common::Unretained(this)),
                                 handler_);
}

void NameDb::ReadRemoteNameDbRequest(std::string string_address, ReadRemoteNameDbCallback callback) {
  hci::Address address;
  ASSERT(hci::Address::FromString(string_address, address));
  pimpl_->ReadRemoteNameDbRequest(address, std::move(callback));
}

bool NameDb::IsNameCached(std::string string_address) const {
  hci::Address address;
  ASSERT(hci::Address::FromString(string_address, address));
  return pimpl_->module_->IsNameCached(address);
}

std::array<uint8_t, 248> NameDb::ReadCachedRemoteName(std::string string_address) const {
  hci::Address address;
  ASSERT(hci::Address::FromString(string_address, address));
  return pimpl_->module_->ReadCachedRemoteName(address);
}

/**
 * Module methods
 */
void NameDb::ListDependencies(ModuleList* list) {
  list->add<neighbor::NameDbModule>();
}

void NameDb::Start() {
  pimpl_ = std::make_unique<impl>(GetDependency<neighbor::NameDbModule>(), GetHandler());
}

void NameDb::Stop() {
  pimpl_.reset();
}

std::string NameDb::ToString() const {
  return kModuleName;
}

}  // namespace shim
}  // namespace bluetooth

system/gd/shim/name_db.h

deleted100644 → 0
+0 −54
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <array>
#include <memory>
#include <string>

#include "module.h"

namespace bluetooth {
namespace shim {

using ReadRemoteNameDbCallback = std::function<void(std::string string_address, bool success)>;

class NameDb : public bluetooth::Module {
 public:
  void ReadRemoteNameDbRequest(std::string string_address, ReadRemoteNameDbCallback callback);

  bool IsNameCached(std::string string_address) const;
  std::array<uint8_t, 248> ReadCachedRemoteName(std::string string_address) const;

  NameDb() = default;
  ~NameDb() = default;

  static const ModuleFactory Factory;

 protected:
  void ListDependencies(ModuleList* list) override;  // Module
  void Start() override;                             // Module
  void Stop() override;                              // Module
  std::string ToString() const override;             // Module

 private:
  struct impl;
  std::unique_ptr<impl> pimpl_;
  DISALLOW_COPY_AND_ASSIGN(NameDb);
};

}  // namespace shim
}  // namespace bluetooth
+0 −1
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ class Inquiry;
class HciLayer;
class L2cap;
class Name;
class NameDb;
class Scanning;
class SecurityModule;
}  // namespace shim
+0 −1
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@
#include "shim/inquiry.h"
#include "shim/l2cap.h"
#include "shim/name.h"
#include "shim/name_db.h"
#include "stack_manager.h"
#include "storage/legacy.h"

Loading