polkit_rs/auto/
system_bus_name.rs

1// Generated by gir (https://github.com/gtk-rs/gir @ b2a1c6f9b362)
2// from ../misc (@ ???)
3// DO NOT EDIT
4
5use crate::{Subject, UnixUser, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "PolkitSystemBusName")]
15    pub struct SystemBusName(Object<ffi::PolkitSystemBusName, ffi::PolkitSystemBusNameClass>) @implements Subject;
16
17    match fn {
18        type_ => || ffi::polkit_system_bus_name_get_type(),
19    }
20}
21
22impl SystemBusName {
23    #[doc(alias = "polkit_system_bus_name_get_name")]
24    #[doc(alias = "get_name")]
25    pub fn name(&self) -> glib::GString {
26        unsafe { from_glib_none(ffi::polkit_system_bus_name_get_name(self.to_glib_none().0)) }
27    }
28
29    #[doc(alias = "polkit_system_bus_name_get_process_sync")]
30    #[doc(alias = "get_process_sync")]
31    pub fn process_sync(
32        &self,
33        cancellable: Option<&impl IsA<gio::Cancellable>>,
34    ) -> Result<Subject, glib::Error> {
35        unsafe {
36            let mut error = std::ptr::null_mut();
37            let ret = ffi::polkit_system_bus_name_get_process_sync(
38                self.to_glib_none().0,
39                cancellable.map(|p| p.as_ref()).to_glib_none().0,
40                &mut error,
41            );
42            if error.is_null() {
43                Ok(from_glib_full(ret))
44            } else {
45                Err(from_glib_full(error))
46            }
47        }
48    }
49
50    #[doc(alias = "polkit_system_bus_name_get_user_sync")]
51    #[doc(alias = "get_user_sync")]
52    pub fn user_sync(
53        &self,
54        cancellable: Option<&impl IsA<gio::Cancellable>>,
55    ) -> Result<UnixUser, glib::Error> {
56        unsafe {
57            let mut error = std::ptr::null_mut();
58            let ret = ffi::polkit_system_bus_name_get_user_sync(
59                self.to_glib_none().0,
60                cancellable.map(|p| p.as_ref()).to_glib_none().0,
61                &mut error,
62            );
63            if error.is_null() {
64                Ok(from_glib_full(ret))
65            } else {
66                Err(from_glib_full(error))
67            }
68        }
69    }
70
71    #[doc(alias = "polkit_system_bus_name_set_name")]
72    #[doc(alias = "name")]
73    pub fn set_name(&self, name: &str) {
74        unsafe {
75            ffi::polkit_system_bus_name_set_name(self.to_glib_none().0, name.to_glib_none().0);
76        }
77    }
78
79    #[doc(alias = "polkit_system_bus_name_new")]
80    pub fn new(name: &str) -> Self {
81        unsafe {
82            let subject: Subject =
83                from_glib_full(ffi::polkit_system_bus_name_new(name.to_glib_none().0));
84            subject.unsafe_cast()
85        }
86    }
87
88    #[doc(alias = "name")]
89    pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
90        unsafe extern "C" fn notify_name_trampoline<F: Fn(&SystemBusName) + 'static>(
91            this: *mut ffi::PolkitSystemBusName,
92            _param_spec: glib::ffi::gpointer,
93            f: glib::ffi::gpointer,
94        ) {
95            unsafe {
96                let f: &F = &*(f as *const F);
97                f(&from_glib_borrow(this))
98            }
99        }
100        unsafe {
101            let f: Box_<F> = Box_::new(f);
102            connect_raw(
103                self.as_ptr() as *mut _,
104                c"notify::name".as_ptr() as *const _,
105                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
106                    notify_name_trampoline::<F> as *const (),
107                )),
108                Box_::into_raw(f),
109            )
110        }
111    }
112}
113
114impl std::fmt::Display for SystemBusName {
115    #[inline]
116    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
117        f.write_str(&self.name())
118    }
119}