nm_rs/auto/connection.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6#[cfg(feature = "v1_8")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
8use crate::SettingDummy;
9#[cfg(feature = "v1_12")]
10#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
11use crate::SettingTCConfig;
12use crate::{
13 Setting, Setting8021x, SettingAdsl, SettingBluetooth, SettingBond, SettingBridge,
14 SettingBridgePort, SettingCdma, SettingCompareFlags, SettingConnection, SettingDcb,
15 SettingGeneric, SettingGsm, SettingIP4Config, SettingIP6Config, SettingInfiniband,
16 SettingOlpcMesh, SettingPpp, SettingPppoe, SettingSecretFlags, SettingSerial, SettingTeam,
17 SettingTeamPort, SettingVlan, SettingVpn, SettingWimax, SettingWired, SettingWireless,
18 SettingWirelessSecurity, ffi,
19};
20#[cfg(feature = "v1_2")]
21#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
22use crate::{SettingIPTunnel, SettingMacvlan, SettingVxlan};
23#[cfg(feature = "v1_6")]
24#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
25use crate::{SettingMacsec, SettingProxy};
26#[cfg(feature = "v1_14")]
27#[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
28use crate::{SettingOvsBridge, SettingOvsPatch, SettingOvsPort, SettingTun};
29use glib::{
30 object::ObjectType as _,
31 prelude::*,
32 signal::{SignalHandlerId, connect_raw},
33 translate::*,
34};
35use std::boxed::Box as Box_;
36
37glib::wrapper! {
38 /// NMConnection is the interface implemented by #NMRemoteConnection on the
39 /// client side, and #NMSettingsConnection on the daemon side.
40 ///
41 /// ## Signals
42 ///
43 ///
44 /// #### `changed`
45 /// The ::changed signal is emitted when any property (including secrets)
46 /// of any setting of the connection is modified, or when settings are
47 /// added or removed.
48 ///
49 ///
50 ///
51 ///
52 /// #### `secrets-cleared`
53 /// The ::secrets-cleared signal is emitted when the secrets of a connection
54 /// are cleared.
55 ///
56 ///
57 ///
58 ///
59 /// #### `secrets-updated`
60 /// The ::secrets-updated signal is emitted when the secrets of a setting
61 /// have been changed.
62 ///
63 ///
64 ///
65 /// # Implements
66 ///
67 /// [`ConnectionExt`][trait@crate::prelude::ConnectionExt]
68 #[doc(alias = "NMConnection")]
69 pub struct Connection(Interface<ffi::NMConnection, ffi::NMConnectionInterface>);
70
71 match fn {
72 type_ => || ffi::nm_connection_get_type(),
73 }
74}
75
76impl Connection {
77 pub const NONE: Option<&'static Connection> = None;
78}
79
80/// Trait containing all [`struct@Connection`] methods.
81///
82/// # Implementors
83///
84/// [`Connection`][struct@crate::Connection], [`RemoteConnection`][struct@crate::RemoteConnection], [`SimpleConnection`][struct@crate::SimpleConnection]
85pub trait ConnectionExt: IsA<Connection> + 'static {
86 /// Adds a #NMSetting to the connection, replacing any previous #NMSetting of the
87 /// same name which has previously been added to the #NMConnection. The
88 /// connection takes ownership of the #NMSetting object and does not increase
89 /// the setting object's reference count.
90 /// ## `setting`
91 /// the #NMSetting to add to the connection object
92 #[doc(alias = "nm_connection_add_setting")]
93 fn add_setting(&self, setting: impl IsA<Setting>) {
94 unsafe {
95 ffi::nm_connection_add_setting(
96 self.as_ref().to_glib_none().0,
97 setting.upcast().into_glib_ptr(),
98 );
99 }
100 }
101
102 /// Clears and frees any secrets that may be stored in the connection, to avoid
103 /// keeping secret data in memory when not needed.
104 #[doc(alias = "nm_connection_clear_secrets")]
105 fn clear_secrets(&self) {
106 unsafe {
107 ffi::nm_connection_clear_secrets(self.as_ref().to_glib_none().0);
108 }
109 }
110
111 /// Clears and frees secrets determined by @func.
112 /// ## `func`
113 /// function to be called to determine whether a
114 /// specific secret should be cleared or not. If [`None`], all secrets are cleared.
115 #[doc(alias = "nm_connection_clear_secrets_with_flags")]
116 fn clear_secrets_with_flags(
117 &self,
118 func: Option<&mut dyn FnMut(&Setting, &str, &SettingSecretFlags) -> bool>,
119 ) {
120 let mut func_data: Option<&mut dyn FnMut(&Setting, &str, &SettingSecretFlags) -> bool> =
121 func;
122 unsafe extern "C" fn func_func(
123 setting: *mut ffi::NMSetting,
124 secret: *const std::ffi::c_char,
125 flags: ffi::NMSettingSecretFlags,
126 user_data: glib::ffi::gpointer,
127 ) -> glib::ffi::gboolean {
128 let setting = from_glib_borrow(setting);
129 let secret: Borrowed<glib::GString> = from_glib_borrow(secret);
130 let Some(flags) = SettingSecretFlags::from_bits(flags) else {
131 panic!("SettingsSecretFlags got invalid arguments");
132 };
133 let callback = user_data
134 as *mut Option<&mut dyn FnMut(&Setting, &str, &SettingSecretFlags) -> bool>;
135 if let Some(ref mut callback) = *callback {
136 callback(&setting, secret.as_str(), &flags)
137 } else {
138 panic!("cannot get closure...")
139 }
140 .into_glib()
141 }
142 let func = if func_data.is_some() {
143 Some(func_func as _)
144 } else {
145 None
146 };
147 let super_callback0: &mut Option<
148 &mut dyn FnMut(&Setting, &str, &SettingSecretFlags) -> bool,
149 > = &mut func_data;
150 unsafe {
151 ffi::nm_connection_clear_secrets_with_flags(
152 self.as_ref().to_glib_none().0,
153 func,
154 super_callback0 as *mut _ as *mut _,
155 );
156 }
157 }
158
159 /// Deletes all of @self's settings.
160 #[doc(alias = "nm_connection_clear_settings")]
161 fn clear_settings(&self) {
162 unsafe {
163 ffi::nm_connection_clear_settings(self.as_ref().to_glib_none().0);
164 }
165 }
166
167 #[doc(alias = "nm_connection_compare")]
168 fn compare(&self, b: &impl IsA<Connection>, flags: SettingCompareFlags) -> bool {
169 unsafe {
170 from_glib(ffi::nm_connection_compare(
171 self.as_ref().to_glib_none().0,
172 b.as_ref().to_glib_none().0,
173 flags.into_glib(),
174 ))
175 }
176 }
177
178 //#[doc(alias = "nm_connection_diff")]
179 //fn diff(&self, b: &impl IsA<Connection>, flags: SettingCompareFlags, out_settings: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 95 }) -> bool {
180 // unsafe { TODO: call ffi:nm_connection_diff() }
181 //}
182
183 /// Print the connection (including secrets!) to stdout. For debugging
184 /// purposes ONLY, should NOT be used for serialization of the setting,
185 /// or machine-parsed in any way. The output format is not guaranteed to
186 /// be stable and may change at any time.
187 #[doc(alias = "nm_connection_dump")]
188 fn dump(&self) {
189 unsafe {
190 ffi::nm_connection_dump(self.as_ref().to_glib_none().0);
191 }
192 }
193
194 //#[doc(alias = "nm_connection_for_each_setting_value")]
195 //fn for_each_setting_value(&self, func: /*Unimplemented*/FnMut(&Setting, &str, /*Ignored*/glib::Value, /*Ignored*/glib::ParamFlags), user_data: /*Unimplemented*/Option<Basic: Pointer>) {
196 // unsafe { TODO: call ffi:nm_connection_for_each_setting_value() }
197 //}
198
199 /// A shortcut to return the type from the connection's #NMSettingConnection.
200 ///
201 /// # Returns
202 ///
203 /// the type from the connection's 'connection' setting
204 #[doc(alias = "nm_connection_get_connection_type")]
205 #[doc(alias = "get_connection_type")]
206 fn connection_type(&self) -> glib::GString {
207 unsafe {
208 from_glib_none(ffi::nm_connection_get_connection_type(
209 self.as_ref().to_glib_none().0,
210 ))
211 }
212 }
213
214 /// A shortcut to return the ID from the connection's #NMSettingConnection.
215 ///
216 /// # Returns
217 ///
218 /// the ID from the connection's 'connection' setting
219 #[doc(alias = "nm_connection_get_id")]
220 #[doc(alias = "get_id")]
221 fn id(&self) -> glib::GString {
222 unsafe { from_glib_none(ffi::nm_connection_get_id(self.as_ref().to_glib_none().0)) }
223 }
224
225 /// Returns the interface name as stored in NMSettingConnection:interface_name.
226 /// If the connection contains no NMSettingConnection, it will return [`None`].
227 ///
228 /// For hardware devices and software devices created outside of NetworkManager,
229 /// this name is used to match the device. for software devices created by
230 /// NetworkManager, this is the name of the created interface.
231 ///
232 /// # Returns
233 ///
234 /// Name of the kernel interface or [`None`]
235 #[doc(alias = "nm_connection_get_interface_name")]
236 #[doc(alias = "get_interface_name")]
237 fn interface_name(&self) -> glib::GString {
238 unsafe {
239 from_glib_none(ffi::nm_connection_get_interface_name(
240 self.as_ref().to_glib_none().0,
241 ))
242 }
243 }
244
245 /// Returns the connection's D-Bus path.
246 ///
247 /// # Returns
248 ///
249 /// the D-Bus path of the connection, previously set by a call to
250 /// nm_connection_set_path().
251 #[doc(alias = "nm_connection_get_path")]
252 #[doc(alias = "get_path")]
253 fn path(&self) -> glib::GString {
254 unsafe { from_glib_none(ffi::nm_connection_get_path(self.as_ref().to_glib_none().0)) }
255 }
256
257 /// Gets the #NMSetting with the given #GType, if one has been previously added
258 /// to the #NMConnection.
259 /// ## `setting_type`
260 /// the #GType of the setting object to return
261 ///
262 /// # Returns
263 ///
264 /// the #NMSetting, or [`None`] if no setting of that type was previously
265 /// added to the #NMConnection
266 #[doc(alias = "nm_connection_get_setting")]
267 #[doc(alias = "get_setting")]
268 fn setting(&self, setting_type: glib::types::Type) -> Setting {
269 unsafe {
270 from_glib_none(ffi::nm_connection_get_setting(
271 self.as_ref().to_glib_none().0,
272 setting_type.into_glib(),
273 ))
274 }
275 }
276
277 /// A shortcut to return any #NMSetting8021x the connection might contain.
278 ///
279 /// # Returns
280 ///
281 /// an #NMSetting8021x if the connection contains one, otherwise [`None`]
282 #[doc(alias = "nm_connection_get_setting_802_1x")]
283 #[doc(alias = "get_setting_802_1x")]
284 fn setting_802_1x(&self) -> Setting8021x {
285 unsafe {
286 from_glib_none(ffi::nm_connection_get_setting_802_1x(
287 self.as_ref().to_glib_none().0,
288 ))
289 }
290 }
291
292 /// A shortcut to return any #NMSettingAdsl the connection might contain.
293 ///
294 /// # Returns
295 ///
296 /// an #NMSettingAdsl if the connection contains one, otherwise [`None`]
297 #[doc(alias = "nm_connection_get_setting_adsl")]
298 #[doc(alias = "get_setting_adsl")]
299 fn setting_adsl(&self) -> SettingAdsl {
300 unsafe {
301 from_glib_none(ffi::nm_connection_get_setting_adsl(
302 self.as_ref().to_glib_none().0,
303 ))
304 }
305 }
306
307 /// A shortcut to return any #NMSettingBluetooth the connection might contain.
308 ///
309 /// # Returns
310 ///
311 /// an #NMSettingBluetooth if the connection contains one, otherwise [`None`]
312 #[doc(alias = "nm_connection_get_setting_bluetooth")]
313 #[doc(alias = "get_setting_bluetooth")]
314 fn setting_bluetooth(&self) -> SettingBluetooth {
315 unsafe {
316 from_glib_none(ffi::nm_connection_get_setting_bluetooth(
317 self.as_ref().to_glib_none().0,
318 ))
319 }
320 }
321
322 /// A shortcut to return any #NMSettingBond the connection might contain.
323 ///
324 /// # Returns
325 ///
326 /// an #NMSettingBond if the connection contains one, otherwise [`None`]
327 #[doc(alias = "nm_connection_get_setting_bond")]
328 #[doc(alias = "get_setting_bond")]
329 fn setting_bond(&self) -> SettingBond {
330 unsafe {
331 from_glib_none(ffi::nm_connection_get_setting_bond(
332 self.as_ref().to_glib_none().0,
333 ))
334 }
335 }
336
337 /// A shortcut to return any #NMSettingBridge the connection might contain.
338 ///
339 /// # Returns
340 ///
341 /// an #NMSettingBridge if the connection contains one, otherwise [`None`]
342 #[doc(alias = "nm_connection_get_setting_bridge")]
343 #[doc(alias = "get_setting_bridge")]
344 fn setting_bridge(&self) -> SettingBridge {
345 unsafe {
346 from_glib_none(ffi::nm_connection_get_setting_bridge(
347 self.as_ref().to_glib_none().0,
348 ))
349 }
350 }
351
352 /// A shortcut to return any #NMSettingBridgePort the connection might contain.
353 ///
354 /// # Returns
355 ///
356 /// an #NMSettingBridgePort if the connection contains one, otherwise [`None`]
357 #[doc(alias = "nm_connection_get_setting_bridge_port")]
358 #[doc(alias = "get_setting_bridge_port")]
359 fn setting_bridge_port(&self) -> SettingBridgePort {
360 unsafe {
361 from_glib_none(ffi::nm_connection_get_setting_bridge_port(
362 self.as_ref().to_glib_none().0,
363 ))
364 }
365 }
366
367 /// Gets the #NMSetting with the given name, if one has been previously added
368 /// the #NMConnection.
369 /// ## `name`
370 /// a setting name
371 ///
372 /// # Returns
373 ///
374 /// the #NMSetting, or [`None`] if no setting with that name was previously
375 /// added to the #NMConnection
376 #[doc(alias = "nm_connection_get_setting_by_name")]
377 #[doc(alias = "get_setting_by_name")]
378 fn setting_by_name(&self, name: &str) -> Setting {
379 unsafe {
380 from_glib_none(ffi::nm_connection_get_setting_by_name(
381 self.as_ref().to_glib_none().0,
382 name.to_glib_none().0,
383 ))
384 }
385 }
386
387 /// A shortcut to return any #NMSettingCdma the connection might contain.
388 ///
389 /// # Returns
390 ///
391 /// an #NMSettingCdma if the connection contains one, otherwise [`None`]
392 #[doc(alias = "nm_connection_get_setting_cdma")]
393 #[doc(alias = "get_setting_cdma")]
394 fn setting_cdma(&self) -> SettingCdma {
395 unsafe {
396 from_glib_none(ffi::nm_connection_get_setting_cdma(
397 self.as_ref().to_glib_none().0,
398 ))
399 }
400 }
401
402 /// A shortcut to return any #NMSettingConnection the connection might contain.
403 ///
404 /// # Returns
405 ///
406 /// an #NMSettingConnection if the connection contains one, otherwise [`None`]
407 #[doc(alias = "nm_connection_get_setting_connection")]
408 #[doc(alias = "get_setting_connection")]
409 fn setting_connection(&self) -> SettingConnection {
410 unsafe {
411 from_glib_none(ffi::nm_connection_get_setting_connection(
412 self.as_ref().to_glib_none().0,
413 ))
414 }
415 }
416
417 /// A shortcut to return any #NMSettingDcb the connection might contain.
418 ///
419 /// # Returns
420 ///
421 /// an #NMSettingDcb if the connection contains one, otherwise NULL
422 #[doc(alias = "nm_connection_get_setting_dcb")]
423 #[doc(alias = "get_setting_dcb")]
424 fn setting_dcb(&self) -> SettingDcb {
425 unsafe {
426 from_glib_none(ffi::nm_connection_get_setting_dcb(
427 self.as_ref().to_glib_none().0,
428 ))
429 }
430 }
431
432 /// A shortcut to return any #NMSettingDummy the connection might contain.
433 ///
434 /// # Returns
435 ///
436 /// an #NMSettingDummy if the connection contains one, otherwise [`None`]
437 #[cfg(feature = "v1_8")]
438 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
439 #[doc(alias = "nm_connection_get_setting_dummy")]
440 #[doc(alias = "get_setting_dummy")]
441 fn setting_dummy(&self) -> SettingDummy {
442 unsafe {
443 from_glib_none(ffi::nm_connection_get_setting_dummy(
444 self.as_ref().to_glib_none().0,
445 ))
446 }
447 }
448
449 /// A shortcut to return any #NMSettingGeneric the connection might contain.
450 ///
451 /// # Returns
452 ///
453 /// an #NMSettingGeneric if the connection contains one, otherwise NULL
454 #[doc(alias = "nm_connection_get_setting_generic")]
455 #[doc(alias = "get_setting_generic")]
456 fn setting_generic(&self) -> SettingGeneric {
457 unsafe {
458 from_glib_none(ffi::nm_connection_get_setting_generic(
459 self.as_ref().to_glib_none().0,
460 ))
461 }
462 }
463
464 /// A shortcut to return any #NMSettingGsm the connection might contain.
465 ///
466 /// # Returns
467 ///
468 /// an #NMSettingGsm if the connection contains one, otherwise [`None`]
469 #[doc(alias = "nm_connection_get_setting_gsm")]
470 #[doc(alias = "get_setting_gsm")]
471 fn setting_gsm(&self) -> SettingGsm {
472 unsafe {
473 from_glib_none(ffi::nm_connection_get_setting_gsm(
474 self.as_ref().to_glib_none().0,
475 ))
476 }
477 }
478
479 /// A shortcut to return any #NMSettingInfiniband the connection might contain.
480 ///
481 /// # Returns
482 ///
483 /// an #NMSettingInfiniband if the connection contains one, otherwise [`None`]
484 #[doc(alias = "nm_connection_get_setting_infiniband")]
485 #[doc(alias = "get_setting_infiniband")]
486 fn setting_infiniband(&self) -> SettingInfiniband {
487 unsafe {
488 from_glib_none(ffi::nm_connection_get_setting_infiniband(
489 self.as_ref().to_glib_none().0,
490 ))
491 }
492 }
493
494 /// A shortcut to return any #NMSettingIP4Config the connection might contain.
495 ///
496 /// Note that it returns the value as type #NMSettingIPConfig, since the vast
497 /// majority of IPv4-setting-related methods are on that type, not
498 /// #NMSettingIP4Config.
499 ///
500 /// # Returns
501 ///
502 /// an #NMSettingIP4Config if the
503 /// connection contains one, otherwise [`None`]
504 #[doc(alias = "nm_connection_get_setting_ip4_config")]
505 #[doc(alias = "get_setting_ip4_config")]
506 fn setting_ip4_config(&self) -> SettingIP4Config {
507 unsafe {
508 from_glib_none(ffi::nm_connection_get_setting_ip4_config(
509 self.as_ref().to_glib_none().0,
510 ))
511 }
512 }
513
514 /// A shortcut to return any #NMSettingIP6Config the connection might contain.
515 ///
516 /// Note that it returns the value as type #NMSettingIPConfig, since the vast
517 /// majority of IPv6-setting-related methods are on that type, not
518 /// #NMSettingIP6Config.
519 ///
520 /// # Returns
521 ///
522 /// an #NMSettingIP6Config if the
523 /// connection contains one, otherwise [`None`]
524 #[doc(alias = "nm_connection_get_setting_ip6_config")]
525 #[doc(alias = "get_setting_ip6_config")]
526 fn setting_ip6_config(&self) -> SettingIP6Config {
527 unsafe {
528 from_glib_none(ffi::nm_connection_get_setting_ip6_config(
529 self.as_ref().to_glib_none().0,
530 ))
531 }
532 }
533
534 /// A shortcut to return any #NMSettingIPTunnel the connection might contain.
535 ///
536 /// # Returns
537 ///
538 /// an #NMSettingIPTunnel if the connection contains one, otherwise [`None`]
539 #[cfg(feature = "v1_2")]
540 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
541 #[doc(alias = "nm_connection_get_setting_ip_tunnel")]
542 #[doc(alias = "get_setting_ip_tunnel")]
543 fn setting_ip_tunnel(&self) -> SettingIPTunnel {
544 unsafe {
545 from_glib_none(ffi::nm_connection_get_setting_ip_tunnel(
546 self.as_ref().to_glib_none().0,
547 ))
548 }
549 }
550
551 /// A shortcut to return any #NMSettingMacsec the connection might contain.
552 ///
553 /// # Returns
554 ///
555 /// an #NMSettingMacsec if the connection contains one, otherwise [`None`]
556 #[cfg(feature = "v1_6")]
557 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
558 #[doc(alias = "nm_connection_get_setting_macsec")]
559 #[doc(alias = "get_setting_macsec")]
560 fn setting_macsec(&self) -> SettingMacsec {
561 unsafe {
562 from_glib_none(ffi::nm_connection_get_setting_macsec(
563 self.as_ref().to_glib_none().0,
564 ))
565 }
566 }
567
568 /// A shortcut to return any #NMSettingMacvlan the connection might contain.
569 ///
570 /// # Returns
571 ///
572 /// an #NMSettingMacvlan if the connection contains one, otherwise [`None`]
573 #[cfg(feature = "v1_2")]
574 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
575 #[doc(alias = "nm_connection_get_setting_macvlan")]
576 #[doc(alias = "get_setting_macvlan")]
577 fn setting_macvlan(&self) -> SettingMacvlan {
578 unsafe {
579 from_glib_none(ffi::nm_connection_get_setting_macvlan(
580 self.as_ref().to_glib_none().0,
581 ))
582 }
583 }
584
585 /// A shortcut to return any #NMSettingOlpcMesh the connection might contain.
586 ///
587 /// # Returns
588 ///
589 /// an #NMSettingOlpcMesh if the connection contains one, otherwise [`None`]
590 #[doc(alias = "nm_connection_get_setting_olpc_mesh")]
591 #[doc(alias = "get_setting_olpc_mesh")]
592 fn setting_olpc_mesh(&self) -> SettingOlpcMesh {
593 unsafe {
594 from_glib_none(ffi::nm_connection_get_setting_olpc_mesh(
595 self.as_ref().to_glib_none().0,
596 ))
597 }
598 }
599
600 /// A shortcut to return any #NMSettingOvsBridge the connection might contain.
601 ///
602 /// # Returns
603 ///
604 /// an #NMSettingOvsBridge if the connection contains one, otherwise [`None`]
605 #[cfg(feature = "v1_14")]
606 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
607 #[doc(alias = "nm_connection_get_setting_ovs_bridge")]
608 #[doc(alias = "get_setting_ovs_bridge")]
609 fn setting_ovs_bridge(&self) -> SettingOvsBridge {
610 unsafe {
611 from_glib_none(ffi::nm_connection_get_setting_ovs_bridge(
612 self.as_ref().to_glib_none().0,
613 ))
614 }
615 }
616
617 //#[cfg(feature = "v1_14")]
618 //#[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
619 //#[doc(alias = "nm_connection_get_setting_ovs_interface")]
620 //#[doc(alias = "get_setting_ovs_interface")]
621 //fn setting_ovs_interface(&self) -> /*Ignored*/SettingOvsInterface {
622 // unsafe { TODO: call ffi:nm_connection_get_setting_ovs_interface() }
623 //}
624
625 /// A shortcut to return any #NMSettingOvsPatch the connection might contain.
626 ///
627 /// # Returns
628 ///
629 /// an #NMSettingOvsPatch if the connection contains one, otherwise [`None`]
630 #[cfg(feature = "v1_14")]
631 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
632 #[doc(alias = "nm_connection_get_setting_ovs_patch")]
633 #[doc(alias = "get_setting_ovs_patch")]
634 fn setting_ovs_patch(&self) -> SettingOvsPatch {
635 unsafe {
636 from_glib_none(ffi::nm_connection_get_setting_ovs_patch(
637 self.as_ref().to_glib_none().0,
638 ))
639 }
640 }
641
642 /// A shortcut to return any #NMSettingOvsPort the connection might contain.
643 ///
644 /// # Returns
645 ///
646 /// an #NMSettingOvsPort if the connection contains one, otherwise [`None`]
647 #[cfg(feature = "v1_14")]
648 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
649 #[doc(alias = "nm_connection_get_setting_ovs_port")]
650 #[doc(alias = "get_setting_ovs_port")]
651 fn setting_ovs_port(&self) -> SettingOvsPort {
652 unsafe {
653 from_glib_none(ffi::nm_connection_get_setting_ovs_port(
654 self.as_ref().to_glib_none().0,
655 ))
656 }
657 }
658
659 /// A shortcut to return any #NMSettingPpp the connection might contain.
660 ///
661 /// # Returns
662 ///
663 /// an #NMSettingPpp if the connection contains one, otherwise [`None`]
664 #[doc(alias = "nm_connection_get_setting_ppp")]
665 #[doc(alias = "get_setting_ppp")]
666 fn setting_ppp(&self) -> SettingPpp {
667 unsafe {
668 from_glib_none(ffi::nm_connection_get_setting_ppp(
669 self.as_ref().to_glib_none().0,
670 ))
671 }
672 }
673
674 /// A shortcut to return any #NMSettingPppoe the connection might contain.
675 ///
676 /// # Returns
677 ///
678 /// an #NMSettingPppoe if the connection contains one, otherwise [`None`]
679 #[doc(alias = "nm_connection_get_setting_pppoe")]
680 #[doc(alias = "get_setting_pppoe")]
681 fn setting_pppoe(&self) -> SettingPppoe {
682 unsafe {
683 from_glib_none(ffi::nm_connection_get_setting_pppoe(
684 self.as_ref().to_glib_none().0,
685 ))
686 }
687 }
688
689 /// A shortcut to return any #NMSettingProxy the connection might contain.
690 ///
691 /// # Returns
692 ///
693 /// an #NMSettingProxy if the connection contains one, otherwise [`None`]
694 #[cfg(feature = "v1_6")]
695 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
696 #[doc(alias = "nm_connection_get_setting_proxy")]
697 #[doc(alias = "get_setting_proxy")]
698 fn setting_proxy(&self) -> SettingProxy {
699 unsafe {
700 from_glib_none(ffi::nm_connection_get_setting_proxy(
701 self.as_ref().to_glib_none().0,
702 ))
703 }
704 }
705
706 /// A shortcut to return any #NMSettingSerial the connection might contain.
707 ///
708 /// # Returns
709 ///
710 /// an #NMSettingSerial if the connection contains one, otherwise [`None`]
711 #[doc(alias = "nm_connection_get_setting_serial")]
712 #[doc(alias = "get_setting_serial")]
713 fn setting_serial(&self) -> SettingSerial {
714 unsafe {
715 from_glib_none(ffi::nm_connection_get_setting_serial(
716 self.as_ref().to_glib_none().0,
717 ))
718 }
719 }
720
721 /// A shortcut to return any #NMSettingTCConfig the connection might contain.
722 ///
723 /// # Returns
724 ///
725 /// an #NMSettingTCConfig if the connection contains one, otherwise [`None`]
726 #[cfg(feature = "v1_12")]
727 #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
728 #[doc(alias = "nm_connection_get_setting_tc_config")]
729 #[doc(alias = "get_setting_tc_config")]
730 fn setting_tc_config(&self) -> SettingTCConfig {
731 unsafe {
732 from_glib_none(ffi::nm_connection_get_setting_tc_config(
733 self.as_ref().to_glib_none().0,
734 ))
735 }
736 }
737
738 /// A shortcut to return any #NMSettingTeam the connection might contain.
739 ///
740 /// # Returns
741 ///
742 /// an #NMSettingTeam if the connection contains one, otherwise [`None`]
743 #[doc(alias = "nm_connection_get_setting_team")]
744 #[doc(alias = "get_setting_team")]
745 fn setting_team(&self) -> SettingTeam {
746 unsafe {
747 from_glib_none(ffi::nm_connection_get_setting_team(
748 self.as_ref().to_glib_none().0,
749 ))
750 }
751 }
752
753 /// A shortcut to return any #NMSettingTeamPort the connection might contain.
754 ///
755 /// # Returns
756 ///
757 /// an #NMSettingTeamPort if the connection contains one, otherwise [`None`]
758 #[doc(alias = "nm_connection_get_setting_team_port")]
759 #[doc(alias = "get_setting_team_port")]
760 fn setting_team_port(&self) -> SettingTeamPort {
761 unsafe {
762 from_glib_none(ffi::nm_connection_get_setting_team_port(
763 self.as_ref().to_glib_none().0,
764 ))
765 }
766 }
767
768 /// A shortcut to return any #NMSettingTun the connection might contain.
769 ///
770 /// # Returns
771 ///
772 /// an #NMSettingTun if the connection contains one, otherwise [`None`]
773 #[cfg(feature = "v1_14")]
774 #[cfg_attr(docsrs, doc(cfg(feature = "v1_14")))]
775 #[doc(alias = "nm_connection_get_setting_tun")]
776 #[doc(alias = "get_setting_tun")]
777 fn setting_tun(&self) -> SettingTun {
778 unsafe {
779 from_glib_none(ffi::nm_connection_get_setting_tun(
780 self.as_ref().to_glib_none().0,
781 ))
782 }
783 }
784
785 /// A shortcut to return any #NMSettingVlan the connection might contain.
786 ///
787 /// # Returns
788 ///
789 /// an #NMSettingVlan if the connection contains one, otherwise [`None`]
790 #[doc(alias = "nm_connection_get_setting_vlan")]
791 #[doc(alias = "get_setting_vlan")]
792 fn setting_vlan(&self) -> SettingVlan {
793 unsafe {
794 from_glib_none(ffi::nm_connection_get_setting_vlan(
795 self.as_ref().to_glib_none().0,
796 ))
797 }
798 }
799
800 /// A shortcut to return any #NMSettingVpn the connection might contain.
801 ///
802 /// # Returns
803 ///
804 /// an #NMSettingVpn if the connection contains one, otherwise [`None`]
805 #[doc(alias = "nm_connection_get_setting_vpn")]
806 #[doc(alias = "get_setting_vpn")]
807 fn setting_vpn(&self) -> SettingVpn {
808 unsafe {
809 from_glib_none(ffi::nm_connection_get_setting_vpn(
810 self.as_ref().to_glib_none().0,
811 ))
812 }
813 }
814
815 /// A shortcut to return any #NMSettingVxlan the connection might contain.
816 ///
817 /// # Returns
818 ///
819 /// an #NMSettingVxlan if the connection contains one, otherwise [`None`]
820 #[cfg(feature = "v1_2")]
821 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
822 #[doc(alias = "nm_connection_get_setting_vxlan")]
823 #[doc(alias = "get_setting_vxlan")]
824 fn setting_vxlan(&self) -> SettingVxlan {
825 unsafe {
826 from_glib_none(ffi::nm_connection_get_setting_vxlan(
827 self.as_ref().to_glib_none().0,
828 ))
829 }
830 }
831
832 /// A shortcut to return any #NMSettingWimax the connection might contain.
833 ///
834 /// # Returns
835 ///
836 /// an #NMSettingWimax if the connection contains one, otherwise [`None`]
837 #[doc(alias = "nm_connection_get_setting_wimax")]
838 #[doc(alias = "get_setting_wimax")]
839 fn setting_wimax(&self) -> SettingWimax {
840 unsafe {
841 from_glib_none(ffi::nm_connection_get_setting_wimax(
842 self.as_ref().to_glib_none().0,
843 ))
844 }
845 }
846
847 /// A shortcut to return any #NMSettingWired the connection might contain.
848 ///
849 /// # Returns
850 ///
851 /// an #NMSettingWired if the connection contains one, otherwise [`None`]
852 #[doc(alias = "nm_connection_get_setting_wired")]
853 #[doc(alias = "get_setting_wired")]
854 fn setting_wired(&self) -> SettingWired {
855 unsafe {
856 from_glib_none(ffi::nm_connection_get_setting_wired(
857 self.as_ref().to_glib_none().0,
858 ))
859 }
860 }
861
862 /// A shortcut to return any #NMSettingWireless the connection might contain.
863 ///
864 /// # Returns
865 ///
866 /// an #NMSettingWireless if the connection contains one, otherwise [`None`]
867 #[doc(alias = "nm_connection_get_setting_wireless")]
868 #[doc(alias = "get_setting_wireless")]
869 fn setting_wireless(&self) -> SettingWireless {
870 unsafe {
871 from_glib_none(ffi::nm_connection_get_setting_wireless(
872 self.as_ref().to_glib_none().0,
873 ))
874 }
875 }
876
877 /// A shortcut to return any #NMSettingWirelessSecurity the connection might contain.
878 ///
879 /// # Returns
880 ///
881 /// an #NMSettingWirelessSecurity if the connection contains one, otherwise [`None`]
882 #[doc(alias = "nm_connection_get_setting_wireless_security")]
883 #[doc(alias = "get_setting_wireless_security")]
884 fn setting_wireless_security(&self) -> SettingWirelessSecurity {
885 unsafe {
886 from_glib_none(ffi::nm_connection_get_setting_wireless_security(
887 self.as_ref().to_glib_none().0,
888 ))
889 }
890 }
891
892 /// Retrieves the settings in @self.
893 ///
894 /// The returned array is [`None`]-terminated.
895 ///
896 /// # Returns
897 ///
898 /// a
899 /// [`None`]-terminated array containing every setting of @self.
900 /// If the connection has no settings, [`None`] is returned.
901 #[cfg(feature = "v1_10")]
902 #[cfg_attr(docsrs, doc(cfg(feature = "v1_10")))]
903 #[doc(alias = "nm_connection_get_settings")]
904 #[doc(alias = "get_settings")]
905 fn settings(&self) -> Vec<Setting> {
906 unsafe {
907 let mut out_length = std::mem::MaybeUninit::uninit();
908 let ret = FromGlibContainer::from_glib_container_num(
909 ffi::nm_connection_get_settings(
910 self.as_ref().to_glib_none().0,
911 out_length.as_mut_ptr(),
912 ),
913 out_length.assume_init() as _,
914 );
915 ret
916 }
917 }
918
919 /// A shortcut to return the UUID from the connection's #NMSettingConnection.
920 ///
921 /// # Returns
922 ///
923 /// the UUID from the connection's 'connection' setting
924 #[doc(alias = "nm_connection_get_uuid")]
925 #[doc(alias = "get_uuid")]
926 fn uuid(&self) -> glib::GString {
927 unsafe { from_glib_none(ffi::nm_connection_get_uuid(self.as_ref().to_glib_none().0)) }
928 }
929
930 /// Returns the name that nm_device_disambiguate_names() would
931 /// return for the virtual device that would be created for @self.
932 /// Eg, "VLAN (eth1.1)".
933 ///
934 /// # Returns
935 ///
936 /// the name of @self's device,
937 /// or [`None`] if @self is not a virtual connection type
938 #[doc(alias = "nm_connection_get_virtual_device_description")]
939 #[doc(alias = "get_virtual_device_description")]
940 fn virtual_device_description(&self) -> glib::GString {
941 unsafe {
942 from_glib_full(ffi::nm_connection_get_virtual_device_description(
943 self.as_ref().to_glib_none().0,
944 ))
945 }
946 }
947
948 /// A convenience function to check if the given @self is a particular
949 /// type (ie wired, Wi-Fi, ppp, etc). Checks the #NMSettingConnection:type
950 /// property of the connection and matches that against @type_.
951 /// ## `type_`
952 /// a setting name to check the connection's type against (like
953 /// [`SETTING_WIRELESS_SETTING_NAME`][crate::SETTING_WIRELESS_SETTING_NAME] or [`SETTING_WIRED_SETTING_NAME`][crate::SETTING_WIRED_SETTING_NAME])
954 ///
955 /// # Returns
956 ///
957 /// [`true`] if the connection is of the given @type_, [`false`] if not
958 #[doc(alias = "nm_connection_is_type")]
959 fn is_type(&self, type_: &str) -> bool {
960 unsafe {
961 from_glib(ffi::nm_connection_is_type(
962 self.as_ref().to_glib_none().0,
963 type_.to_glib_none().0,
964 ))
965 }
966 }
967
968 /// Checks if @self refers to a virtual device (and thus can potentially be
969 /// activated even if the device it refers to doesn't exist).
970 ///
971 /// # Returns
972 ///
973 /// whether @self refers to a virtual device
974 #[doc(alias = "nm_connection_is_virtual")]
975 fn is_virtual(&self) -> bool {
976 unsafe {
977 from_glib(ffi::nm_connection_is_virtual(
978 self.as_ref().to_glib_none().0,
979 ))
980 }
981 }
982
983 /// Returns the name of the first setting object in the connection which would
984 /// need secrets to make a successful connection. The returned hints are only
985 /// intended as a guide to what secrets may be required, because in some
986 /// circumstances, there is no way to conclusively determine exactly which
987 /// secrets are needed.
988 ///
989 /// # Returns
990 ///
991 /// the setting name of the #NMSetting object which has
992 /// invalid or missing secrets
993 ///
994 /// ## `hints`
995 ///
996 /// the address of a pointer to a #GPtrArray, initialized to [`None`], which on
997 /// return points to an allocated #GPtrArray containing the property names of
998 /// secrets of the #NMSetting which may be required; the caller owns the array
999 /// and must free the array itself with g_ptr_array_free(), but not free its
1000 /// elements
1001 #[doc(alias = "nm_connection_need_secrets")]
1002 fn need_secrets(&self) -> (Option<glib::GString>, Vec<glib::GString>) {
1003 unsafe {
1004 let mut hints = std::ptr::null_mut();
1005 let ret = from_glib_none(ffi::nm_connection_need_secrets(
1006 self.as_ref().to_glib_none().0,
1007 &mut hints,
1008 ));
1009 (ret, FromGlibPtrContainer::from_glib_container(hints))
1010 }
1011 }
1012
1013 //#[doc(alias = "nm_connection_normalize")]
1014 //fn normalize(&self, parameters: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 25 }) -> Result<bool, glib::Error> {
1015 // unsafe { TODO: call ffi:nm_connection_normalize() }
1016 //}
1017
1018 /// Removes the #NMSetting with the given #GType from the #NMConnection. This
1019 /// operation dereferences the #NMSetting object.
1020 /// ## `setting_type`
1021 /// the #GType of the setting object to remove
1022 #[doc(alias = "nm_connection_remove_setting")]
1023 fn remove_setting(&self, setting_type: glib::types::Type) {
1024 unsafe {
1025 ffi::nm_connection_remove_setting(
1026 self.as_ref().to_glib_none().0,
1027 setting_type.into_glib(),
1028 );
1029 }
1030 }
1031
1032 //#[doc(alias = "nm_connection_replace_settings")]
1033 //fn replace_settings(&self, new_settings: /*Ignored*/&glib::Variant) -> Result<(), glib::Error> {
1034 // unsafe { TODO: call ffi:nm_connection_replace_settings() }
1035 //}
1036
1037 /// Deep-copies the settings of @new_connection and replaces the settings of @self
1038 /// with the copied settings.
1039 /// ## `new_connection`
1040 /// a #NMConnection to replace the settings of @self with
1041 #[doc(alias = "nm_connection_replace_settings_from_connection")]
1042 fn replace_settings_from_connection(&self, new_connection: &impl IsA<Connection>) {
1043 unsafe {
1044 ffi::nm_connection_replace_settings_from_connection(
1045 self.as_ref().to_glib_none().0,
1046 new_connection.as_ref().to_glib_none().0,
1047 );
1048 }
1049 }
1050
1051 /// Sets the D-Bus path of the connection. This property is not serialized, and
1052 /// is only for the reference of the caller. Sets the #NMConnection:path
1053 /// property.
1054 /// ## `path`
1055 /// the D-Bus path of the connection as given by the settings service
1056 /// which provides the connection
1057 #[doc(alias = "nm_connection_set_path")]
1058 fn set_path(&self, path: &str) {
1059 unsafe {
1060 ffi::nm_connection_set_path(self.as_ref().to_glib_none().0, path.to_glib_none().0);
1061 }
1062 }
1063
1064 //#[doc(alias = "nm_connection_to_dbus")]
1065 //fn to_dbus(&self, flags: ConnectionSerializationFlags) -> /*Ignored*/glib::Variant {
1066 // unsafe { TODO: call ffi:nm_connection_to_dbus() }
1067 //}
1068
1069 //#[doc(alias = "nm_connection_update_secrets")]
1070 //fn update_secrets(&self, setting_name: &str, secrets: /*Ignored*/&glib::Variant) -> Result<(), glib::Error> {
1071 // unsafe { TODO: call ffi:nm_connection_update_secrets() }
1072 //}
1073
1074 /// Validates the connection and all its settings. Each setting's properties
1075 /// have allowed values, and some values are dependent on other values. For
1076 /// example, if a Wi-Fi connection is security enabled, the #NMSettingWireless
1077 /// setting object's 'security' property must contain the setting name of the
1078 /// #NMSettingWirelessSecurity object, which must also be present in the
1079 /// connection for the connection to be valid. As another example, the
1080 /// #NMSettingWired object's 'mac-address' property must be a validly formatted
1081 /// MAC address. The returned #GError contains information about which
1082 /// setting and which property failed validation, and how it failed validation.
1083 ///
1084 /// # Returns
1085 ///
1086 /// [`true`] if the connection is valid, [`false`] if it is not
1087 #[doc(alias = "nm_connection_verify")]
1088 fn verify(&self) -> Result<(), glib::Error> {
1089 unsafe {
1090 let mut error = std::ptr::null_mut();
1091 let is_ok = ffi::nm_connection_verify(self.as_ref().to_glib_none().0, &mut error);
1092 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1093 if error.is_null() {
1094 Ok(())
1095 } else {
1096 Err(from_glib_full(error))
1097 }
1098 }
1099 }
1100
1101 /// Verifies the secrets in the connection.
1102 ///
1103 /// # Returns
1104 ///
1105 /// [`true`] if the secrets are valid, [`false`] if they are not
1106 #[cfg(feature = "v1_2")]
1107 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
1108 #[doc(alias = "nm_connection_verify_secrets")]
1109 fn verify_secrets(&self) -> Result<(), glib::Error> {
1110 unsafe {
1111 let mut error = std::ptr::null_mut();
1112 let is_ok =
1113 ffi::nm_connection_verify_secrets(self.as_ref().to_glib_none().0, &mut error);
1114 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1115 if error.is_null() {
1116 Ok(())
1117 } else {
1118 Err(from_glib_full(error))
1119 }
1120 }
1121 }
1122
1123 /// The ::changed signal is emitted when any property (including secrets)
1124 /// of any setting of the connection is modified, or when settings are
1125 /// added or removed.
1126 #[doc(alias = "changed")]
1127 fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1128 unsafe extern "C" fn changed_trampoline<P: IsA<Connection>, F: Fn(&P) + 'static>(
1129 this: *mut ffi::NMConnection,
1130 f: glib::ffi::gpointer,
1131 ) {
1132 let f: &F = &*(f as *const F);
1133 f(Connection::from_glib_borrow(this).unsafe_cast_ref())
1134 }
1135 unsafe {
1136 let f: Box_<F> = Box_::new(f);
1137 connect_raw(
1138 self.as_ptr() as *mut _,
1139 c"changed".as_ptr() as *const _,
1140 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1141 changed_trampoline::<Self, F> as *const (),
1142 )),
1143 Box_::into_raw(f),
1144 )
1145 }
1146 }
1147
1148 /// The ::secrets-cleared signal is emitted when the secrets of a connection
1149 /// are cleared.
1150 #[doc(alias = "secrets-cleared")]
1151 fn connect_secrets_cleared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1152 unsafe extern "C" fn secrets_cleared_trampoline<P: IsA<Connection>, F: Fn(&P) + 'static>(
1153 this: *mut ffi::NMConnection,
1154 f: glib::ffi::gpointer,
1155 ) {
1156 let f: &F = &*(f as *const F);
1157 f(Connection::from_glib_borrow(this).unsafe_cast_ref())
1158 }
1159 unsafe {
1160 let f: Box_<F> = Box_::new(f);
1161 connect_raw(
1162 self.as_ptr() as *mut _,
1163 c"secrets-cleared".as_ptr() as *const _,
1164 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1165 secrets_cleared_trampoline::<Self, F> as *const (),
1166 )),
1167 Box_::into_raw(f),
1168 )
1169 }
1170 }
1171
1172 /// The ::secrets-updated signal is emitted when the secrets of a setting
1173 /// have been changed.
1174 /// ## `setting_name`
1175 /// the setting name of the #NMSetting for which secrets were
1176 /// updated
1177 #[doc(alias = "secrets-updated")]
1178 fn connect_secrets_updated<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
1179 unsafe extern "C" fn secrets_updated_trampoline<
1180 P: IsA<Connection>,
1181 F: Fn(&P, &str) + 'static,
1182 >(
1183 this: *mut ffi::NMConnection,
1184 setting_name: *mut std::ffi::c_char,
1185 f: glib::ffi::gpointer,
1186 ) {
1187 let f: &F = &*(f as *const F);
1188 f(
1189 Connection::from_glib_borrow(this).unsafe_cast_ref(),
1190 &glib::GString::from_glib_borrow(setting_name),
1191 )
1192 }
1193 unsafe {
1194 let f: Box_<F> = Box_::new(f);
1195 connect_raw(
1196 self.as_ptr() as *mut _,
1197 c"secrets-updated".as_ptr() as *const _,
1198 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1199 secrets_updated_trampoline::<Self, F> as *const (),
1200 )),
1201 Box_::into_raw(f),
1202 )
1203 }
1204 }
1205}
1206
1207impl<O: IsA<Connection>> ConnectionExt for O {}