From 666ac09607f1bfdcb5d53d9ed0282bc50b4ea661 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Sun, 3 Sep 2023 09:23:28 -0600 Subject: [PATCH] Some basic structure. Added some structures, enums, etc. to hold the data we will need. Added an initialize_apis that only looks for config files so far. TODO: Use zbus to create our service, register the name, etc. to start. Decide on a config file format (maybe after getting some zbus details fleshed out and knowing better what will fit well) Add error messages and don't fail on errors, just log them. --- Cargo.toml | 2 ++ src/lib.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 11 +++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index f9b6be2..426079b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde = { version = "1.0.188", features = ["derive"] } +zbus = "3.14.1" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b2e06aa --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,57 @@ +use std::fs; +use std::{error::Error, future::pending}; +use serde::{Serialize, Deserialize}; +use zbus::{ConnectionBuilder, dbus_interface}; + +// We use s(teamos)m(anager) prefix on all types to help avoid conflicts + +// Types of api we support, so far only dbus and script. +// For dbus type we call into other dbus apis specified. +// For script type we run a script and provide stdout, stderr, and exitcode back. +#[derive(Serialize, Deserialize, Debug)] +pub enum SmApiType { + DBusType = 0, + ScriptType = 1, +} + +// SmDBusApi represents a dbus api to be called +// 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 +} + +// SmScript represents a script to be executed +#[derive(Serialize, Deserialize, Debug)] +pub struct SmScript { + path: String +} +// An SmOperation is what happens when an incoming dbus method is called. +// If the SmEntry type is DBusType this should be a DBusApi with the data neede. +// Otherwise it should be a script with the path to execute +#[derive(Serialize, Deserialize, Debug)] +pub enum SmOperation { + SmScript(String), + SmDbusApi(String, String, String) +} + +// Each api config file contains one or more entries. +#[derive(Serialize, Deserialize, Debug)] +pub struct SmEntry { + api_type: SmApiType, + incoming: SmDbusApi, // TBD: The incoming zbus method for this entry + outgoing: SmOperation, // TBD: Either the outgoing zbus method or a script to run +} + +pub fn initialize_apis(path: String) -> Vec:: +{ + let mut res = Vec::::new(); + for file in fs::read_dir(path).unwrap() { + // Deserialize the file and add all entries to res + + } + return res; +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b9899a8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,11 @@ +use steamos_manager::{self, SmEntry, initialize_apis}; + +fn main() { + // 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()); +}