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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{Connection, VpnEditor, VpnEditorPluginCapability, ffi};
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
use crate::{VpnEditorPluginVT, VpnPluginInfo};
use glib::{
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
///
///
/// ## Properties
///
///
/// #### `description`
/// Longer description of the VPN plugin.
///
/// Readable
///
///
/// #### `name`
/// Short display name of the VPN plugin.
///
/// Readable
///
///
/// #### `service`
/// D-Bus service name of the plugin's VPN service.
///
/// Readable
///
/// # Implements
///
/// [`VpnEditorPluginExt`][trait@crate::prelude::VpnEditorPluginExt]
#[doc(alias = "NMVpnEditorPlugin")]
pub struct VpnEditorPlugin(Interface<ffi::NMVpnEditorPlugin, ffi::NMVpnEditorPluginInterface>);
match fn {
type_ => || ffi::nm_vpn_editor_plugin_get_type(),
}
}
impl VpnEditorPlugin {
pub const NONE: Option<&'static VpnEditorPlugin> = None;
/// Load the shared library @plugin_name and create a new
/// #NMVpnEditorPlugin instance via the #NMVpnEditorPluginFactory
/// function.
///
/// This is similar to nm_vpn_editor_plugin_load_from_file(), but
/// it does no validation of the plugin name, instead passes it directly
/// to dlopen(). If you have the full path to a plugin file,
/// nm_vpn_editor_plugin_load_from_file() is preferred.
/// ## `plugin_name`
/// The name of the shared library to load.
/// This path will be directly passed to dlopen() without
/// further checks.
/// ## `check_service`
/// if not-null, check that the loaded plugin advertises
/// the given service.
///
/// # Returns
///
/// a new plugin instance or [`None`] on error.
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "nm_vpn_editor_plugin_load")]
pub fn load(plugin_name: &str, check_service: &str) -> Result<VpnEditorPlugin, glib::Error> {
assert_initialized_main_thread!();
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::nm_vpn_editor_plugin_load(
plugin_name.to_glib_none().0,
check_service.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
//#[cfg(feature = "v1_2")]
//#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
//#[doc(alias = "nm_vpn_editor_plugin_load_from_file")]
//pub fn load_from_file(plugin_name: &str, check_service: &str, check_owner: i32, check_file: /*Unimplemented*/FnMut(&str, /*Unimplemented*/Option<Basic: Pointer>, Option<&glib::Error>) -> bool, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Result<VpnEditorPlugin, glib::Error> {
// unsafe { TODO: call ffi:nm_vpn_editor_plugin_load_from_file() }
//}
}
/// Trait containing all [`struct@VpnEditorPlugin`] methods.
///
/// # Implementors
///
/// [`VpnEditorPlugin`][struct@crate::VpnEditorPlugin]
pub trait VpnEditorPluginExt: IsA<VpnEditorPlugin> + 'static {
#[doc(alias = "nm_vpn_editor_plugin_export")]
fn export(&self, path: &str, connection: &impl IsA<Connection>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::nm_vpn_editor_plugin_export(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
connection.as_ref().to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "nm_vpn_editor_plugin_get_capabilities")]
#[doc(alias = "get_capabilities")]
fn capabilities(&self) -> VpnEditorPluginCapability {
unsafe {
from_glib(ffi::nm_vpn_editor_plugin_get_capabilities(
self.as_ref().to_glib_none().0,
))
}
}
/// ## `connection`
/// the #NMConnection to be edited
///
/// # Returns
///
/// a new #NMVpnEditor or [`None`] on error
#[doc(alias = "nm_vpn_editor_plugin_get_editor")]
#[doc(alias = "get_editor")]
fn editor(&self, connection: &impl IsA<Connection>) -> Result<VpnEditor, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::nm_vpn_editor_plugin_get_editor(
self.as_ref().to_glib_none().0,
connection.as_ref().to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
///
/// # Returns
///
/// if set, return the #NMVpnPluginInfo instance.
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "nm_vpn_editor_plugin_get_plugin_info")]
#[doc(alias = "get_plugin_info")]
fn plugin_info(&self) -> VpnPluginInfo {
unsafe {
from_glib_none(ffi::nm_vpn_editor_plugin_get_plugin_info(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "nm_vpn_editor_plugin_get_suggested_filename")]
#[doc(alias = "get_suggested_filename")]
fn suggested_filename(&self, connection: &impl IsA<Connection>) -> glib::GString {
unsafe {
from_glib_full(ffi::nm_vpn_editor_plugin_get_suggested_filename(
self.as_ref().to_glib_none().0,
connection.as_ref().to_glib_none().0,
))
}
}
/// Returns an opaque VT function table for the plugin to extend
/// functionality. The actual meaning of NMVpnEditorPluginVT is not
/// defined in public API of libnm, instead it must be agreed by
/// both the plugin and the caller. See the header-only file
/// 'nm-vpn-editor-plugin-call.h' which defines the meaning.
/// ## `vt_size`
/// the size of the buffer. Can be 0 to only query the
/// size of plugin's VT.
///
/// # Returns
///
/// the actual size of the @self's virtual function table.
///
/// ## `vt`
/// buffer to be filled with the VT table of the plugin
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "nm_vpn_editor_plugin_get_vt")]
#[doc(alias = "get_vt")]
fn vt(&self, vt_size: usize) -> (usize, VpnEditorPluginVT) {
unsafe {
let mut vt = VpnEditorPluginVT::uninitialized();
let ret = ffi::nm_vpn_editor_plugin_get_vt(
self.as_ref().to_glib_none().0,
&mut vt.to_glib_none_mut().0,
vt_size,
);
(ret, vt)
}
}
/// ## `path`
/// full path to the file to attempt to read into a new #NMConnection
///
/// # Returns
///
/// a new #NMConnection imported from @path, or [`None`]
/// on error or if the file at @path was not recognized by this plugin
#[doc(alias = "nm_vpn_editor_plugin_import")]
fn import(&self, path: &str) -> Result<Connection, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::nm_vpn_editor_plugin_import(
self.as_ref().to_glib_none().0,
path.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Set or clear the plugin-info instance.
/// This takes a weak reference on @plugin_info, to avoid circular
/// reference as the plugin-info might also reference the editor-plugin.
/// ## `plugin_info`
/// a #NMVpnPluginInfo instance or [`None`]
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "nm_vpn_editor_plugin_set_plugin_info")]
fn set_plugin_info(&self, plugin_info: Option<&VpnPluginInfo>) {
unsafe {
ffi::nm_vpn_editor_plugin_set_plugin_info(
self.as_ref().to_glib_none().0,
plugin_info.to_glib_none().0,
);
}
}
/// Longer description of the VPN plugin.
fn description(&self) -> Option<glib::GString> {
ObjectExt::property(self.as_ref(), "description")
}
/// Short display name of the VPN plugin.
fn name(&self) -> Option<glib::GString> {
ObjectExt::property(self.as_ref(), "name")
}
/// D-Bus service name of the plugin's VPN service.
fn service(&self) -> Option<glib::GString> {
ObjectExt::property(self.as_ref(), "service")
}
#[doc(alias = "description")]
fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_description_trampoline<
P: IsA<VpnEditorPlugin>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::NMVpnEditorPlugin,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::description".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_description_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "name")]
fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_name_trampoline<
P: IsA<VpnEditorPlugin>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::NMVpnEditorPlugin,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::name".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "service")]
fn connect_service_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_service_trampoline<
P: IsA<VpnEditorPlugin>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::NMVpnEditorPlugin,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(VpnEditorPlugin::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::service".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_service_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<VpnEditorPlugin>> VpnEditorPluginExt for O {}