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

Commit 913a01c0 authored by Charlie Boutier's avatar Charlie Boutier Committed by David Duarte
Browse files

topshim: Add controller shim

Test: m bt_topshim_facade
Change-Id: I98a14186400e9d1edd0e4388530f4689d6ba574a
parent e19c23ef
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ cc_library_static {
        "btif/btif_shim.cc",
        "gatt/gatt_shim.cc",
        "hfp/hfp_shim.cc",
        "controller/controller_shim.cc",
    ],
    generated_headers: ["libbt_topshim_bridge_header", "cxx-bridge-header"],
    generated_sources: ["libbt_topshim_bridge_code"],
@@ -75,6 +76,7 @@ gensrcs {
        "src/profiles/a2dp.rs",
        "src/profiles/avrcp.rs",
        "src/profiles/gatt.rs",
        "src/controller.rs",
    ],
    output_extension: "rs.h",
    export_include_dirs: ["."],
@@ -89,6 +91,7 @@ gensrcs {
        "src/profiles/a2dp.rs",
        "src/profiles/avrcp.rs",
        "src/profiles/gatt.rs",
        "src/controller.rs",
    ],
    output_extension: "cc",
    export_include_dirs: ["."],
+5 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ cxxbridge_header("btif_bridge_header") {
    "src/profiles/a2dp.rs",
    "src/profiles/avrcp.rs",
    "src/profiles/gatt.rs",
    "src/controller.rs",
  ]
  all_dependent_configs = [ ":rust_topshim_config" ]
  deps = [":cxxlibheader"]
@@ -39,8 +40,9 @@ cxxbridge_cc("btif_bridge_code") {
    "src/profiles/a2dp.rs",
    "src/profiles/avrcp.rs",
    "src/profiles/gatt.rs",
    "src/controller.rs",
  ]
  deps = [":btif_bridge_header"]
  deps = [":btif_bridge_header", "//bt/gd:BluetoothGeneratedPackets_h"]
  configs = [ "//bt/gd:gd_defaults" ]
}

@@ -50,9 +52,10 @@ source_set("btif_cxx_bridge_code") {
    "btav/btav_shim.cc",
    "btav_sink/btav_sink_shim.cc",
    "gatt/gatt_shim.cc",
    "controller/controller_shim.cc",
  ]

  deps = [":btif_bridge_header"]
  deps = [":btif_bridge_header", "//bt/gd:BluetoothGeneratedPackets_h"]
  configs += ["//bt/gd:gd_defaults"]
}

+54 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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.
 */

#include "gd/rust/topshim/controller/controller_shim.h"

#include <memory>

#include "rust/cxx.h"
#include "src/controller.rs.h"
#include "types/raw_address.h"

namespace bluetooth {
namespace topshim {
namespace rust {
namespace internal {
static ControllerIntf* g_controller_intf;

static RustRawAddress to_rust_address(const RawAddress& address) {
  RustRawAddress raddr;
  std::copy(std::begin(address.address), std::end(address.address), std::begin(raddr.address));
  return raddr;
}
}  // namespace internal

ControllerIntf::~ControllerIntf() {}

std::unique_ptr<ControllerIntf> GetControllerInterface() {
  if (internal::g_controller_intf) std::abort();
  auto controller_intf = std::make_unique<ControllerIntf>();
  internal::g_controller_intf = controller_intf.get();
  return controller_intf;
}

RustRawAddress ControllerIntf::read_local_addr() const {
  if (!controller_) std::abort();
  return internal::to_rust_address(*controller_->get_address());
}

}  // namespace rust
}  // namespace topshim
}  // namespace bluetooth
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */
#ifndef GD_RUST_TOPSHIM_CONTROLLER_SHIM
#define GD_RUST_TOPSHIM_CONTROLLER_SHIM

#include <memory>

#include "main/shim/controller.h"
#include "rust/cxx.h"
#include "types/raw_address.h"

namespace bluetooth {
namespace topshim {
namespace rust {

struct RustRawAddress;

class ControllerIntf {
 public:
  ControllerIntf() : controller_(controller_get_interface()) {}
  ~ControllerIntf();

  RustRawAddress read_local_addr() const;

 private:
  const controller_t* controller_;
};

// ControllerIntf* GetControllerInterface();
std::unique_ptr<ControllerIntf> GetControllerInterface();

}  // namespace rust
}  // namespace topshim
}  // namespace bluetooth

#endif  // GD_RUST_TOPSHIM_CONTROLLER_SHIM
 No newline at end of file
+13 −0
Original line number Diff line number Diff line
syntax = "proto3";

package blueberry;

message Empty {}

message BluetoothAddress {
  bytes address = 1;
}

service ReadOnlyProperty {
  rpc ReadLocalAddress(Empty) returns (BluetoothAddress) {}
}
 No newline at end of file
Loading