Some actual progress

This commit is contained in:
Candifloss 2024-09-15 21:13:09 +05:30
parent 2d32e1612e
commit fb42d4affd

View File

@ -1,5 +1,5 @@
use zbus::{Connection, Result};
use futures_util::stream::TryStreamExt; use futures_util::stream::TryStreamExt;
use zbus::{Connection, Result};
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@ -11,22 +11,21 @@ async fn main() -> Result<()> {
let mut stream = zbus::MessageStream::from(&connection); // Convert connection to a MessageStream, yields Message items let mut stream = zbus::MessageStream::from(&connection); // Convert connection to a MessageStream, yields Message items
while let Some(msg) = stream.try_next().await? { while let Some(msg) = stream.try_next().await? {
println!("{}", msg); // Check if the message is a method call to the "Notify" method
let msg_header = msg.header(); if let Some(member) = msg.header().member().map(|m| m.as_str()) {
dbg!(&msg); if member == "GetServerInformation" {
println!("Member is: {}", member);
match msg_header.message_type() { // Respond with server information
zbus::message::Type::MethodCall => { let response = ("SNot", "candifloss.cc", "0.1.0", "1.0"); // (name, vendor, version, spec_version)
// real code would check msg_header path(), interface() and member() connection.reply(&msg, &response).await?;
// handle invalid calls, introspection, errors etc } else if member == "Notify" {
let body = msg.body(); println!("Member is: {}", member);
let arg: &str = body.deserialize()?; // Respond with a notification ID (usually a unique number)
println!("{}", arg); let notification_id: u32 = 1; // This could be incremented or generated
connection.reply(&msg, &(format!("Hello {}!", arg))).await?; connection.reply(&msg, &notification_id).await?;
} else {
// break; println!("Unhandled method: {}", member);
} }
_ => continue,
} }
} }