Skip to content

Commit

Permalink
tune api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 27, 2024
1 parent 203692c commit 45ade32
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
38 changes: 19 additions & 19 deletions cidre/src/av/audio/session/route.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{av, define_obj_type, ns, objc};
use crate::{arc, av, define_obj_type, ns, objc};

define_obj_type!(
/// The location of a data source on an iOS device.
Expand Down Expand Up @@ -106,11 +106,11 @@ define_obj_type!(
impl ChannelDesc {
/// A human-readable name for the channel.
#[objc::msg_send(channelName)]
pub fn channel_name(&self) -> &ns::String;
pub fn channel_name(&self) -> arc::R<ns::String>;

/// The UID (unique identifier) of the port owning the channel
#[objc::msg_send(owningPortUID)]
pub fn owning_port_uid(&self) -> &ns::String;
pub fn owning_port_uid(&self) -> arc::R<ns::String>;

#[objc::msg_send(channelNumber)]
pub fn channel_number(&self) -> usize;
Expand All @@ -129,11 +129,11 @@ impl DataSrcDesc {
// TODO: verify leak
/// System-assigned ID for the data source.
#[objc::msg_send(dataSourceID)]
pub fn data_src_id(&self) -> &ns::String;
pub fn data_src_id(&self) -> arc::R<ns::String>;

/// Human-readable name for the data source.
#[objc::msg_send(dataSourceName)]
pub fn data_source_name(&self) -> &ns::String;
pub fn data_source_name(&self) -> arc::R<ns::String>;

/// Location and orientation can be used to distinguish between multiple data sources
/// belonging to a single port. For example, in the case of a port of type
Expand All @@ -142,21 +142,21 @@ impl DataSrcDesc {
///
/// Will be nil for data sources for which the location is not known.
#[objc::msg_send(location)]
pub fn location(&self) -> Option<&Location>;
pub fn location(&self) -> Option<arc::R<Location>>;

/// Describes the orientation of a data source. Will be nil for data sources for which the
/// orientation is not known.
#[objc::msg_send(orientation)]
pub fn orientation(&self) -> Option<&Orientation>;
pub fn orientation(&self) -> Option<arc::R<Orientation>>;

#[objc::msg_send(supportedPolarPatterns)]
pub fn supported_polar_patterns(&self) -> Option<&ns::Array<PolarPattern>>;
pub fn supported_polar_patterns(&self) -> Option<arc::R<ns::Array<PolarPattern>>>;

#[objc::msg_send(selectedPolarPattern)]
pub fn selected_polar_pattern(&self) -> Option<&PolarPattern>;
pub fn selected_polar_pattern(&self) -> Option<arc::R<PolarPattern>>;

#[objc::msg_send(preferredPolarPattern)]
pub fn preferred_polar_pattern(&self) -> Option<&PolarPattern>;
pub fn preferred_polar_pattern(&self) -> Option<arc::R<PolarPattern>>;

// - (BOOL)setPreferredPolarPattern:(nullable AVAudioSessionPolarPattern)pattern error:(NSError **)outError

Expand Down Expand Up @@ -189,13 +189,13 @@ define_obj_type!(

impl PortDesc {
#[objc::msg_send(portType)]
pub fn port_type(&self) -> &av::AudioSessionPort;
pub fn port_type(&self) -> arc::R<av::AudioSessionPort>;

#[objc::msg_send(portName)]
pub fn port_name(&self) -> &ns::String;
pub fn port_name(&self) -> arc::R<ns::String>;

#[objc::msg_send(UID)]
pub fn uid(&self) -> &ns::String;
pub fn uid(&self) -> arc::R<ns::String>;

/// This property's value will be true if the associated hardware port has built-in
/// processing for two-way voice communication.
Expand All @@ -206,16 +206,16 @@ impl PortDesc {
pub fn is_spatial_audio_enabled(&self) -> bool;

#[objc::msg_send(channels)]
pub fn channels(&self) -> Option<&ns::Array<ChannelDesc>>;
pub fn channels(&self) -> Option<arc::R<ns::Array<ChannelDesc>>>;

#[objc::msg_send(dataSources)]
pub fn data_srcs(&self) -> Option<&ns::Array<DataSrcDesc>>;
pub fn data_srcs(&self) -> Option<arc::R<ns::Array<DataSrcDesc>>>;

#[objc::msg_send(selectedDataSource)]
pub fn selected_data_src(&self) -> Option<&DataSrcDesc>;
pub fn selected_data_src(&self) -> Option<arc::R<DataSrcDesc>>;

#[objc::msg_send(preferredDataSource)]
pub fn preferred_data_src(&self) -> Option<&DataSrcDesc>;
pub fn preferred_data_src(&self) -> Option<arc::R<DataSrcDesc>>;

#[objc::msg_send(setPreferredDataSource:error:)]
pub unsafe fn set_preferred_data_src_err<'ear>(
Expand All @@ -236,8 +236,8 @@ define_obj_type!(

impl RouteDesc {
#[objc::msg_send(inputs)]
pub fn inputs(&self) -> &ns::Array<PortDesc>;
pub fn inputs(&self) -> arc::R<ns::Array<PortDesc>>;

#[objc::msg_send(outputs)]
pub fn outputs(&self) -> &ns::Array<PortDesc>;
pub fn outputs(&self) -> arc::R<ns::Array<PortDesc>>;
}
9 changes: 6 additions & 3 deletions cidre/src/mlc/layer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::{define_obj_type, mlc, ns, objc};
use crate::{arc, define_obj_type, mlc, ns, objc};

define_obj_type!(pub Layer(ns::Id));
define_obj_type!(
#[doc(alias = "MLCLayer")]
pub Layer(ns::Id)
);
impl Layer {
#[objc::msg_send(layerID)]
pub fn layer_id(&self) -> usize;

#[objc::msg_send(label)]
pub fn label(&self) -> &ns::String;
pub fn label(&self) -> arc::R<ns::String>;

#[objc::msg_send(setLabel:)]
pub fn set_label(&mut self, val: &ns::String);
Expand Down
6 changes: 3 additions & 3 deletions cidre/src/mlc/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ impl Tensor {
pub fn tensor_id(&self) -> usize;

#[objc::msg_send(descriptor)]
pub fn desc(&self) -> &mlc::TensorDesc;
pub fn desc(&self) -> arc::R<mlc::TensorDesc>;

#[objc::msg_send(data)]
pub fn data(&self) -> Option<&ns::Data>;
pub fn data(&self) -> Option<arc::R<ns::Data>>;

#[objc::msg_send(label)]
pub fn label(&self) -> &ns::String;
pub fn label(&self) -> arc::R<ns::String>;

#[objc::msg_send(setLabel:)]
pub fn set_label(&mut self, val: &ns::String);
Expand Down
5 changes: 4 additions & 1 deletion cidre/src/mtl/compute_command_encoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{define_mtl, define_obj_type, mtl, ns, objc};

define_obj_type!(pub ComputeCmdEncoder(mtl::CmdEncoder));
define_obj_type!(
#[doc(alias = "MTLComputeCommandEncoder")]
pub ComputeCmdEncoder(mtl::CmdEncoder)
);

impl ComputeCmdEncoder {
define_mtl!(
Expand Down
8 changes: 4 additions & 4 deletions cidre/src/ns/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ pub struct Range {

impl Range {
#[inline]
pub fn new(loc: ns::UInteger, len: ns::UInteger) -> Self {
pub const fn new(loc: ns::UInteger, len: ns::UInteger) -> Self {
Self { loc, len }
}

#[doc(alias = "NSMaxRange")]
#[inline]
pub fn max(&self) -> ns::UInteger {
pub const fn max(&self) -> ns::UInteger {
self.loc + self.len
}

Expand Down Expand Up @@ -46,7 +46,7 @@ impl Range {
/// ```
#[doc(alias = "NSLocationInRange")]
#[inline]
pub fn loc_in_range(location: ns::UInteger, range: &Self) -> bool {
pub const fn loc_in_range(location: ns::UInteger, range: &Self) -> bool {
location >= range.loc && (location - range.loc) < range.len
}

Expand All @@ -58,7 +58,7 @@ impl Range {
/// assert!(!a.contains(10));
/// ```
#[inline]
pub fn contains(&self, location: ns::UInteger) -> bool {
pub const fn contains(&self, location: ns::UInteger) -> bool {
Range::loc_in_range(location, self)
}
}
Expand Down

0 comments on commit 45ade32

Please sign in to comment.