nm_rs/auto/
wifi_p2p_peer.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, 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    /// #### `flags`
21    ///  The flags of the P2P peer.
22    ///
23    /// Readable
24    ///
25    ///
26    /// #### `hw-address`
27    ///  The hardware address of the P2P peer.
28    ///
29    /// Readable
30    ///
31    ///
32    /// #### `last-seen`
33    ///  The timestamp (in CLOCK_BOOTTIME seconds) for the last time the
34    /// P2P peer was found.  A value of -1 means the peer has never been seen.
35    ///
36    /// Readable
37    ///
38    ///
39    /// #### `manufacturer`
40    ///  The manufacturer of the P2P peer.
41    ///
42    /// Readable
43    ///
44    ///
45    /// #### `model`
46    ///  The model of the P2P peer.
47    ///
48    /// Readable
49    ///
50    ///
51    /// #### `model-number`
52    ///  The hardware address of the P2P peer.
53    ///
54    /// Readable
55    ///
56    ///
57    /// #### `name`
58    ///  The name of the P2P peer.
59    ///
60    /// Readable
61    ///
62    ///
63    /// #### `serial`
64    ///  The serial number of the P2P peer.
65    ///
66    /// Readable
67    ///
68    ///
69    /// #### `strength`
70    ///  The current signal strength of the P2P peer.
71    ///
72    /// Readable
73    ///
74    ///
75    /// #### `wfd-ies`
76    ///  The WFD information elements of the P2P peer.
77    ///
78    /// Readable
79    /// <details><summary><h4>Object</h4></summary>
80    ///
81    ///
82    /// #### `client`
83    ///  The NMClient instance as returned by nm_object_get_client().
84    ///
85    /// When an NMObject gets removed from the NMClient cache,
86    /// the NMObject:path property stays unchanged, but this client
87    /// instance gets reset to [`None`]. You can use this property to
88    /// track removal of the object from the cache.
89    ///
90    /// Readable
91    ///
92    ///
93    /// #### `path`
94    ///  The D-Bus object path.
95    ///
96    /// The D-Bus path of an object instance never changes, even if the object
97    /// gets removed from the cache. To see whether the object is still in the
98    /// cache, check NMObject:client.
99    ///
100    /// Readable
101    /// </details>
102    ///
103    /// # Implements
104    ///
105    /// [`ObjectExt`][trait@crate::prelude::ObjectExt]
106    #[doc(alias = "NMWifiP2PPeer")]
107    pub struct WifiP2PPeer(Object<ffi::NMWifiP2PPeer, ffi::NMWifiP2PPeerClass>) @extends Object;
108
109    match fn {
110        type_ => || ffi::nm_wifi_p2p_peer_get_type(),
111    }
112}
113
114impl WifiP2PPeer {
115    /// Validates a given connection against a given Wi-Fi P2P peer to ensure that
116    /// the connection may be activated with that peer. The connection must match the
117    /// @self's address and in the future possibly other attributes.
118    /// ## `connection`
119    /// an #NMConnection to validate against @self
120    ///
121    /// # Returns
122    ///
123    /// [`true`] if the connection may be activated with this Wi-Fi P2P Peer,
124    /// [`false`] if it cannot be.
125    #[doc(alias = "nm_wifi_p2p_peer_connection_valid")]
126    pub fn connection_valid(&self, connection: &impl IsA<Connection>) -> bool {
127        unsafe {
128            from_glib(ffi::nm_wifi_p2p_peer_connection_valid(
129                self.to_glib_none().0,
130                connection.as_ref().to_glib_none().0,
131            ))
132        }
133    }
134
135    /// Filters a given array of connections for a given #NMWifiP2PPeer object and
136    /// returns connections which may be activated with the P2P peer.  Any
137    /// returned connections will match the @peers's HW address and in the future
138    /// possibly other attributes.
139    ///
140    /// To obtain the list of connections that are compatible with this P2P peer,
141    /// use nm_client_get_connections() and then filter the returned list for a given
142    /// #NMDevice using nm_device_filter_connections() and finally filter that list
143    /// with this function.
144    /// ## `connections`
145    /// an array of #NMConnections to
146    /// filter
147    ///
148    /// # Returns
149    ///
150    /// an array of
151    /// #NMConnections that could be activated with the given @self. The array should
152    /// be freed with g_ptr_array_unref() when it is no longer required.
153    #[doc(alias = "nm_wifi_p2p_peer_filter_connections")]
154    pub fn filter_connections(&self, connections: &[Connection]) -> Vec<Connection> {
155        unsafe {
156            FromGlibPtrContainer::from_glib_container(ffi::nm_wifi_p2p_peer_filter_connections(
157                self.to_glib_none().0,
158                connections.to_glib_none().0,
159            ))
160        }
161    }
162
163    /// Gets the flags of the P2P peer.
164    ///
165    /// # Returns
166    ///
167    /// the flags
168    #[doc(alias = "nm_wifi_p2p_peer_get_flags")]
169    #[doc(alias = "get_flags")]
170    pub fn flags(&self) -> NM80211ApFlags {
171        unsafe { from_glib(ffi::nm_wifi_p2p_peer_get_flags(self.to_glib_none().0)) }
172    }
173
174    /// Gets the hardware address of the P2P peer.
175    ///
176    /// # Returns
177    ///
178    /// the hardware address
179    #[doc(alias = "nm_wifi_p2p_peer_get_hw_address")]
180    #[doc(alias = "get_hw_address")]
181    #[doc(alias = "hw-address")]
182    pub fn hw_address(&self) -> glib::GString {
183        unsafe { from_glib_none(ffi::nm_wifi_p2p_peer_get_hw_address(self.to_glib_none().0)) }
184    }
185
186    /// Returns the timestamp (in CLOCK_BOOTTIME seconds) for the last time the
187    /// P2P peer was seen.  A value of -1 means the P2P peer has never been seen.
188    ///
189    /// # Returns
190    ///
191    /// the last seen time in seconds
192    #[doc(alias = "nm_wifi_p2p_peer_get_last_seen")]
193    #[doc(alias = "get_last_seen")]
194    #[doc(alias = "last-seen")]
195    pub fn last_seen(&self) -> i32 {
196        unsafe { ffi::nm_wifi_p2p_peer_get_last_seen(self.to_glib_none().0) }
197    }
198
199    /// Gets the manufacturer of the P2P peer.
200    ///
201    /// # Returns
202    ///
203    /// the manufacturer
204    #[doc(alias = "nm_wifi_p2p_peer_get_manufacturer")]
205    #[doc(alias = "get_manufacturer")]
206    pub fn manufacturer(&self) -> glib::GString {
207        unsafe {
208            from_glib_none(ffi::nm_wifi_p2p_peer_get_manufacturer(
209                self.to_glib_none().0,
210            ))
211        }
212    }
213
214    /// Gets the model of the P2P peer.
215    ///
216    /// # Returns
217    ///
218    /// the model
219    #[doc(alias = "nm_wifi_p2p_peer_get_model")]
220    #[doc(alias = "get_model")]
221    pub fn model(&self) -> glib::GString {
222        unsafe { from_glib_none(ffi::nm_wifi_p2p_peer_get_model(self.to_glib_none().0)) }
223    }
224
225    /// Gets the model number of the P2P peer.
226    ///
227    /// # Returns
228    ///
229    /// the model number
230    #[doc(alias = "nm_wifi_p2p_peer_get_model_number")]
231    #[doc(alias = "get_model_number")]
232    #[doc(alias = "model-number")]
233    pub fn model_number(&self) -> glib::GString {
234        unsafe {
235            from_glib_none(ffi::nm_wifi_p2p_peer_get_model_number(
236                self.to_glib_none().0,
237            ))
238        }
239    }
240
241    /// Gets the name of the P2P peer.
242    ///
243    /// # Returns
244    ///
245    /// the name
246    #[doc(alias = "nm_wifi_p2p_peer_get_name")]
247    #[doc(alias = "get_name")]
248    pub fn name(&self) -> glib::GString {
249        unsafe { from_glib_none(ffi::nm_wifi_p2p_peer_get_name(self.to_glib_none().0)) }
250    }
251
252    /// Gets the serial number of the P2P peer.
253    ///
254    /// # Returns
255    ///
256    /// the serial number
257    #[doc(alias = "nm_wifi_p2p_peer_get_serial")]
258    #[doc(alias = "get_serial")]
259    pub fn serial(&self) -> glib::GString {
260        unsafe { from_glib_none(ffi::nm_wifi_p2p_peer_get_serial(self.to_glib_none().0)) }
261    }
262
263    /// Gets the current signal strength of the P2P peer as a percentage.
264    ///
265    /// # Returns
266    ///
267    /// the signal strength (0 to 100)
268    #[doc(alias = "nm_wifi_p2p_peer_get_strength")]
269    #[doc(alias = "get_strength")]
270    pub fn strength(&self) -> u8 {
271        unsafe { ffi::nm_wifi_p2p_peer_get_strength(self.to_glib_none().0) }
272    }
273
274    //#[doc(alias = "nm_wifi_p2p_peer_get_wfd_ies")]
275    //#[doc(alias = "get_wfd_ies")]
276    //#[doc(alias = "wfd-ies")]
277    //pub fn wfd_ies(&self) -> /*Ignored*/glib::Bytes {
278    //    unsafe { TODO: call ffi:nm_wifi_p2p_peer_get_wfd_ies() }
279    //}
280
281    #[cfg(feature = "v1_16")]
282    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
283    #[doc(alias = "flags")]
284    pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
285        unsafe extern "C" fn notify_flags_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
286            this: *mut ffi::NMWifiP2PPeer,
287            _param_spec: glib::ffi::gpointer,
288            f: glib::ffi::gpointer,
289        ) {
290            let f: &F = &*(f as *const F);
291            f(&from_glib_borrow(this))
292        }
293        unsafe {
294            let f: Box_<F> = Box_::new(f);
295            connect_raw(
296                self.as_ptr() as *mut _,
297                c"notify::flags".as_ptr() as *const _,
298                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299                    notify_flags_trampoline::<F> as *const (),
300                )),
301                Box_::into_raw(f),
302            )
303        }
304    }
305
306    #[cfg(feature = "v1_16")]
307    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
308    #[doc(alias = "hw-address")]
309    pub fn connect_hw_address_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
310        unsafe extern "C" fn notify_hw_address_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
311            this: *mut ffi::NMWifiP2PPeer,
312            _param_spec: glib::ffi::gpointer,
313            f: glib::ffi::gpointer,
314        ) {
315            let f: &F = &*(f as *const F);
316            f(&from_glib_borrow(this))
317        }
318        unsafe {
319            let f: Box_<F> = Box_::new(f);
320            connect_raw(
321                self.as_ptr() as *mut _,
322                c"notify::hw-address".as_ptr() as *const _,
323                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324                    notify_hw_address_trampoline::<F> as *const (),
325                )),
326                Box_::into_raw(f),
327            )
328        }
329    }
330
331    #[cfg(feature = "v1_16")]
332    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
333    #[doc(alias = "last-seen")]
334    pub fn connect_last_seen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
335        unsafe extern "C" fn notify_last_seen_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
336            this: *mut ffi::NMWifiP2PPeer,
337            _param_spec: glib::ffi::gpointer,
338            f: glib::ffi::gpointer,
339        ) {
340            let f: &F = &*(f as *const F);
341            f(&from_glib_borrow(this))
342        }
343        unsafe {
344            let f: Box_<F> = Box_::new(f);
345            connect_raw(
346                self.as_ptr() as *mut _,
347                c"notify::last-seen".as_ptr() as *const _,
348                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
349                    notify_last_seen_trampoline::<F> as *const (),
350                )),
351                Box_::into_raw(f),
352            )
353        }
354    }
355
356    #[cfg(feature = "v1_16")]
357    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
358    #[doc(alias = "manufacturer")]
359    pub fn connect_manufacturer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
360        unsafe extern "C" fn notify_manufacturer_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
361            this: *mut ffi::NMWifiP2PPeer,
362            _param_spec: glib::ffi::gpointer,
363            f: glib::ffi::gpointer,
364        ) {
365            let f: &F = &*(f as *const F);
366            f(&from_glib_borrow(this))
367        }
368        unsafe {
369            let f: Box_<F> = Box_::new(f);
370            connect_raw(
371                self.as_ptr() as *mut _,
372                c"notify::manufacturer".as_ptr() as *const _,
373                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
374                    notify_manufacturer_trampoline::<F> as *const (),
375                )),
376                Box_::into_raw(f),
377            )
378        }
379    }
380
381    #[cfg(feature = "v1_16")]
382    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
383    #[doc(alias = "model")]
384    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
385        unsafe extern "C" fn notify_model_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
386            this: *mut ffi::NMWifiP2PPeer,
387            _param_spec: glib::ffi::gpointer,
388            f: glib::ffi::gpointer,
389        ) {
390            let f: &F = &*(f as *const F);
391            f(&from_glib_borrow(this))
392        }
393        unsafe {
394            let f: Box_<F> = Box_::new(f);
395            connect_raw(
396                self.as_ptr() as *mut _,
397                c"notify::model".as_ptr() as *const _,
398                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
399                    notify_model_trampoline::<F> as *const (),
400                )),
401                Box_::into_raw(f),
402            )
403        }
404    }
405
406    #[cfg(feature = "v1_16")]
407    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
408    #[doc(alias = "model-number")]
409    pub fn connect_model_number_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
410        unsafe extern "C" fn notify_model_number_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
411            this: *mut ffi::NMWifiP2PPeer,
412            _param_spec: glib::ffi::gpointer,
413            f: glib::ffi::gpointer,
414        ) {
415            let f: &F = &*(f as *const F);
416            f(&from_glib_borrow(this))
417        }
418        unsafe {
419            let f: Box_<F> = Box_::new(f);
420            connect_raw(
421                self.as_ptr() as *mut _,
422                c"notify::model-number".as_ptr() as *const _,
423                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
424                    notify_model_number_trampoline::<F> as *const (),
425                )),
426                Box_::into_raw(f),
427            )
428        }
429    }
430
431    #[cfg(feature = "v1_16")]
432    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
433    #[doc(alias = "name")]
434    pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
435        unsafe extern "C" fn notify_name_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
436            this: *mut ffi::NMWifiP2PPeer,
437            _param_spec: glib::ffi::gpointer,
438            f: glib::ffi::gpointer,
439        ) {
440            let f: &F = &*(f as *const F);
441            f(&from_glib_borrow(this))
442        }
443        unsafe {
444            let f: Box_<F> = Box_::new(f);
445            connect_raw(
446                self.as_ptr() as *mut _,
447                c"notify::name".as_ptr() as *const _,
448                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
449                    notify_name_trampoline::<F> as *const (),
450                )),
451                Box_::into_raw(f),
452            )
453        }
454    }
455
456    #[cfg(feature = "v1_16")]
457    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
458    #[doc(alias = "serial")]
459    pub fn connect_serial_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
460        unsafe extern "C" fn notify_serial_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
461            this: *mut ffi::NMWifiP2PPeer,
462            _param_spec: glib::ffi::gpointer,
463            f: glib::ffi::gpointer,
464        ) {
465            let f: &F = &*(f as *const F);
466            f(&from_glib_borrow(this))
467        }
468        unsafe {
469            let f: Box_<F> = Box_::new(f);
470            connect_raw(
471                self.as_ptr() as *mut _,
472                c"notify::serial".as_ptr() as *const _,
473                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
474                    notify_serial_trampoline::<F> as *const (),
475                )),
476                Box_::into_raw(f),
477            )
478        }
479    }
480
481    #[cfg(feature = "v1_16")]
482    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
483    #[doc(alias = "strength")]
484    pub fn connect_strength_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
485        unsafe extern "C" fn notify_strength_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
486            this: *mut ffi::NMWifiP2PPeer,
487            _param_spec: glib::ffi::gpointer,
488            f: glib::ffi::gpointer,
489        ) {
490            let f: &F = &*(f as *const F);
491            f(&from_glib_borrow(this))
492        }
493        unsafe {
494            let f: Box_<F> = Box_::new(f);
495            connect_raw(
496                self.as_ptr() as *mut _,
497                c"notify::strength".as_ptr() as *const _,
498                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
499                    notify_strength_trampoline::<F> as *const (),
500                )),
501                Box_::into_raw(f),
502            )
503        }
504    }
505
506    #[cfg(feature = "v1_16")]
507    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
508    #[doc(alias = "wfd-ies")]
509    pub fn connect_wfd_ies_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
510        unsafe extern "C" fn notify_wfd_ies_trampoline<F: Fn(&WifiP2PPeer) + 'static>(
511            this: *mut ffi::NMWifiP2PPeer,
512            _param_spec: glib::ffi::gpointer,
513            f: glib::ffi::gpointer,
514        ) {
515            let f: &F = &*(f as *const F);
516            f(&from_glib_borrow(this))
517        }
518        unsafe {
519            let f: Box_<F> = Box_::new(f);
520            connect_raw(
521                self.as_ptr() as *mut _,
522                c"notify::wfd-ies".as_ptr() as *const _,
523                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
524                    notify_wfd_ies_trampoline::<F> as *const (),
525                )),
526                Box_::into_raw(f),
527            )
528        }
529    }
530}
531
532impl std::fmt::Display for WifiP2PPeer {
533    #[inline]
534    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
535        f.write_str(&self.name())
536    }
537}