nm_rs/auto/
setting.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
6use crate::{Connection, SettingCompareFlags, SettingSecretFlags, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    ///
16    ///
17    /// This is an Abstract Base Class, you cannot instantiate it.
18    ///
19    /// ## Properties
20    ///
21    ///
22    /// #### `name`
23    ///  The setting's name, which uniquely identifies the setting within the
24    /// connection.  Each setting type has a name unique to that type, for
25    /// example "ppp" or "802-11-wireless" or "802-3-ethernet".
26    ///
27    /// Readable
28    ///
29    /// # Implements
30    ///
31    /// [`SettingExt`][trait@crate::prelude::SettingExt]
32    #[doc(alias = "NMSetting")]
33    pub struct Setting(Object<ffi::NMSetting, ffi::NMSettingClass>);
34
35    match fn {
36        type_ => || ffi::nm_setting_get_type(),
37    }
38}
39
40impl Setting {
41    pub const NONE: Option<&'static Setting> = None;
42
43    /// Get the type of the enum that defines the values that the property accepts. It is only
44    /// useful for properties configured to accept values from certain enum type, otherwise
45    /// it will return `G_TYPE_INVALID`. Note that flags (children of G_TYPE_FLAGS) are also
46    /// considered enums.
47    ///
48    /// Note that the GObject property might be implemented as an integer, actually, and not
49    /// as enum. Find out what underlying type is used, checking the #GParamSpec, before
50    /// setting the GObject property.
51    /// ## `setting_type`
52    /// the GType of the NMSetting instance
53    /// ## `property_name`
54    /// the name of the property
55    ///
56    /// # Returns
57    ///
58    /// the enum's GType, or `G_TYPE_INVALID` if the property is not of enum type
59    #[cfg(feature = "v1_46")]
60    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
61    #[doc(alias = "nm_setting_get_enum_property_type")]
62    #[doc(alias = "get_enum_property_type")]
63    pub fn enum_property_type(
64        setting_type: glib::types::Type,
65        property_name: &str,
66    ) -> glib::types::Type {
67        assert_initialized_main_thread!();
68        unsafe {
69            from_glib(ffi::nm_setting_get_enum_property_type(
70                setting_type.into_glib(),
71                property_name.to_glib_none().0,
72            ))
73        }
74    }
75
76    /// Returns the #GType of the setting's class for a given setting name.
77    /// ## `name`
78    /// a setting name
79    ///
80    /// # Returns
81    ///
82    /// the #GType of the setting's class, or `G_TYPE_INVALID` if
83    ///   @name is not recognized.
84    #[doc(alias = "nm_setting_lookup_type")]
85    pub fn lookup_type(name: &str) -> glib::types::Type {
86        assert_initialized_main_thread!();
87        unsafe { from_glib(ffi::nm_setting_lookup_type(name.to_glib_none().0)) }
88    }
89}
90
91impl std::fmt::Display for Setting {
92    #[inline]
93    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
94        f.write_str(&SettingExt::to_str(self))
95    }
96}
97
98/// Trait containing all [`struct@Setting`] methods.
99///
100/// # Implementors
101///
102/// [`Setting6Lowpan`][struct@crate::Setting6Lowpan], [`Setting8021x`][struct@crate::Setting8021x], [`SettingAdsl`][struct@crate::SettingAdsl], [`SettingBluetooth`][struct@crate::SettingBluetooth], [`SettingBondPort`][struct@crate::SettingBondPort], [`SettingBond`][struct@crate::SettingBond], [`SettingBridgePort`][struct@crate::SettingBridgePort], [`SettingBridge`][struct@crate::SettingBridge], [`SettingCdma`][struct@crate::SettingCdma], [`SettingConnection`][struct@crate::SettingConnection], [`SettingDcb`][struct@crate::SettingDcb], [`SettingDummy`][struct@crate::SettingDummy], [`SettingEthtool`][struct@crate::SettingEthtool], [`SettingGeneric`][struct@crate::SettingGeneric], [`SettingGsm`][struct@crate::SettingGsm], [`SettingHostname`][struct@crate::SettingHostname], [`SettingHsr`][struct@crate::SettingHsr], [`SettingIPConfig`][struct@crate::SettingIPConfig], [`SettingIPTunnel`][struct@crate::SettingIPTunnel], [`SettingInfiniband`][struct@crate::SettingInfiniband], [`SettingIpvlan`][struct@crate::SettingIpvlan], [`SettingLink`][struct@crate::SettingLink], [`SettingLoopback`][struct@crate::SettingLoopback], [`SettingMacsec`][struct@crate::SettingMacsec], [`SettingMacvlan`][struct@crate::SettingMacvlan], [`SettingMatch`][struct@crate::SettingMatch], [`SettingOlpcMesh`][struct@crate::SettingOlpcMesh], [`SettingOvsBridge`][struct@crate::SettingOvsBridge], [`SettingOvsDpdk`][struct@crate::SettingOvsDpdk], [`SettingOvsExternalIDs`][struct@crate::SettingOvsExternalIDs], [`SettingOvsOtherConfig`][struct@crate::SettingOvsOtherConfig], [`SettingOvsPatch`][struct@crate::SettingOvsPatch], [`SettingOvsPort`][struct@crate::SettingOvsPort], [`SettingPpp`][struct@crate::SettingPpp], [`SettingPppoe`][struct@crate::SettingPppoe], [`SettingPrefixDelegation`][struct@crate::SettingPrefixDelegation], [`SettingProxy`][struct@crate::SettingProxy], [`SettingSerial`][struct@crate::SettingSerial], [`SettingSriov`][struct@crate::SettingSriov], [`SettingTCConfig`][struct@crate::SettingTCConfig], [`SettingTeamPort`][struct@crate::SettingTeamPort], [`SettingTeam`][struct@crate::SettingTeam], [`SettingTun`][struct@crate::SettingTun], [`SettingUser`][struct@crate::SettingUser], [`SettingVeth`][struct@crate::SettingVeth], [`SettingVlan`][struct@crate::SettingVlan], [`SettingVpn`][struct@crate::SettingVpn], [`SettingVrf`][struct@crate::SettingVrf], [`SettingVxlan`][struct@crate::SettingVxlan], [`SettingWifiP2P`][struct@crate::SettingWifiP2P], [`SettingWimax`][struct@crate::SettingWimax], [`SettingWireGuard`][struct@crate::SettingWireGuard], [`SettingWired`][struct@crate::SettingWired], [`SettingWirelessSecurity`][struct@crate::SettingWirelessSecurity], [`SettingWireless`][struct@crate::SettingWireless], [`SettingWpan`][struct@crate::SettingWpan], [`Setting`][struct@crate::Setting]
103pub trait SettingExt: IsA<Setting> + 'static {
104    #[doc(alias = "nm_setting_compare")]
105    fn compare(&self, b: &impl IsA<Setting>, flags: SettingCompareFlags) -> bool {
106        unsafe {
107            from_glib(ffi::nm_setting_compare(
108                self.as_ref().to_glib_none().0,
109                b.as_ref().to_glib_none().0,
110                flags.into_glib(),
111            ))
112        }
113    }
114
115    //#[doc(alias = "nm_setting_diff")]
116    //fn diff(&self, b: &impl IsA<Setting>, flags: SettingCompareFlags, invert_results: bool, results: /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 7 }) -> bool {
117    //    unsafe { TODO: call ffi:nm_setting_diff() }
118    //}
119
120    /// Duplicates a #NMSetting.
121    ///
122    /// # Returns
123    ///
124    /// a new #NMSetting containing the same properties and values as the
125    /// source #NMSetting
126    #[doc(alias = "nm_setting_duplicate")]
127    #[must_use]
128    fn duplicate(&self) -> Setting {
129        unsafe { from_glib_full(ffi::nm_setting_duplicate(self.as_ref().to_glib_none().0)) }
130    }
131
132    //#[doc(alias = "nm_setting_enumerate_values")]
133    //fn enumerate_values(&self, func: /*Unimplemented*/FnMut(&Setting, &str, /*Ignored*/glib::Value, /*Ignored*/glib::ParamFlags), user_data: /*Unimplemented*/Option<Basic: Pointer>) {
134    //    unsafe { TODO: call ffi:nm_setting_enumerate_values() }
135    //}
136
137    //#[doc(alias = "nm_setting_get_dbus_property_type")]
138    //#[doc(alias = "get_dbus_property_type")]
139    //fn dbus_property_type(&self, property_name: &str) -> /*Ignored*/glib::VariantType {
140    //    unsafe { TODO: call ffi:nm_setting_get_dbus_property_type() }
141    //}
142
143    /// Returns the type name of the #NMSetting object
144    ///
145    /// # Returns
146    ///
147    /// a string containing the type name of the #NMSetting object,
148    /// like 'ppp' or 'wireless' or 'wired'.
149    #[doc(alias = "nm_setting_get_name")]
150    #[doc(alias = "get_name")]
151    fn name(&self) -> glib::GString {
152        unsafe { from_glib_none(ffi::nm_setting_get_name(self.as_ref().to_glib_none().0)) }
153    }
154
155    /// For a given secret, retrieves the #NMSettingSecretFlags describing how to
156    /// handle that secret.
157    /// ## `secret_name`
158    /// the secret key name to get flags for
159    /// ## `out_flags`
160    /// on success, the #NMSettingSecretFlags for the secret
161    ///
162    /// # Returns
163    ///
164    /// [`true`] on success (if the given secret name was a valid property of
165    /// this setting, and if that property is secret), [`false`] if not
166    #[doc(alias = "nm_setting_get_secret_flags")]
167    #[doc(alias = "get_secret_flags")]
168    fn secret_flags(
169        &self,
170        secret_name: &str,
171        out_flags: SettingSecretFlags,
172    ) -> Result<(), glib::Error> {
173        unsafe {
174            let mut error = std::ptr::null_mut();
175            let is_ok = ffi::nm_setting_get_secret_flags(
176                self.as_ref().to_glib_none().0,
177                secret_name.to_glib_none().0,
178                &mut out_flags.into_glib(),
179                &mut error,
180            );
181            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
182            if error.is_null() {
183                Ok(())
184            } else {
185                Err(from_glib_full(error))
186            }
187        }
188    }
189
190    //#[cfg(feature = "v1_26")]
191    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
192    //#[doc(alias = "nm_setting_option_clear_by_name")]
193    //fn option_clear_by_name(&self, predicate: Option<&mut dyn FnMut() -> bool>) {
194    //    unsafe { TODO: call ffi:nm_setting_option_clear_by_name() }
195    //}
196
197    //#[cfg(feature = "v1_26")]
198    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
199    //#[doc(alias = "nm_setting_option_get")]
200    //fn option_get(&self, opt_name: &str) -> /*Ignored*/glib::Variant {
201    //    unsafe { TODO: call ffi:nm_setting_option_get() }
202    //}
203
204    /// Gives the name of all set options.
205    ///
206    /// # Returns
207    ///
208    ///
209    ///   A [`None`] terminated array of key names. If no names are present, this returns
210    ///   [`None`]. The returned array and the names are owned by `NMSetting` and might be invalidated
211    ///   by the next operation.
212    #[cfg(feature = "v1_26")]
213    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
214    #[doc(alias = "nm_setting_option_get_all_names")]
215    fn option_get_all_names(&self) -> Vec<glib::GString> {
216        unsafe {
217            let mut out_len = std::mem::MaybeUninit::uninit();
218            let ret = FromGlibContainer::from_glib_none_num(
219                ffi::nm_setting_option_get_all_names(
220                    self.as_ref().to_glib_none().0,
221                    out_len.as_mut_ptr(),
222                ),
223                out_len.assume_init() as _,
224            );
225            ret
226        }
227    }
228
229    /// ## `opt_name`
230    /// the option to get
231    ///
232    /// # Returns
233    ///
234    /// [`true`] if @opt_name is set to a boolean variant.
235    ///
236    /// ## `out_value`
237    /// the optional output value.
238    ///   If the option is unset, [`false`] will be returned.
239    #[cfg(feature = "v1_26")]
240    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
241    #[doc(alias = "nm_setting_option_get_boolean")]
242    fn option_get_boolean(&self, opt_name: &str) -> Option<bool> {
243        unsafe {
244            let mut out_value = std::mem::MaybeUninit::uninit();
245            let ret = from_glib(ffi::nm_setting_option_get_boolean(
246                self.as_ref().to_glib_none().0,
247                opt_name.to_glib_none().0,
248                out_value.as_mut_ptr(),
249            ));
250            if ret { Some(true) } else { None }
251        }
252    }
253
254    /// ## `opt_name`
255    /// the option to get
256    ///
257    /// # Returns
258    ///
259    /// [`true`] if @opt_name is set to a uint32 variant.
260    ///
261    /// ## `out_value`
262    /// the optional output value.
263    ///   If the option is unset, 0 will be returned.
264    #[cfg(feature = "v1_26")]
265    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
266    #[doc(alias = "nm_setting_option_get_uint32")]
267    fn option_get_uint32(&self, opt_name: &str) -> Option<u32> {
268        unsafe {
269            let mut out_value = std::mem::MaybeUninit::uninit();
270            let ret = from_glib(ffi::nm_setting_option_get_uint32(
271                self.as_ref().to_glib_none().0,
272                opt_name.to_glib_none().0,
273                out_value.as_mut_ptr(),
274            ));
275            if ret {
276                Some(out_value.assume_init())
277            } else {
278                None
279            }
280        }
281    }
282
283    //#[cfg(feature = "v1_26")]
284    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
285    //#[doc(alias = "nm_setting_option_set")]
286    //fn option_set(&self, opt_name: &str, variant: /*Ignored*/Option<&glib::Variant>) {
287    //    unsafe { TODO: call ffi:nm_setting_option_set() }
288    //}
289
290    /// Like nm_setting_option_set() to set a boolean GVariant.
291    /// ## `value`
292    /// the value to set.
293    #[cfg(feature = "v1_26")]
294    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
295    #[doc(alias = "nm_setting_option_set_boolean")]
296    fn option_set_boolean(&self, opt_name: &str, value: bool) {
297        unsafe {
298            ffi::nm_setting_option_set_boolean(
299                self.as_ref().to_glib_none().0,
300                opt_name.to_glib_none().0,
301                value.into_glib(),
302            );
303        }
304    }
305
306    /// Like nm_setting_option_set() to set a uint32 GVariant.
307    /// ## `value`
308    /// the value to set.
309    #[cfg(feature = "v1_26")]
310    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
311    #[doc(alias = "nm_setting_option_set_uint32")]
312    fn option_set_uint32(&self, opt_name: &str, value: u32) {
313        unsafe {
314            ffi::nm_setting_option_set_uint32(
315                self.as_ref().to_glib_none().0,
316                opt_name.to_glib_none().0,
317                value,
318            );
319        }
320    }
321
322    /// For a given secret, stores the #NMSettingSecretFlags describing how to
323    /// handle that secret.
324    /// ## `secret_name`
325    /// the secret key name to set flags for
326    /// ## `flags`
327    /// the #NMSettingSecretFlags for the secret
328    ///
329    /// # Returns
330    ///
331    /// [`true`] on success (if the given secret name was a valid property of
332    /// this setting, and if that property is secret), [`false`] if not
333    #[doc(alias = "nm_setting_set_secret_flags")]
334    fn set_secret_flags(
335        &self,
336        secret_name: &str,
337        flags: SettingSecretFlags,
338    ) -> Result<(), glib::Error> {
339        unsafe {
340            let mut error = std::ptr::null_mut();
341            let is_ok = ffi::nm_setting_set_secret_flags(
342                self.as_ref().to_glib_none().0,
343                secret_name.to_glib_none().0,
344                flags.into_glib(),
345                &mut error,
346            );
347            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
348            if error.is_null() {
349                Ok(())
350            } else {
351                Err(from_glib_full(error))
352            }
353        }
354    }
355
356    /// Convert the setting (including secrets!) into a string. For debugging
357    /// purposes ONLY, should NOT be used for serialization of the setting,
358    /// or machine-parsed in any way. The output format is not guaranteed to
359    /// be stable and may change at any time.
360    ///
361    /// # Returns
362    ///
363    /// an allocated string containing a textual representation of the
364    /// setting's properties and values, which the caller should
365    /// free with g_free()
366    #[doc(alias = "nm_setting_to_string")]
367    #[doc(alias = "to_string")]
368    fn to_str(&self) -> glib::GString {
369        unsafe { from_glib_full(ffi::nm_setting_to_string(self.as_ref().to_glib_none().0)) }
370    }
371
372    /// Validates the setting.  Each setting's properties have allowed values, and
373    /// some are dependent on other values (hence the need for @connection).  The
374    /// returned #GError contains information about which property of the setting
375    /// failed validation, and in what way that property failed validation.
376    /// ## `connection`
377    /// the #NMConnection that @self came from, or
378    ///   [`None`] if @self is being verified in isolation.
379    ///
380    /// # Returns
381    ///
382    /// [`true`] if the setting is valid, [`false`] if it is not
383    #[doc(alias = "nm_setting_verify")]
384    fn verify(&self, connection: Option<&impl IsA<Connection>>) -> Result<(), glib::Error> {
385        unsafe {
386            let mut error = std::ptr::null_mut();
387            let is_ok = ffi::nm_setting_verify(
388                self.as_ref().to_glib_none().0,
389                connection.map(|p| p.as_ref()).to_glib_none().0,
390                &mut error,
391            );
392            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
393            if error.is_null() {
394                Ok(())
395            } else {
396                Err(from_glib_full(error))
397            }
398        }
399    }
400
401    /// Verifies the secrets in the setting.
402    /// The returned #GError contains information about which secret of the setting
403    /// failed validation, and in what way that secret failed validation.
404    /// The secret validation is done separately from main setting validation, because
405    /// in some cases connection failure is not desired just for the secrets.
406    /// ## `connection`
407    /// the #NMConnection that @self came from, or
408    ///   [`None`] if @self is being verified in isolation.
409    ///
410    /// # Returns
411    ///
412    /// [`true`] if the setting secrets are valid, [`false`] if they are not
413    #[cfg(feature = "v1_2")]
414    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
415    #[doc(alias = "nm_setting_verify_secrets")]
416    fn verify_secrets(&self, connection: Option<&impl IsA<Connection>>) -> Result<(), glib::Error> {
417        unsafe {
418            let mut error = std::ptr::null_mut();
419            let is_ok = ffi::nm_setting_verify_secrets(
420                self.as_ref().to_glib_none().0,
421                connection.map(|p| p.as_ref()).to_glib_none().0,
422                &mut error,
423            );
424            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
425            if error.is_null() {
426                Ok(())
427            } else {
428                Err(from_glib_full(error))
429            }
430        }
431    }
432
433    #[doc(alias = "name")]
434    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
435        unsafe extern "C" fn notify_name_trampoline<P: IsA<Setting>, F: Fn(&P) + 'static>(
436            this: *mut ffi::NMSetting,
437            _param_spec: glib::ffi::gpointer,
438            f: glib::ffi::gpointer,
439        ) {
440            let f: &F = &*(f as *const F);
441            f(Setting::from_glib_borrow(this).unsafe_cast_ref())
442        }
443        unsafe {
444            let f: Box_<F> = Box_::new(f);
445            connect_raw(
446                self.as_ptr() as *mut _,
447                c"notify::name".as_ptr() as *const _,
448                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
449                    notify_name_trampoline::<Self, F> as *const (),
450                )),
451                Box_::into_raw(f),
452            )
453        }
454    }
455}
456
457impl<O: IsA<Setting>> SettingExt for O {}