diff --git a/Cargo.toml b/Cargo.toml index b99f3a0..55fb73d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "re_set-lib" -version = "3.1.7" +version = "3.1.11" edition = "2021" description = "Data structure library for ReSet" repository = "https://github.com/Xetibo/ReSet-Lib" diff --git a/src/audio/audio_structures.rs b/src/audio/audio_structures.rs index 56c49f4..791634e 100644 --- a/src/audio/audio_structures.rs +++ b/src/audio/audio_structures.rs @@ -27,6 +27,29 @@ pub struct Volume { value: u32, } +pub trait TAudioObject: Arg + for<'z> Get<'z> + Send + Sync + 'static { + fn alias(&self) -> String; + fn name(&self) -> String; + fn volume(&self) -> Vec; + fn index(&self) -> u32; + fn channels(&self) -> u16; + fn muted(&self) -> bool; + fn toggle_muted(&mut self); + fn active(&self) -> i32; +} + +pub trait TAudioStreamObject: Arg + for<'z> Get<'z> + Send + Sync + 'static { + fn index(&self) -> u32; + fn name(&self) -> String; + fn application_name(&self) -> String; + fn audio_object_index(&self) -> u32; + fn channels(&self) -> u16; + fn volume(&self) -> Vec; + fn muted(&self) -> bool; + fn toggle_muted(&mut self); + fn corked(&self) -> bool; +} + impl Volume { pub fn from_i32(value: i32) -> Option { match value { @@ -170,6 +193,40 @@ impl From<&SourceInfo<'_>> for Source { } } +impl TAudioObject for Source { + fn alias(&self) -> String { + self.alias.clone() + } + + fn name(&self) -> String { + self.name.clone() + } + + fn volume(&self) -> Vec { + self.volume.clone() + } + + fn index(&self) -> u32 { + self.index + } + + fn channels(&self) -> u16 { + self.channels + } + + fn muted(&self) -> bool { + self.muted + } + + fn toggle_muted(&mut self) { + self.muted = !self.muted; + } + + fn active(&self) -> i32 { + self.active + } +} + #[derive(Debug, Clone, Default)] pub struct Sink { pub index: u32, @@ -250,6 +307,40 @@ impl From<&SinkInfo<'_>> for Sink { } } +impl TAudioObject for Sink { + fn alias(&self) -> String { + self.alias.clone() + } + + fn name(&self) -> String { + self.name.clone() + } + + fn volume(&self) -> Vec { + self.volume.clone() + } + + fn index(&self) -> u32 { + self.index + } + + fn channels(&self) -> u16 { + self.channels + } + + fn muted(&self) -> bool { + self.muted + } + + fn toggle_muted(&mut self) { + self.muted = !self.muted; + } + + fn active(&self) -> i32 { + self.active + } +} + #[derive(Debug, Clone, Default)] pub struct InputStream { pub index: u32, @@ -330,6 +421,44 @@ impl From<&SinkInputInfo<'_>> for InputStream { } } +impl TAudioStreamObject for InputStream { + fn index(&self) -> u32 { + self.index + } + + fn name(&self) -> String { + self.name.clone() + } + + fn application_name(&self) -> String { + self.application_name.clone() + } + + fn audio_object_index(&self) -> u32 { + self.index + } + + fn channels(&self) -> u16 { + self.channels + } + + fn volume(&self) -> Vec { + self.volume.clone() + } + + fn muted(&self) -> bool { + self.muted + } + + fn toggle_muted(&mut self) { + self.muted = !self.muted; + } + + fn corked(&self) -> bool { + self.corked + } +} + #[derive(Debug, Clone, Default)] pub struct OutputStream { pub index: u32, @@ -410,6 +539,44 @@ impl From<&SourceOutputInfo<'_>> for OutputStream { } } +impl TAudioStreamObject for OutputStream { + fn index(&self) -> u32 { + self.index + } + + fn name(&self) -> String { + self.name.clone() + } + + fn application_name(&self) -> String { + self.application_name.clone() + } + + fn audio_object_index(&self) -> u32 { + self.index + } + + fn channels(&self) -> u16 { + self.channels + } + + fn volume(&self) -> Vec { + self.volume.clone() + } + + fn muted(&self) -> bool { + self.muted + } + + fn toggle_muted(&mut self) { + self.muted = !self.muted; + } + + fn corked(&self) -> bool { + self.corked + } +} + #[derive(Debug, Clone, Default)] pub struct Card { pub index: u32, diff --git a/src/signals.rs b/src/signals.rs index 842d519..6d9fd11 100644 --- a/src/signals.rs +++ b/src/signals.rs @@ -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}, @@ -290,6 +292,22 @@ impl dbus::message::SignalArgs for WifiDeviceReset { const INTERFACE: &'static str = WIRELESS; } +pub trait TAudioObjectEvent: Send + Sync + 'static { + fn object(&self) -> AudioObject; + fn object_move(self) -> AudioObject; + fn object_ref(&self) -> &AudioObject; +} + +pub trait TAudioStreamEvent: Send + Sync + 'static { + fn stream(&self) -> AudioStreamObject; + fn stream_move(self) -> AudioStreamObject; + fn stream_ref(&self) -> &AudioStreamObject; +} + +pub trait TAudioEventRemoved: Send + Sync + 'static { + fn index(&self) -> u32; +} + #[derive(Debug)] pub struct SinkAdded { pub sink: Sink, @@ -318,6 +336,20 @@ impl GetVal<(Sink,)> for SinkAdded { } } +impl TAudioObjectEvent 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, @@ -346,6 +378,20 @@ impl GetVal<(Sink,)> for SinkChanged { } } +impl TAudioObjectEvent 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, @@ -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, @@ -402,6 +454,20 @@ impl GetVal<(InputStream,)> for InputStreamAdded { } } +impl TAudioStreamEvent 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, @@ -424,6 +490,20 @@ impl dbus::message::SignalArgs for InputStreamChanged { const INTERFACE: &'static str = AUDIO; } +impl TAudioStreamEvent 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, @@ -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, @@ -480,6 +566,20 @@ impl GetVal<(Source,)> for SourceAdded { } } +impl TAudioObjectEvent 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, @@ -508,6 +608,20 @@ impl GetVal<(Source,)> for SourceChanged { } } +impl TAudioObjectEvent 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, @@ -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, @@ -564,6 +684,20 @@ impl GetVal<(OutputStream,)> for OutputStreamAdded { } } +impl TAudioStreamEvent 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, @@ -586,6 +720,20 @@ impl dbus::message::SignalArgs for OutputStreamChanged { const INTERFACE: &'static str = AUDIO; } +impl TAudioStreamEvent 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, @@ -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, diff --git a/src/utils/plugin.rs b/src/utils/plugin.rs index 3280cb2..431c5a9 100644 --- a/src/utils/plugin.rs +++ b/src/utils/plugin.rs @@ -15,18 +15,22 @@ pub enum PluginImplementation { } #[repr(C)] -pub struct PluginCapabilities(Vec<&'static str>, PluginImplementation); +pub struct PluginCapabilities(Vec<&'static str>, bool, PluginImplementation); impl PluginCapabilities { - pub fn get_capabilities(&self) -> Vec<&'static str> { - self.0.clone() + pub fn get_capabilities(&self) -> (Vec<&'static str>, bool) { + (self.0.clone(), self.1) } pub fn get_implementation(&self) -> &PluginImplementation { - &self.1 + &self.2 } - pub fn new(capabilities: Vec<&'static str>, implementation: PluginImplementation) -> Self { - Self(capabilities, implementation) + pub fn new( + capabilities: Vec<&'static str>, + requires_backend: bool, + implementation: PluginImplementation, + ) -> Self { + Self(capabilities, requires_backend, implementation) } } diff --git a/src/utils/plugin_setup.rs b/src/utils/plugin_setup.rs index 200875c..69000ea 100644 --- a/src/utils/plugin_setup.rs +++ b/src/utils/plugin_setup.rs @@ -206,7 +206,7 @@ pub struct BackendPluginFunctions { #[allow(improper_ctypes_definitions)] impl BackendPluginFunctions { pub fn new( - capabilities: Vec<&'static str>, + capabilities: (Vec<&'static str>, bool), backend_startup: libloading::Symbol<'static, unsafe extern "C" fn()>, shutdown: libloading::Symbol<'static, unsafe extern "C" fn()>, name: libloading::Symbol<'static, unsafe extern "C" fn() -> String>, @@ -214,7 +214,7 @@ impl BackendPluginFunctions { tests: libloading::Symbol<'static, unsafe extern "C" fn() -> Vec>, ) -> Self { Self { - capabilities, + capabilities: capabilities.0, startup: backend_startup, shutdown, name, @@ -230,7 +230,7 @@ unsafe impl Sync for BackendPluginFunctions {} #[allow(improper_ctypes_definitions)] pub struct FrontendPluginFunctions { - pub capabilities: Vec<&'static str>, + pub capabilities: (Vec<&'static str>, bool), pub frontend_startup: libloading::Symbol<'static, unsafe extern "C" fn()>, pub frontend_shutdown: libloading::Symbol<'static, unsafe extern "C" fn()>, pub frontend_data: @@ -241,7 +241,7 @@ pub struct FrontendPluginFunctions { #[allow(improper_ctypes_definitions)] impl FrontendPluginFunctions { pub fn new( - capabilities: Vec<&'static str>, + capabilities: (Vec<&'static str>, bool), frontend_startup: libloading::Symbol<'static, unsafe extern "C" fn()>, frontend_shutdown: libloading::Symbol<'static, unsafe extern "C" fn()>, frontend_data: libloading::Symbol<