Skip to content

Commit

Permalink
wip: Add generic audio events
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Apr 3, 2024
1 parent 57febba commit 8b4735e
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/audio/audio_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct Volume {
value: u32,
}

pub trait TAudioObject {
pub trait TAudioObject: Arg + for<'z> Get<'z> + 'static {
fn alias(&self) -> String;
fn name(&self) -> String;
fn volume(&self) -> Vec<u32>;
Expand All @@ -38,7 +38,7 @@ pub trait TAudioObject {
fn active(&self) -> i32;
}

pub trait TAudioStreamObject {
pub trait TAudioStreamObject: Arg + for<'z> Get<'z> + 'static {
fn index(&self) -> u32;
fn name(&self) -> String;
fn application_name(&self) -> String;
Expand Down
156 changes: 155 additions & 1 deletion src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use dbus::{
};

use crate::{
audio::audio_structures::{InputStream, OutputStream, Sink, Source},
audio::audio_structures::{
InputStream, OutputStream, Sink, Source, TAudioObject, TAudioStreamObject,
},
bluetooth::bluetooth_structures::BluetoothDevice,
network::network_structures::{AccessPoint, WifiDevice},
utils::dbus_utils::{AUDIO, BLUETOOTH, WIRELESS},
Expand Down Expand Up @@ -290,6 +292,22 @@ impl dbus::message::SignalArgs for WifiDeviceReset {
const INTERFACE: &'static str = WIRELESS;
}

pub trait TAudioObjectEvent<AudioObject: TAudioObject> {
fn object(&self) -> AudioObject;
fn object_move(self) -> AudioObject;
fn object_ref(&self) -> &AudioObject;
}

pub trait TAudioStreamEvent<AudioStreamObject: TAudioStreamObject> {
fn stream(&self) -> AudioStreamObject;
fn stream_move(self) -> AudioStreamObject;
fn stream_ref(&self) -> &AudioStreamObject;
}

pub trait TAudioEventRemoved {
fn index(&self) -> u32;
}

#[derive(Debug)]
pub struct SinkAdded {
pub sink: Sink,
Expand Down Expand Up @@ -318,6 +336,20 @@ impl GetVal<(Sink,)> for SinkAdded {
}
}

impl TAudioObjectEvent<Sink> for SinkAdded {
fn object(&self) -> Sink {
self.sink.clone()
}

fn object_move(self) -> Sink {
self.sink
}

fn object_ref(&self) -> &Sink {
&self.sink
}
}

#[derive(Debug)]
pub struct SinkChanged {
pub sink: Sink,
Expand Down Expand Up @@ -346,6 +378,20 @@ impl GetVal<(Sink,)> for SinkChanged {
}
}

impl TAudioObjectEvent<Sink> for SinkChanged {
fn object(&self) -> Sink {
self.sink.clone()
}

fn object_move(self) -> Sink {
self.sink
}

fn object_ref(&self) -> &Sink {
&self.sink
}
}

#[derive(Debug)]
pub struct SinkRemoved {
pub index: u32,
Expand Down Expand Up @@ -374,6 +420,12 @@ impl GetVal<(u32,)> for SinkRemoved {
}
}

impl TAudioEventRemoved for SinkRemoved {
fn index(&self) -> u32 {
self.index
}
}

#[derive(Debug)]
pub struct InputStreamAdded {
pub stream: InputStream,
Expand Down Expand Up @@ -402,6 +454,20 @@ impl GetVal<(InputStream,)> for InputStreamAdded {
}
}

impl TAudioStreamEvent<InputStream> for InputStreamAdded {
fn stream(&self) -> InputStream {
self.stream.clone()
}

fn stream_move(self) -> InputStream {
self.stream
}

fn stream_ref(&self) -> &InputStream {
&self.stream
}
}

#[derive(Debug)]
pub struct InputStreamChanged {
pub stream: InputStream,
Expand All @@ -424,6 +490,20 @@ impl dbus::message::SignalArgs for InputStreamChanged {
const INTERFACE: &'static str = AUDIO;
}

impl TAudioStreamEvent<InputStream> for InputStreamChanged {
fn stream(&self) -> InputStream {
self.stream.clone()
}

fn stream_move(self) -> InputStream {
self.stream
}

fn stream_ref(&self) -> &InputStream {
&self.stream
}
}

#[derive(Debug)]
pub struct InputStreamRemoved {
pub index: u32,
Expand Down Expand Up @@ -452,6 +532,12 @@ impl GetVal<(u32,)> for InputStreamRemoved {
}
}

impl TAudioEventRemoved for InputStreamRemoved {
fn index(&self) -> u32 {
self.index
}
}

#[derive(Debug)]
pub struct SourceAdded {
pub source: Source,
Expand Down Expand Up @@ -480,6 +566,20 @@ impl GetVal<(Source,)> for SourceAdded {
}
}

impl TAudioObjectEvent<Source> for SourceAdded {
fn object(&self) -> Source {
self.source.clone()
}

fn object_move(self) -> Source {
self.source
}

fn object_ref(&self) -> &Source {
&self.source
}
}

#[derive(Debug)]
pub struct SourceChanged {
pub source: Source,
Expand Down Expand Up @@ -508,6 +608,20 @@ impl GetVal<(Source,)> for SourceChanged {
}
}

impl TAudioObjectEvent<Source> for SourceChanged {
fn object(&self) -> Source {
self.source.clone()
}

fn object_move(self) -> Source {
self.source
}

fn object_ref(&self) -> &Source {
&self.source
}
}

#[derive(Debug)]
pub struct SourceRemoved {
pub index: u32,
Expand Down Expand Up @@ -536,6 +650,12 @@ impl GetVal<(u32,)> for SourceRemoved {
}
}

impl TAudioEventRemoved for SourceRemoved {
fn index(&self) -> u32 {
self.index
}
}

#[derive(Debug)]
pub struct OutputStreamAdded {
pub stream: OutputStream,
Expand Down Expand Up @@ -564,6 +684,20 @@ impl GetVal<(OutputStream,)> for OutputStreamAdded {
}
}

impl TAudioStreamEvent<OutputStream> for OutputStreamAdded {
fn stream(&self) -> OutputStream {
self.stream.clone()
}

fn stream_move(self) -> OutputStream {
self.stream
}

fn stream_ref(&self) -> &OutputStream {
&self.stream
}
}

#[derive(Debug)]
pub struct OutputStreamChanged {
pub stream: OutputStream,
Expand All @@ -586,6 +720,20 @@ impl dbus::message::SignalArgs for OutputStreamChanged {
const INTERFACE: &'static str = AUDIO;
}

impl TAudioStreamEvent<OutputStream> for OutputStreamChanged {
fn stream(&self) -> OutputStream {
self.stream.clone()
}

fn stream_move(self) -> OutputStream {
self.stream
}

fn stream_ref(&self) -> &OutputStream {
&self.stream
}
}

#[derive(Debug)]
pub struct OutputStreamRemoved {
pub index: u32,
Expand Down Expand Up @@ -614,6 +762,12 @@ impl GetVal<(u32,)> for OutputStreamRemoved {
}
}

impl TAudioEventRemoved for OutputStreamRemoved {
fn index(&self) -> u32 {
self.index
}
}

#[derive(Debug)]
pub struct PropertiesChanged {
pub interface: String,
Expand Down

0 comments on commit 8b4735e

Please sign in to comment.