gio/auto/socket_control_message.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;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// .
10 ///
11 /// The message can represent some sort of special instruction to or
12 /// information from the socket or can represent a special kind of
13 /// transfer to the peer (for example, sending a file descriptor over
14 /// a UNIX socket).
15 ///
16 /// These messages are sent with [`SocketExtManual::send_message()`][crate::prelude::SocketExtManual::send_message()] and received
17 /// with [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()].
18 ///
19 /// To extend the set of control messages that can be sent, subclass this
20 /// class and override the `get_size`, `get_level`, `get_type` and `serialize`
21 /// methods.
22 ///
23 /// To extend the set of control messages that can be received, subclass
24 /// this class and implement the `deserialize` method. Also, make sure your
25 /// class is registered with the [type@GObject.Type] type system before calling
26 /// [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()] to read such a message.
27 ///
28 /// This is an Abstract Base Class, you cannot instantiate it.
29 ///
30 /// # Implements
31 ///
32 /// [`SocketControlMessageExt`][trait@crate::prelude::SocketControlMessageExt], [`trait@glib::ObjectExt`], [`SocketControlMessageExtManual`][trait@crate::prelude::SocketControlMessageExtManual]
33 #[doc(alias = "GSocketControlMessage")]
34 pub struct SocketControlMessage(Object<ffi::GSocketControlMessage, ffi::GSocketControlMessageClass>);
35
36 match fn {
37 type_ => || ffi::g_socket_control_message_get_type(),
38 }
39}
40
41impl SocketControlMessage {
42 pub const NONE: Option<&'static SocketControlMessage> = None;
43
44 /// Tries to deserialize a socket control message of a given
45 /// @level and @type_. This will ask all known (to GType) subclasses
46 /// of #GSocketControlMessage if they can understand this kind
47 /// of message and if so deserialize it into a #GSocketControlMessage.
48 ///
49 /// If there is no implementation for this kind of control message, [`None`]
50 /// will be returned.
51 /// ## `level`
52 /// a socket level
53 /// ## `type_`
54 /// a socket control message type for the given @level
55 ///
56 /// # Returns
57 ///
58 /// the deserialized message or [`None`]
59 #[doc(alias = "g_socket_control_message_deserialize")]
60 pub fn deserialize(level: i32, type_: i32, data: &[u8]) -> Option<SocketControlMessage> {
61 let size = data.len() as _;
62 unsafe {
63 from_glib_full(ffi::g_socket_control_message_deserialize(
64 level,
65 type_,
66 size,
67 data.to_glib_none().0 as glib::ffi::gpointer,
68 ))
69 }
70 }
71}
72
73/// Trait containing all [`struct@SocketControlMessage`] methods.
74///
75/// # Implementors
76///
77/// [`IPTosMessage`][struct@crate::IPTosMessage], [`IPv6TclassMessage`][struct@crate::IPv6TclassMessage], [`SocketControlMessage`][struct@crate::SocketControlMessage], [`UnixCredentialsMessage`][struct@crate::UnixCredentialsMessage]
78pub trait SocketControlMessageExt: IsA<SocketControlMessage> + 'static {
79 /// Returns the "level" (i.e. the originating protocol) of the control message.
80 /// This is often SOL_SOCKET.
81 ///
82 /// # Returns
83 ///
84 /// an integer describing the level
85 #[doc(alias = "g_socket_control_message_get_level")]
86 #[doc(alias = "get_level")]
87 fn level(&self) -> i32 {
88 unsafe { ffi::g_socket_control_message_get_level(self.as_ref().to_glib_none().0) }
89 }
90
91 /// Returns the protocol specific type of the control message.
92 /// For instance, for UNIX fd passing this would be SCM_RIGHTS.
93 ///
94 /// # Returns
95 ///
96 /// an integer describing the type of control message
97 #[doc(alias = "g_socket_control_message_get_msg_type")]
98 #[doc(alias = "get_msg_type")]
99 fn msg_type(&self) -> i32 {
100 unsafe { ffi::g_socket_control_message_get_msg_type(self.as_ref().to_glib_none().0) }
101 }
102
103 /// Returns the space required for the control message, not including
104 /// headers or alignment.
105 ///
106 /// # Returns
107 ///
108 /// The number of bytes required.
109 #[doc(alias = "g_socket_control_message_get_size")]
110 #[doc(alias = "get_size")]
111 fn size(&self) -> usize {
112 unsafe { ffi::g_socket_control_message_get_size(self.as_ref().to_glib_none().0) }
113 }
114}
115
116impl<O: IsA<SocketControlMessage>> SocketControlMessageExt for O {}