diff --git a/Cargo.toml b/Cargo.toml index 426079b..be88b73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index b2e06aa..ed65eb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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:: +pub fn initialize_apis(path: String) -> Result<(Vec::)> { - let mut res = Vec::::new(); - for file in fs::read_dir(path).unwrap() { - // Deserialize the file and add all entries to res - + let res = Vec::::new(); + for file in fs::read_dir(path)? { + // Deserialize the file and add SmEntry to res } - return res; -} \ No newline at end of file + return Ok(res); +} + +pub fn create_dbus_apis(connection: zbus::Connection, entries: Vec::) -> bool +{ + // Create each of the given apis as dbus methods that users, etc. + // can use to call into us. + for api in entries + { + // + + } + return true; +} diff --git a/src/main.rs b/src/main.rs index b9899a8..e921503 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = 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 + { + + } }