1use 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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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}