nm_rs/auto/
setting_bridge_port.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_18")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
8use crate::BridgeVlan;
9use crate::{Setting, ffi};
10use glib::{
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// Bridge Port Settings
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `hairpin-mode`
24    ///  Enables or disables "hairpin mode" for the port, which allows frames to
25    /// be sent back out through the port the frame was received on.
26    ///
27    /// Readable | Writeable
28    ///
29    ///
30    /// #### `path-cost`
31    ///  The Spanning Tree Protocol (STP) port cost for destinations via this
32    /// port.
33    ///
34    /// Readable | Writeable
35    ///
36    ///
37    /// #### `priority`
38    ///  The Spanning Tree Protocol (STP) priority of this bridge port.
39    ///
40    /// Readable | Writeable
41    ///
42    ///
43    /// #### `vlans`
44    ///  Array of bridge VLAN objects. In addition to the VLANs
45    /// specified here, the port will also have the default-pvid
46    /// VLAN configured on the bridge by the bridge.vlan-default-pvid
47    /// property.
48    ///
49    /// In nmcli the VLAN list can be specified with the following
50    /// syntax:
51    ///
52    ///  $vid [pvid] [untagged] [, $vid [pvid] [untagged]]...
53    ///
54    /// where $vid is either a single id between 1 and 4094 or a
55    /// range, represented as a couple of ids separated by a dash.
56    ///
57    /// Readable | Writeable
58    /// <details><summary><h4>Setting</h4></summary>
59    ///
60    ///
61    /// #### `name`
62    ///  The setting's name, which uniquely identifies the setting within the
63    /// connection.  Each setting type has a name unique to that type, for
64    /// example "ppp" or "802-11-wireless" or "802-3-ethernet".
65    ///
66    /// Readable
67    /// </details>
68    ///
69    /// # Implements
70    ///
71    /// [`SettingExt`][trait@crate::prelude::SettingExt]
72    #[doc(alias = "NMSettingBridgePort")]
73    pub struct SettingBridgePort(Object<ffi::NMSettingBridgePort, ffi::NMSettingBridgePortClass>) @extends Setting;
74
75    match fn {
76        type_ => || ffi::nm_setting_bridge_port_get_type(),
77    }
78}
79
80impl SettingBridgePort {
81    /// Creates a new #NMSettingBridgePort object with default values.
82    ///
83    /// # Returns
84    ///
85    /// the new empty #NMSettingBridgePort object
86    #[doc(alias = "nm_setting_bridge_port_new")]
87    pub fn new() -> SettingBridgePort {
88        assert_initialized_main_thread!();
89        unsafe { Setting::from_glib_full(ffi::nm_setting_bridge_port_new()).unsafe_cast() }
90    }
91
92    // rustdoc-stripper-ignore-next
93    /// Creates a new builder-pattern struct instance to construct [`SettingBridgePort`] objects.
94    ///
95    /// This method returns an instance of [`SettingBridgePortBuilder`](crate::builders::SettingBridgePortBuilder) which can be used to create [`SettingBridgePort`] objects.
96    pub fn builder() -> SettingBridgePortBuilder {
97        SettingBridgePortBuilder::new()
98    }
99
100    /// Appends a new vlan and associated information to the setting.  The
101    /// given vlan gets sealed and a reference to it is added.
102    /// ## `vlan`
103    /// the vlan to add
104    #[cfg(feature = "v1_18")]
105    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
106    #[doc(alias = "nm_setting_bridge_port_add_vlan")]
107    pub fn add_vlan(&self, vlan: &BridgeVlan) {
108        unsafe {
109            ffi::nm_setting_bridge_port_add_vlan(self.to_glib_none().0, vlan.to_glib_none().0);
110        }
111    }
112
113    /// Removes all configured VLANs.
114    #[cfg(feature = "v1_18")]
115    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
116    #[doc(alias = "nm_setting_bridge_port_clear_vlans")]
117    pub fn clear_vlans(&self) {
118        unsafe {
119            ffi::nm_setting_bridge_port_clear_vlans(self.to_glib_none().0);
120        }
121    }
122
123    ///
124    /// # Returns
125    ///
126    /// the #NMSettingBridgePort:hairpin-mode property of the setting
127    #[doc(alias = "nm_setting_bridge_port_get_hairpin_mode")]
128    #[doc(alias = "get_hairpin_mode")]
129    #[doc(alias = "hairpin-mode")]
130    pub fn is_hairpin_mode(&self) -> bool {
131        unsafe {
132            from_glib(ffi::nm_setting_bridge_port_get_hairpin_mode(
133                self.to_glib_none().0,
134            ))
135        }
136    }
137
138    ///
139    /// # Returns
140    ///
141    /// the number of VLANs
142    #[cfg(feature = "v1_18")]
143    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
144    #[doc(alias = "nm_setting_bridge_port_get_num_vlans")]
145    #[doc(alias = "get_num_vlans")]
146    pub fn num_vlans(&self) -> u32 {
147        unsafe { ffi::nm_setting_bridge_port_get_num_vlans(self.to_glib_none().0) }
148    }
149
150    ///
151    /// # Returns
152    ///
153    /// the #NMSettingBridgePort:path-cost property of the setting
154    #[doc(alias = "nm_setting_bridge_port_get_path_cost")]
155    #[doc(alias = "get_path_cost")]
156    #[doc(alias = "path-cost")]
157    pub fn path_cost(&self) -> u16 {
158        unsafe { ffi::nm_setting_bridge_port_get_path_cost(self.to_glib_none().0) }
159    }
160
161    ///
162    /// # Returns
163    ///
164    /// the #NMSettingBridgePort:priority property of the setting
165    #[doc(alias = "nm_setting_bridge_port_get_priority")]
166    #[doc(alias = "get_priority")]
167    pub fn priority(&self) -> u16 {
168        unsafe { ffi::nm_setting_bridge_port_get_priority(self.to_glib_none().0) }
169    }
170
171    /// ## `idx`
172    /// index number of the VLAN to return
173    ///
174    /// # Returns
175    ///
176    /// the VLAN at index @idx
177    #[cfg(feature = "v1_18")]
178    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
179    #[doc(alias = "nm_setting_bridge_port_get_vlan")]
180    #[doc(alias = "get_vlan")]
181    pub fn vlan(&self, idx: u32) -> BridgeVlan {
182        unsafe {
183            from_glib_none(ffi::nm_setting_bridge_port_get_vlan(
184                self.to_glib_none().0,
185                idx,
186            ))
187        }
188    }
189
190    /// Removes the vlan at index @idx.
191    /// ## `idx`
192    /// index number of the VLAN.
193    #[cfg(feature = "v1_18")]
194    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
195    #[doc(alias = "nm_setting_bridge_port_remove_vlan")]
196    pub fn remove_vlan(&self, idx: u32) {
197        unsafe {
198            ffi::nm_setting_bridge_port_remove_vlan(self.to_glib_none().0, idx);
199        }
200    }
201
202    /// Remove the VLAN with range @vid_start to @vid_end.
203    /// If @vid_end is zero, it is assumed to be equal to @vid_start
204    /// and so the single-id VLAN with id @vid_start is removed.
205    /// ## `vid_start`
206    /// the vlan start index
207    /// ## `vid_end`
208    /// the vlan end index
209    ///
210    /// # Returns
211    ///
212    /// [`true`] if the vlan was found and removed; [`false`] otherwise
213    #[cfg(feature = "v1_18")]
214    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
215    #[doc(alias = "nm_setting_bridge_port_remove_vlan_by_vid")]
216    pub fn remove_vlan_by_vid(&self, vid_start: u16, vid_end: u16) -> bool {
217        unsafe {
218            from_glib(ffi::nm_setting_bridge_port_remove_vlan_by_vid(
219                self.to_glib_none().0,
220                vid_start,
221                vid_end,
222            ))
223        }
224    }
225
226    /// Enables or disables "hairpin mode" for the port, which allows frames to
227    /// be sent back out through the port the frame was received on.
228    #[doc(alias = "hairpin-mode")]
229    pub fn set_hairpin_mode(&self, hairpin_mode: bool) {
230        ObjectExt::set_property(self, "hairpin-mode", hairpin_mode)
231    }
232
233    /// The Spanning Tree Protocol (STP) port cost for destinations via this
234    /// port.
235    #[doc(alias = "path-cost")]
236    pub fn set_path_cost(&self, path_cost: u32) {
237        ObjectExt::set_property(self, "path-cost", path_cost)
238    }
239
240    /// The Spanning Tree Protocol (STP) priority of this bridge port.
241    pub fn set_priority(&self, priority: u32) {
242        ObjectExt::set_property(self, "priority", priority)
243    }
244
245    /// Array of bridge VLAN objects. In addition to the VLANs
246    /// specified here, the port will also have the default-pvid
247    /// VLAN configured on the bridge by the bridge.vlan-default-pvid
248    /// property.
249    ///
250    /// In nmcli the VLAN list can be specified with the following
251    /// syntax:
252    ///
253    ///  $vid [pvid] [untagged] [, $vid [pvid] [untagged]]...
254    ///
255    /// where $vid is either a single id between 1 and 4094 or a
256    /// range, represented as a couple of ids separated by a dash.
257    #[cfg(feature = "v1_18")]
258    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
259    pub fn vlans(&self) -> Vec<BridgeVlan> {
260        use glib::value::FromValue;
261        let vals = ObjectExt::property::<glib::ValueArray>(self, "vlans");
262        vals.iter()
263            .map(|value| unsafe { BridgeVlan::from_value(value) })
264            .collect()
265    }
266
267    /// Array of bridge VLAN objects. In addition to the VLANs
268    /// specified here, the port will also have the default-pvid
269    /// VLAN configured on the bridge by the bridge.vlan-default-pvid
270    /// property.
271    ///
272    /// In nmcli the VLAN list can be specified with the following
273    /// syntax:
274    ///
275    ///  $vid [pvid] [untagged] [, $vid [pvid] [untagged]]...
276    ///
277    /// where $vid is either a single id between 1 and 4094 or a
278    /// range, represented as a couple of ids separated by a dash.
279    #[cfg(feature = "v1_18")]
280    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
281    pub fn set_vlans(&self, vlans: &[&BridgeVlan]) {
282        ObjectExt::set_property(
283            self,
284            "vlans",
285            vlans
286                .iter()
287                .map(|vlan| vlan.to_value())
288                .collect::<glib::ValueArray>(),
289        )
290    }
291
292    #[doc(alias = "hairpin-mode")]
293    pub fn connect_hairpin_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
294        unsafe extern "C" fn notify_hairpin_mode_trampoline<F: Fn(&SettingBridgePort) + 'static>(
295            this: *mut ffi::NMSettingBridgePort,
296            _param_spec: glib::ffi::gpointer,
297            f: glib::ffi::gpointer,
298        ) {
299            let f: &F = &*(f as *const F);
300            f(&from_glib_borrow(this))
301        }
302        unsafe {
303            let f: Box_<F> = Box_::new(f);
304            connect_raw(
305                self.as_ptr() as *mut _,
306                c"notify::hairpin-mode".as_ptr() as *const _,
307                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
308                    notify_hairpin_mode_trampoline::<F> as *const (),
309                )),
310                Box_::into_raw(f),
311            )
312        }
313    }
314
315    #[doc(alias = "path-cost")]
316    pub fn connect_path_cost_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
317        unsafe extern "C" fn notify_path_cost_trampoline<F: Fn(&SettingBridgePort) + 'static>(
318            this: *mut ffi::NMSettingBridgePort,
319            _param_spec: glib::ffi::gpointer,
320            f: glib::ffi::gpointer,
321        ) {
322            let f: &F = &*(f as *const F);
323            f(&from_glib_borrow(this))
324        }
325        unsafe {
326            let f: Box_<F> = Box_::new(f);
327            connect_raw(
328                self.as_ptr() as *mut _,
329                c"notify::path-cost".as_ptr() as *const _,
330                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
331                    notify_path_cost_trampoline::<F> as *const (),
332                )),
333                Box_::into_raw(f),
334            )
335        }
336    }
337
338    #[doc(alias = "priority")]
339    pub fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
340        unsafe extern "C" fn notify_priority_trampoline<F: Fn(&SettingBridgePort) + 'static>(
341            this: *mut ffi::NMSettingBridgePort,
342            _param_spec: glib::ffi::gpointer,
343            f: glib::ffi::gpointer,
344        ) {
345            let f: &F = &*(f as *const F);
346            f(&from_glib_borrow(this))
347        }
348        unsafe {
349            let f: Box_<F> = Box_::new(f);
350            connect_raw(
351                self.as_ptr() as *mut _,
352                c"notify::priority".as_ptr() as *const _,
353                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
354                    notify_priority_trampoline::<F> as *const (),
355                )),
356                Box_::into_raw(f),
357            )
358        }
359    }
360
361    #[cfg(feature = "v1_18")]
362    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
363    #[doc(alias = "vlans")]
364    pub fn connect_vlans_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
365        unsafe extern "C" fn notify_vlans_trampoline<F: Fn(&SettingBridgePort) + 'static>(
366            this: *mut ffi::NMSettingBridgePort,
367            _param_spec: glib::ffi::gpointer,
368            f: glib::ffi::gpointer,
369        ) {
370            let f: &F = &*(f as *const F);
371            f(&from_glib_borrow(this))
372        }
373        unsafe {
374            let f: Box_<F> = Box_::new(f);
375            connect_raw(
376                self.as_ptr() as *mut _,
377                c"notify::vlans".as_ptr() as *const _,
378                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
379                    notify_vlans_trampoline::<F> as *const (),
380                )),
381                Box_::into_raw(f),
382            )
383        }
384    }
385}
386
387impl Default for SettingBridgePort {
388    fn default() -> Self {
389        Self::new()
390    }
391}
392
393// rustdoc-stripper-ignore-next
394/// A [builder-pattern] type to construct [`SettingBridgePort`] objects.
395///
396/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
397#[must_use = "The builder must be built to be used"]
398pub struct SettingBridgePortBuilder {
399    builder: glib::object::ObjectBuilder<'static, SettingBridgePort>,
400}
401
402impl SettingBridgePortBuilder {
403    fn new() -> Self {
404        Self {
405            builder: glib::object::Object::builder(),
406        }
407    }
408
409    /// Enables or disables "hairpin mode" for the port, which allows frames to
410    /// be sent back out through the port the frame was received on.
411    pub fn hairpin_mode(self, hairpin_mode: bool) -> Self {
412        Self {
413            builder: self.builder.property("hairpin-mode", hairpin_mode),
414        }
415    }
416
417    /// The Spanning Tree Protocol (STP) port cost for destinations via this
418    /// port.
419    pub fn path_cost(self, path_cost: u32) -> Self {
420        Self {
421            builder: self.builder.property("path-cost", path_cost),
422        }
423    }
424
425    /// The Spanning Tree Protocol (STP) priority of this bridge port.
426    pub fn priority(self, priority: u32) -> Self {
427        Self {
428            builder: self.builder.property("priority", priority),
429        }
430    }
431
432    /// Array of bridge VLAN objects. In addition to the VLANs
433    /// specified here, the port will also have the default-pvid
434    /// VLAN configured on the bridge by the bridge.vlan-default-pvid
435    /// property.
436    ///
437    /// In nmcli the VLAN list can be specified with the following
438    /// syntax:
439    ///
440    ///  $vid [pvid] [untagged] [, $vid [pvid] [untagged]]...
441    ///
442    /// where $vid is either a single id between 1 and 4094 or a
443    /// range, represented as a couple of ids separated by a dash.
444    #[cfg(feature = "v1_18")]
445    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
446    pub fn vlans(self, vlans: &[&BridgeVlan]) -> Self {
447        Self {
448            builder: self.builder.property(
449                "vlans",
450                vlans
451                    .iter()
452                    .map(|vlan| vlan.to_value())
453                    .collect::<glib::ValueArray>(),
454            ),
455        }
456    }
457
458    // rustdoc-stripper-ignore-next
459    /// Build the [`SettingBridgePort`].
460    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
461    pub fn build(self) -> SettingBridgePort {
462        assert_initialized_main_thread!();
463        self.builder.build()
464    }
465}