nm_rs/auto/setting_bond.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::{ffi,Setting};
7use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
8use std::{boxed::Box as Box_};
9
10glib::wrapper! {
11 /// Bonding Settings
12 ///
13 /// ## Properties
14 ///
15 ///
16 /// #### `options`
17 /// Dictionary of key/value pairs of bonding options. Both keys and values
18 /// must be strings. Option names must contain only alphanumeric characters
19 /// (ie, [a-zA-Z0-9]).
20 ///
21 /// Readable | Writeable
22 /// <details><summary><h4>Setting</h4></summary>
23 ///
24 ///
25 /// #### `name`
26 /// The setting's name, which uniquely identifies the setting within the
27 /// connection. Each setting type has a name unique to that type, for
28 /// example "ppp" or "802-11-wireless" or "802-3-ethernet".
29 ///
30 /// Readable
31 /// </details>
32 ///
33 /// # Implements
34 ///
35 /// [`SettingExt`][trait@crate::prelude::SettingExt]
36 #[doc(alias = "NMSettingBond")]
37 pub struct SettingBond(Object<ffi::NMSettingBond, ffi::NMSettingBondClass>) @extends Setting;
38
39 match fn {
40 type_ => || ffi::nm_setting_bond_get_type(),
41 }
42}
43
44impl SettingBond {
45 /// Creates a new #NMSettingBond object with default values.
46 ///
47 /// # Returns
48 ///
49 /// the new empty #NMSettingBond object
50 #[doc(alias = "nm_setting_bond_new")]
51 pub fn new() -> SettingBond {
52 assert_initialized_main_thread!();
53 unsafe {
54 Setting::from_glib_full(ffi::nm_setting_bond_new()).unsafe_cast()
55 }
56 }
57
58 // rustdoc-stripper-ignore-next
59 /// Creates a new builder-pattern struct instance to construct [`SettingBond`] objects.
60 ///
61 /// This method returns an instance of [`SettingBondBuilder`](crate::builders::SettingBondBuilder) which can be used to create [`SettingBond`] objects.
62 pub fn builder() -> SettingBondBuilder {
63 SettingBondBuilder::new()
64 }
65
66
67 /// Add an option to the table. Adding a new name replaces any existing name/value pair
68 /// that may already exist.
69 /// ## `name`
70 /// name for the option
71 /// ## `value`
72 /// value for the option
73 ///
74 /// # Returns
75 ///
76 /// returns [`false`] if either @name or @value is [`None`], in that case
77 /// the option is not set. Otherwise, the function does not fail and does not validate
78 /// the arguments. All validation happens via nm_connection_verify() or do basic validation
79 /// yourself with nm_setting_bond_validate_option().
80 ///
81 /// Note: Before 1.30, libnm would perform basic validation of the name and the value
82 /// via nm_setting_bond_validate_option() and reject the request by returning FALSE.
83 /// Since 1.30, libnm no longer rejects any values as the setter is not supposed
84 /// to perform validation.
85 #[doc(alias = "nm_setting_bond_add_option")]
86 pub fn add_option(&self, name: &str, value: &str) -> bool {
87 unsafe {
88 from_glib(ffi::nm_setting_bond_add_option(self.to_glib_none().0, name.to_glib_none().0, value.to_glib_none().0))
89 }
90 }
91
92 /// Returns the number of options that should be set for this bond when it
93 /// is activated. This can be used to retrieve each option individually
94 /// using nm_setting_bond_get_option().
95 ///
96 /// # Returns
97 ///
98 /// the number of bonding options
99 #[doc(alias = "nm_setting_bond_get_num_options")]
100 #[doc(alias = "get_num_options")]
101 pub fn num_options(&self) -> u32 {
102 unsafe {
103 ffi::nm_setting_bond_get_num_options(self.to_glib_none().0)
104 }
105 }
106
107 /// Given an index, return the value of the bonding option at that index. Indexes
108 /// are *not* guaranteed to be static across modifications to options done by
109 /// nm_setting_bond_add_option() and nm_setting_bond_remove_option(),
110 /// and should not be used to refer to options except for short periods of time
111 /// such as during option iteration.
112 /// ## `idx`
113 /// index of the desired option, from 0 to
114 /// nm_setting_bond_get_num_options() - 1
115 ///
116 /// # Returns
117 ///
118 /// [`true`] on success if the index was valid and an option was found,
119 /// [`false`] if the index was invalid (ie, greater than the number of options
120 /// currently held by the setting)
121 ///
122 /// ## `out_name`
123 /// on return, the name of the bonding option;
124 /// this value is owned by the setting and should not be modified
125 ///
126 /// ## `out_value`
127 /// on return, the value of the name of the
128 /// bonding option; this value is owned by the setting and should not be
129 /// modified
130 #[doc(alias = "nm_setting_bond_get_option")]
131 #[doc(alias = "get_option")]
132 pub fn option(&self, idx: u32) -> Option<(glib::GString, glib::GString)> {
133 unsafe {
134 let mut out_name = std::ptr::null();
135 let mut out_value = std::ptr::null();
136 let ret = from_glib(ffi::nm_setting_bond_get_option(self.to_glib_none().0, idx, &mut out_name, &mut out_value));
137 if ret { Some((from_glib_none(out_name), from_glib_none(out_value))) } else { None }
138 }
139 }
140
141 /// Returns the value associated with the bonding option specified by
142 /// @name, if it exists.
143 /// ## `name`
144 /// the option name for which to retrieve the value
145 ///
146 /// # Returns
147 ///
148 /// the value, or [`None`] if the key/value pair was never added to the
149 /// setting; the value is owned by the setting and must not be modified
150 #[doc(alias = "nm_setting_bond_get_option_by_name")]
151 #[doc(alias = "get_option_by_name")]
152 pub fn option_by_name(&self, name: &str) -> glib::GString {
153 unsafe {
154 from_glib_none(ffi::nm_setting_bond_get_option_by_name(self.to_glib_none().0, name.to_glib_none().0))
155 }
156 }
157
158 /// ## `name`
159 /// the name of the option
160 ///
161 /// # Returns
162 ///
163 /// the value of the bond option if not overridden by an entry in
164 /// the #NMSettingBond:options property.
165 #[doc(alias = "nm_setting_bond_get_option_default")]
166 #[doc(alias = "get_option_default")]
167 pub fn option_default(&self, name: &str) -> glib::GString {
168 unsafe {
169 from_glib_none(ffi::nm_setting_bond_get_option_default(self.to_glib_none().0, name.to_glib_none().0))
170 }
171 }
172
173 /// ## `name`
174 /// the name of the option
175 ///
176 /// # Returns
177 ///
178 /// the value of the bond option after normalization, which is what NetworkManager
179 /// will actually apply when activating the connection. [`None`] if the option won't be applied
180 /// to the connection.
181 #[cfg(feature = "v1_24")]
182 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
183 #[doc(alias = "nm_setting_bond_get_option_normalized")]
184 #[doc(alias = "get_option_normalized")]
185 pub fn option_normalized(&self, name: &str) -> glib::GString {
186 unsafe {
187 from_glib_none(ffi::nm_setting_bond_get_option_normalized(self.to_glib_none().0, name.to_glib_none().0))
188 }
189 }
190
191 /// Returns a list of valid bond options.
192 ///
193 /// The @self argument is unused and may be passed as [`None`].
194 ///
195 /// # Returns
196 ///
197 /// a [`None`]-terminated array of strings of valid bond options.
198 #[doc(alias = "nm_setting_bond_get_valid_options")]
199 #[doc(alias = "get_valid_options")]
200 pub fn valid_options(&self) -> Vec<glib::GString> {
201 unsafe {
202 FromGlibPtrContainer::from_glib_none(ffi::nm_setting_bond_get_valid_options(self.to_glib_none().0))
203 }
204 }
205
206 /// Remove the bonding option referenced by @name from the internal option
207 /// list.
208 /// ## `name`
209 /// name of the option to remove
210 ///
211 /// # Returns
212 ///
213 /// [`true`] if the option was found and removed from the internal option
214 /// list, [`false`] if it was not.
215 #[doc(alias = "nm_setting_bond_remove_option")]
216 pub fn remove_option(&self, name: &str) -> bool {
217 unsafe {
218 from_glib(ffi::nm_setting_bond_remove_option(self.to_glib_none().0, name.to_glib_none().0))
219 }
220 }
221
222 //pub fn options(&self) -> /*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 } {
223 // ObjectExt::property(self, "options")
224 //}
225
226 //pub fn set_options(&self, options: /*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }) {
227 // ObjectExt::set_property(self,"options", options)
228 //}
229
230 /// Checks whether @name is a valid bond option and @value is a valid value for
231 /// the @name. If @value is [`None`], the function only validates the option name.
232 /// ## `name`
233 /// the name of the option to validate
234 /// ## `value`
235 /// the value of the option to validate.
236 ///
237 /// # Returns
238 ///
239 /// [`true`], if the @value is valid for the given name.
240 /// If the @name is not a valid option, [`false`] will be returned.
241 #[doc(alias = "nm_setting_bond_validate_option")]
242 pub fn validate_option(name: &str, value: Option<&str>) -> bool {
243 assert_initialized_main_thread!();
244 unsafe {
245 from_glib(ffi::nm_setting_bond_validate_option(name.to_glib_none().0, value.to_glib_none().0))
246 }
247 }
248
249 #[doc(alias = "options")]
250 pub fn connect_options_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
251 unsafe extern "C" fn notify_options_trampoline<F: Fn(&SettingBond) + 'static>(this: *mut ffi::NMSettingBond, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
252 let f: &F = &*(f as *const F);
253 f(&from_glib_borrow(this))
254 }
255 unsafe {
256 let f: Box_<F> = Box_::new(f);
257 connect_raw(self.as_ptr() as *mut _, c"notify::options".as_ptr() as *const _,
258 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_options_trampoline::<F> as *const ())), Box_::into_raw(f))
259 }
260 }
261}
262
263impl Default for SettingBond {
264 fn default() -> Self {
265 Self::new()
266 }
267 }
268
269// rustdoc-stripper-ignore-next
270 /// A [builder-pattern] type to construct [`SettingBond`] objects.
271 ///
272 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
273#[must_use = "The builder must be built to be used"]
274pub struct SettingBondBuilder {
275 builder: glib::object::ObjectBuilder<'static, SettingBond>,
276 }
277
278 impl SettingBondBuilder {
279 fn new() -> Self {
280 Self { builder: glib::object::Object::builder() }
281 }
282
283 //pub fn options(self, options: /*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }) -> Self {
284 // Self { builder: self.builder.property("options", options), }
285 //}
286
287 // rustdoc-stripper-ignore-next
288 /// Build the [`SettingBond`].
289 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
290 pub fn build(self) -> SettingBond {
291assert_initialized_main_thread!();
292 self.builder.build() }
293}