1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 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::{SocketControlMessage, UnixFDList};
use glib::{prelude::*, translate::*};
use std::fmt;

glib::wrapper! {
    /// This [`SocketControlMessage`][crate::SocketControlMessage] contains a [`UnixFDList`][crate::UnixFDList].
    /// It may be sent using [`SocketExtManual::send_message()`][crate::prelude::SocketExtManual::send_message()] and received using
    /// [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()] over UNIX sockets (ie: sockets in the
    /// [`SocketFamily::Unix`][crate::SocketFamily::Unix] family). The file descriptors are copied
    /// between processes by the kernel.
    ///
    /// For an easier way to send and receive file descriptors over
    /// stream-oriented UNIX sockets, see `g_unix_connection_send_fd()` and
    /// `g_unix_connection_receive_fd()`.
    ///
    /// Note that `<gio/gunixfdmessage.h>` belongs to the UNIX-specific GIO
    /// interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
    /// file when using it.
    ///
    /// ## Properties
    ///
    ///
    /// #### `fd-list`
    ///  Readable | Writeable | Construct Only
    ///
    /// # Implements
    ///
    /// [`UnixFDMessageExt`][trait@crate::prelude::UnixFDMessageExt], [`SocketControlMessageExt`][trait@crate::prelude::SocketControlMessageExt], [`trait@glib::ObjectExt`], [`UnixFDMessageExtManual`][trait@crate::prelude::UnixFDMessageExtManual], [`SocketControlMessageExtManual`][trait@crate::prelude::SocketControlMessageExtManual]
    #[doc(alias = "GUnixFDMessage")]
    pub struct UnixFDMessage(Object<ffi::GUnixFDMessage, ffi::GUnixFDMessageClass>) @extends SocketControlMessage;

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

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

    /// Creates a new [`UnixFDMessage`][crate::UnixFDMessage] containing an empty file descriptor
    /// list.
    ///
    /// # Returns
    ///
    /// a new [`UnixFDMessage`][crate::UnixFDMessage]
    #[doc(alias = "g_unix_fd_message_new")]
    pub fn new() -> UnixFDMessage {
        unsafe { SocketControlMessage::from_glib_full(ffi::g_unix_fd_message_new()).unsafe_cast() }
    }

    /// Creates a new [`UnixFDMessage`][crate::UnixFDMessage] containing `list`.
    /// ## `fd_list`
    /// a [`UnixFDList`][crate::UnixFDList]
    ///
    /// # Returns
    ///
    /// a new [`UnixFDMessage`][crate::UnixFDMessage]
    #[doc(alias = "g_unix_fd_message_new_with_fd_list")]
    #[doc(alias = "new_with_fd_list")]
    pub fn with_fd_list(fd_list: &impl IsA<UnixFDList>) -> UnixFDMessage {
        unsafe {
            SocketControlMessage::from_glib_full(ffi::g_unix_fd_message_new_with_fd_list(
                fd_list.as_ref().to_glib_none().0,
            ))
            .unsafe_cast()
        }
    }
}

impl Default for UnixFDMessage {
    fn default() -> Self {
        Self::new()
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::UnixFDMessage>> Sealed for T {}
}

/// Trait containing all [`struct@UnixFDMessage`] methods.
///
/// # Implementors
///
/// [`UnixFDMessage`][struct@crate::UnixFDMessage]
pub trait UnixFDMessageExt: IsA<UnixFDMessage> + sealed::Sealed + 'static {
    /// Gets the [`UnixFDList`][crate::UnixFDList] contained in `self`. This function does not
    /// return a reference to the caller, but the returned list is valid for
    /// the lifetime of `self`.
    ///
    /// # Returns
    ///
    /// the [`UnixFDList`][crate::UnixFDList] from `self`
    #[doc(alias = "g_unix_fd_message_get_fd_list")]
    #[doc(alias = "get_fd_list")]
    fn fd_list(&self) -> UnixFDList {
        unsafe {
            from_glib_none(ffi::g_unix_fd_message_get_fd_list(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<UnixFDMessage>> UnixFDMessageExt for O {}

impl fmt::Display for UnixFDMessage {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("UnixFDMessage")
    }
}