rust/bt-pacs: Expose AudioContexts New ServerBuilder needs the client to provide available and supported contexts to start. Add them to the public API. Test: cargo build Bug: b/309977153 Change-Id: Ic23162506b80d78837b7ab9930f202c6ec8ee475 Reviewed-on: https://bluetooth-review.googlesource.com/c/bluetooth/+/2761 Reviewed-by: Dayeong Lee <dayeonglee@google.com>
diff --git a/rust/bt-pacs/src/lib.rs b/rust/bt-pacs/src/lib.rs index b77a577..3e34f35 100644 --- a/rust/bt-pacs/src/lib.rs +++ b/rust/bt-pacs/src/lib.rs
@@ -2,20 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -use bt_common::core::ltv::LtValue; +use bt_common::Uuid; use bt_common::core::CodecId; +use bt_common::core::ltv::LtValue; use bt_common::generic_audio::codec_capabilities::CodecCapability; use bt_common::generic_audio::metadata_ltv::Metadata; use bt_common::generic_audio::{AudioLocation, ContextType}; use bt_common::packet_encoding::{Decodable, Encodable}; -use bt_common::Uuid; -use bt_gatt::{client::FromCharacteristic, Characteristic}; +use bt_gatt::{Characteristic, client::FromCharacteristic}; use std::collections::HashSet; pub mod debug; pub mod server; +pub use server::types::AudioContexts; + /// UUID from Assigned Numbers section 3.4. pub const PACS_UUID: Uuid = Uuid::from_u16(0x1850); @@ -460,12 +462,12 @@ use super::*; use bt_common::{ - generic_audio::codec_capabilities::{CodecCapabilityType, SamplingFrequency}, Uuid, + generic_audio::codec_capabilities::{CodecCapabilityType, SamplingFrequency}, }; use bt_gatt::{ - types::{AttributePermissions, Handle}, Characteristic, + types::{AttributePermissions, Handle}, }; use pretty_assertions::assert_eq;
diff --git a/rust/bt-pacs/src/server.rs b/rust/bt-pacs/src/server.rs index 5531187..c279433 100644 --- a/rust/bt-pacs/src/server.rs +++ b/rust/bt-pacs/src/server.rs
@@ -17,8 +17,10 @@ //! // Define supported and available audio contexts for this PACS. //! let supported = AudioContexts::new(...); //! let available = AudioContexts::new(...); -//! let pacs_server = ServerBuilder::new(supported, -//! available).with_sources(...).with_sinks(...).build()?; +//! let pacs_server = ServerBuilder::new() +//! .with_sources(...) +//! .with_sinks(...) +//! .build(supported, available)?; //! //! // Publish the server. //! pacs_server.publish(gatt_server).expect("publishes fine"); @@ -28,10 +30,10 @@ //! } use bt_common::generic_audio::ContextType; +use bt_gatt::Server as _; use bt_gatt::server::LocalService; use bt_gatt::server::{ReadResponder, ServiceDefinition, WriteResponder}; use bt_gatt::types::{GattError, Handle}; -use bt_gatt::Server as _; use futures::task::{Poll, Waker}; use futures::{Future, Stream}; use pin_project::pin_project; @@ -43,7 +45,7 @@ SupportedAudioContexts, }; -mod types; +pub(crate) mod types; use crate::server::types::*; #[pin_project(project = LocalServiceProj)] @@ -394,10 +396,10 @@ mod tests { use super::*; - use bt_common::core::{CodecId, CodingFormat}; - use bt_common::generic_audio::codec_capabilities::*; - use bt_common::generic_audio::AudioLocation; use bt_common::PeerId; + use bt_common::core::{CodecId, CodingFormat}; + use bt_common::generic_audio::AudioLocation; + use bt_common::generic_audio::codec_capabilities::*; use bt_gatt::server; use bt_gatt::test_utils::{FakeServer, FakeServerEvent, FakeTypes}; use bt_gatt::types::ServiceKind;
diff --git a/rust/bt-pacs/src/server/types.rs b/rust/bt-pacs/src/server/types.rs index db45e52..a718502 100644 --- a/rust/bt-pacs/src/server/types.rs +++ b/rust/bt-pacs/src/server/types.rs
@@ -4,11 +4,11 @@ //! Define types and trait implementations specific to the PACS server. +use bt_gatt::Characteristic; use bt_gatt::client::FromCharacteristic; use bt_gatt::types::{ AttributePermissions, CharacteristicProperties, CharacteristicProperty, Handle, SecurityLevels, }; -use bt_gatt::Characteristic; use std::collections::HashSet; @@ -132,7 +132,6 @@ } impl AudioContexts { - #[cfg(test)] pub fn new(sink: HashSet<ContextType>, source: HashSet<ContextType>) -> Self { AudioContexts { sink, source } }