Rework to get a map of connections in ConnectionManager

This commit is contained in:
2020-05-10 19:04:14 +01:00
parent 04bf72637d
commit 6d79491e32
7 changed files with 175 additions and 40 deletions

53
src/padfoot/connection.rs Normal file
View File

@@ -0,0 +1,53 @@
use rand::Rng;
use std::collections::HashMap;
pub const CONN_BUS_NAME: &'static str = "org.freedesktop.Telepathy.Connection.padfoot.delta";
pub const CONN_OBJECT_PATH: &'static str = "org/freedesktop/Telepathy/Connection/padfoot/delta";
#[derive(Debug)]
pub struct Connection {
path: String,
account: String,
password: String,
}
impl Connection {
pub fn new(params: HashMap<&str, super::Variant>) -> Result<Self, dbus::tree::MethodErr> {
let err = Err(dbus::tree::MethodErr::no_arg());
// Generate a unique identifier for this connection
let id = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(16)
.collect::<String>();
let path = super::CONN_OBJECT_PATH.to_owned() + "/" + &id;
let acct = match params.get("account") {
Some(variant) => match variant.0.as_str() {
Some(str) => str.to_string(),
None => return err,
},
None => return err,
};
let password = match params.get("password") {
Some(variant) => match variant.0.as_str() {
Some(str) => str.to_string(),
None => return err,
},
None => return err,
};
Ok(Connection {
path: path,
account: acct,
password: password,
})
}
pub fn path(&self) -> String {
return self.path.to_owned();
}
}