1use crate::{VpnPluginFailure, VpnServiceState, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15#[cfg(feature = "gio_v2_22")]
16#[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_22")))]
17glib::wrapper! {
18 #[doc(alias = "NMVpnServicePlugin")]
80 pub struct VpnServicePlugin(Object<ffi::NMVpnServicePlugin, ffi::NMVpnServicePluginClass>) @implements gio::Initable;
81
82 match fn {
83 type_ => || ffi::nm_vpn_service_plugin_get_type(),
84 }
85}
86
87#[cfg(not(any(feature = "gio_v2_22")))]
88glib::wrapper! {
89 #[doc(alias = "NMVpnServicePlugin")]
90 pub struct VpnServicePlugin(Object<ffi::NMVpnServicePlugin, ffi::NMVpnServicePluginClass>);
91
92 match fn {
93 type_ => || ffi::nm_vpn_service_plugin_get_type(),
94 }
95}
96
97impl VpnServicePlugin {
98 pub const NONE: Option<&'static VpnServicePlugin> = None;
99
100 }
111
112pub trait VpnServicePluginExt: IsA<VpnServicePlugin> + 'static {
118 #[doc(alias = "nm_vpn_service_plugin_disconnect")]
119 fn disconnect(&self) -> Result<(), glib::Error> {
120 unsafe {
121 let mut error = std::ptr::null_mut();
122 let is_ok =
123 ffi::nm_vpn_service_plugin_disconnect(self.as_ref().to_glib_none().0, &mut error);
124 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
125 if error.is_null() {
126 Ok(())
127 } else {
128 Err(from_glib_full(error))
129 }
130 }
131 }
132
133 #[doc(alias = "nm_vpn_service_plugin_failure")]
134 fn failure(&self, reason: VpnPluginFailure) {
135 unsafe {
136 ffi::nm_vpn_service_plugin_failure(self.as_ref().to_glib_none().0, reason.into_glib());
137 }
138 }
139
140 #[doc(alias = "nm_vpn_service_plugin_secrets_required")]
156 fn secrets_required(&self, message: &str, hints: &str) {
157 unsafe {
158 ffi::nm_vpn_service_plugin_secrets_required(
159 self.as_ref().to_glib_none().0,
160 message.to_glib_none().0,
161 &mut hints.to_glib_none().0,
162 );
163 }
164 }
165
166 #[doc(alias = "nm_vpn_service_plugin_set_login_banner")]
182 fn set_login_banner(&self, banner: &str) {
183 unsafe {
184 ffi::nm_vpn_service_plugin_set_login_banner(
185 self.as_ref().to_glib_none().0,
186 banner.to_glib_none().0,
187 );
188 }
189 }
190
191 #[cfg(feature = "v1_12")]
198 #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
199 #[doc(alias = "nm_vpn_service_plugin_shutdown")]
200 fn shutdown(&self) {
201 unsafe {
202 ffi::nm_vpn_service_plugin_shutdown(self.as_ref().to_glib_none().0);
203 }
204 }
205
206 #[cfg(feature = "v1_2")]
208 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
209 #[doc(alias = "service-name")]
210 fn service_name(&self) -> Option<glib::GString> {
211 ObjectExt::property(self.as_ref(), "service-name")
212 }
213
214 #[cfg(feature = "v1_2")]
216 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
217 fn state(&self) -> VpnServiceState {
218 ObjectExt::property(self.as_ref(), "state")
219 }
220
221 #[cfg(feature = "v1_2")]
223 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
224 fn set_state(&self, state: VpnServiceState) {
225 ObjectExt::set_property(self.as_ref(), "state", state)
226 }
227
228 #[cfg(feature = "v1_2")]
230 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
231 #[doc(alias = "watch-peer")]
232 fn is_watch_peer(&self) -> bool {
233 ObjectExt::property(self.as_ref(), "watch-peer")
234 }
235
236 #[doc(alias = "failure")]
242 fn connect_failure<F: Fn(&Self, u32) + 'static>(&self, f: F) -> SignalHandlerId {
243 unsafe extern "C" fn failure_trampoline<
244 P: IsA<VpnServicePlugin>,
245 F: Fn(&P, u32) + 'static,
246 >(
247 this: *mut ffi::NMVpnServicePlugin,
248 object: std::ffi::c_uint,
249 f: glib::ffi::gpointer,
250 ) {
251 let f: &F = &*(f as *const F);
252 f(
253 VpnServicePlugin::from_glib_borrow(this).unsafe_cast_ref(),
254 object,
255 )
256 }
257 unsafe {
258 let f: Box_<F> = Box_::new(f);
259 connect_raw(
260 self.as_ptr() as *mut _,
261 c"failure".as_ptr() as *const _,
262 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
263 failure_trampoline::<Self, F> as *const (),
264 )),
265 Box_::into_raw(f),
266 )
267 }
268 }
269
270 #[doc(alias = "login-banner")]
281 fn connect_login_banner<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
282 unsafe extern "C" fn login_banner_trampoline<
283 P: IsA<VpnServicePlugin>,
284 F: Fn(&P, &str) + 'static,
285 >(
286 this: *mut ffi::NMVpnServicePlugin,
287 object: *mut std::ffi::c_char,
288 f: glib::ffi::gpointer,
289 ) {
290 let f: &F = &*(f as *const F);
291 f(
292 VpnServicePlugin::from_glib_borrow(this).unsafe_cast_ref(),
293 &glib::GString::from_glib_borrow(object),
294 )
295 }
296 unsafe {
297 let f: Box_<F> = Box_::new(f);
298 connect_raw(
299 self.as_ptr() as *mut _,
300 c"login-banner".as_ptr() as *const _,
301 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
302 login_banner_trampoline::<Self, F> as *const (),
303 )),
304 Box_::into_raw(f),
305 )
306 }
307 }
308
309 #[doc(alias = "quit")]
310 fn connect_quit<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
311 unsafe extern "C" fn quit_trampoline<P: IsA<VpnServicePlugin>, F: Fn(&P) + 'static>(
312 this: *mut ffi::NMVpnServicePlugin,
313 f: glib::ffi::gpointer,
314 ) {
315 let f: &F = &*(f as *const F);
316 f(VpnServicePlugin::from_glib_borrow(this).unsafe_cast_ref())
317 }
318 unsafe {
319 let f: Box_<F> = Box_::new(f);
320 connect_raw(
321 self.as_ptr() as *mut _,
322 c"quit".as_ptr() as *const _,
323 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324 quit_trampoline::<Self, F> as *const (),
325 )),
326 Box_::into_raw(f),
327 )
328 }
329 }
330
331 #[doc(alias = "state-changed")]
337 fn connect_state_changed<F: Fn(&Self, u32) + 'static>(&self, f: F) -> SignalHandlerId {
338 unsafe extern "C" fn state_changed_trampoline<
339 P: IsA<VpnServicePlugin>,
340 F: Fn(&P, u32) + 'static,
341 >(
342 this: *mut ffi::NMVpnServicePlugin,
343 object: std::ffi::c_uint,
344 f: glib::ffi::gpointer,
345 ) {
346 let f: &F = &*(f as *const F);
347 f(
348 VpnServicePlugin::from_glib_borrow(this).unsafe_cast_ref(),
349 object,
350 )
351 }
352 unsafe {
353 let f: Box_<F> = Box_::new(f);
354 connect_raw(
355 self.as_ptr() as *mut _,
356 c"state-changed".as_ptr() as *const _,
357 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
358 state_changed_trampoline::<Self, F> as *const (),
359 )),
360 Box_::into_raw(f),
361 )
362 }
363 }
364
365 #[cfg(feature = "v1_2")]
366 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
367 #[doc(alias = "state")]
368 fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
369 unsafe extern "C" fn notify_state_trampoline<
370 P: IsA<VpnServicePlugin>,
371 F: Fn(&P) + 'static,
372 >(
373 this: *mut ffi::NMVpnServicePlugin,
374 _param_spec: glib::ffi::gpointer,
375 f: glib::ffi::gpointer,
376 ) {
377 let f: &F = &*(f as *const F);
378 f(VpnServicePlugin::from_glib_borrow(this).unsafe_cast_ref())
379 }
380 unsafe {
381 let f: Box_<F> = Box_::new(f);
382 connect_raw(
383 self.as_ptr() as *mut _,
384 c"notify::state".as_ptr() as *const _,
385 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
386 notify_state_trampoline::<Self, F> as *const (),
387 )),
388 Box_::into_raw(f),
389 )
390 }
391 }
392}
393
394impl<O: IsA<VpnServicePlugin>> VpnServicePluginExt for O {}