polkit_agent_rs/auto/
session.rs1use crate::ffi;
6use crate::polkit;
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "PolkitAgentSession")]
17 pub struct Session(Object<ffi::PolkitAgentSession, ffi::PolkitAgentSessionClass>);
18
19 match fn {
20 type_ => || ffi::polkit_agent_session_get_type(),
21 }
22}
23
24impl Session {
25 #[doc(alias = "polkit_agent_session_new")]
26 pub fn new(identity: &impl IsA<polkit::Identity>, cookie: &str) -> Session {
27 unsafe {
28 from_glib_full(ffi::polkit_agent_session_new(
29 identity.as_ref().to_glib_none().0,
30 cookie.to_glib_none().0,
31 ))
32 }
33 }
34
35 #[doc(alias = "polkit_agent_session_cancel")]
36 pub fn cancel(&self) {
37 unsafe {
38 ffi::polkit_agent_session_cancel(self.to_glib_none().0);
39 }
40 }
41
42 #[doc(alias = "polkit_agent_session_initiate")]
43 pub fn initiate(&self) {
44 unsafe {
45 ffi::polkit_agent_session_initiate(self.to_glib_none().0);
46 }
47 }
48
49 #[doc(alias = "polkit_agent_session_response")]
50 pub fn response(&self, response: &str) {
51 unsafe {
52 ffi::polkit_agent_session_response(self.to_glib_none().0, response.to_glib_none().0);
53 }
54 }
55
56 pub fn cookie(&self) -> Option<glib::GString> {
57 ObjectExt::property(self, "cookie")
58 }
59
60 pub fn identity(&self) -> Option<polkit::Identity> {
61 ObjectExt::property(self, "identity")
62 }
63
64 #[doc(alias = "completed")]
65 pub fn connect_completed<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
66 unsafe extern "C" fn completed_trampoline<F: Fn(&Session, bool) + 'static>(
67 this: *mut ffi::PolkitAgentSession,
68 gained_authorization: glib::ffi::gboolean,
69 f: glib::ffi::gpointer,
70 ) {
71 unsafe {
72 let f: &F = &*(f as *const F);
73 f(&from_glib_borrow(this), from_glib(gained_authorization))
74 }
75 }
76 unsafe {
77 let f: Box_<F> = Box_::new(f);
78 connect_raw(
79 self.as_ptr() as *mut _,
80 c"completed".as_ptr() as *const _,
81 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
82 completed_trampoline::<F> as *const (),
83 )),
84 Box_::into_raw(f),
85 )
86 }
87 }
88
89 #[doc(alias = "request")]
90 pub fn connect_request<F: Fn(&Self, &str, bool) + 'static>(&self, f: F) -> SignalHandlerId {
91 unsafe extern "C" fn request_trampoline<F: Fn(&Session, &str, bool) + 'static>(
92 this: *mut ffi::PolkitAgentSession,
93 request: *mut std::ffi::c_char,
94 echo_on: glib::ffi::gboolean,
95 f: glib::ffi::gpointer,
96 ) {
97 unsafe {
98 let f: &F = &*(f as *const F);
99 f(
100 &from_glib_borrow(this),
101 &glib::GString::from_glib_borrow(request),
102 from_glib(echo_on),
103 )
104 }
105 }
106 unsafe {
107 let f: Box_<F> = Box_::new(f);
108 connect_raw(
109 self.as_ptr() as *mut _,
110 c"request".as_ptr() as *const _,
111 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
112 request_trampoline::<F> as *const (),
113 )),
114 Box_::into_raw(f),
115 )
116 }
117 }
118
119 #[doc(alias = "show-error")]
120 pub fn connect_show_error<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
121 unsafe extern "C" fn show_error_trampoline<F: Fn(&Session, &str) + 'static>(
122 this: *mut ffi::PolkitAgentSession,
123 text: *mut std::ffi::c_char,
124 f: glib::ffi::gpointer,
125 ) {
126 unsafe {
127 let f: &F = &*(f as *const F);
128 f(
129 &from_glib_borrow(this),
130 &glib::GString::from_glib_borrow(text),
131 )
132 }
133 }
134 unsafe {
135 let f: Box_<F> = Box_::new(f);
136 connect_raw(
137 self.as_ptr() as *mut _,
138 c"show-error".as_ptr() as *const _,
139 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
140 show_error_trampoline::<F> as *const (),
141 )),
142 Box_::into_raw(f),
143 )
144 }
145 }
146
147 #[doc(alias = "show-info")]
148 pub fn connect_show_info<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
149 unsafe extern "C" fn show_info_trampoline<F: Fn(&Session, &str) + 'static>(
150 this: *mut ffi::PolkitAgentSession,
151 text: *mut std::ffi::c_char,
152 f: glib::ffi::gpointer,
153 ) {
154 unsafe {
155 let f: &F = &*(f as *const F);
156 f(
157 &from_glib_borrow(this),
158 &glib::GString::from_glib_borrow(text),
159 )
160 }
161 }
162 unsafe {
163 let f: Box_<F> = Box_::new(f);
164 connect_raw(
165 self.as_ptr() as *mut _,
166 c"show-info".as_ptr() as *const _,
167 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
168 show_info_trampoline::<F> as *const (),
169 )),
170 Box_::into_raw(f),
171 )
172 }
173 }
174}