2
2
3
3
use std:: { ffi:: OsString , fmt, ops:: Deref , ptr} ;
4
4
5
- use glib:: { prelude:: * , subclass:: prelude:: * , translate:: * , ExitCode , VariantDict } ;
5
+ use glib:: { prelude:: * , subclass:: prelude:: * , translate:: * , Error , ExitCode , VariantDict } ;
6
6
use libc:: { c_char, c_int, c_void} ;
7
7
8
- use crate :: { ffi, ActionGroup , ActionMap , Application } ;
8
+ use crate :: { ffi, ActionGroup , ActionMap , Application , DBusConnection } ;
9
9
10
10
pub struct ArgumentList {
11
11
pub ( crate ) ptr : * mut * mut * mut c_char ,
@@ -110,6 +110,10 @@ pub trait ApplicationImpl:
110
110
fn handle_local_options ( & self , options : & VariantDict ) -> ExitCode {
111
111
self . parent_handle_local_options ( options)
112
112
}
113
+
114
+ fn dbus_register ( & self , connection : & DBusConnection , object_path : & str ) -> Result < ( ) , Error > {
115
+ self . parent_dbus_register ( connection, object_path)
116
+ }
113
117
}
114
118
115
119
pub trait ApplicationImplExt : ApplicationImpl {
@@ -266,6 +270,33 @@ pub trait ApplicationImplExt: ApplicationImpl {
266
270
}
267
271
}
268
272
}
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
+ Err ( from_glib_full ( err) )
294
+ } else {
295
+ debug_assert ! ( err. is_null( ) ) ;
296
+ Ok ( ( ) )
297
+ }
298
+ }
299
+ }
269
300
}
270
301
271
302
impl < T : ApplicationImpl > ApplicationImplExt for T { }
@@ -286,6 +317,7 @@ unsafe impl<T: ApplicationImpl> IsSubclassable<T> for Application {
286
317
klass. shutdown = Some ( application_shutdown :: < T > ) ;
287
318
klass. startup = Some ( application_startup :: < T > ) ;
288
319
klass. handle_local_options = Some ( application_handle_local_options :: < T > ) ;
320
+ klass. dbus_register = Some ( application_dbus_register :: < T > )
289
321
}
290
322
}
291
323
@@ -390,6 +422,29 @@ unsafe extern "C" fn application_handle_local_options<T: ApplicationImpl>(
390
422
imp. handle_local_options ( & from_glib_borrow ( options) ) . into ( )
391
423
}
392
424
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
+
393
448
#[ cfg( test) ]
394
449
mod tests {
395
450
use super :: * ;
0 commit comments