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
53mod sealed {
54    pub trait Sealed {}
55    impl<T: super::IsA<super::SocketAddress>> Sealed for T {}
56}
57
58/// Trait containing all [`struct@SocketAddress`] methods.
59///
60/// # Implementors
61///
62/// [`InetSocketAddress`][struct@crate::InetSocketAddress], [`NativeSocketAddress`][struct@crate::NativeSocketAddress], [`SocketAddress`][struct@crate::SocketAddress], [`UnixSocketAddress`][struct@crate::UnixSocketAddress]
63pub trait SocketAddressExt: IsA<SocketAddress> + sealed::Sealed + 'static {
64    /// Gets the socket family type of @self.
65    ///
66    /// # Returns
67    ///
68    /// the socket family type of @self
69    #[doc(alias = "g_socket_address_get_family")]
70    #[doc(alias = "get_family")]
71    fn family(&self) -> SocketFamily {
72        unsafe {
73            from_glib(ffi::g_socket_address_get_family(
74                self.as_ref().to_glib_none().0,
75            ))
76        }
77    }
78
79    /// Gets the size of @self's native struct sockaddr.
80    /// You can use this to allocate memory to pass to
81    /// g_socket_address_to_native().
82    ///
83    /// # Returns
84    ///
85    /// the size of the native struct sockaddr that
86    ///     @self represents
87    #[doc(alias = "g_socket_address_get_native_size")]
88    #[doc(alias = "get_native_size")]
89    fn native_size(&self) -> isize {
90        unsafe { ffi::g_socket_address_get_native_size(self.as_ref().to_glib_none().0) }
91    }
92
93    //#[doc(alias = "g_socket_address_to_native")]
94    //fn to_native(&self, dest: /*Unimplemented*/Option<Basic: Pointer>, destlen: usize) -> Result<(), glib::Error> {
95    //    unsafe { TODO: call ffi:g_socket_address_to_native() }
96    //}
97
98    #[doc(alias = "family")]
99    fn connect_family_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
100        unsafe extern "C" fn notify_family_trampoline<
101            P: IsA<SocketAddress>,
102            F: Fn(&P) + Send + Sync + 'static,
103        >(
104            this: *mut ffi::GSocketAddress,
105            _param_spec: glib::ffi::gpointer,
106            f: glib::ffi::gpointer,
107        ) {
108            let f: &F = &*(f as *const F);
109            f(SocketAddress::from_glib_borrow(this).unsafe_cast_ref())
110        }
111        unsafe {
112            let f: Box_<F> = Box_::new(f);
113            connect_raw(
114                self.as_ptr() as *mut _,
115                b"notify::family\0".as_ptr() as *const _,
116                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
117                    notify_family_trampoline::<Self, F> as *const (),
118                )),
119                Box_::into_raw(f),
120            )
121        }
122    }
123}
124
125impl<O: IsA<SocketAddress>> SocketAddressExt for O {}