// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{SocketFamily, ffi};
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "GInetAddress")]
    pub struct InetAddress(Object<ffi::GInetAddress, ffi::GInetAddressClass>);

    match fn {
        type_ => || ffi::g_inet_address_get_type(),
    }
}

impl InetAddress {
    pub const NONE: Option<&'static InetAddress> = None;

    #[doc(alias = "g_inet_address_new_any")]
    pub fn new_any(family: SocketFamily) -> InetAddress {
        unsafe { from_glib_full(ffi::g_inet_address_new_any(family.into_glib())) }
    }

    #[doc(alias = "g_inet_address_new_from_string")]
    #[doc(alias = "new_from_string")]
    pub fn from_string(string: &str) -> Option<InetAddress> {
        unsafe { from_glib_full(ffi::g_inet_address_new_from_string(string.to_glib_none().0)) }
    }

    #[doc(alias = "g_inet_address_new_loopback")]
    pub fn new_loopback(family: SocketFamily) -> InetAddress {
        unsafe { from_glib_full(ffi::g_inet_address_new_loopback(family.into_glib())) }
    }
}

impl std::fmt::Display for InetAddress {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(&InetAddressExt::to_str(self))
    }
}

unsafe impl Send for InetAddress {}
unsafe impl Sync for InetAddress {}

pub trait InetAddressExt: IsA<InetAddress> + 'static {
    #[doc(alias = "g_inet_address_equal")]
    fn equal(&self, other_address: &impl IsA<InetAddress>) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_equal(
                self.as_ref().to_glib_none().0,
                other_address.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_family")]
    #[doc(alias = "get_family")]
    fn family(&self) -> SocketFamily {
        unsafe {
            from_glib(ffi::g_inet_address_get_family(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(feature = "v2_86")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
    #[doc(alias = "g_inet_address_get_flowinfo")]
    #[doc(alias = "get_flowinfo")]
    fn flowinfo(&self) -> u32 {
        unsafe { ffi::g_inet_address_get_flowinfo(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "g_inet_address_get_is_any")]
    #[doc(alias = "get_is_any")]
    #[doc(alias = "is-any")]
    fn is_any(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_any(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_link_local")]
    #[doc(alias = "get_is_link_local")]
    #[doc(alias = "is-link-local")]
    fn is_link_local(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_link_local(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_loopback")]
    #[doc(alias = "get_is_loopback")]
    #[doc(alias = "is-loopback")]
    fn is_loopback(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_loopback(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_mc_global")]
    #[doc(alias = "get_is_mc_global")]
    #[doc(alias = "is-mc-global")]
    fn is_mc_global(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_mc_global(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_mc_link_local")]
    #[doc(alias = "get_is_mc_link_local")]
    #[doc(alias = "is-mc-link-local")]
    fn is_mc_link_local(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_mc_link_local(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_mc_node_local")]
    #[doc(alias = "get_is_mc_node_local")]
    #[doc(alias = "is-mc-node-local")]
    fn is_mc_node_local(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_mc_node_local(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_mc_org_local")]
    #[doc(alias = "get_is_mc_org_local")]
    #[doc(alias = "is-mc-org-local")]
    fn is_mc_org_local(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_mc_org_local(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_mc_site_local")]
    #[doc(alias = "get_is_mc_site_local")]
    #[doc(alias = "is-mc-site-local")]
    fn is_mc_site_local(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_mc_site_local(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_multicast")]
    #[doc(alias = "get_is_multicast")]
    #[doc(alias = "is-multicast")]
    fn is_multicast(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_multicast(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_is_site_local")]
    #[doc(alias = "get_is_site_local")]
    #[doc(alias = "is-site-local")]
    fn is_site_local(&self) -> bool {
        unsafe {
            from_glib(ffi::g_inet_address_get_is_site_local(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_inet_address_get_native_size")]
    #[doc(alias = "get_native_size")]
    fn native_size(&self) -> usize {
        unsafe { ffi::g_inet_address_get_native_size(self.as_ref().to_glib_none().0) }
    }

    #[cfg(feature = "v2_86")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
    #[doc(alias = "g_inet_address_get_scope_id")]
    #[doc(alias = "get_scope_id")]
    #[doc(alias = "scope-id")]
    fn scope_id(&self) -> u32 {
        unsafe { ffi::g_inet_address_get_scope_id(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "g_inet_address_to_string")]
    #[doc(alias = "to_string")]
    fn to_str(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::g_inet_address_to_string(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //fn bytes(&self) -> /*Unimplemented*/Basic: Pointer {
    //    ObjectExt::property(self.as_ref(), "bytes")
    //}

    #[doc(alias = "is-any")]
    fn connect_is_any_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_any_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-any".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_any_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-link-local")]
    fn connect_is_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_link_local_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-link-local".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_link_local_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-loopback")]
    fn connect_is_loopback_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_loopback_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-loopback".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_loopback_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-mc-global")]
    fn connect_is_mc_global_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_mc_global_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-mc-global".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_mc_global_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-mc-link-local")]
    fn connect_is_mc_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_mc_link_local_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-mc-link-local".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_mc_link_local_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-mc-node-local")]
    fn connect_is_mc_node_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_mc_node_local_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-mc-node-local".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_mc_node_local_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-mc-org-local")]
    fn connect_is_mc_org_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_mc_org_local_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-mc-org-local".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_mc_org_local_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-mc-site-local")]
    fn connect_is_mc_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_mc_site_local_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-mc-site-local".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_mc_site_local_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-multicast")]
    fn connect_is_multicast_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_multicast_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-multicast".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_multicast_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-site-local")]
    fn connect_is_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_site_local_trampoline<
            P: IsA<InetAddress>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GInetAddress,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::is-site-local".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_site_local_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<InetAddress>> InetAddressExt for O {}
