22
33use std:: { ffi:: OsString , fmt, ops:: Deref , ptr} ;
44
5- use glib:: { prelude:: * , subclass:: prelude:: * , translate:: * , ExitCode , VariantDict } ;
5+ use glib:: { prelude:: * , subclass:: prelude:: * , translate:: * , Error , ExitCode , VariantDict } ;
66use libc:: { c_char, c_int, c_void} ;
77
8- use crate :: { ffi, Application } ;
8+ use crate :: { ffi, Application , DBusConnection } ;
99
1010pub struct ArgumentList {
1111 pub ( crate ) ptr : * mut * mut * mut c_char ,
@@ -108,6 +108,10 @@ pub trait ApplicationImpl: ObjectImpl + ApplicationImplExt {
108108 fn handle_local_options ( & self , options : & VariantDict ) -> ExitCode {
109109 self . parent_handle_local_options ( options)
110110 }
111+
112+ fn dbus_register ( & self , connection : & DBusConnection , object_path : & str ) -> Result < ( ) , Error > {
113+ self . parent_dbus_register ( connection, object_path)
114+ }
111115}
112116
113117mod sealed {
@@ -269,6 +273,33 @@ pub trait ApplicationImplExt: sealed::Sealed + ObjectSubclass {
269273 }
270274 }
271275 }
276+
277+ fn parent_dbus_register (
278+ & self ,
279+ connection : & DBusConnection ,
280+ object_path : & str ,
281+ ) -> Result < ( ) , glib:: Error > {
282+ unsafe {
283+ let data = Self :: type_data ( ) ;
284+ let parent_class = data. as_ref ( ) . parent_class ( ) as * mut ffi:: GApplicationClass ;
285+ let f = ( * parent_class)
286+ . dbus_register
287+ . expect ( "No parent class implementation for \" dbus_register\" " ) ;
288+ let mut err = ptr:: null_mut ( ) ;
289+ let res = f (
290+ self . obj ( ) . unsafe_cast_ref :: < Application > ( ) . to_glib_none ( ) . 0 ,
291+ connection. to_glib_none ( ) . 0 ,
292+ object_path. to_glib_none ( ) . 0 ,
293+ & mut err,
294+ ) ;
295+ if res == glib:: ffi:: GFALSE {
296+ Err ( from_glib_full ( err) )
297+ } else {
298+ debug_assert ! ( err. is_null( ) ) ;
299+ Ok ( ( ) )
300+ }
301+ }
302+ }
272303}
273304
274305impl < T : ApplicationImpl > ApplicationImplExt for T { }
@@ -289,6 +320,7 @@ unsafe impl<T: ApplicationImpl> IsSubclassable<T> for Application {
289320 klass. shutdown = Some ( application_shutdown :: < T > ) ;
290321 klass. startup = Some ( application_startup :: < T > ) ;
291322 klass. handle_local_options = Some ( application_handle_local_options :: < T > ) ;
323+ klass. dbus_register = Some ( application_dbus_register :: < T > )
292324 }
293325}
294326
@@ -393,6 +425,29 @@ unsafe extern "C" fn application_handle_local_options<T: ApplicationImpl>(
393425 imp. handle_local_options ( & from_glib_borrow ( options) ) . into ( )
394426}
395427
428+ unsafe extern "C" fn application_dbus_register < T : ApplicationImpl > (
429+ ptr : * mut ffi:: GApplication ,
430+ connection : * mut ffi:: GDBusConnection ,
431+ object_path : * const c_char ,
432+ error : * mut * mut glib:: ffi:: GError ,
433+ ) -> glib:: ffi:: gboolean {
434+ let instance = & * ( ptr as * mut T :: Instance ) ;
435+ let imp = instance. imp ( ) ;
436+
437+ match imp. dbus_register (
438+ & from_glib_borrow ( connection) ,
439+ & glib:: GString :: from_glib_borrow ( object_path) ,
440+ ) {
441+ Ok ( ( ) ) => glib:: ffi:: GTRUE ,
442+ Err ( e) => {
443+ if !error. is_null ( ) {
444+ * error = e. into_glib_ptr ( ) ;
445+ }
446+ glib:: ffi:: GFALSE
447+ }
448+ }
449+ }
450+
396451#[ cfg( test) ]
397452mod tests {
398453 use super :: * ;
0 commit comments