More stuff implemented.

Use zbus to register the bus name.
Use async_std to get dbus session connection.
Added missing interface_name in SmDbusApi.
Removed parameters from SmDbusApi since those are passed, but not
kept with the method definition, etc.
This commit is contained in:
Jeremy Whiting 2023-09-05 13:09:05 -06:00
parent 666ac09607
commit f2133a5256
3 changed files with 52 additions and 16 deletions

View file

@ -6,5 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
serde = { version = "1.0.188", features = ["derive"] }
zbus = "3.14.1"

View file

@ -1,7 +1,9 @@
use std::fs;
use std::{fs, io};
use std::{error::Error, future::pending};
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use zbus::{ConnectionBuilder, dbus_interface};
use zbus::{Connection, ConnectionBuilder, Result, dbus_interface, zvariant::Value};
// We use s(teamos)m(anager) prefix on all types to help avoid conflicts
@ -18,10 +20,10 @@ pub enum SmApiType {
// TODO: This may change to better match what zbus needs.
#[derive(Serialize, Deserialize, Debug)]
pub struct SmDbusApi {
bus_name: String,
object_path: String,
method_name: String,
// parameters: Vec
bus_name: String, // The servcive name, i.e. org.freedesktop.Notifications
object_path: String, // The object path, i.e. /org/freedesktop/Notifications
interface_name: String, // The interface used i.e. org.freedesktop.Notifications
method_name: String // The method name, i.e. Notify
}
// SmScript represents a script to be executed
@ -46,12 +48,23 @@ pub struct SmEntry {
outgoing: SmOperation, // TBD: Either the outgoing zbus method or a script to run
}
pub fn initialize_apis(path: String) -> Vec::<SmEntry>
pub fn initialize_apis(path: String) -> Result<(Vec::<SmEntry>)>
{
let mut res = Vec::<SmEntry>::new();
for file in fs::read_dir(path).unwrap() {
// Deserialize the file and add all entries to res
let res = Vec::<SmEntry>::new();
for file in fs::read_dir(path)? {
// Deserialize the file and add SmEntry to res
}
return Ok(res);
}
pub fn create_dbus_apis(connection: zbus::Connection, entries: Vec::<SmEntry>) -> bool
{
// Create each of the given apis as dbus methods that users, etc.
// can use to call into us.
for api in entries
{
//
}
return res;
return true;
}

View file

@ -1,11 +1,33 @@
use steamos_manager::{self, SmEntry, initialize_apis};
use std::io::ErrorKind;
fn main() {
use steamos_manager::*;
use zbus::{Connection, Result};
#[async_std::main]
async fn main() -> Result<()>
{
// This daemon is responsible for creating a dbus api that steam client can use to do various OS
// level things (change brightness, etc.) In order to do that it reads a folder of dbus api
// configuration files and exposes each configuration with the api in the config file. In order
// to know what to do with each it gets the information from the same config file about whether
// to run a script or call some other dbus api.
let mut manager_apis: Vec<SmEntry> = initialize_apis("/usr/share/steamos-manager".to_string());
let session_connection = Connection::session().await?;
session_connection.request_name("com.steampowered.SteamOSManager").await?;
let result = initialize_apis("/usr/share/steamos-manager".to_string());
match result {
Ok(manager_apis) => {
let worked: bool = create_dbus_apis(session_connection, manager_apis);
}
Err(error) => {
println!("There was an error reading configuration files, doing nothing. {:?}", error);
}
}
loop
{
}
}