Skip to content

Commit

Permalink
fix(Extensions): update log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Dec 22, 2024
1 parent 211ac90 commit c9d6d13
Show file tree
Hide file tree
Showing 29 changed files with 255 additions and 145 deletions.
20 changes: 16 additions & 4 deletions extensions/core/src/bluetooth/bluez.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use adapter::BluetoothAdapter;
use device::BluetoothDevice;
use futures_util::stream::StreamExt;
use godot::{obj::WithBaseField, prelude::*};
use godot::{classes::Engine, obj::WithBaseField, prelude::*};
use zbus::fdo::ObjectManagerProxy;
use zbus::{fdo::ManagedObjects, names::BusName};

Expand Down Expand Up @@ -221,10 +221,23 @@ impl BluezInstance {
impl IResource for BluezInstance {
/// Called upon object initialization in the engine
fn init(base: Base<Self::Base>) -> Self {
log::info!("Initializing Bluez instance");
log::debug!("Initializing Bluez instance");

// Create a channel to communicate with the service
let (tx, rx) = channel();
let conn = get_dbus_system_blocking().ok();

// Don't run in the editor
let engine = Engine::singleton();
if engine.is_editor_hint() {
return Self {
base,
rx,
conn,
adapters: Default::default(),
devices: Default::default(),
};
}

// Spawn a task using the shared tokio runtime to listen for signals
RUNTIME.spawn(async move {
Expand All @@ -234,7 +247,6 @@ impl IResource for BluezInstance {
});

// Create a new Bluez instance
let conn = get_dbus_system_blocking().ok();
let mut instance = Self {
base,
rx,
Expand Down Expand Up @@ -276,7 +288,7 @@ impl IResource for BluezInstance {
/// Runs Bluez tasks in Tokio to listen for DBus signals and send them
/// over the given channel so they can be processed during each engine frame.
async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
log::info!("Spawning Bluez tasks");
log::debug!("Spawning Bluez tasks");
// Establish a connection to the system bus
let conn = get_dbus_system().await?;

Expand Down
4 changes: 2 additions & 2 deletions extensions/core/src/bluetooth/bluez/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl BluetoothAdapter {
/// Create a new [BluetoothAdapter] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
log::info!("BluetoothAdapter created with path: {path}");
log::debug!("BluetoothAdapter created with path: {path}");
let (tx, rx) = channel();
let dbus_path = path.clone().into();

Expand Down Expand Up @@ -176,7 +176,7 @@ impl BluetoothAdapter {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.as_str()) {
if let Some(res) = resource_loader.load(res_path.as_str()) {
log::info!("Resource already exists with path '{res_path}', loading that instead");
log::debug!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<BluetoothAdapter> = res.cast();
device
} else {
Expand Down
4 changes: 2 additions & 2 deletions extensions/core/src/bluetooth/bluez/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl BluetoothDevice {
/// Create a new [BluetoothDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
log::info!("BluetoothDevice created with path: {path}");
log::debug!("BluetoothDevice created with path: {path}");
let (tx, rx) = channel();
let dbus_path = path.clone().into();

Expand Down Expand Up @@ -173,7 +173,7 @@ impl BluetoothDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.as_str()) {
if let Some(res) = resource_loader.load(res_path.as_str()) {
log::info!("Resource already exists with path '{res_path}', loading that instead");
log::debug!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<BluetoothDevice> = res.cast();
device
} else {
Expand Down
131 changes: 97 additions & 34 deletions extensions/core/src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use zvariant::NoneValue;

pub mod bluez;
pub mod inputplumber;
pub mod networkmanager;
pub mod powerstation;
pub mod udisks2;
pub mod upower;
Expand All @@ -26,6 +27,68 @@ impl From<zbus::fdo::Error> for RunError {
}
}

/// Interface for converting DBus types -> Godot types
pub trait GodotVariant {
fn as_godot_variant(&self) -> Option<Variant>;
}

impl GodotVariant for zvariant::OwnedValue {
/// Convert the DBus variant type into a Godot variant type
fn as_godot_variant(&self) -> Option<Variant> {
let value = zvariant::Value::try_from(self).ok()?;
value.as_godot_variant()
}
}

impl<'a> GodotVariant for zvariant::Value<'a> {
/// Convert the DBus variant type into a Godot variant type
fn as_godot_variant(&self) -> Option<Variant> {
match self {
zvariant::Value::U8(value) => Some(value.to_variant()),
zvariant::Value::Bool(value) => Some(value.to_variant()),
zvariant::Value::I16(value) => Some(value.to_variant()),
zvariant::Value::U16(value) => Some(value.to_variant()),
zvariant::Value::I32(value) => Some(value.to_variant()),
zvariant::Value::U32(value) => Some(value.to_variant()),
zvariant::Value::I64(value) => Some(value.to_variant()),
zvariant::Value::U64(value) => Some(value.to_variant()),
zvariant::Value::F64(value) => Some(value.to_variant()),
zvariant::Value::Str(value) => Some(value.to_string().to_variant()),
zvariant::Value::Signature(_) => None,
zvariant::Value::ObjectPath(value) => Some(value.to_string().to_variant()),
zvariant::Value::Value(_) => None,
zvariant::Value::Array(value) => {
let mut arr = array![];
for item in value.iter() {
let Some(variant) = item.as_godot_variant() else {
continue;
};
arr.push(&variant);
}

Some(arr.to_variant())
}
zvariant::Value::Dict(value) => {
let mut dict = Dictionary::new();
for (key, val) in value.iter() {
let Some(key) = key.as_godot_variant() else {
continue;
};
let Some(val) = val.as_godot_variant() else {
continue;
};
dict.set(key, val);
}

Some(dict.to_variant())
}
zvariant::Value::Structure(_) => None,
zvariant::Value::Fd(_) => None,
}
}
}

/// Interface for converting Godot types -> DBus types
pub trait DBusVariant {
fn as_zvariant(&self) -> Option<zvariant::Value>;
}
Expand Down Expand Up @@ -55,44 +118,44 @@ impl DBusVariant for Variant {
let value: String = value.into();
Some(zvariant::Value::new(value))
}
VariantType::VECTOR2 => todo!(),
VariantType::VECTOR2I => todo!(),
VariantType::RECT2 => todo!(),
VariantType::RECT2I => todo!(),
VariantType::VECTOR3 => todo!(),
VariantType::VECTOR3I => todo!(),
VariantType::TRANSFORM2D => todo!(),
VariantType::VECTOR4 => todo!(),
VariantType::VECTOR4I => todo!(),
VariantType::PLANE => todo!(),
VariantType::QUATERNION => todo!(),
VariantType::AABB => todo!(),
VariantType::BASIS => todo!(),
VariantType::TRANSFORM3D => todo!(),
VariantType::PROJECTION => todo!(),
VariantType::COLOR => todo!(),
VariantType::STRING_NAME => todo!(),
VariantType::NODE_PATH => todo!(),
VariantType::VECTOR2 => None,
VariantType::VECTOR2I => None,
VariantType::RECT2 => None,
VariantType::RECT2I => None,
VariantType::VECTOR3 => None,
VariantType::VECTOR3I => None,
VariantType::TRANSFORM2D => None,
VariantType::VECTOR4 => None,
VariantType::VECTOR4I => None,
VariantType::PLANE => None,
VariantType::QUATERNION => None,
VariantType::AABB => None,
VariantType::BASIS => None,
VariantType::TRANSFORM3D => None,
VariantType::PROJECTION => None,
VariantType::COLOR => None,
VariantType::STRING_NAME => None,
VariantType::NODE_PATH => None,
VariantType::RID => {
let value: i64 = self.to();
Some(zvariant::Value::new(value))
}
VariantType::OBJECT => todo!(),
VariantType::CALLABLE => todo!(),
VariantType::SIGNAL => todo!(),
VariantType::DICTIONARY => todo!(),
VariantType::ARRAY => todo!(),
VariantType::PACKED_BYTE_ARRAY => todo!(),
VariantType::PACKED_INT32_ARRAY => todo!(),
VariantType::PACKED_INT64_ARRAY => todo!(),
VariantType::PACKED_FLOAT32_ARRAY => todo!(),
VariantType::PACKED_FLOAT64_ARRAY => todo!(),
VariantType::PACKED_STRING_ARRAY => todo!(),
VariantType::PACKED_VECTOR2_ARRAY => todo!(),
VariantType::PACKED_VECTOR3_ARRAY => todo!(),
VariantType::PACKED_COLOR_ARRAY => todo!(),
VariantType::PACKED_VECTOR4_ARRAY => todo!(),
VariantType::MAX => todo!(),
VariantType::OBJECT => None,
VariantType::CALLABLE => None,
VariantType::SIGNAL => None,
VariantType::DICTIONARY => None,
VariantType::ARRAY => None,
VariantType::PACKED_BYTE_ARRAY => None,
VariantType::PACKED_INT32_ARRAY => None,
VariantType::PACKED_INT64_ARRAY => None,
VariantType::PACKED_FLOAT32_ARRAY => None,
VariantType::PACKED_FLOAT64_ARRAY => None,
VariantType::PACKED_STRING_ARRAY => None,
VariantType::PACKED_VECTOR2_ARRAY => None,
VariantType::PACKED_VECTOR3_ARRAY => None,
VariantType::PACKED_COLOR_ARRAY => None,
VariantType::PACKED_VECTOR4_ARRAY => None,
VariantType::MAX => None,

// Unsupported conversion
_ => None,
Expand Down
30 changes: 22 additions & 8 deletions extensions/core/src/disk/udisks2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use block_device::BlockDevice;
use drive_device::DriveDevice;
use filesystem_device::FilesystemDevice;
use futures_util::stream::StreamExt;
use godot::{obj::WithBaseField, prelude::*};
use godot::{classes::Engine, obj::WithBaseField, prelude::*};
use partition_device::PartitionDevice;
use zbus::fdo::{ManagedObjects, ObjectManagerProxy};
use zbus::names::BusName;
Expand Down Expand Up @@ -174,17 +174,17 @@ impl UDisks2Instance {
let partitions = block_device.bind().get_partitions();
if partitions.is_empty() {
if !self.partition_devices.contains_key(dbus_path) {
log::info!(
log::debug!(
"Adding {dbus_path} as unprotected device. It is not a partition_devices"
);
unprotected_devices.push(block_device);
continue;
}
log::info!("Skipping {dbus_path}. It is a partition_device.");
log::debug!("Skipping {dbus_path}. It is a partition_device.");
} else {
for partition_device in partitions.iter_shared() {
let Some(filesystem_device) = partition_device.bind().get_filesystem() else {
log::info!(
log::debug!(
"Adding {dbus_path} as unprotected device. It does not have a FilesystemDevice"
);
unprotected_devices.push(block_device);
Expand All @@ -198,7 +198,7 @@ impl UDisks2Instance {
}
}
}
log::info!(
log::debug!(
"Adding {dbus_path} as unprotected device. It does not have any mounts in PROTECTED_MOUNTS"
);
unprotected_devices.push(block_device);
Expand Down Expand Up @@ -314,10 +314,25 @@ impl UDisks2Instance {
impl IResource for UDisks2Instance {
/// Called upon object initialization in the engine
fn init(base: Base<Self::Base>) -> Self {
log::info!("Initializing UDisks2 instance");
log::debug!("Initializing UDisks2 instance");

// Create a channel to communicate with the service
let (tx, rx) = channel();
let conn = get_dbus_system_blocking().ok();

// Don't run in the editor
let engine = Engine::singleton();
if engine.is_editor_hint() {
return Self {
base,
rx,
conn,
block_devices: Default::default(),
drive_devices: Default::default(),
partition_devices: Default::default(),
filesystem_devices: Default::default(),
};
}

// Spawn a task using the shared tokio runtime to listen for signals
RUNTIME.spawn(async move {
Expand All @@ -327,7 +342,6 @@ impl IResource for UDisks2Instance {
});

// Create a new UDisks2 instance
let conn = get_dbus_system_blocking().ok();
let mut instance = Self {
base,
rx,
Expand Down Expand Up @@ -382,7 +396,7 @@ impl IResource for UDisks2Instance {
/// Runs UDisks2 tasks in Tokio to listen for DBus signals and send them
/// over the given channel so they can be processed during each engine frame.
async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
log::info!("Spawning UDisks2 tasks");
log::debug!("Spawning UDisks2 tasks");
// Establish a connection to the system bus
let conn = get_dbus_system().await?;

Expand Down
4 changes: 2 additions & 2 deletions extensions/core/src/disk/udisks2/block_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl BlockDevice {
/// Create a new [BlockDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
log::info!("BlockDevice created with path: {path}");
log::debug!("BlockDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -87,7 +87,7 @@ impl BlockDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.as_str()) {
if let Some(res) = resource_loader.load(res_path.as_str()) {
log::info!("Resource already exists with path '{res_path}', loading that instead");
log::debug!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<BlockDevice> = res.cast();
device
} else {
Expand Down
4 changes: 2 additions & 2 deletions extensions/core/src/disk/udisks2/drive_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl DriveDevice {
/// Create a new [DriveDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
log::info!("DriveDevice created with path: {path}");
log::debug!("DriveDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -77,7 +77,7 @@ impl DriveDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.as_str()) {
if let Some(res) = resource_loader.load(res_path.as_str()) {
log::info!("Resource already exists with path '{res_path}', loading that instead");
log::debug!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<DriveDevice> = res.cast();
device
} else {
Expand Down
4 changes: 2 additions & 2 deletions extensions/core/src/disk/udisks2/filesystem_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl FilesystemDevice {
/// Create a new [FilesystemDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
log::info!("FilesystemDevice created with path: {path}");
log::debug!("FilesystemDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -64,7 +64,7 @@ impl FilesystemDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.as_str()) {
if let Some(res) = resource_loader.load(res_path.as_str()) {
log::info!("Resource already exists with path '{res_path}', loading that instead");
log::debug!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<FilesystemDevice> = res.cast();
device
} else {
Expand Down
4 changes: 2 additions & 2 deletions extensions/core/src/disk/udisks2/partition_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl PartitionDevice {
/// Create a new [PartitionDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
log::info!("PartitionDevice created with path: {path}");
log::debug!("PartitionDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -109,7 +109,7 @@ impl PartitionDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.as_str()) {
if let Some(res) = resource_loader.load(res_path.as_str()) {
log::info!("Resource already exists with path '{res_path}', loading that instead");
log::debug!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<PartitionDevice> = res.cast();
device
} else {
Expand Down
Loading

0 comments on commit c9d6d13

Please sign in to comment.