nm_rs/auto/setting_tc_config.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::{Setting, TCQdisc, TCTfilter, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11 value::FromValue,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 /// Linux Traffic Control Settings
17 ///
18 /// ## Properties
19 ///
20 ///
21 /// #### `qdiscs`
22 /// Array of TC queueing disciplines.
23 ///
24 /// When the #NMSettingTCConfig setting is present, qdiscs from this
25 /// property are applied upon activation. If the property is empty,
26 /// all qdiscs are removed and the device will only
27 /// have the default qdisc assigned by kernel according to the
28 /// "net.core.default_qdisc" sysctl.
29 ///
30 /// If the #NMSettingTCConfig setting is not present, NetworkManager
31 /// doesn't touch the qdiscs present on the interface.
32 ///
33 /// Readable | Writeable
34 ///
35 ///
36 /// #### `tfilters`
37 /// Array of TC traffic filters.
38 ///
39 /// When the #NMSettingTCConfig setting is present, filters from this
40 /// property are applied upon activation. If the property is empty,
41 /// NetworkManager removes all the filters.
42 ///
43 /// If the #NMSettingTCConfig setting is not present, NetworkManager
44 /// doesn't touch the filters present on the interface.
45 ///
46 /// Readable | Writeable
47 /// <details><summary><h4>Setting</h4></summary>
48 ///
49 ///
50 /// #### `name`
51 /// The setting's name, which uniquely identifies the setting within the
52 /// connection. Each setting type has a name unique to that type, for
53 /// example "ppp" or "802-11-wireless" or "802-3-ethernet".
54 ///
55 /// Readable
56 /// </details>
57 ///
58 /// # Implements
59 ///
60 /// [`SettingExt`][trait@crate::prelude::SettingExt]
61 #[doc(alias = "NMSettingTCConfig")]
62 pub struct SettingTCConfig(Object<ffi::NMSettingTCConfig, ffi::NMSettingTCConfigClass>) @extends Setting;
63
64 match fn {
65 type_ => || ffi::nm_setting_tc_config_get_type(),
66 }
67}
68
69impl SettingTCConfig {
70 /// Creates a new #NMSettingTCConfig object with default values.
71 ///
72 /// # Returns
73 ///
74 /// the new empty #NMSettingTCConfig object
75 #[doc(alias = "nm_setting_tc_config_new")]
76 pub fn new() -> SettingTCConfig {
77 assert_initialized_main_thread!();
78 unsafe { Setting::from_glib_full(ffi::nm_setting_tc_config_new()).unsafe_cast() }
79 }
80
81 // rustdoc-stripper-ignore-next
82 /// Creates a new builder-pattern struct instance to construct [`SettingTCConfig`] objects.
83 ///
84 /// This method returns an instance of [`SettingTCConfigBuilder`](crate::builders::SettingTCConfigBuilder) which can be used to create [`SettingTCConfig`] objects.
85 pub fn builder() -> SettingTCConfigBuilder {
86 SettingTCConfigBuilder::new()
87 }
88
89 /// Appends a new qdisc and associated information to the setting. The
90 /// given qdisc is duplicated internally and is not changed by this function.
91 /// If an identical qdisc (considering attributes as well) already exists, the
92 /// qdisc is not added and the function returns [`false`].
93 /// ## `qdisc`
94 /// the qdisc to add
95 ///
96 /// # Returns
97 ///
98 /// [`true`] if the qdisc was added; [`false`] if the qdisc was already known.
99 #[doc(alias = "nm_setting_tc_config_add_qdisc")]
100 pub fn add_qdisc(&self, qdisc: &TCQdisc) -> bool {
101 unsafe {
102 from_glib(ffi::nm_setting_tc_config_add_qdisc(
103 self.to_glib_none().0,
104 qdisc.to_glib_none().0,
105 ))
106 }
107 }
108
109 /// Appends a new tfilter and associated information to the setting. The
110 /// given tfilter is duplicated internally and is not changed by this function.
111 /// If an identical tfilter (considering attributes as well) already exists, the
112 /// tfilter is not added and the function returns [`false`].
113 /// ## `tfilter`
114 /// the tfilter to add
115 ///
116 /// # Returns
117 ///
118 /// [`true`] if the tfilter was added; [`false`] if the tfilter was already known.
119 #[doc(alias = "nm_setting_tc_config_add_tfilter")]
120 pub fn add_tfilter(&self, tfilter: &TCTfilter) -> bool {
121 unsafe {
122 from_glib(ffi::nm_setting_tc_config_add_tfilter(
123 self.to_glib_none().0,
124 tfilter.to_glib_none().0,
125 ))
126 }
127 }
128
129 /// Removes all configured queueing disciplines.
130 #[doc(alias = "nm_setting_tc_config_clear_qdiscs")]
131 pub fn clear_qdiscs(&self) {
132 unsafe {
133 ffi::nm_setting_tc_config_clear_qdiscs(self.to_glib_none().0);
134 }
135 }
136
137 /// Removes all configured queueing disciplines.
138 #[doc(alias = "nm_setting_tc_config_clear_tfilters")]
139 pub fn clear_tfilters(&self) {
140 unsafe {
141 ffi::nm_setting_tc_config_clear_tfilters(self.to_glib_none().0);
142 }
143 }
144
145 ///
146 /// # Returns
147 ///
148 /// the number of configured queueing disciplines
149 #[doc(alias = "nm_setting_tc_config_get_num_qdiscs")]
150 #[doc(alias = "get_num_qdiscs")]
151 pub fn num_qdiscs(&self) -> u32 {
152 unsafe { ffi::nm_setting_tc_config_get_num_qdiscs(self.to_glib_none().0) }
153 }
154
155 ///
156 /// # Returns
157 ///
158 /// the number of configured queueing disciplines
159 #[doc(alias = "nm_setting_tc_config_get_num_tfilters")]
160 #[doc(alias = "get_num_tfilters")]
161 pub fn num_tfilters(&self) -> u32 {
162 unsafe { ffi::nm_setting_tc_config_get_num_tfilters(self.to_glib_none().0) }
163 }
164
165 /// ## `idx`
166 /// index number of the qdisc to return
167 ///
168 /// # Returns
169 ///
170 /// the qdisc at index @idx
171 #[doc(alias = "nm_setting_tc_config_get_qdisc")]
172 #[doc(alias = "get_qdisc")]
173 pub fn qdisc(&self, idx: u32) -> TCQdisc {
174 unsafe {
175 from_glib_none(ffi::nm_setting_tc_config_get_qdisc(
176 self.to_glib_none().0,
177 idx,
178 ))
179 }
180 }
181
182 /// ## `idx`
183 /// index number of the tfilter to return
184 ///
185 /// # Returns
186 ///
187 /// the tfilter at index @idx
188 #[doc(alias = "nm_setting_tc_config_get_tfilter")]
189 #[doc(alias = "get_tfilter")]
190 pub fn tfilter(&self, idx: u32) -> TCTfilter {
191 unsafe {
192 from_glib_none(ffi::nm_setting_tc_config_get_tfilter(
193 self.to_glib_none().0,
194 idx,
195 ))
196 }
197 }
198
199 /// Removes the qdisc at index @idx.
200 /// ## `idx`
201 /// index number of the qdisc
202 #[doc(alias = "nm_setting_tc_config_remove_qdisc")]
203 pub fn remove_qdisc(&self, idx: u32) {
204 unsafe {
205 ffi::nm_setting_tc_config_remove_qdisc(self.to_glib_none().0, idx);
206 }
207 }
208
209 /// Removes the first matching qdisc that matches @qdisc.
210 /// ## `qdisc`
211 /// the qdisc to remove
212 ///
213 /// # Returns
214 ///
215 /// [`true`] if the qdisc was found and removed; [`false`] if it was not.
216 #[doc(alias = "nm_setting_tc_config_remove_qdisc_by_value")]
217 pub fn remove_qdisc_by_value(&self, qdisc: &TCQdisc) -> bool {
218 unsafe {
219 from_glib(ffi::nm_setting_tc_config_remove_qdisc_by_value(
220 self.to_glib_none().0,
221 qdisc.to_glib_none().0,
222 ))
223 }
224 }
225
226 /// Removes the tfilter at index @idx.
227 /// ## `idx`
228 /// index number of the tfilter
229 #[doc(alias = "nm_setting_tc_config_remove_tfilter")]
230 pub fn remove_tfilter(&self, idx: u32) {
231 unsafe {
232 ffi::nm_setting_tc_config_remove_tfilter(self.to_glib_none().0, idx);
233 }
234 }
235
236 /// Removes the first matching tfilter that matches @tfilter.
237 /// ## `tfilter`
238 /// the tfilter to remove
239 ///
240 /// # Returns
241 ///
242 /// [`true`] if the tfilter was found and removed; [`false`] if it was not.
243 #[doc(alias = "nm_setting_tc_config_remove_tfilter_by_value")]
244 pub fn remove_tfilter_by_value(&self, tfilter: &TCTfilter) -> bool {
245 unsafe {
246 from_glib(ffi::nm_setting_tc_config_remove_tfilter_by_value(
247 self.to_glib_none().0,
248 tfilter.to_glib_none().0,
249 ))
250 }
251 }
252
253 /// Array of TC queueing disciplines.
254 ///
255 /// When the #NMSettingTCConfig setting is present, qdiscs from this
256 /// property are applied upon activation. If the property is empty,
257 /// all qdiscs are removed and the device will only
258 /// have the default qdisc assigned by kernel according to the
259 /// "net.core.default_qdisc" sysctl.
260 ///
261 /// If the #NMSettingTCConfig setting is not present, NetworkManager
262 /// doesn't touch the qdiscs present on the interface.
263 pub fn qdiscs(&self) -> Vec<TCQdisc> {
264 let vals = ObjectExt::property::<glib::ValueArray>(self, "qdiscs");
265 vals.iter()
266 .map(|value| unsafe { TCQdisc::from_value(value) })
267 .collect()
268 }
269
270 /// Array of TC queueing disciplines.
271 ///
272 /// When the #NMSettingTCConfig setting is present, qdiscs from this
273 /// property are applied upon activation. If the property is empty,
274 /// all qdiscs are removed and the device will only
275 /// have the default qdisc assigned by kernel according to the
276 /// "net.core.default_qdisc" sysctl.
277 ///
278 /// If the #NMSettingTCConfig setting is not present, NetworkManager
279 /// doesn't touch the qdiscs present on the interface.
280 pub fn set_qdiscs(&self, qdiscs: &[&TCQdisc]) {
281 ObjectExt::set_property(
282 self,
283 "qdiscs",
284 qdiscs
285 .iter()
286 .map(|tcqdisc| tcqdisc.to_value())
287 .collect::<glib::ValueArray>(),
288 )
289 }
290
291 /// Array of TC traffic filters.
292 ///
293 /// When the #NMSettingTCConfig setting is present, filters from this
294 /// property are applied upon activation. If the property is empty,
295 /// NetworkManager removes all the filters.
296 ///
297 /// If the #NMSettingTCConfig setting is not present, NetworkManager
298 /// doesn't touch the filters present on the interface.
299 pub fn tfilters(&self) -> Vec<TCTfilter> {
300 let vals = ObjectExt::property::<glib::ValueArray>(self, "tfilters");
301 vals.iter()
302 .map(|value| unsafe { TCTfilter::from_value(value) })
303 .collect()
304 }
305
306 /// Array of TC traffic filters.
307 ///
308 /// When the #NMSettingTCConfig setting is present, filters from this
309 /// property are applied upon activation. If the property is empty,
310 /// NetworkManager removes all the filters.
311 ///
312 /// If the #NMSettingTCConfig setting is not present, NetworkManager
313 /// doesn't touch the filters present on the interface.
314 pub fn set_tfilters(&self, tfilters: &[&TCTfilter]) {
315 ObjectExt::set_property(
316 self,
317 "tfilters",
318 tfilters
319 .iter()
320 .map(|tctfilter| tctfilter.to_value())
321 .collect::<glib::ValueArray>(),
322 )
323 }
324
325 #[doc(alias = "qdiscs")]
326 pub fn connect_qdiscs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
327 unsafe extern "C" fn notify_qdiscs_trampoline<F: Fn(&SettingTCConfig) + 'static>(
328 this: *mut ffi::NMSettingTCConfig,
329 _param_spec: glib::ffi::gpointer,
330 f: glib::ffi::gpointer,
331 ) {
332 let f: &F = &*(f as *const F);
333 f(&from_glib_borrow(this))
334 }
335 unsafe {
336 let f: Box_<F> = Box_::new(f);
337 connect_raw(
338 self.as_ptr() as *mut _,
339 c"notify::qdiscs".as_ptr() as *const _,
340 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
341 notify_qdiscs_trampoline::<F> as *const (),
342 )),
343 Box_::into_raw(f),
344 )
345 }
346 }
347
348 #[doc(alias = "tfilters")]
349 pub fn connect_tfilters_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
350 unsafe extern "C" fn notify_tfilters_trampoline<F: Fn(&SettingTCConfig) + 'static>(
351 this: *mut ffi::NMSettingTCConfig,
352 _param_spec: glib::ffi::gpointer,
353 f: glib::ffi::gpointer,
354 ) {
355 let f: &F = &*(f as *const F);
356 f(&from_glib_borrow(this))
357 }
358 unsafe {
359 let f: Box_<F> = Box_::new(f);
360 connect_raw(
361 self.as_ptr() as *mut _,
362 c"notify::tfilters".as_ptr() as *const _,
363 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
364 notify_tfilters_trampoline::<F> as *const (),
365 )),
366 Box_::into_raw(f),
367 )
368 }
369 }
370}
371
372#[cfg(feature = "v1_12")]
373#[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
374impl Default for SettingTCConfig {
375 fn default() -> Self {
376 Self::new()
377 }
378}
379
380// rustdoc-stripper-ignore-next
381/// A [builder-pattern] type to construct [`SettingTCConfig`] objects.
382///
383/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
384#[must_use = "The builder must be built to be used"]
385pub struct SettingTCConfigBuilder {
386 builder: glib::object::ObjectBuilder<'static, SettingTCConfig>,
387}
388
389impl SettingTCConfigBuilder {
390 fn new() -> Self {
391 Self {
392 builder: glib::object::Object::builder(),
393 }
394 }
395
396 /// Array of TC queueing disciplines.
397 ///
398 /// When the #NMSettingTCConfig setting is present, qdiscs from this
399 /// property are applied upon activation. If the property is empty,
400 /// all qdiscs are removed and the device will only
401 /// have the default qdisc assigned by kernel according to the
402 /// "net.core.default_qdisc" sysctl.
403 ///
404 /// If the #NMSettingTCConfig setting is not present, NetworkManager
405 /// doesn't touch the qdiscs present on the interface.
406 pub fn qdiscs(self, qdiscs: &[&TCQdisc]) -> Self {
407 Self {
408 builder: self.builder.property(
409 "qdiscs",
410 qdiscs
411 .iter()
412 .map(|tcqdisc| tcqdisc.to_value())
413 .collect::<glib::ValueArray>(),
414 ),
415 }
416 }
417
418 /// Array of TC traffic filters.
419 ///
420 /// When the #NMSettingTCConfig setting is present, filters from this
421 /// property are applied upon activation. If the property is empty,
422 /// NetworkManager removes all the filters.
423 ///
424 /// If the #NMSettingTCConfig setting is not present, NetworkManager
425 /// doesn't touch the filters present on the interface.
426 pub fn tfilters(self, tfilters: &[&TCTfilter]) -> Self {
427 Self {
428 builder: self.builder.property(
429 "tfilters",
430 tfilters
431 .iter()
432 .map(|tctfilter| tctfilter.to_value())
433 .collect::<glib::ValueArray>(),
434 ),
435 }
436 }
437
438 // rustdoc-stripper-ignore-next
439 /// Build the [`SettingTCConfig`].
440 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
441 pub fn build(self) -> SettingTCConfig {
442 assert_initialized_main_thread!();
443 self.builder.build()
444 }
445}