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, ActionGroup , ActionMap , Application } ;
8+ use crate :: { ffi, ActionGroup , ActionMap , Application , DBusConnection } ;
99
1010pub struct ArgumentList {
1111 pub ( crate ) ptr : * mut * mut * mut c_char ,
@@ -110,6 +110,10 @@ pub trait ApplicationImpl:
110110 fn handle_local_options ( & self , options : & VariantDict ) -> ExitCode {
111111 self . parent_handle_local_options ( options)
112112 }
113+
114+ fn dbus_register ( & self , connection : & DBusConnection , object_path : & str ) -> Result < ( ) , Error > {
115+ self . parent_dbus_register ( connection, object_path)
116+ }
113117}
114118
115119pub trait ApplicationImplExt : ApplicationImpl {
@@ -266,6 +270,33 @@ pub trait ApplicationImplExt: ApplicationImpl {
266270 }
267271 }
268272 }
273+
274+ fn parent_dbus_register (
275+ & self ,
276+ connection : & DBusConnection ,
277+ object_path : & str ,
278+ ) -> Result < ( ) , glib:: Error > {
279+ unsafe {
280+ let data = Self :: type_data ( ) ;
281+ let parent_class = data. as_ref ( ) . parent_class ( ) as * mut ffi:: GApplicationClass ;
282+ let f = ( * parent_class)
283+ . dbus_register
284+ . expect ( "No parent class implementation for \" dbus_register\" " ) ;
285+ let mut err = ptr:: null_mut ( ) ;
286+ let res = f (
287+ self . obj ( ) . unsafe_cast_ref :: < Application > ( ) . to_glib_none ( ) . 0 ,
288+ connection. to_glib_none ( ) . 0 ,
289+ object_path. to_glib_none ( ) . 0 ,
290+ & mut err,
291+ ) ;
292+ if res == glib:: ffi:: GFALSE {
293+ debug_assert ! ( !err. is_null( ) ) ;
294+ Err ( from_glib_full ( err) )
295+ } else {
296+ Ok ( ( ) )
297+ }
298+ }
299+ }
269300}
270301
271302impl < T : ApplicationImpl > ApplicationImplExt for T { }
@@ -286,6 +317,7 @@ unsafe impl<T: ApplicationImpl> IsSubclassable<T> for Application {
286317 klass. shutdown = Some ( application_shutdown :: < T > ) ;
287318 klass. startup = Some ( application_startup :: < T > ) ;
288319 klass. handle_local_options = Some ( application_handle_local_options :: < T > ) ;
320+ klass. dbus_register = Some ( application_dbus_register :: < T > )
289321 }
290322}
291323
@@ -390,6 +422,29 @@ unsafe extern "C" fn application_handle_local_options<T: ApplicationImpl>(
390422 imp. handle_local_options ( & from_glib_borrow ( options) ) . into ( )
391423}
392424
425+ unsafe extern "C" fn application_dbus_register < T : ApplicationImpl > (
426+ ptr : * mut ffi:: GApplication ,
427+ connection : * mut ffi:: GDBusConnection ,
428+ object_path : * const c_char ,
429+ error : * mut * mut glib:: ffi:: GError ,
430+ ) -> glib:: ffi:: gboolean {
431+ let instance = & * ( ptr as * mut T :: Instance ) ;
432+ let imp = instance. imp ( ) ;
433+
434+ match imp. dbus_register (
435+ & from_glib_borrow ( connection) ,
436+ & glib:: GString :: from_glib_borrow ( object_path) ,
437+ ) {
438+ Ok ( ( ) ) => glib:: ffi:: GTRUE ,
439+ Err ( e) => {
440+ if !error. is_null ( ) {
441+ * error = e. into_glib_ptr ( ) ;
442+ }
443+ glib:: ffi:: GFALSE
444+ }
445+ }
446+ }
447+
393448#[ cfg( test) ]
394449mod tests {
395450 use super :: * ;
0 commit comments