gio/auto/
socket_address.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, SocketConnectable, SocketFamily};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// `GSocketAddress` is the equivalent of
15    /// [`struct sockaddr`](man:sockaddr(3type)) and its subtypes in the BSD sockets
16    /// API. This is an abstract class; use [`InetSocketAddress`][crate::InetSocketAddress] for
17    /// internet sockets, or [`UnixSocketAddress`][crate::UnixSocketAddress] for UNIX domain sockets.
18    ///
19    /// This is an Abstract Base Class, you cannot instantiate it.
20    ///
21    /// ## Properties
22    ///
23    ///
24    /// #### `family`
25    ///  The family of the socket address.
26    ///
27    /// Readable
28    ///
29    /// # Implements
30    ///
31    /// [`SocketAddressExt`][trait@crate::prelude::SocketAddressExt], [`trait@glib::ObjectExt`], [`SocketConnectableExt`][trait@crate::prelude::SocketConnectableExt]
32    #[doc(alias = "GSocketAddress")]
33    pub struct SocketAddress(Object<ffi::GSocketAddress, ffi::GSocketAddressClass>) @implements SocketConnectable;
34
35    match fn {
36        type_ => || ffi::g_socket_address_get_type(),
37    }
38}
39
40impl SocketAddress {
41    pub const NONE: Option<&'static SocketAddress> = None;
42
43    //#[doc(alias = "g_socket_address_new_from_native")]
44    //#[doc(alias = "new_from_native")]
45    //pub fn from_native(native: /*Unimplemented*/Basic: Pointer, len: usize) -> SocketAddress {
46    //    unsafe { TODO: call ffi:g_socket_address_new_from_native() }
47    //}
48}
49
50unsafe impl Send for SocketAddress {}
51unsafe impl Sync for SocketAddress {}
52
53/// Trait containing all [`struct@SocketAddress`] methods.
54///
55/// # Implementors
56///
57/// [`InetSocketAddress`][struct@crate::InetSocketAddress], [`NativeSocketAddress`][struct@crate::NativeSocketAddress], [`SocketAddress`][struct@crate::SocketAddress], [`UnixSocketAddress`][struct@crate::UnixSocketAddress]
58pub trait SocketAddressExt: IsA<SocketAddress> + 'static {
59    /// Gets the socket family type of @self.
60    ///
61    /// # Returns
62    ///
63    /// the socket family type of @self
64    #[doc(alias = "g_socket_address_get_family")]
65    #[doc(alias = "get_family")]
66    fn family(&self) -> SocketFamily {
67        unsafe {
68            from_glib(ffi::g_socket_address_get_family(
69                self.as_ref().to_glib_none().0,
70            ))
71        }
72    }
73
74    /// Gets the size of @self's native struct sockaddr.
75    /// You can use this to allocate memory to pass to
76    /// g_socket_address_to_native().
77    ///
78    /// # Returns
79    ///
80    /// the size of the native struct sockaddr that
81    ///     @self represents
82    #[doc(alias = "g_socket_address_get_native_size")]
83    #[doc(alias = "get_native_size")]
84    fn native_size(&self) -> isize {
85        unsafe { ffi::g_socket_address_get_native_size(self.as_ref().to_glib_none().0) }
86    }
87
88    //#[doc(alias = "g_socket_address_to_native")]
89    //fn to_native(&self, dest: /*Unimplemented*/Option<Basic: Pointer>, destlen: usize) -> Result<(), glib::Error> {
90    //    unsafe { TODO: call ffi:g_socket_address_to_native() }
91    //}
92
93    #[doc(alias = "family")]
94    fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
95        unsafe extern "C" fn notify_family_trampoline<
96            P: IsA<SocketAddress>,
97            F: Fn(&P) + Send + Sync + 'static,
98        >(
99            this: *mut ffi::GSocketAddress,
100            _param_spec: glib::ffi::gpointer,
101            f: glib::ffi::gpointer,
102        ) {
103            let f: &F = &*(f as *const F);
104            f(SocketAddress::from_glib_borrow(this).unsafe_cast_ref())
105        }
106        unsafe {
107            let f: Box_<F> = Box_::new(f);
108            connect_raw(
109                self.as_ptr() as *mut _,
110                c"notify::family".as_ptr() as *const _,
111                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
112                    notify_family_trampoline::<Self, F> as *const (),
113                )),
114                Box_::into_raw(f),
115            )
116        }
117    }
118}
119
120impl<O: IsA<SocketAddress>> SocketAddressExt for O {}