Skip to content

Commit

Permalink
Merge pull request #21 from alexmoon/unstable-features
Browse files Browse the repository at this point in the history
Add `unstable` and `l2cap` features
  • Loading branch information
alexmoon authored Oct 6, 2024
2 parents 707b5d6 + ea0386d commit 4cbbe81
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 65 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
cargo clippy --all-targets -- -D warnings
- name: Clippy (all features)
if: ${{ runner.os != 'Windows' }}
run: |
cargo clippy --all-targets --all-features -- -D warnings
Expand All @@ -55,7 +56,7 @@ jobs:
run: |
rustup target add aarch64-linux-android
# not using --all-targets because examples don't build for Android due to `Adapter::default()`
cargo clippy --lib --tests --target=aarch64-linux-android -- -D warnings
cargo clippy --lib --tests --target=aarch64-linux-android --features unstable -- -D warnings
- name: Test
run: cargo test --all
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ keywords = ["bluetooth", "BLE", "gatt", "bluez", "corebluetooth"]
categories = ["asynchronous", "hardware-support", "os"]

[package.metadata.docs.rs]
features = ["serde"]
features = ["serde", "unstable", "l2cap"]
default-target = "x86_64-apple-darwin"
targets = [
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"aarch64-linux-android"
]

[features]
unstable = []
l2cap = []
serde = ["dep:serde", "uuid/serde", "bluer/serde"]

[dependencies]
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/android/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use java_spaghetti::Global;
use uuid::Uuid;

use super::bindings::android::bluetooth::BluetoothDevice;
#[cfg(feature = "l2cap")]
use super::l2cap_channel::{L2capChannelReader, L2capChannelWriter};
use crate::pairing::PairingAgent;
use crate::{DeviceId, Result, Service, ServicesChanged};

#[derive(Clone)]
pub struct DeviceImpl {
pub(super) id: DeviceId,
#[cfg_attr(not(feature = "l2cap"), allow(unused))]
pub(super) device: Global<BluetoothDevice>,
}

Expand Down Expand Up @@ -97,6 +99,7 @@ impl DeviceImpl {
todo!()
}

#[cfg(feature = "l2cap")]
pub async fn open_l2cap_channel(
&self,
psm: u16,
Expand Down
2 changes: 2 additions & 0 deletions src/android/l2cap_channel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "l2cap")]

use std::sync::Arc;
use std::{fmt, slice, thread};

Expand Down
2 changes: 2 additions & 0 deletions src/bluer/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;
use futures_core::Stream;
use futures_lite::StreamExt;

#[cfg(feature = "l2cap")]
use super::l2cap_channel::{L2capChannelReader, L2capChannelWriter};
use super::DeviceId;
use crate::device::ServicesChanged;
Expand Down Expand Up @@ -292,6 +293,7 @@ impl DeviceImpl {
}
}

#[cfg(feature = "l2cap")]
pub async fn open_l2cap_channel(
&self,
_psm: u16,
Expand Down
2 changes: 2 additions & 0 deletions src/bluer/l2cap_channel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "l2cap")]

use std::fmt;

use crate::Result;
Expand Down
2 changes: 2 additions & 0 deletions src/corebluetooth/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use objc_foundation::{INSArray, INSFastEnumeration, INSString, NSArray};
use objc_id::ShareId;

use super::delegates::{PeripheralDelegate, PeripheralEvent};
#[cfg(feature = "l2cap")]
use super::l2cap_channel::{L2capChannelReader, L2capChannelWriter};
use super::types::{CBPeripheral, CBPeripheralState, CBService, CBUUID};
use crate::device::ServicesChanged;
Expand Down Expand Up @@ -209,6 +210,7 @@ impl DeviceImpl {
}
}

#[cfg(feature = "l2cap")]
pub async fn open_l2cap_channel(
&self,
_psm: u16,
Expand Down
2 changes: 2 additions & 0 deletions src/corebluetooth/l2cap_channel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "l2cap")]

use std::fmt;

use crate::Result;
Expand Down
5 changes: 4 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use futures_core::Stream;
use futures_lite::StreamExt;

use crate::error::ErrorKind;
#[cfg(feature = "l2cap")]
use crate::l2cap_channel::L2capChannel;
use crate::pairing::PairingAgent;
use crate::{sys, DeviceId, Error, Result, Service, Uuid};
Expand Down Expand Up @@ -158,8 +159,10 @@ impl Device {
///
/// # Platform specific
///
/// Returns [`NotSupported`][crate::error::ErrorKind::NotSupported] on iOS/MacOS, Windows and Linux.
/// Returns [`NotSupported`][crate::error::ErrorKind::NotSupported] on iOS/MacOS and Linux.
/// The `l2cap` feature is not available on Windows.
#[inline]
#[cfg(feature = "l2cap")]
pub async fn open_l2cap_channel(&self, psm: u16, secure: bool) -> Result<L2capChannel> {
let (reader, writer) = self.0.open_l2cap_channel(psm, secure).await?;
Ok(L2capChannel { reader, writer })
Expand Down
2 changes: 2 additions & 0 deletions src/l2cap_channel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "l2cap")]

use crate::{sys, Result};

/// A Bluetooth LE L2CAP Connection-oriented Channel (CoC)
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ pub mod pairing;
mod service;
mod util;

#[cfg(all(target_os = "android", not(feature = "unstable")))]
compile_error!("Android support is unstable and requires the 'unstable' feature to be enabled");

#[cfg(all(windows, feature = "l2cap"))]
compile_error!("L2CAP support is not available on Windows");

#[cfg(all(feature = "l2cap", not(feature = "unstable")))]
compile_error!("L2CAP support is unstable and requires the 'unstable' feature to be enabled");

#[cfg(target_os = "android")]
mod android;
#[cfg(target_os = "linux")]
Expand All @@ -143,6 +152,7 @@ pub use characteristic::Characteristic;
pub use descriptor::Descriptor;
pub use device::{Device, ServicesChanged};
pub use error::Error;
#[cfg(feature = "l2cap")]
pub use l2cap_channel::{L2capChannel, L2capChannelReader, L2capChannelWriter};
pub use service::Service;
pub use sys::DeviceId;
Expand Down
1 change: 0 additions & 1 deletion src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub mod characteristic;
pub mod descriptor;
pub mod device;
pub mod error;
pub mod l2cap_channel;
pub mod service;
mod types;

Expand Down
9 changes: 0 additions & 9 deletions src/windows/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use windows::Devices::Enumeration::{DevicePairingKinds, DevicePairingRequestedEv
use windows::Foundation::TypedEventHandler;

use super::error::{check_communication_status, check_pairing_status, check_unpairing_status};
use super::l2cap_channel::{L2capChannelReader, L2capChannelWriter};
use crate::device::ServicesChanged;
use crate::error::ErrorKind;
use crate::pairing::{IoCapability, PairingAgent, Passkey};
Expand Down Expand Up @@ -272,14 +271,6 @@ impl DeviceImpl {
pub async fn rssi(&self) -> Result<i16> {
Err(ErrorKind::NotSupported.into())
}

pub async fn open_l2cap_channel(
&self,
_psm: u16,
_secure: bool,
) -> std::prelude::v1::Result<(L2capChannelReader, L2capChannelWriter), crate::Error> {
Err(ErrorKind::NotSupported.into())
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
52 changes: 0 additions & 52 deletions src/windows/l2cap_channel.rs

This file was deleted.

0 comments on commit 4cbbe81

Please sign in to comment.