nm_rs/auto/
access_point.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, NM80211ApFlags, NM80211ApSecurityFlags, NM80211Mode, Object, 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    /// ## Properties
18    ///
19    ///
20    /// #### `bandwidth`
21    ///  The channel bandwidth announced by the AP in MHz.
22    ///
23    /// Readable
24    ///
25    ///
26    /// #### `bssid`
27    ///  The BSSID of the access point.
28    ///
29    /// Readable
30    ///
31    ///
32    /// #### `flags`
33    ///  The flags of the access point.
34    ///
35    /// Readable
36    ///
37    ///
38    /// #### `frequency`
39    ///  The frequency of the access point.
40    ///
41    /// Readable
42    ///
43    ///
44    /// #### `hw-address`
45    ///  Alias for #NMAccessPoint:bssid.
46    ///
47    /// Readable
48    ///
49    ///
50    /// #### `last-seen`
51    ///  The timestamp (in CLOCK_BOOTTIME seconds) for the last time the
52    /// access point was found in scan results.  A value of -1 means the
53    /// access point has not been found in a scan.
54    ///
55    /// Readable
56    ///
57    ///
58    /// #### `max-bitrate`
59    ///  The maximum bit rate of the access point in kbit/s.
60    ///
61    /// Readable
62    ///
63    ///
64    /// #### `mode`
65    ///  The mode of the access point; either "infrastructure" (a central
66    /// coordinator of the wireless network allowing clients to connect) or
67    /// "ad-hoc" (a network with no central controller).
68    ///
69    /// Readable
70    ///
71    ///
72    /// #### `rsn-flags`
73    ///  The RSN flags of the access point.
74    ///
75    /// Readable
76    ///
77    ///
78    /// #### `ssid`
79    ///  The SSID of the access point, or [`None`] if it is not known.
80    ///
81    /// Readable
82    ///
83    ///
84    /// #### `strength`
85    ///  The current signal strength of the access point.
86    ///
87    /// Readable
88    ///
89    ///
90    /// #### `wpa-flags`
91    ///  The WPA flags of the access point.
92    ///
93    /// Readable
94    /// <details><summary><h4>Object</h4></summary>
95    ///
96    ///
97    /// #### `client`
98    ///  The NMClient instance as returned by nm_object_get_client().
99    ///
100    /// When an NMObject gets removed from the NMClient cache,
101    /// the NMObject:path property stays unchanged, but this client
102    /// instance gets reset to [`None`]. You can use this property to
103    /// track removal of the object from the cache.
104    ///
105    /// Readable
106    ///
107    ///
108    /// #### `path`
109    ///  The D-Bus object path.
110    ///
111    /// The D-Bus path of an object instance never changes, even if the object
112    /// gets removed from the cache. To see whether the object is still in the
113    /// cache, check NMObject:client.
114    ///
115    /// Readable
116    /// </details>
117    ///
118    /// # Implements
119    ///
120    /// [`ObjectExt`][trait@crate::prelude::ObjectExt]
121    #[doc(alias = "NMAccessPoint")]
122    pub struct AccessPoint(Object<ffi::NMAccessPoint, ffi::NMAccessPointClass>) @extends Object;
123
124    match fn {
125        type_ => || ffi::nm_access_point_get_type(),
126    }
127}
128
129impl AccessPoint {
130    /// Validates a given connection against a given Wi-Fi access point to ensure that
131    /// the connection may be activated with that AP.  The connection must match the
132    /// @self's SSID, (if given) BSSID, and other attributes like security settings,
133    /// channel, band, etc.
134    /// ## `connection`
135    /// an #NMConnection to validate against @self
136    ///
137    /// # Returns
138    ///
139    /// [`true`] if the connection may be activated with this Wi-Fi AP,
140    /// [`false`] if it cannot be.
141    #[doc(alias = "nm_access_point_connection_valid")]
142    pub fn connection_valid(&self, connection: &impl IsA<Connection>) -> bool {
143        unsafe {
144            from_glib(ffi::nm_access_point_connection_valid(
145                self.to_glib_none().0,
146                connection.as_ref().to_glib_none().0,
147            ))
148        }
149    }
150
151    /// Filters a given array of connections for a given #NMAccessPoint object and
152    /// returns connections which may be activated with the access point.  Any
153    /// returned connections will match the @self's SSID and (if given) BSSID and
154    /// other attributes like security settings, channel, etc.
155    ///
156    /// To obtain the list of connections that are compatible with this access point,
157    /// use nm_client_get_connections() and then filter the returned list for a given
158    /// #NMDevice using nm_device_filter_connections() and finally filter that list
159    /// with this function.
160    /// ## `connections`
161    /// an array of #NMConnections to
162    /// filter
163    ///
164    /// # Returns
165    ///
166    /// an array of
167    /// #NMConnections that could be activated with the given @self.  The array should
168    /// be freed with g_ptr_array_unref() when it is no longer required.
169    ///
170    /// WARNING: the transfer annotation for this function may not work correctly
171    ///   with bindings. See https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/305.
172    ///   You can filter the list yourself with nm_access_point_connection_valid().
173    #[doc(alias = "nm_access_point_filter_connections")]
174    pub fn filter_connections(&self, connections: &[Connection]) -> Vec<Connection> {
175        unsafe {
176            FromGlibPtrContainer::from_glib_full(ffi::nm_access_point_filter_connections(
177                self.to_glib_none().0,
178                connections.to_glib_none().0,
179            ))
180        }
181    }
182
183    /// Gets the bandwidth advertised by the access point in MHz.
184    ///
185    /// # Returns
186    ///
187    /// the advertised bandwidth (MHz)
188    #[cfg(feature = "v1_46")]
189    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
190    #[doc(alias = "nm_access_point_get_bandwidth")]
191    #[doc(alias = "get_bandwidth")]
192    pub fn bandwidth(&self) -> u32 {
193        unsafe { ffi::nm_access_point_get_bandwidth(self.to_glib_none().0) }
194    }
195
196    /// Gets the Basic Service Set ID (BSSID) of the Wi-Fi access point.
197    ///
198    /// # Returns
199    ///
200    /// the BSSID of the access point. This is an internal string and must
201    /// not be modified or freed.
202    #[doc(alias = "nm_access_point_get_bssid")]
203    #[doc(alias = "get_bssid")]
204    pub fn bssid(&self) -> glib::GString {
205        unsafe { from_glib_none(ffi::nm_access_point_get_bssid(self.to_glib_none().0)) }
206    }
207
208    /// Gets the flags of the access point.
209    ///
210    /// # Returns
211    ///
212    /// the flags
213    #[doc(alias = "nm_access_point_get_flags")]
214    #[doc(alias = "get_flags")]
215    pub fn flags(&self) -> NM80211ApFlags {
216        unsafe { from_glib(ffi::nm_access_point_get_flags(self.to_glib_none().0)) }
217    }
218
219    /// Gets the frequency of the access point in MHz.
220    ///
221    /// # Returns
222    ///
223    /// the frequency in MHz
224    #[doc(alias = "nm_access_point_get_frequency")]
225    #[doc(alias = "get_frequency")]
226    pub fn frequency(&self) -> u32 {
227        unsafe { ffi::nm_access_point_get_frequency(self.to_glib_none().0) }
228    }
229
230    /// Returns the timestamp (in CLOCK_BOOTTIME seconds) for the last time the
231    /// access point was found in scan results.  A value of -1 means the access
232    /// point has not been found in a scan.
233    ///
234    /// # Returns
235    ///
236    /// the last seen time in seconds
237    #[cfg(feature = "v1_2")]
238    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
239    #[doc(alias = "nm_access_point_get_last_seen")]
240    #[doc(alias = "get_last_seen")]
241    #[doc(alias = "last-seen")]
242    pub fn last_seen(&self) -> i32 {
243        unsafe { ffi::nm_access_point_get_last_seen(self.to_glib_none().0) }
244    }
245
246    /// Gets the maximum bit rate of the access point in kbit/s.
247    ///
248    /// # Returns
249    ///
250    /// the maximum bit rate (kbit/s)
251    #[doc(alias = "nm_access_point_get_max_bitrate")]
252    #[doc(alias = "get_max_bitrate")]
253    #[doc(alias = "max-bitrate")]
254    pub fn max_bitrate(&self) -> u32 {
255        unsafe { ffi::nm_access_point_get_max_bitrate(self.to_glib_none().0) }
256    }
257
258    /// Gets the mode of the access point.
259    ///
260    /// # Returns
261    ///
262    /// the mode
263    #[doc(alias = "nm_access_point_get_mode")]
264    #[doc(alias = "get_mode")]
265    pub fn mode(&self) -> NM80211Mode {
266        unsafe { from_glib(ffi::nm_access_point_get_mode(self.to_glib_none().0)) }
267    }
268
269    /// Gets the RSN (Robust Secure Network, ie WPA version 2) flags of the access
270    /// point.
271    ///
272    /// # Returns
273    ///
274    /// the RSN flags
275    #[doc(alias = "nm_access_point_get_rsn_flags")]
276    #[doc(alias = "get_rsn_flags")]
277    #[doc(alias = "rsn-flags")]
278    pub fn rsn_flags(&self) -> NM80211ApSecurityFlags {
279        unsafe { from_glib(ffi::nm_access_point_get_rsn_flags(self.to_glib_none().0)) }
280    }
281
282    //#[doc(alias = "nm_access_point_get_ssid")]
283    //#[doc(alias = "get_ssid")]
284    //pub fn ssid(&self) -> /*Ignored*/glib::Bytes {
285    //    unsafe { TODO: call ffi:nm_access_point_get_ssid() }
286    //}
287
288    /// Gets the current signal strength of the access point as a percentage.
289    ///
290    /// # Returns
291    ///
292    /// the signal strength (0 to 100)
293    #[doc(alias = "nm_access_point_get_strength")]
294    #[doc(alias = "get_strength")]
295    pub fn strength(&self) -> u8 {
296        unsafe { ffi::nm_access_point_get_strength(self.to_glib_none().0) }
297    }
298
299    /// Gets the WPA (version 1) flags of the access point.
300    ///
301    /// # Returns
302    ///
303    /// the WPA flags
304    #[doc(alias = "nm_access_point_get_wpa_flags")]
305    #[doc(alias = "get_wpa_flags")]
306    #[doc(alias = "wpa-flags")]
307    pub fn wpa_flags(&self) -> NM80211ApSecurityFlags {
308        unsafe { from_glib(ffi::nm_access_point_get_wpa_flags(self.to_glib_none().0)) }
309    }
310
311    #[cfg(feature = "v1_46")]
312    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
313    #[doc(alias = "bandwidth")]
314    pub fn connect_bandwidth_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
315        unsafe extern "C" fn notify_bandwidth_trampoline<F: Fn(&AccessPoint) + 'static>(
316            this: *mut ffi::NMAccessPoint,
317            _param_spec: glib::ffi::gpointer,
318            f: glib::ffi::gpointer,
319        ) {
320            let f: &F = &*(f as *const F);
321            f(&from_glib_borrow(this))
322        }
323        unsafe {
324            let f: Box_<F> = Box_::new(f);
325            connect_raw(
326                self.as_ptr() as *mut _,
327                c"notify::bandwidth".as_ptr() as *const _,
328                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329                    notify_bandwidth_trampoline::<F> as *const (),
330                )),
331                Box_::into_raw(f),
332            )
333        }
334    }
335
336    #[doc(alias = "bssid")]
337    pub fn connect_bssid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
338        unsafe extern "C" fn notify_bssid_trampoline<F: Fn(&AccessPoint) + 'static>(
339            this: *mut ffi::NMAccessPoint,
340            _param_spec: glib::ffi::gpointer,
341            f: glib::ffi::gpointer,
342        ) {
343            let f: &F = &*(f as *const F);
344            f(&from_glib_borrow(this))
345        }
346        unsafe {
347            let f: Box_<F> = Box_::new(f);
348            connect_raw(
349                self.as_ptr() as *mut _,
350                c"notify::bssid".as_ptr() as *const _,
351                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
352                    notify_bssid_trampoline::<F> as *const (),
353                )),
354                Box_::into_raw(f),
355            )
356        }
357    }
358
359    #[doc(alias = "flags")]
360    pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
361        unsafe extern "C" fn notify_flags_trampoline<F: Fn(&AccessPoint) + 'static>(
362            this: *mut ffi::NMAccessPoint,
363            _param_spec: glib::ffi::gpointer,
364            f: glib::ffi::gpointer,
365        ) {
366            let f: &F = &*(f as *const F);
367            f(&from_glib_borrow(this))
368        }
369        unsafe {
370            let f: Box_<F> = Box_::new(f);
371            connect_raw(
372                self.as_ptr() as *mut _,
373                c"notify::flags".as_ptr() as *const _,
374                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
375                    notify_flags_trampoline::<F> as *const (),
376                )),
377                Box_::into_raw(f),
378            )
379        }
380    }
381
382    #[doc(alias = "frequency")]
383    pub fn connect_frequency_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
384        unsafe extern "C" fn notify_frequency_trampoline<F: Fn(&AccessPoint) + 'static>(
385            this: *mut ffi::NMAccessPoint,
386            _param_spec: glib::ffi::gpointer,
387            f: glib::ffi::gpointer,
388        ) {
389            let f: &F = &*(f as *const F);
390            f(&from_glib_borrow(this))
391        }
392        unsafe {
393            let f: Box_<F> = Box_::new(f);
394            connect_raw(
395                self.as_ptr() as *mut _,
396                c"notify::frequency".as_ptr() as *const _,
397                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
398                    notify_frequency_trampoline::<F> as *const (),
399                )),
400                Box_::into_raw(f),
401            )
402        }
403    }
404
405    #[cfg(feature = "v1_2")]
406    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
407    #[doc(alias = "last-seen")]
408    pub fn connect_last_seen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
409        unsafe extern "C" fn notify_last_seen_trampoline<F: Fn(&AccessPoint) + 'static>(
410            this: *mut ffi::NMAccessPoint,
411            _param_spec: glib::ffi::gpointer,
412            f: glib::ffi::gpointer,
413        ) {
414            let f: &F = &*(f as *const F);
415            f(&from_glib_borrow(this))
416        }
417        unsafe {
418            let f: Box_<F> = Box_::new(f);
419            connect_raw(
420                self.as_ptr() as *mut _,
421                c"notify::last-seen".as_ptr() as *const _,
422                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
423                    notify_last_seen_trampoline::<F> as *const (),
424                )),
425                Box_::into_raw(f),
426            )
427        }
428    }
429
430    #[doc(alias = "max-bitrate")]
431    pub fn connect_max_bitrate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
432        unsafe extern "C" fn notify_max_bitrate_trampoline<F: Fn(&AccessPoint) + 'static>(
433            this: *mut ffi::NMAccessPoint,
434            _param_spec: glib::ffi::gpointer,
435            f: glib::ffi::gpointer,
436        ) {
437            let f: &F = &*(f as *const F);
438            f(&from_glib_borrow(this))
439        }
440        unsafe {
441            let f: Box_<F> = Box_::new(f);
442            connect_raw(
443                self.as_ptr() as *mut _,
444                c"notify::max-bitrate".as_ptr() as *const _,
445                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
446                    notify_max_bitrate_trampoline::<F> as *const (),
447                )),
448                Box_::into_raw(f),
449            )
450        }
451    }
452
453    #[doc(alias = "mode")]
454    pub fn connect_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
455        unsafe extern "C" fn notify_mode_trampoline<F: Fn(&AccessPoint) + 'static>(
456            this: *mut ffi::NMAccessPoint,
457            _param_spec: glib::ffi::gpointer,
458            f: glib::ffi::gpointer,
459        ) {
460            let f: &F = &*(f as *const F);
461            f(&from_glib_borrow(this))
462        }
463        unsafe {
464            let f: Box_<F> = Box_::new(f);
465            connect_raw(
466                self.as_ptr() as *mut _,
467                c"notify::mode".as_ptr() as *const _,
468                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
469                    notify_mode_trampoline::<F> as *const (),
470                )),
471                Box_::into_raw(f),
472            )
473        }
474    }
475
476    #[doc(alias = "rsn-flags")]
477    pub fn connect_rsn_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
478        unsafe extern "C" fn notify_rsn_flags_trampoline<F: Fn(&AccessPoint) + 'static>(
479            this: *mut ffi::NMAccessPoint,
480            _param_spec: glib::ffi::gpointer,
481            f: glib::ffi::gpointer,
482        ) {
483            let f: &F = &*(f as *const F);
484            f(&from_glib_borrow(this))
485        }
486        unsafe {
487            let f: Box_<F> = Box_::new(f);
488            connect_raw(
489                self.as_ptr() as *mut _,
490                c"notify::rsn-flags".as_ptr() as *const _,
491                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
492                    notify_rsn_flags_trampoline::<F> as *const (),
493                )),
494                Box_::into_raw(f),
495            )
496        }
497    }
498
499    #[doc(alias = "ssid")]
500    pub fn connect_ssid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
501        unsafe extern "C" fn notify_ssid_trampoline<F: Fn(&AccessPoint) + 'static>(
502            this: *mut ffi::NMAccessPoint,
503            _param_spec: glib::ffi::gpointer,
504            f: glib::ffi::gpointer,
505        ) {
506            let f: &F = &*(f as *const F);
507            f(&from_glib_borrow(this))
508        }
509        unsafe {
510            let f: Box_<F> = Box_::new(f);
511            connect_raw(
512                self.as_ptr() as *mut _,
513                c"notify::ssid".as_ptr() as *const _,
514                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
515                    notify_ssid_trampoline::<F> as *const (),
516                )),
517                Box_::into_raw(f),
518            )
519        }
520    }
521
522    #[doc(alias = "strength")]
523    pub fn connect_strength_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
524        unsafe extern "C" fn notify_strength_trampoline<F: Fn(&AccessPoint) + 'static>(
525            this: *mut ffi::NMAccessPoint,
526            _param_spec: glib::ffi::gpointer,
527            f: glib::ffi::gpointer,
528        ) {
529            let f: &F = &*(f as *const F);
530            f(&from_glib_borrow(this))
531        }
532        unsafe {
533            let f: Box_<F> = Box_::new(f);
534            connect_raw(
535                self.as_ptr() as *mut _,
536                c"notify::strength".as_ptr() as *const _,
537                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
538                    notify_strength_trampoline::<F> as *const (),
539                )),
540                Box_::into_raw(f),
541            )
542        }
543    }
544
545    #[doc(alias = "wpa-flags")]
546    pub fn connect_wpa_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
547        unsafe extern "C" fn notify_wpa_flags_trampoline<F: Fn(&AccessPoint) + 'static>(
548            this: *mut ffi::NMAccessPoint,
549            _param_spec: glib::ffi::gpointer,
550            f: glib::ffi::gpointer,
551        ) {
552            let f: &F = &*(f as *const F);
553            f(&from_glib_borrow(this))
554        }
555        unsafe {
556            let f: Box_<F> = Box_::new(f);
557            connect_raw(
558                self.as_ptr() as *mut _,
559                c"notify::wpa-flags".as_ptr() as *const _,
560                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
561                    notify_wpa_flags_trampoline::<F> as *const (),
562                )),
563                Box_::into_raw(f),
564            )
565        }
566    }
567}