Skip to content

Commit

Permalink
pw_bluetooth: Modernize APIs
Browse files Browse the repository at this point in the history
Update pw_bluetooth APIs to use:
- pw_async2
- pw_multibuf
- pw_channel
- pw::expected

New targets, headers, and types are created (with the suffix "2") to
avoid breaking existing clients of these APIs.

Bug: b/350994818
Change-Id: I1cac6a1c71bd8a37bba33be4d50fa12f2194a916
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/219393
Commit-Queue: Ben Lawson <benlawson@google.com>
Reviewed-by: Marie Janssen <jamuraa@google.com>
Reviewed-by: Kayce Basques <kayce@google.com>
Pigweed-Auto-Submit: Ben Lawson <benlawson@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Nov 12, 2024
1 parent 5516467 commit a615b8b
Show file tree
Hide file tree
Showing 21 changed files with 1,971 additions and 64 deletions.
12 changes: 6 additions & 6 deletions docs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ _doxygen_input_files = [ # keep-sorted: start
"$dir_pw_async2_basic/public_overrides/pw_async2/dispatcher_native.h",
"$dir_pw_async_basic/public/pw_async_basic/dispatcher.h",
"$dir_pw_base64/public/pw_base64/base64.h",
"$dir_pw_bluetooth/public/pw_bluetooth/gatt/client.h",
"$dir_pw_bluetooth/public/pw_bluetooth/gatt/server.h",
"$dir_pw_bluetooth/public/pw_bluetooth/host.h",
"$dir_pw_bluetooth/public/pw_bluetooth/low_energy/central.h",
"$dir_pw_bluetooth/public/pw_bluetooth/low_energy/connection.h",
"$dir_pw_bluetooth/public/pw_bluetooth/low_energy/peripheral.h",
"$dir_pw_bluetooth/public/pw_bluetooth/controller2.h",
"$dir_pw_bluetooth/public/pw_bluetooth/gatt/client2.h",
"$dir_pw_bluetooth/public/pw_bluetooth/gatt/server2.h",
"$dir_pw_bluetooth/public/pw_bluetooth/low_energy/central2.h",
"$dir_pw_bluetooth/public/pw_bluetooth/low_energy/connection2.h",
"$dir_pw_bluetooth/public/pw_bluetooth/low_energy/peripheral2.h",
"$dir_pw_bluetooth_proxy/public/pw_bluetooth_proxy/h4_packet.h",
"$dir_pw_bluetooth_proxy/public/pw_bluetooth_proxy/proxy_host.h",
"$dir_pw_build/public/pw_build/linker_symbol.h",
Expand Down
63 changes: 63 additions & 0 deletions pw_bluetooth/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"])

label_flag(
name = "config",
build_setting_default = "//pw_build:default_module_config",
)

cc_library(
name = "pw_bluetooth",
hdrs = [
"public/pw_bluetooth/address.h",
"public/pw_bluetooth/assigned_uuids.h",
"public/pw_bluetooth/config.h",
"public/pw_bluetooth/constants.h",
"public/pw_bluetooth/controller.h",
"public/pw_bluetooth/gatt/client.h",
Expand Down Expand Up @@ -52,7 +58,54 @@ cc_library(
"//pw_chrono:system_clock",
"//pw_containers",
"//pw_function",
"//pw_multibuf",
"//pw_result",
"//pw_status",
"//pw_string:string",
],
)

cc_library(
name = "pw_bluetooth2",
hdrs = [
"public/pw_bluetooth/address.h",
"public/pw_bluetooth/assigned_uuids.h",
"public/pw_bluetooth/config.h",
"public/pw_bluetooth/constants.h",
"public/pw_bluetooth/controller2.h",
"public/pw_bluetooth/gatt/client2.h",
"public/pw_bluetooth/gatt/constants.h",
"public/pw_bluetooth/gatt/error.h",
"public/pw_bluetooth/gatt/server2.h",
"public/pw_bluetooth/gatt/types.h",
"public/pw_bluetooth/internal/hex.h",
"public/pw_bluetooth/internal/raii_ptr.h",
"public/pw_bluetooth/low_energy/advertising_data.h",
"public/pw_bluetooth/low_energy/bond_data2.h",
"public/pw_bluetooth/low_energy/central2.h",
"public/pw_bluetooth/low_energy/connection2.h",
"public/pw_bluetooth/low_energy/peripheral2.h",
"public/pw_bluetooth/low_energy/phy.h",
"public/pw_bluetooth/low_energy/security_mode.h",
"public/pw_bluetooth/pairing_delegate2.h",
"public/pw_bluetooth/peer.h",
"public/pw_bluetooth/types.h",
"public/pw_bluetooth/uuid.h",
"public/pw_bluetooth/vendor.h",
],
includes = ["public"],
deps = [
":config",
"//pw_async2:dispatcher",
"//pw_async2:once_sender",
"//pw_channel",
"//pw_chrono:system_clock",
"//pw_containers",
"//pw_function",
"//pw_multibuf",
"//pw_result",
"//pw_result:expected",
"//pw_span",
"//pw_status",
"//pw_string:string",
],
Expand Down Expand Up @@ -91,6 +144,16 @@ pw_cc_test(
],
)

pw_cc_test(
name = "api2_test",
srcs = [
"api2_test.cc",
],
deps = [
":pw_bluetooth2",
],
)

pw_cc_test(
name = "result_test",
srcs = [
Expand Down
68 changes: 68 additions & 0 deletions pw_bluetooth/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,27 @@
import("//build_overrides/pigweed.gni")

import("$dir_pigweed/third_party/emboss/build_defs.gni")
import("$dir_pw_async2/backend.gni")
import("$dir_pw_bloat/bloat.gni")
import("$dir_pw_build/module_config.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_chrono/backend.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")

declare_args() {
# The build target that overrides the default configuration options for this
# module. This should point to a source set that provides defines through a
# public config (which may -include a file or add defines directly).
pw_bluetooth_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
}

pw_source_set("config") {
public = [ "public/pw_bluetooth/config.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [ pw_bluetooth_CONFIG ]
}

config("public_include_path") {
include_dirs = [ "public" ]
visibility = [ ":*" ]
Expand Down Expand Up @@ -66,10 +81,56 @@ pw_source_set("pw_bluetooth") {
"public/pw_bluetooth/vendor.h",
]
public_deps = [
":config",
"$dir_pw_chrono:system_clock",
"$dir_pw_string:string",
dir_pw_containers,
dir_pw_function,
dir_pw_multibuf,
dir_pw_result,
dir_pw_span,
dir_pw_status,
]
}

pw_source_set("pw_bluetooth2") {
public_configs = [ ":public_include_path" ]
public = [
"public/pw_bluetooth/address.h",
"public/pw_bluetooth/assigned_uuids.h",
"public/pw_bluetooth/constants.h",
"public/pw_bluetooth/controller2.h",
"public/pw_bluetooth/gatt/client2.h",
"public/pw_bluetooth/gatt/constants.h",
"public/pw_bluetooth/gatt/error.h",
"public/pw_bluetooth/gatt/server2.h",
"public/pw_bluetooth/gatt/types.h",
"public/pw_bluetooth/internal/hex.h",
"public/pw_bluetooth/internal/raii_ptr.h",
"public/pw_bluetooth/low_energy/advertising_data.h",
"public/pw_bluetooth/low_energy/bond_data2.h",
"public/pw_bluetooth/low_energy/central2.h",
"public/pw_bluetooth/low_energy/connection2.h",
"public/pw_bluetooth/low_energy/peripheral2.h",
"public/pw_bluetooth/low_energy/phy.h",
"public/pw_bluetooth/low_energy/security_mode.h",
"public/pw_bluetooth/pairing_delegate2.h",
"public/pw_bluetooth/peer.h",
"public/pw_bluetooth/types.h",
"public/pw_bluetooth/uuid.h",
"public/pw_bluetooth/vendor.h",
]
public_deps = [
":config",
"$dir_pw_async2:dispatcher",
"$dir_pw_async2:once_sender",
"$dir_pw_chrono:system_clock",
"$dir_pw_result:expected",
"$dir_pw_string:string",
dir_pw_channel,
dir_pw_containers,
dir_pw_function,
dir_pw_multibuf,
dir_pw_result,
dir_pw_span,
dir_pw_status,
Expand Down Expand Up @@ -213,6 +274,7 @@ pw_test_group("tests") {
tests = [
":address_test",
":api_test",
":api2_test",
":result_test",
":uuid_test",
":emboss_test",
Expand Down Expand Up @@ -241,6 +303,12 @@ pw_test("emboss_util_test") {
]
}

pw_test("api2_test") {
enable_if = pw_async2_DISPATCHER_BACKEND != ""
sources = [ "api2_test.cc" ]
deps = [ ":pw_bluetooth2" ]
}

pw_test("result_test") {
sources = [ "result_test.cc" ]
deps = [ ":pw_bluetooth" ]
Expand Down
63 changes: 63 additions & 0 deletions pw_bluetooth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

include($ENV{PW_ROOT}/pw_build/pigweed.cmake)

pw_add_module_config(pw_bluetooth_CONFIG)

pw_add_library(pw_bluetooth.config INTERFACE
HEADERS
public/pw_bluetooth/config.h
PUBLIC_INCLUDES
public
PUBLIC_DEPS
${pw_bluetooth_CONFIG}
)

pw_add_library(pw_bluetooth INTERFACE
HEADERS
public/pw_bluetooth/address.h
Expand Down Expand Up @@ -45,11 +56,54 @@ pw_add_library(pw_bluetooth INTERFACE
PUBLIC_DEPS
pw_containers
pw_function
pw_multibuf
pw_status
pw_string.string
pw_chrono.system_clock
)

pw_add_library(pw_bluetooth.pw_bluetooth2 INTERFACE
HEADERS
public/pw_bluetooth/address.h
public/pw_bluetooth/assigned_uuids.h
public/pw_bluetooth/constants.h
public/pw_bluetooth/config.h
public/pw_bluetooth/controller2.h
public/pw_bluetooth/gatt/client2.h
public/pw_bluetooth/gatt/constants.h
public/pw_bluetooth/gatt/error.h
public/pw_bluetooth/gatt/server2.h
public/pw_bluetooth/gatt/types.h
public/pw_bluetooth/internal/hex.h
public/pw_bluetooth/internal/raii_ptr.h
public/pw_bluetooth/low_energy/advertising_data.h
public/pw_bluetooth/low_energy/bond_data2.h
public/pw_bluetooth/low_energy/central2.h
public/pw_bluetooth/low_energy/connection2.h
public/pw_bluetooth/low_energy/peripheral2.h
public/pw_bluetooth/low_energy/security_mode.h
public/pw_bluetooth/pairing_delegate2.h
public/pw_bluetooth/peer.h
public/pw_bluetooth/types.h
public/pw_bluetooth/uuid.h
public/pw_bluetooth/vendor.h
PUBLIC_INCLUDES
public
PUBLIC_DEPS
pw_bluetooth.config
pw_async2.dispatcher
pw_async2.once_sender
pw_result.expected
pw_channel
pw_containers
pw_function
pw_multibuf
pw_result
pw_span
pw_status
)


pw_add_library(pw_bluetooth.emboss_util INTERFACE
HEADERS
public/pw_bluetooth/emboss_util.h
Expand Down Expand Up @@ -79,6 +133,15 @@ pw_add_test(pw_bluetooth.api_test
modules
)

pw_add_test(pw_bluetooth.api2_test
SOURCES
api2_test.cc
PRIVATE_DEPS
pw_bluetooth.pw_bluetooth2
GROUPS
modules
)

pw_add_test(pw_bluetooth.result_test
SOURCES
result_test.cc
Expand Down
30 changes: 30 additions & 0 deletions pw_bluetooth/api2_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 The Pigweed Authors
//
// 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
//
// https://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 "pw_bluetooth/controller2.h"
#include "pw_bluetooth/gatt/client2.h"
#include "pw_bluetooth/gatt/server2.h"
#include "pw_bluetooth/low_energy/central2.h"
#include "pw_bluetooth/low_energy/peripheral2.h"
#include "pw_bluetooth/pairing_delegate2.h"
#include "pw_unit_test/framework.h"

namespace pw::bluetooth {
namespace {

// This empty test ensures that the included API compiles.
TEST(ApiTest, ApiCompiles) {}

} // namespace
} // namespace pw::bluetooth
Loading

0 comments on commit a615b8b

Please sign in to comment.