diff --git a/Cargo.toml b/Cargo.toml
index be88b73..0360eb6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,3 +9,4 @@ edition = "2021"
async-std = { version = "1.12.0", features = ["attributes"] }
serde = { version = "1.0.188", features = ["derive"] }
zbus = "3.14.1"
+zbus_macros = "3.14.1"
diff --git a/com.steampowered.SteamOSManager1.xml b/com.steampowered.SteamOSManager1.xml
new file mode 100644
index 0000000..58b55e8
--- /dev/null
+++ b/com.steampowered.SteamOSManager1.xml
@@ -0,0 +1,226 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/lib.rs b/src/lib.rs
index ed65eb2..760d179 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,19 +1,47 @@
-use std::{fs, io};
+/*
+ * Copyright © 2023 Collabora Ltd.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+use std::fs;
use std::{error::Error, future::pending};
use std::collections::HashMap;
+use std::convert::TryFrom;
use serde::{Serialize, Deserialize};
-use zbus::{Connection, ConnectionBuilder, Result, dbus_interface, zvariant::Value};
+use zbus::{Connection, ConnectionBuilder, Result, dbus_interface, zvariant::{from_slice, to_bytes, EncodingContext, Value}};
+
+pub mod manager;
// 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.
+// For SysFS type we manipulate sys fs values, on/off or setting a specific value
#[derive(Serialize, Deserialize, Debug)]
pub enum SmApiType {
- DBusType = 0,
ScriptType = 1,
+ SysFSType = 2,
}
// SmDBusApi represents a dbus api to be called
@@ -31,13 +59,21 @@ pub struct SmDbusApi {
pub struct SmScript {
path: String
}
+
+// SmSysfs represents a read/write to a sysfs path or paths
+#[derive(Serialize, Deserialize, Debug)]
+pub struct SmSysfs {
+ path: String,
+ // value: zbus::zvariant::Value<'a>
+}
// 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)
+ SmDbusApi(String, String, String),
+ // SmSysfs(String, zbus::zvariant::Value)
}
// Each api config file contains one or more entries.
@@ -48,12 +84,12 @@ pub struct SmEntry {
outgoing: SmOperation, // TBD: Either the outgoing zbus method or a script to run
}
-pub fn initialize_apis(path: String) -> Result<(Vec::)>
+pub fn initialize_apis(path: String) -> Result>
{
let res = Vec::::new();
- for file in fs::read_dir(path)? {
+ // for file in fs::read_dir(path)? {
// Deserialize the file and add SmEntry to res
- }
+ // }
return Ok(res);
}
@@ -61,10 +97,10 @@ pub fn create_dbus_apis(connection: zbus::Connection, entries: Vec::) -
{
// Create each of the given apis as dbus methods that users, etc.
// can use to call into us.
- for api in entries
- {
+ // for api in entries
+ // {
//
- }
+ // }
return true;
}
diff --git a/src/main.rs b/src/main.rs
index e921503..f5f8945 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,33 +1,48 @@
-use std::io::ErrorKind;
+/*
+ * Copyright © 2023 Collabora Ltd.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+use zbus::{ConnectionBuilder, Result};
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.
+ // level things. It implements com.steampowered.SteamOSManager1 interface
+
+ let manager = manager::SMManager {};
- 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);
- }
- }
+ let _system_connection = ConnectionBuilder::session()?
+ .name("com.steampowered.SteamOSManager1")?
+ .serve_at("/com/steampowered/SteamOSManager1", manager)?
+ .build()
+ .await?;
loop
{
-
+ std::future::pending::<()>().await;
}
}
diff --git a/src/manager.rs b/src/manager.rs
new file mode 100644
index 0000000..9a42c04
--- /dev/null
+++ b/src/manager.rs
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2023 Collabora Ltd.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+use zbus_macros::dbus_interface;
+use zbus::{ObjectServer, SignalContext, MessageHeader};
+pub struct SMManager {
+
+}
+
+#[dbus_interface(name = "com.steampowered.SteamOSManager1")]
+impl SMManager {
+ async fn say_hello(&self, name: &str) -> String {
+ format!("Hello {}!", name)
+ }
+}
+