Implement the Presence interface for the protocol
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -13,6 +13,7 @@ use padfoot::{
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
// TODO: move this to the ConnectionManager?
|
||||
fn run() -> Result<()> {
|
||||
let (cm, msg_r) = ConnectionManager::new();
|
||||
let cm_rc = std::rc::Rc::new(cm);
|
||||
@@ -24,7 +25,12 @@ fn run() -> Result<()> {
|
||||
let mut tree = f.tree(());
|
||||
|
||||
let cm_iface = telepathy::connection_manager_server(&f, (), move |_| cm_rc.clone());
|
||||
let proto_iface = telepathy::protocol_server(&f, (), move |_| proto_rc.clone());
|
||||
|
||||
let proto_rc_1 = proto_rc.clone();
|
||||
let proto_iface = telepathy::protocol_server(&f, (), move |_| proto_rc_1.clone());
|
||||
|
||||
let proto_presence_iface =
|
||||
telepathy::protocol_interface_presence_server(&f, (), move |_| proto_rc.clone());
|
||||
|
||||
tree = tree.add(
|
||||
f.object_path(CM_OBJECT_PATH, ())
|
||||
@@ -34,7 +40,8 @@ fn run() -> Result<()> {
|
||||
tree = tree.add(
|
||||
f.object_path(PROTO_OBJECT_PATH, ())
|
||||
.introspectable()
|
||||
.add(proto_iface),
|
||||
.add(proto_iface)
|
||||
.add(proto_presence_iface),
|
||||
);
|
||||
|
||||
tree = tree.add(f.object_path("/", ()).introspectable());
|
||||
|
@@ -1,3 +1,4 @@
|
||||
use crate::padfoot::{statuses, SimpleStatusSpec};
|
||||
use crate::telepathy;
|
||||
|
||||
use dbus::tree::MethodErr;
|
||||
@@ -11,12 +12,6 @@ pub type SimplePresenceSpec = (
|
||||
String, // status message
|
||||
);
|
||||
|
||||
pub type SimpleStatusSpec = (
|
||||
u32, // connection presence type
|
||||
bool, // may set on self?
|
||||
bool, // can have message?
|
||||
);
|
||||
|
||||
impl AsRef<dyn telepathy::ConnectionInterfaceSimplePresence + 'static> for std::rc::Rc<Connection> {
|
||||
fn as_ref(&self) -> &(dyn telepathy::ConnectionInterfaceSimplePresence + 'static) {
|
||||
&**self
|
||||
@@ -55,12 +50,7 @@ impl telepathy::ConnectionInterfaceSimplePresence for Connection {
|
||||
fn statuses(&self) -> Result<HashMap<String, SimpleStatusSpec>, MethodErr> {
|
||||
println!("Connection<{}>::statuses()", self.id());
|
||||
|
||||
let mut out = HashMap::<String, SimpleStatusSpec>::new();
|
||||
|
||||
out.insert("available".to_string(), (2, true, false));
|
||||
out.insert("offline".to_string(), (1, true, false));
|
||||
|
||||
Ok(out)
|
||||
Ok(statuses())
|
||||
}
|
||||
|
||||
fn maximum_status_message_length(&self) -> Result<u32, MethodErr> {
|
||||
|
@@ -54,6 +54,13 @@ pub fn parameters() -> Vec<ParamSpec> {
|
||||
]
|
||||
}
|
||||
|
||||
pub fn protocol_interfaces() -> Vec<String> {
|
||||
vec![
|
||||
"org.freedesktop.Telepathy.Protocol".to_string(),
|
||||
"org.freedesktop.Telepathy.Protocol.Interface.Presence".to_string(),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn requestables() -> Vec<RequestableChannelSpec> {
|
||||
let mut rf = HashMap::<String, Variant>::new();
|
||||
|
||||
@@ -101,7 +108,7 @@ impl telepathy::Protocol for Protocol {
|
||||
fn interfaces(&self) -> Result<Vec<String>, MethodErr> {
|
||||
println!("Protocol::interfaces()");
|
||||
|
||||
Ok(vec![])
|
||||
Ok(protocol_interfaces())
|
||||
}
|
||||
|
||||
fn parameters(&self) -> Result<Vec<ParamSpec>, MethodErr> {
|
||||
@@ -148,3 +155,32 @@ impl telepathy::Protocol for Protocol {
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
pub type SimpleStatusSpec = (
|
||||
u32, // connection presence type
|
||||
bool, // may set on self?
|
||||
bool, // can have message?
|
||||
);
|
||||
|
||||
pub fn statuses() -> HashMap<String, SimpleStatusSpec> {
|
||||
let mut out = HashMap::<String, SimpleStatusSpec>::new();
|
||||
|
||||
out.insert("available".to_string(), (2, true, false));
|
||||
out.insert("offline".to_string(), (1, true, false));
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
impl AsRef<dyn telepathy::ProtocolInterfacePresence + 'static> for std::rc::Rc<Protocol> {
|
||||
fn as_ref(&self) -> &(dyn telepathy::ProtocolInterfacePresence + 'static) {
|
||||
&**self
|
||||
}
|
||||
}
|
||||
|
||||
impl telepathy::ProtocolInterfacePresence for Protocol {
|
||||
fn statuses(&self) -> Result<HashMap<String, SimpleStatusSpec>, MethodErr> {
|
||||
println!("Protocol::presences()");
|
||||
|
||||
Ok(statuses())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user