11use crate :: error:: { Result , ResultExt , Error , ErrorKind , ErrorStr } ;
2- use crate :: device:: OpMode ;
2+ use crate :: device:: { Device , OpMode } ;
33
44use std:: rc:: Rc ;
55use std:: sync:: Arc ;
@@ -9,6 +9,7 @@ use slog::{Logger, debug};
99
1010use dbus:: { Connection , SignalArgs } ;
1111use dbus:: tree:: { MTFn , ObjectPath , Interface , Signal , Property , Access , EmitsChangedSignal } ;
12+ use dbus:: tree:: MethodErr ;
1213
1314use dbus_tokio:: AConnection ;
1415use dbus_tokio:: tree:: { ATree , AFactory , ATreeServer } ;
@@ -107,7 +108,7 @@ impl Service {
107108}
108109
109110
110- pub fn build ( log : Logger , connection : Rc < Connection > ) -> Result < Service > {
111+ pub fn build ( log : Logger , connection : Rc < Connection > , device : Rc < Device > ) -> Result < Service > {
111112 let factory = AFactory :: new_afn :: < ( ) > ( ) ;
112113
113114 connection. register_name ( "org.surface.dtx" , dbus:: NameFlag :: ReplaceExisting as u32 )
@@ -132,13 +133,22 @@ pub fn build(log: Logger, connection: Rc<Connection>) -> Result<Service> {
132133
133134 let device_mode = Arc :: new ( device_mode) ;
134135
136+ // request method
137+ let dtxreq = factory. method ( "Request" , ( ) , move |m| {
138+ match device. commands ( ) . latch_request ( ) {
139+ Ok ( ( ) ) => { Ok ( vec ! [ m. msg. method_return( ) ] ) } ,
140+ Err ( e) => { Err ( MethodErr :: failed ( & e) ) } ,
141+ }
142+ } ) ;
143+
135144 // interface
136145 let iface: Arc < _ > = factory. interface ( "org.surface.dtx" , ( ) )
146+ . add_m ( dtxreq)
137147 . add_s ( state_signal. clone ( ) )
138148 . add_p ( device_mode. clone ( ) )
139149 . into ( ) ;
140150
141- // interface
151+ // object
142152 let object: Arc < _ > = factory. object_path ( "/org/surface/dtx" , ( ) )
143153 . introspectable ( )
144154 . add ( iface. clone ( ) )
0 commit comments