polkit_rs/auto/
authority.rs

1// Generated by gir (https://github.com/gtk-rs/gir @ b2a1c6f9b362)
2// from ../misc (@ ???)
3// DO NOT EDIT
4
5use crate::{
6    ActionDescription, AuthorityFeatures, AuthorizationResult, CheckAuthorizationFlags, Details,
7    Identity, Subject, TemporaryAuthorization, ffi,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::{boxed::Box as Box_, pin::Pin};
16
17glib::wrapper! {
18    #[doc(alias = "PolkitAuthority")]
19    pub struct Authority(Object<ffi::PolkitAuthority, ffi::PolkitAuthorityClass>);
20
21    match fn {
22        type_ => || ffi::polkit_authority_get_type(),
23    }
24}
25
26impl Authority {
27    #[doc(alias = "polkit_authority_authentication_agent_response")]
28    pub fn authentication_agent_response<P: FnOnce(Result<(), glib::Error>) + 'static>(
29        &self,
30        cookie: &str,
31        identity: &impl IsA<Identity>,
32        cancellable: Option<&impl IsA<gio::Cancellable>>,
33        callback: P,
34    ) {
35        let main_context = glib::MainContext::ref_thread_default();
36        let is_main_context_owner = main_context.is_owner();
37        let has_acquired_main_context = (!is_main_context_owner)
38            .then(|| main_context.acquire().ok())
39            .flatten();
40        assert!(
41            is_main_context_owner || has_acquired_main_context.is_some(),
42            "Async operations only allowed if the thread is owning the MainContext"
43        );
44
45        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
46            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
47        unsafe extern "C" fn authentication_agent_response_trampoline<
48            P: FnOnce(Result<(), glib::Error>) + 'static,
49        >(
50            _source_object: *mut glib::gobject_ffi::GObject,
51            res: *mut gio::ffi::GAsyncResult,
52            user_data: glib::ffi::gpointer,
53        ) {
54            let mut error = std::ptr::null_mut();
55            unsafe {
56                ffi::polkit_authority_authentication_agent_response_finish(
57                    _source_object as *mut _,
58                    res,
59                    &mut error,
60                );
61
62                let result = if error.is_null() {
63                    Ok(())
64                } else {
65                    Err(from_glib_full(error))
66                };
67                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
68                    Box_::from_raw(user_data as *mut _);
69                let callback: P = callback.into_inner();
70                callback(result);
71            }
72        }
73        let callback = authentication_agent_response_trampoline::<P>;
74        unsafe {
75            ffi::polkit_authority_authentication_agent_response(
76                self.to_glib_none().0,
77                cookie.to_glib_none().0,
78                identity.as_ref().to_glib_none().0,
79                cancellable.map(|p| p.as_ref()).to_glib_none().0,
80                Some(callback),
81                Box_::into_raw(user_data) as *mut _,
82            );
83        }
84    }
85
86    pub fn authentication_agent_response_future(
87        &self,
88        cookie: &str,
89        identity: &(impl IsA<Identity> + Clone + 'static),
90    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
91        let cookie = String::from(cookie);
92        let identity = identity.clone();
93        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
94            obj.authentication_agent_response(&cookie, &identity, Some(cancellable), move |res| {
95                send.resolve(res);
96            });
97        }))
98    }
99
100    #[doc(alias = "polkit_authority_authentication_agent_response_sync")]
101    pub fn authentication_agent_response_sync(
102        &self,
103        cookie: &str,
104        identity: &impl IsA<Identity>,
105        cancellable: Option<&impl IsA<gio::Cancellable>>,
106    ) -> Result<(), glib::Error> {
107        unsafe {
108            let mut error = std::ptr::null_mut();
109            let is_ok = ffi::polkit_authority_authentication_agent_response_sync(
110                self.to_glib_none().0,
111                cookie.to_glib_none().0,
112                identity.as_ref().to_glib_none().0,
113                cancellable.map(|p| p.as_ref()).to_glib_none().0,
114                &mut error,
115            );
116            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
117            if error.is_null() {
118                Ok(())
119            } else {
120                Err(from_glib_full(error))
121            }
122        }
123    }
124
125    #[doc(alias = "polkit_authority_check_authorization")]
126    pub fn check_authorization<P: FnOnce(Result<AuthorizationResult, glib::Error>) + 'static>(
127        &self,
128        subject: &impl IsA<Subject>,
129        action_id: &str,
130        details: Option<&Details>,
131        flags: CheckAuthorizationFlags,
132        cancellable: Option<&impl IsA<gio::Cancellable>>,
133        callback: P,
134    ) {
135        let main_context = glib::MainContext::ref_thread_default();
136        let is_main_context_owner = main_context.is_owner();
137        let has_acquired_main_context = (!is_main_context_owner)
138            .then(|| main_context.acquire().ok())
139            .flatten();
140        assert!(
141            is_main_context_owner || has_acquired_main_context.is_some(),
142            "Async operations only allowed if the thread is owning the MainContext"
143        );
144
145        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
146            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
147        unsafe extern "C" fn check_authorization_trampoline<
148            P: FnOnce(Result<AuthorizationResult, glib::Error>) + 'static,
149        >(
150            _source_object: *mut glib::gobject_ffi::GObject,
151            res: *mut gio::ffi::GAsyncResult,
152            user_data: glib::ffi::gpointer,
153        ) {
154            unsafe {
155                let mut error = std::ptr::null_mut();
156                let ret = ffi::polkit_authority_check_authorization_finish(
157                    _source_object as *mut _,
158                    res,
159                    &mut error,
160                );
161                let result = if error.is_null() {
162                    Ok(from_glib_full(ret))
163                } else {
164                    Err(from_glib_full(error))
165                };
166                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
167                    Box_::from_raw(user_data as *mut _);
168                let callback: P = callback.into_inner();
169                callback(result);
170            }
171        }
172        let callback = check_authorization_trampoline::<P>;
173        unsafe {
174            ffi::polkit_authority_check_authorization(
175                self.to_glib_none().0,
176                subject.as_ref().to_glib_none().0,
177                action_id.to_glib_none().0,
178                details.to_glib_none().0,
179                flags.into_glib(),
180                cancellable.map(|p| p.as_ref()).to_glib_none().0,
181                Some(callback),
182                Box_::into_raw(user_data) as *mut _,
183            );
184        }
185    }
186
187    pub fn check_authorization_future(
188        &self,
189        subject: &(impl IsA<Subject> + Clone + 'static),
190        action_id: &str,
191        details: Option<&Details>,
192        flags: CheckAuthorizationFlags,
193    ) -> Pin<
194        Box_<dyn std::future::Future<Output = Result<AuthorizationResult, glib::Error>> + 'static>,
195    > {
196        let subject = subject.clone();
197        let action_id = String::from(action_id);
198        let details = details.map(ToOwned::to_owned);
199        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
200            obj.check_authorization(
201                &subject,
202                &action_id,
203                details.as_ref().map(::std::borrow::Borrow::borrow),
204                flags,
205                Some(cancellable),
206                move |res| {
207                    send.resolve(res);
208                },
209            );
210        }))
211    }
212
213    #[doc(alias = "polkit_authority_check_authorization_sync")]
214    pub fn check_authorization_sync(
215        &self,
216        subject: &impl IsA<Subject>,
217        action_id: &str,
218        details: Option<&Details>,
219        flags: CheckAuthorizationFlags,
220        cancellable: Option<&impl IsA<gio::Cancellable>>,
221    ) -> Result<AuthorizationResult, glib::Error> {
222        unsafe {
223            let mut error = std::ptr::null_mut();
224            let ret = ffi::polkit_authority_check_authorization_sync(
225                self.to_glib_none().0,
226                subject.as_ref().to_glib_none().0,
227                action_id.to_glib_none().0,
228                details.to_glib_none().0,
229                flags.into_glib(),
230                cancellable.map(|p| p.as_ref()).to_glib_none().0,
231                &mut error,
232            );
233            if error.is_null() {
234                Ok(from_glib_full(ret))
235            } else {
236                Err(from_glib_full(error))
237            }
238        }
239    }
240
241    #[doc(alias = "polkit_authority_enumerate_actions")]
242    pub fn enumerate_actions<P: FnOnce(Result<Vec<ActionDescription>, glib::Error>) + 'static>(
243        &self,
244        cancellable: Option<&impl IsA<gio::Cancellable>>,
245        callback: P,
246    ) {
247        let main_context = glib::MainContext::ref_thread_default();
248        let is_main_context_owner = main_context.is_owner();
249        let has_acquired_main_context = (!is_main_context_owner)
250            .then(|| main_context.acquire().ok())
251            .flatten();
252        assert!(
253            is_main_context_owner || has_acquired_main_context.is_some(),
254            "Async operations only allowed if the thread is owning the MainContext"
255        );
256
257        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
258            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
259        unsafe extern "C" fn enumerate_actions_trampoline<
260            P: FnOnce(Result<Vec<ActionDescription>, glib::Error>) + 'static,
261        >(
262            _source_object: *mut glib::gobject_ffi::GObject,
263            res: *mut gio::ffi::GAsyncResult,
264            user_data: glib::ffi::gpointer,
265        ) {
266            unsafe {
267                let mut error = std::ptr::null_mut();
268                let ret = ffi::polkit_authority_enumerate_actions_finish(
269                    _source_object as *mut _,
270                    res,
271                    &mut error,
272                );
273                let result = if error.is_null() {
274                    Ok(FromGlibPtrContainer::from_glib_full(ret))
275                } else {
276                    Err(from_glib_full(error))
277                };
278                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
279                    Box_::from_raw(user_data as *mut _);
280                let callback: P = callback.into_inner();
281                callback(result);
282            }
283        }
284        let callback = enumerate_actions_trampoline::<P>;
285        unsafe {
286            ffi::polkit_authority_enumerate_actions(
287                self.to_glib_none().0,
288                cancellable.map(|p| p.as_ref()).to_glib_none().0,
289                Some(callback),
290                Box_::into_raw(user_data) as *mut _,
291            );
292        }
293    }
294
295    pub fn enumerate_actions_future(
296        &self,
297    ) -> Pin<
298        Box_<
299            dyn std::future::Future<Output = Result<Vec<ActionDescription>, glib::Error>> + 'static,
300        >,
301    > {
302        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
303            obj.enumerate_actions(Some(cancellable), move |res| {
304                send.resolve(res);
305            });
306        }))
307    }
308
309    #[doc(alias = "polkit_authority_enumerate_actions_sync")]
310    pub fn enumerate_actions_sync(
311        &self,
312        cancellable: Option<&impl IsA<gio::Cancellable>>,
313    ) -> Result<Vec<ActionDescription>, glib::Error> {
314        unsafe {
315            let mut error = std::ptr::null_mut();
316            let ret = ffi::polkit_authority_enumerate_actions_sync(
317                self.to_glib_none().0,
318                cancellable.map(|p| p.as_ref()).to_glib_none().0,
319                &mut error,
320            );
321            if error.is_null() {
322                Ok(FromGlibPtrContainer::from_glib_full(ret))
323            } else {
324                Err(from_glib_full(error))
325            }
326        }
327    }
328
329    #[doc(alias = "polkit_authority_enumerate_temporary_authorizations")]
330    pub fn enumerate_temporary_authorizations<
331        P: FnOnce(Result<Vec<TemporaryAuthorization>, glib::Error>) + 'static,
332    >(
333        &self,
334        subject: &impl IsA<Subject>,
335        cancellable: Option<&impl IsA<gio::Cancellable>>,
336        callback: P,
337    ) {
338        let main_context = glib::MainContext::ref_thread_default();
339        let is_main_context_owner = main_context.is_owner();
340        let has_acquired_main_context = (!is_main_context_owner)
341            .then(|| main_context.acquire().ok())
342            .flatten();
343        assert!(
344            is_main_context_owner || has_acquired_main_context.is_some(),
345            "Async operations only allowed if the thread is owning the MainContext"
346        );
347
348        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
349            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
350        unsafe extern "C" fn enumerate_temporary_authorizations_trampoline<
351            P: FnOnce(Result<Vec<TemporaryAuthorization>, glib::Error>) + 'static,
352        >(
353            _source_object: *mut glib::gobject_ffi::GObject,
354            res: *mut gio::ffi::GAsyncResult,
355            user_data: glib::ffi::gpointer,
356        ) {
357            unsafe {
358                let mut error = std::ptr::null_mut();
359                let ret = ffi::polkit_authority_enumerate_temporary_authorizations_finish(
360                    _source_object as *mut _,
361                    res,
362                    &mut error,
363                );
364                let result = if error.is_null() {
365                    Ok(FromGlibPtrContainer::from_glib_full(ret))
366                } else {
367                    Err(from_glib_full(error))
368                };
369                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
370                    Box_::from_raw(user_data as *mut _);
371                let callback: P = callback.into_inner();
372                callback(result);
373            }
374        }
375        let callback = enumerate_temporary_authorizations_trampoline::<P>;
376        unsafe {
377            ffi::polkit_authority_enumerate_temporary_authorizations(
378                self.to_glib_none().0,
379                subject.as_ref().to_glib_none().0,
380                cancellable.map(|p| p.as_ref()).to_glib_none().0,
381                Some(callback),
382                Box_::into_raw(user_data) as *mut _,
383            );
384        }
385    }
386
387    pub fn enumerate_temporary_authorizations_future(
388        &self,
389        subject: &(impl IsA<Subject> + Clone + 'static),
390    ) -> Pin<
391        Box_<
392            dyn std::future::Future<Output = Result<Vec<TemporaryAuthorization>, glib::Error>>
393                + 'static,
394        >,
395    > {
396        let subject = subject.clone();
397        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
398            obj.enumerate_temporary_authorizations(&subject, Some(cancellable), move |res| {
399                send.resolve(res);
400            });
401        }))
402    }
403
404    #[doc(alias = "polkit_authority_enumerate_temporary_authorizations_sync")]
405    pub fn enumerate_temporary_authorizations_sync(
406        &self,
407        subject: &impl IsA<Subject>,
408        cancellable: Option<&impl IsA<gio::Cancellable>>,
409    ) -> Result<Vec<TemporaryAuthorization>, glib::Error> {
410        unsafe {
411            let mut error = std::ptr::null_mut();
412            let ret = ffi::polkit_authority_enumerate_temporary_authorizations_sync(
413                self.to_glib_none().0,
414                subject.as_ref().to_glib_none().0,
415                cancellable.map(|p| p.as_ref()).to_glib_none().0,
416                &mut error,
417            );
418            if error.is_null() {
419                Ok(FromGlibPtrContainer::from_glib_full(ret))
420            } else {
421                Err(from_glib_full(error))
422            }
423        }
424    }
425
426    #[doc(alias = "polkit_authority_get_backend_features")]
427    #[doc(alias = "get_backend_features")]
428    #[doc(alias = "backend-features")]
429    pub fn backend_features(&self) -> AuthorityFeatures {
430        unsafe {
431            from_glib(ffi::polkit_authority_get_backend_features(
432                self.to_glib_none().0,
433            ))
434        }
435    }
436
437    #[doc(alias = "polkit_authority_get_backend_name")]
438    #[doc(alias = "get_backend_name")]
439    #[doc(alias = "backend-name")]
440    pub fn backend_name(&self) -> glib::GString {
441        unsafe {
442            from_glib_none(ffi::polkit_authority_get_backend_name(
443                self.to_glib_none().0,
444            ))
445        }
446    }
447
448    #[doc(alias = "polkit_authority_get_backend_version")]
449    #[doc(alias = "get_backend_version")]
450    #[doc(alias = "backend-version")]
451    pub fn backend_version(&self) -> glib::GString {
452        unsafe {
453            from_glib_none(ffi::polkit_authority_get_backend_version(
454                self.to_glib_none().0,
455            ))
456        }
457    }
458
459    #[doc(alias = "polkit_authority_get_owner")]
460    #[doc(alias = "get_owner")]
461    pub fn owner(&self) -> Option<glib::GString> {
462        unsafe { from_glib_full(ffi::polkit_authority_get_owner(self.to_glib_none().0)) }
463    }
464
465    #[doc(alias = "polkit_authority_register_authentication_agent")]
466    pub fn register_authentication_agent<P: FnOnce(Result<(), glib::Error>) + 'static>(
467        &self,
468        subject: &impl IsA<Subject>,
469        locale: &str,
470        object_path: &str,
471        cancellable: Option<&impl IsA<gio::Cancellable>>,
472        callback: P,
473    ) {
474        let main_context = glib::MainContext::ref_thread_default();
475        let is_main_context_owner = main_context.is_owner();
476        let has_acquired_main_context = (!is_main_context_owner)
477            .then(|| main_context.acquire().ok())
478            .flatten();
479        assert!(
480            is_main_context_owner || has_acquired_main_context.is_some(),
481            "Async operations only allowed if the thread is owning the MainContext"
482        );
483
484        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
485            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
486        unsafe extern "C" fn register_authentication_agent_trampoline<
487            P: FnOnce(Result<(), glib::Error>) + 'static,
488        >(
489            _source_object: *mut glib::gobject_ffi::GObject,
490            res: *mut gio::ffi::GAsyncResult,
491            user_data: glib::ffi::gpointer,
492        ) {
493            unsafe {
494                let mut error = std::ptr::null_mut();
495                ffi::polkit_authority_register_authentication_agent_finish(
496                    _source_object as *mut _,
497                    res,
498                    &mut error,
499                );
500                let result = if error.is_null() {
501                    Ok(())
502                } else {
503                    Err(from_glib_full(error))
504                };
505                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
506                    Box_::from_raw(user_data as *mut _);
507                let callback: P = callback.into_inner();
508                callback(result);
509            }
510        }
511        let callback = register_authentication_agent_trampoline::<P>;
512        unsafe {
513            ffi::polkit_authority_register_authentication_agent(
514                self.to_glib_none().0,
515                subject.as_ref().to_glib_none().0,
516                locale.to_glib_none().0,
517                object_path.to_glib_none().0,
518                cancellable.map(|p| p.as_ref()).to_glib_none().0,
519                Some(callback),
520                Box_::into_raw(user_data) as *mut _,
521            );
522        }
523    }
524
525    pub fn register_authentication_agent_future(
526        &self,
527        subject: &(impl IsA<Subject> + Clone + 'static),
528        locale: &str,
529        object_path: &str,
530    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
531        let subject = subject.clone();
532        let locale = String::from(locale);
533        let object_path = String::from(object_path);
534        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
535            obj.register_authentication_agent(
536                &subject,
537                &locale,
538                &object_path,
539                Some(cancellable),
540                move |res| {
541                    send.resolve(res);
542                },
543            );
544        }))
545    }
546
547    #[doc(alias = "polkit_authority_register_authentication_agent_sync")]
548    pub fn register_authentication_agent_sync(
549        &self,
550        subject: &impl IsA<Subject>,
551        locale: &str,
552        object_path: &str,
553        cancellable: Option<&impl IsA<gio::Cancellable>>,
554    ) -> Result<(), glib::Error> {
555        unsafe {
556            let mut error = std::ptr::null_mut();
557            let is_ok = ffi::polkit_authority_register_authentication_agent_sync(
558                self.to_glib_none().0,
559                subject.as_ref().to_glib_none().0,
560                locale.to_glib_none().0,
561                object_path.to_glib_none().0,
562                cancellable.map(|p| p.as_ref()).to_glib_none().0,
563                &mut error,
564            );
565            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
566            if error.is_null() {
567                Ok(())
568            } else {
569                Err(from_glib_full(error))
570            }
571        }
572    }
573
574    #[doc(alias = "polkit_authority_register_authentication_agent_with_options")]
575    pub fn register_authentication_agent_with_options<
576        P: FnOnce(Result<(), glib::Error>) + 'static,
577    >(
578        &self,
579        subject: &impl IsA<Subject>,
580        locale: &str,
581        object_path: &str,
582        options: Option<&glib::Variant>,
583        cancellable: Option<&impl IsA<gio::Cancellable>>,
584        callback: P,
585    ) {
586        let main_context = glib::MainContext::ref_thread_default();
587        let is_main_context_owner = main_context.is_owner();
588        let has_acquired_main_context = (!is_main_context_owner)
589            .then(|| main_context.acquire().ok())
590            .flatten();
591        assert!(
592            is_main_context_owner || has_acquired_main_context.is_some(),
593            "Async operations only allowed if the thread is owning the MainContext"
594        );
595
596        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
597            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
598        unsafe extern "C" fn register_authentication_agent_with_options_trampoline<
599            P: FnOnce(Result<(), glib::Error>) + 'static,
600        >(
601            _source_object: *mut glib::gobject_ffi::GObject,
602            res: *mut gio::ffi::GAsyncResult,
603            user_data: glib::ffi::gpointer,
604        ) {
605            unsafe {
606                let mut error = std::ptr::null_mut();
607                ffi::polkit_authority_register_authentication_agent_with_options_finish(
608                    _source_object as *mut _,
609                    res,
610                    &mut error,
611                );
612                let result = if error.is_null() {
613                    Ok(())
614                } else {
615                    Err(from_glib_full(error))
616                };
617                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
618                    Box_::from_raw(user_data as *mut _);
619                let callback: P = callback.into_inner();
620                callback(result);
621            }
622        }
623        let callback = register_authentication_agent_with_options_trampoline::<P>;
624        unsafe {
625            ffi::polkit_authority_register_authentication_agent_with_options(
626                self.to_glib_none().0,
627                subject.as_ref().to_glib_none().0,
628                locale.to_glib_none().0,
629                object_path.to_glib_none().0,
630                options.to_glib_none().0,
631                cancellable.map(|p| p.as_ref()).to_glib_none().0,
632                Some(callback),
633                Box_::into_raw(user_data) as *mut _,
634            );
635        }
636    }
637
638    pub fn register_authentication_agent_with_options_future(
639        &self,
640        subject: &(impl IsA<Subject> + Clone + 'static),
641        locale: &str,
642        object_path: &str,
643        options: Option<&glib::Variant>,
644    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
645        let subject = subject.clone();
646        let locale = String::from(locale);
647        let object_path = String::from(object_path);
648        let options = options.map(ToOwned::to_owned);
649        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
650            obj.register_authentication_agent_with_options(
651                &subject,
652                &locale,
653                &object_path,
654                options.as_ref().map(::std::borrow::Borrow::borrow),
655                Some(cancellable),
656                move |res| {
657                    send.resolve(res);
658                },
659            );
660        }))
661    }
662
663    #[doc(alias = "polkit_authority_register_authentication_agent_with_options_sync")]
664    pub fn register_authentication_agent_with_options_sync(
665        &self,
666        subject: &impl IsA<Subject>,
667        locale: &str,
668        object_path: &str,
669        options: Option<&glib::Variant>,
670        cancellable: Option<&impl IsA<gio::Cancellable>>,
671    ) -> Result<(), glib::Error> {
672        unsafe {
673            let mut error = std::ptr::null_mut();
674            let is_ok = ffi::polkit_authority_register_authentication_agent_with_options_sync(
675                self.to_glib_none().0,
676                subject.as_ref().to_glib_none().0,
677                locale.to_glib_none().0,
678                object_path.to_glib_none().0,
679                options.to_glib_none().0,
680                cancellable.map(|p| p.as_ref()).to_glib_none().0,
681                &mut error,
682            );
683            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
684            if error.is_null() {
685                Ok(())
686            } else {
687                Err(from_glib_full(error))
688            }
689        }
690    }
691
692    #[doc(alias = "polkit_authority_revoke_temporary_authorization_by_id")]
693    pub fn revoke_temporary_authorization_by_id<P: FnOnce(Result<(), glib::Error>) + 'static>(
694        &self,
695        id: &str,
696        cancellable: Option<&impl IsA<gio::Cancellable>>,
697        callback: P,
698    ) {
699        let main_context = glib::MainContext::ref_thread_default();
700        let is_main_context_owner = main_context.is_owner();
701        let has_acquired_main_context = (!is_main_context_owner)
702            .then(|| main_context.acquire().ok())
703            .flatten();
704        assert!(
705            is_main_context_owner || has_acquired_main_context.is_some(),
706            "Async operations only allowed if the thread is owning the MainContext"
707        );
708
709        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
710            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
711        unsafe extern "C" fn revoke_temporary_authorization_by_id_trampoline<
712            P: FnOnce(Result<(), glib::Error>) + 'static,
713        >(
714            _source_object: *mut glib::gobject_ffi::GObject,
715            res: *mut gio::ffi::GAsyncResult,
716            user_data: glib::ffi::gpointer,
717        ) {
718            unsafe {
719                let mut error = std::ptr::null_mut();
720                ffi::polkit_authority_revoke_temporary_authorization_by_id_finish(
721                    _source_object as *mut _,
722                    res,
723                    &mut error,
724                );
725                let result = if error.is_null() {
726                    Ok(())
727                } else {
728                    Err(from_glib_full(error))
729                };
730                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
731                    Box_::from_raw(user_data as *mut _);
732                let callback: P = callback.into_inner();
733                callback(result);
734            }
735        }
736        let callback = revoke_temporary_authorization_by_id_trampoline::<P>;
737        unsafe {
738            ffi::polkit_authority_revoke_temporary_authorization_by_id(
739                self.to_glib_none().0,
740                id.to_glib_none().0,
741                cancellable.map(|p| p.as_ref()).to_glib_none().0,
742                Some(callback),
743                Box_::into_raw(user_data) as *mut _,
744            );
745        }
746    }
747
748    pub fn revoke_temporary_authorization_by_id_future(
749        &self,
750        id: &str,
751    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
752        let id = String::from(id);
753        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
754            obj.revoke_temporary_authorization_by_id(&id, Some(cancellable), move |res| {
755                send.resolve(res);
756            });
757        }))
758    }
759
760    #[doc(alias = "polkit_authority_revoke_temporary_authorization_by_id_sync")]
761    pub fn revoke_temporary_authorization_by_id_sync(
762        &self,
763        id: &str,
764        cancellable: Option<&impl IsA<gio::Cancellable>>,
765    ) -> Result<(), glib::Error> {
766        unsafe {
767            let mut error = std::ptr::null_mut();
768            let is_ok = ffi::polkit_authority_revoke_temporary_authorization_by_id_sync(
769                self.to_glib_none().0,
770                id.to_glib_none().0,
771                cancellable.map(|p| p.as_ref()).to_glib_none().0,
772                &mut error,
773            );
774            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
775            if error.is_null() {
776                Ok(())
777            } else {
778                Err(from_glib_full(error))
779            }
780        }
781    }
782
783    #[doc(alias = "polkit_authority_revoke_temporary_authorizations")]
784    pub fn revoke_temporary_authorizations<P: FnOnce(Result<(), glib::Error>) + 'static>(
785        &self,
786        subject: &impl IsA<Subject>,
787        cancellable: Option<&impl IsA<gio::Cancellable>>,
788        callback: P,
789    ) {
790        let main_context = glib::MainContext::ref_thread_default();
791        let is_main_context_owner = main_context.is_owner();
792        let has_acquired_main_context = (!is_main_context_owner)
793            .then(|| main_context.acquire().ok())
794            .flatten();
795        assert!(
796            is_main_context_owner || has_acquired_main_context.is_some(),
797            "Async operations only allowed if the thread is owning the MainContext"
798        );
799
800        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
801            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
802        unsafe extern "C" fn revoke_temporary_authorizations_trampoline<
803            P: FnOnce(Result<(), glib::Error>) + 'static,
804        >(
805            _source_object: *mut glib::gobject_ffi::GObject,
806            res: *mut gio::ffi::GAsyncResult,
807            user_data: glib::ffi::gpointer,
808        ) {
809            unsafe {
810                let mut error = std::ptr::null_mut();
811                ffi::polkit_authority_revoke_temporary_authorizations_finish(
812                    _source_object as *mut _,
813                    res,
814                    &mut error,
815                );
816                let result = if error.is_null() {
817                    Ok(())
818                } else {
819                    Err(from_glib_full(error))
820                };
821                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
822                    Box_::from_raw(user_data as *mut _);
823                let callback: P = callback.into_inner();
824                callback(result);
825            }
826        }
827        let callback = revoke_temporary_authorizations_trampoline::<P>;
828        unsafe {
829            ffi::polkit_authority_revoke_temporary_authorizations(
830                self.to_glib_none().0,
831                subject.as_ref().to_glib_none().0,
832                cancellable.map(|p| p.as_ref()).to_glib_none().0,
833                Some(callback),
834                Box_::into_raw(user_data) as *mut _,
835            );
836        }
837    }
838
839    pub fn revoke_temporary_authorizations_future(
840        &self,
841        subject: &(impl IsA<Subject> + Clone + 'static),
842    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
843        let subject = subject.clone();
844        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
845            obj.revoke_temporary_authorizations(&subject, Some(cancellable), move |res| {
846                send.resolve(res);
847            });
848        }))
849    }
850
851    #[doc(alias = "polkit_authority_revoke_temporary_authorizations_sync")]
852    pub fn revoke_temporary_authorizations_sync(
853        &self,
854        subject: &impl IsA<Subject>,
855        cancellable: Option<&impl IsA<gio::Cancellable>>,
856    ) -> Result<(), glib::Error> {
857        unsafe {
858            let mut error = std::ptr::null_mut();
859            let is_ok = ffi::polkit_authority_revoke_temporary_authorizations_sync(
860                self.to_glib_none().0,
861                subject.as_ref().to_glib_none().0,
862                cancellable.map(|p| p.as_ref()).to_glib_none().0,
863                &mut error,
864            );
865            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
866            if error.is_null() {
867                Ok(())
868            } else {
869                Err(from_glib_full(error))
870            }
871        }
872    }
873
874    #[doc(alias = "polkit_authority_unregister_authentication_agent")]
875    pub fn unregister_authentication_agent<P: FnOnce(Result<(), glib::Error>) + 'static>(
876        &self,
877        subject: &impl IsA<Subject>,
878        object_path: &str,
879        cancellable: Option<&impl IsA<gio::Cancellable>>,
880        callback: P,
881    ) {
882        let main_context = glib::MainContext::ref_thread_default();
883        let is_main_context_owner = main_context.is_owner();
884        let has_acquired_main_context = (!is_main_context_owner)
885            .then(|| main_context.acquire().ok())
886            .flatten();
887        assert!(
888            is_main_context_owner || has_acquired_main_context.is_some(),
889            "Async operations only allowed if the thread is owning the MainContext"
890        );
891
892        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
893            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
894        unsafe extern "C" fn unregister_authentication_agent_trampoline<
895            P: FnOnce(Result<(), glib::Error>) + 'static,
896        >(
897            _source_object: *mut glib::gobject_ffi::GObject,
898            res: *mut gio::ffi::GAsyncResult,
899            user_data: glib::ffi::gpointer,
900        ) {
901            unsafe {
902                let mut error = std::ptr::null_mut();
903                ffi::polkit_authority_unregister_authentication_agent_finish(
904                    _source_object as *mut _,
905                    res,
906                    &mut error,
907                );
908                let result = if error.is_null() {
909                    Ok(())
910                } else {
911                    Err(from_glib_full(error))
912                };
913                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
914                    Box_::from_raw(user_data as *mut _);
915                let callback: P = callback.into_inner();
916                callback(result);
917            }
918        }
919        let callback = unregister_authentication_agent_trampoline::<P>;
920        unsafe {
921            ffi::polkit_authority_unregister_authentication_agent(
922                self.to_glib_none().0,
923                subject.as_ref().to_glib_none().0,
924                object_path.to_glib_none().0,
925                cancellable.map(|p| p.as_ref()).to_glib_none().0,
926                Some(callback),
927                Box_::into_raw(user_data) as *mut _,
928            );
929        }
930    }
931
932    pub fn unregister_authentication_agent_future(
933        &self,
934        subject: &(impl IsA<Subject> + Clone + 'static),
935        object_path: &str,
936    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
937        let subject = subject.clone();
938        let object_path = String::from(object_path);
939        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
940            obj.unregister_authentication_agent(
941                &subject,
942                &object_path,
943                Some(cancellable),
944                move |res| {
945                    send.resolve(res);
946                },
947            );
948        }))
949    }
950
951    #[doc(alias = "polkit_authority_unregister_authentication_agent_sync")]
952    pub fn unregister_authentication_agent_sync(
953        &self,
954        subject: &impl IsA<Subject>,
955        object_path: &str,
956        cancellable: Option<&impl IsA<gio::Cancellable>>,
957    ) -> Result<(), glib::Error> {
958        unsafe {
959            let mut error = std::ptr::null_mut();
960            let is_ok = ffi::polkit_authority_unregister_authentication_agent_sync(
961                self.to_glib_none().0,
962                subject.as_ref().to_glib_none().0,
963                object_path.to_glib_none().0,
964                cancellable.map(|p| p.as_ref()).to_glib_none().0,
965                &mut error,
966            );
967            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
968            if error.is_null() {
969                Ok(())
970            } else {
971                Err(from_glib_full(error))
972            }
973        }
974    }
975
976    #[doc(alias = "polkit_authority_get")]
977    pub fn get() -> Authority {
978        unsafe { from_glib_full(ffi::polkit_authority_get()) }
979    }
980
981    #[doc(alias = "polkit_authority_get_async")]
982    #[doc(alias = "get_async")]
983    pub fn async_<P: FnOnce(Result<Authority, glib::Error>) + 'static>(
984        cancellable: Option<&impl IsA<gio::Cancellable>>,
985        callback: P,
986    ) {
987        let main_context = glib::MainContext::ref_thread_default();
988        let is_main_context_owner = main_context.is_owner();
989        let has_acquired_main_context = (!is_main_context_owner)
990            .then(|| main_context.acquire().ok())
991            .flatten();
992        assert!(
993            is_main_context_owner || has_acquired_main_context.is_some(),
994            "Async operations only allowed if the thread is owning the MainContext"
995        );
996
997        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
998            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
999        unsafe extern "C" fn async__trampoline<
1000            P: FnOnce(Result<Authority, glib::Error>) + 'static,
1001        >(
1002            _source_object: *mut glib::gobject_ffi::GObject,
1003            res: *mut gio::ffi::GAsyncResult,
1004            user_data: glib::ffi::gpointer,
1005        ) {
1006            unsafe {
1007                let mut error = std::ptr::null_mut();
1008                let ret = ffi::polkit_authority_get_finish(res, &mut error);
1009                let result = if error.is_null() {
1010                    Ok(from_glib_full(ret))
1011                } else {
1012                    Err(from_glib_full(error))
1013                };
1014                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
1015                    Box_::from_raw(user_data as *mut _);
1016                let callback: P = callback.into_inner();
1017                callback(result);
1018            }
1019        }
1020        let callback = async__trampoline::<P>;
1021        unsafe {
1022            ffi::polkit_authority_get_async(
1023                cancellable.map(|p| p.as_ref()).to_glib_none().0,
1024                Some(callback),
1025                Box_::into_raw(user_data) as *mut _,
1026            );
1027        }
1028    }
1029
1030    pub fn async__future()
1031    -> Pin<Box_<dyn std::future::Future<Output = Result<Authority, glib::Error>> + 'static>> {
1032        Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
1033            Self::async_(Some(cancellable), move |res| {
1034                send.resolve(res);
1035            });
1036        }))
1037    }
1038
1039    #[doc(alias = "polkit_authority_get_sync")]
1040    #[doc(alias = "get_sync")]
1041    pub fn sync(
1042        cancellable: Option<&impl IsA<gio::Cancellable>>,
1043    ) -> Result<Authority, glib::Error> {
1044        unsafe {
1045            let mut error = std::ptr::null_mut();
1046            let ret = ffi::polkit_authority_get_sync(
1047                cancellable.map(|p| p.as_ref()).to_glib_none().0,
1048                &mut error,
1049            );
1050            if error.is_null() {
1051                Ok(from_glib_full(ret))
1052            } else {
1053                Err(from_glib_full(error))
1054            }
1055        }
1056    }
1057
1058    #[doc(alias = "changed")]
1059    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1060        unsafe extern "C" fn changed_trampoline<F: Fn(&Authority) + 'static>(
1061            this: *mut ffi::PolkitAuthority,
1062            f: glib::ffi::gpointer,
1063        ) {
1064            unsafe {
1065                let f: &F = &*(f as *const F);
1066                f(&from_glib_borrow(this))
1067            }
1068        }
1069        unsafe {
1070            let f: Box_<F> = Box_::new(f);
1071            connect_raw(
1072                self.as_ptr() as *mut _,
1073                c"changed".as_ptr() as *const _,
1074                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1075                    changed_trampoline::<F> as *const (),
1076                )),
1077                Box_::into_raw(f),
1078            )
1079        }
1080    }
1081
1082    #[doc(alias = "sessions-changed")]
1083    pub fn connect_sessions_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1084        unsafe extern "C" fn sessions_changed_trampoline<F: Fn(&Authority) + 'static>(
1085            this: *mut ffi::PolkitAuthority,
1086            f: glib::ffi::gpointer,
1087        ) {
1088            unsafe {
1089                let f: &F = &*(f as *const F);
1090                f(&from_glib_borrow(this))
1091            }
1092        }
1093        unsafe {
1094            let f: Box_<F> = Box_::new(f);
1095            connect_raw(
1096                self.as_ptr() as *mut _,
1097                c"sessions-changed".as_ptr() as *const _,
1098                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1099                    sessions_changed_trampoline::<F> as *const (),
1100                )),
1101                Box_::into_raw(f),
1102            )
1103        }
1104    }
1105
1106    #[doc(alias = "backend-features")]
1107    pub fn connect_backend_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1108        unsafe extern "C" fn notify_backend_features_trampoline<F: Fn(&Authority) + 'static>(
1109            this: *mut ffi::PolkitAuthority,
1110            _param_spec: glib::ffi::gpointer,
1111            f: glib::ffi::gpointer,
1112        ) {
1113            unsafe {
1114                let f: &F = &*(f as *const F);
1115                f(&from_glib_borrow(this))
1116            }
1117        }
1118        unsafe {
1119            let f: Box_<F> = Box_::new(f);
1120            connect_raw(
1121                self.as_ptr() as *mut _,
1122                c"notify::backend-features".as_ptr() as *const _,
1123                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1124                    notify_backend_features_trampoline::<F> as *const (),
1125                )),
1126                Box_::into_raw(f),
1127            )
1128        }
1129    }
1130
1131    #[doc(alias = "backend-name")]
1132    pub fn connect_backend_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1133        unsafe extern "C" fn notify_backend_name_trampoline<F: Fn(&Authority) + 'static>(
1134            this: *mut ffi::PolkitAuthority,
1135            _param_spec: glib::ffi::gpointer,
1136            f: glib::ffi::gpointer,
1137        ) {
1138            unsafe {
1139                let f: &F = &*(f as *const F);
1140                f(&from_glib_borrow(this))
1141            }
1142        }
1143        unsafe {
1144            let f: Box_<F> = Box_::new(f);
1145            connect_raw(
1146                self.as_ptr() as *mut _,
1147                c"notify::backend-name".as_ptr() as *const _,
1148                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1149                    notify_backend_name_trampoline::<F> as *const (),
1150                )),
1151                Box_::into_raw(f),
1152            )
1153        }
1154    }
1155
1156    #[doc(alias = "backend-version")]
1157    pub fn connect_backend_version_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1158        unsafe extern "C" fn notify_backend_version_trampoline<F: Fn(&Authority) + 'static>(
1159            this: *mut ffi::PolkitAuthority,
1160            _param_spec: glib::ffi::gpointer,
1161            f: glib::ffi::gpointer,
1162        ) {
1163            unsafe {
1164                let f: &F = &*(f as *const F);
1165                f(&from_glib_borrow(this))
1166            }
1167        }
1168        unsafe {
1169            let f: Box_<F> = Box_::new(f);
1170            connect_raw(
1171                self.as_ptr() as *mut _,
1172                c"notify::backend-version".as_ptr() as *const _,
1173                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1174                    notify_backend_version_trampoline::<F> as *const (),
1175                )),
1176                Box_::into_raw(f),
1177            )
1178        }
1179    }
1180
1181    #[doc(alias = "owner")]
1182    pub fn connect_owner_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1183        unsafe extern "C" fn notify_owner_trampoline<F: Fn(&Authority) + 'static>(
1184            this: *mut ffi::PolkitAuthority,
1185            _param_spec: glib::ffi::gpointer,
1186            f: glib::ffi::gpointer,
1187        ) {
1188            unsafe {
1189                let f: &F = &*(f as *const F);
1190                f(&from_glib_borrow(this))
1191            }
1192        }
1193        unsafe {
1194            let f: Box_<F> = Box_::new(f);
1195            connect_raw(
1196                self.as_ptr() as *mut _,
1197                c"notify::owner".as_ptr() as *const _,
1198                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1199                    notify_owner_trampoline::<F> as *const (),
1200                )),
1201                Box_::into_raw(f),
1202            )
1203        }
1204    }
1205}