1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Generated by gir (https://github.com/gtk-rs/gir @ 0e476ab5c1de)
// from /usr/share/gir-1.0 (@ ???)
// DO NOT EDIT
use crate::{Subject, UnixUser};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// An object that represents a process owning a unique name on the system bus.
///
/// ## Properties
///
///
/// #### `name`
/// The unique name on the system message bus.
///
/// Readable | Writeable | Construct
///
/// # Implements
///
/// [`trait@glib::ObjectExt`], [`SubjectExt`][trait@crate::prelude::SubjectExt]
#[doc(alias = "PolkitSystemBusName")]
pub struct SystemBusName(Object<ffi::PolkitSystemBusName, ffi::PolkitSystemBusNameClass>) @implements Subject;
match fn {
type_ => || ffi::polkit_system_bus_name_get_type(),
}
}
impl SystemBusName {
/// Gets the unique system bus name for `self`.
///
/// # Returns
///
/// The unique system bus name for `self`. Do not
/// free, this string is owned by `self`.
#[doc(alias = "polkit_system_bus_name_get_name")]
#[doc(alias = "get_name")]
pub fn name(&self) -> glib::GString {
unsafe { from_glib_none(ffi::polkit_system_bus_name_get_name(self.to_glib_none().0)) }
}
/// Synchronously gets a [`UnixProcess`][crate::UnixProcess] object for `self`
/// - the calling thread is blocked until a reply is received.
/// ## `cancellable`
/// A [`gio::Cancellable`][crate::gio::Cancellable] or [`None`].
///
/// # Returns
///
/// A [`UnixProcess`][crate::UnixProcess] object or [`None`] if `error` is set.
#[doc(alias = "polkit_system_bus_name_get_process_sync")]
#[doc(alias = "get_process_sync")]
pub fn process_sync(
&self,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<Option<Subject>, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::polkit_system_bus_name_get_process_sync(
self.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Synchronously gets a [`UnixUser`][crate::UnixUser] object for `self`;
/// the calling thread is blocked until a reply is received.
/// ## `cancellable`
/// A [`gio::Cancellable`][crate::gio::Cancellable] or [`None`].
///
/// # Returns
///
/// A [`UnixUser`][crate::UnixUser] object or [`None`] if `error` is set.
#[doc(alias = "polkit_system_bus_name_get_user_sync")]
#[doc(alias = "get_user_sync")]
pub fn user_sync(
&self,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<Option<UnixUser>, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::polkit_system_bus_name_get_user_sync(
self.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Sets the unique system bus name for `self`.
/// ## `name`
/// A unique system bus name.
#[doc(alias = "polkit_system_bus_name_set_name")]
pub fn set_name(&self, name: &str) {
unsafe {
ffi::polkit_system_bus_name_set_name(self.to_glib_none().0, name.to_glib_none().0);
}
}
/// Creates a new [`SystemBusName`][crate::SystemBusName] for `name`.
/// ## `name`
/// A unique system bus name.
///
/// # Returns
///
/// A [`SystemBusName`][crate::SystemBusName]. Free with `g_object_unref()`.
#[doc(alias = "polkit_system_bus_name_new")]
pub fn new(name: &str) -> Subject {
unsafe { from_glib_full(ffi::polkit_system_bus_name_new(name.to_glib_none().0)) }
}
#[doc(alias = "name")]
pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_name_trampoline<F: Fn(&SystemBusName) + 'static>(
this: *mut ffi::PolkitSystemBusName,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::name\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_name_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl std::fmt::Display for SystemBusName {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&self.name())
}
}