1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.SocketControlMessage;
26 
27 private import gio.c.functions;
28 public  import gio.c.types;
29 private import gobject.ObjectG;
30 public  import gtkc.giotypes;
31 
32 
33 /**
34  * A #GSocketControlMessage is a special-purpose utility message that
35  * can be sent to or received from a #GSocket. These types of
36  * messages are often called "ancillary data".
37  * 
38  * The message can represent some sort of special instruction to or
39  * information from the socket or can represent a special kind of
40  * transfer to the peer (for example, sending a file descriptor over
41  * a UNIX socket).
42  * 
43  * These messages are sent with g_socket_send_message() and received
44  * with g_socket_receive_message().
45  * 
46  * To extend the set of control message that can be sent, subclass this
47  * class and override the get_size, get_level, get_type and serialize
48  * methods.
49  * 
50  * To extend the set of control messages that can be received, subclass
51  * this class and implement the deserialize method. Also, make sure your
52  * class is registered with the GType typesystem before calling
53  * g_socket_receive_message() to read such a message.
54  *
55  * Since: 2.22
56  */
57 public class SocketControlMessage : ObjectG
58 {
59 	/** the main Gtk struct */
60 	protected GSocketControlMessage* gSocketControlMessage;
61 
62 	/** Get the main Gtk struct */
63 	public GSocketControlMessage* getSocketControlMessageStruct(bool transferOwnership = false)
64 	{
65 		if (transferOwnership)
66 			ownedRef = false;
67 		return gSocketControlMessage;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected override void* getStruct()
72 	{
73 		return cast(void*)gSocketControlMessage;
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GSocketControlMessage* gSocketControlMessage, bool ownedRef = false)
80 	{
81 		this.gSocketControlMessage = gSocketControlMessage;
82 		super(cast(GObject*)gSocketControlMessage, ownedRef);
83 	}
84 
85 
86 	/** */
87 	public static GType getType()
88 	{
89 		return g_socket_control_message_get_type();
90 	}
91 
92 	/**
93 	 * Tries to deserialize a socket control message of a given
94 	 * @level and @type. This will ask all known (to GType) subclasses
95 	 * of #GSocketControlMessage if they can understand this kind
96 	 * of message and if so deserialize it into a #GSocketControlMessage.
97 	 *
98 	 * If there is no implementation for this kind of control message, %NULL
99 	 * will be returned.
100 	 *
101 	 * Params:
102 	 *     level = a socket level
103 	 *     type = a socket control message type for the given @level
104 	 *     data = pointer to the message data
105 	 *
106 	 * Returns: the deserialized message or %NULL
107 	 *
108 	 * Since: 2.22
109 	 */
110 	public static SocketControlMessage deserialize(int level, int type, ubyte[] data)
111 	{
112 		auto __p = g_socket_control_message_deserialize(level, type, cast(size_t)data.length, data.ptr);
113 
114 		if(__p is null)
115 		{
116 			return null;
117 		}
118 
119 		return ObjectG.getDObject!(SocketControlMessage)(cast(GSocketControlMessage*) __p, true);
120 	}
121 
122 	/**
123 	 * Returns the "level" (i.e. the originating protocol) of the control message.
124 	 * This is often SOL_SOCKET.
125 	 *
126 	 * Returns: an integer describing the level
127 	 *
128 	 * Since: 2.22
129 	 */
130 	public int getLevel()
131 	{
132 		return g_socket_control_message_get_level(gSocketControlMessage);
133 	}
134 
135 	/**
136 	 * Returns the protocol specific type of the control message.
137 	 * For instance, for UNIX fd passing this would be SCM_RIGHTS.
138 	 *
139 	 * Returns: an integer describing the type of control message
140 	 *
141 	 * Since: 2.22
142 	 */
143 	public int getMsgType()
144 	{
145 		return g_socket_control_message_get_msg_type(gSocketControlMessage);
146 	}
147 
148 	/**
149 	 * Returns the space required for the control message, not including
150 	 * headers or alignment.
151 	 *
152 	 * Returns: The number of bytes required.
153 	 *
154 	 * Since: 2.22
155 	 */
156 	public size_t getSize()
157 	{
158 		return g_socket_control_message_get_size(gSocketControlMessage);
159 	}
160 
161 	/**
162 	 * Converts the data in the message to bytes placed in the
163 	 * message.
164 	 *
165 	 * @data is guaranteed to have enough space to fit the size
166 	 * returned by g_socket_control_message_get_size() on this
167 	 * object.
168 	 *
169 	 * Params:
170 	 *     data = A buffer to write data to
171 	 *
172 	 * Since: 2.22
173 	 */
174 	public void serialize(void* data)
175 	{
176 		g_socket_control_message_serialize(gSocketControlMessage, data);
177 	}
178 }