1#[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 #[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 #[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 pub fn builder() -> SettingBridgePortBuilder {
97 SettingBridgePortBuilder::new()
98 }
99
100 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 pub fn set_priority(&self, priority: u32) {
242 ObjectExt::set_property(self, "priority", priority)
243 }
244
245 #[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 #[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#[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 pub fn hairpin_mode(self, hairpin_mode: bool) -> Self {
412 Self {
413 builder: self.builder.property("hairpin-mode", hairpin_mode),
414 }
415 }
416
417 pub fn path_cost(self, path_cost: u32) -> Self {
420 Self {
421 builder: self.builder.property("path-cost", path_cost),
422 }
423 }
424
425 pub fn priority(self, priority: u32) -> Self {
427 Self {
428 builder: self.builder.property("priority", priority),
429 }
430 }
431
432 #[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 #[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}