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 gobject.ObjectG;
28 private import gtkc.gio;
29 public  import gtkc.giotypes;
30 
31 
32 /**
33  * A #GSocketControlMessage is a special-purpose utility message that
34  * can be sent to or received from a #GSocket. These types of
35  * messages are often called "ancillary data".
36  * 
37  * The message can represent some sort of special instruction to or
38  * information from the socket or can represent a special kind of
39  * transfer to the peer (for example, sending a file descriptor over
40  * a UNIX socket).
41  * 
42  * These messages are sent with g_socket_send_message() and received
43  * with g_socket_receive_message().
44  * 
45  * To extend the set of control message that can be sent, subclass this
46  * class and override the get_size, get_level, get_type and serialize
47  * methods.
48  * 
49  * To extend the set of control messages that can be received, subclass
50  * this class and implement the deserialize method. Also, make sure your
51  * class is registered with the GType typesystem before calling
52  * g_socket_receive_message() to read such a message.
53  */
54 public class SocketControlMessage : ObjectG
55 {
56 	/** the main Gtk struct */
57 	protected GSocketControlMessage* gSocketControlMessage;
58 
59 	/** Get the main Gtk struct */
60 	public GSocketControlMessage* getSocketControlMessageStruct()
61 	{
62 		return gSocketControlMessage;
63 	}
64 
65 	/** the main Gtk struct as a void* */
66 	protected override void* getStruct()
67 	{
68 		return cast(void*)gSocketControlMessage;
69 	}
70 
71 	protected override void setStruct(GObject* obj)
72 	{
73 		gSocketControlMessage = cast(GSocketControlMessage*)obj;
74 		super.setStruct(obj);
75 	}
76 
77 	/**
78 	 * Sets our main struct and passes it to the parent class.
79 	 */
80 	public this (GSocketControlMessage* gSocketControlMessage, bool ownedRef = false)
81 	{
82 		this.gSocketControlMessage = gSocketControlMessage;
83 		super(cast(GObject*)gSocketControlMessage, ownedRef);
84 	}
85 
86 
87 	/** */
88 	public static GType getType()
89 	{
90 		return g_socket_control_message_get_type();
91 	}
92 
93 	/**
94 	 * Tries to deserialize a socket control message of a given
95 	 * @level and @type. This will ask all known (to GType) subclasses
96 	 * of #GSocketControlMessage if they can understand this kind
97 	 * of message and if so deserialize it into a #GSocketControlMessage.
98 	 *
99 	 * If there is no implementation for this kind of control message, %NULL
100 	 * will be returned.
101 	 *
102 	 * Params:
103 	 *     level = a socket level
104 	 *     type = a socket control message type for the given @level
105 	 *     size = the size of the data in bytes
106 	 *     data = pointer to the message data
107 	 *
108 	 * Return: the deserialized message or %NULL
109 	 *
110 	 * Since: 2.22
111 	 */
112 	public static SocketControlMessage deserialize(int level, int type, ubyte[] data)
113 	{
114 		auto p = g_socket_control_message_deserialize(level, type, cast(size_t)data.length, data.ptr);
115 		
116 		if(p is null)
117 		{
118 			return null;
119 		}
120 		
121 		return ObjectG.getDObject!(SocketControlMessage)(cast(GSocketControlMessage*) p, true);
122 	}
123 
124 	/**
125 	 * Returns the "level" (i.e. the originating protocol) of the control message.
126 	 * This is often SOL_SOCKET.
127 	 *
128 	 * Return: an integer describing the level
129 	 *
130 	 * Since: 2.22
131 	 */
132 	public int getLevel()
133 	{
134 		return g_socket_control_message_get_level(gSocketControlMessage);
135 	}
136 
137 	/**
138 	 * Returns the protocol specific type of the control message.
139 	 * For instance, for UNIX fd passing this would be SCM_RIGHTS.
140 	 *
141 	 * Return: an integer describing the type of control message
142 	 *
143 	 * Since: 2.22
144 	 */
145 	public int getMsgType()
146 	{
147 		return g_socket_control_message_get_msg_type(gSocketControlMessage);
148 	}
149 
150 	/**
151 	 * Returns the space required for the control message, not including
152 	 * headers or alignment.
153 	 *
154 	 * Return: The number of bytes required.
155 	 *
156 	 * Since: 2.22
157 	 */
158 	public size_t getSize()
159 	{
160 		return g_socket_control_message_get_size(gSocketControlMessage);
161 	}
162 
163 	/**
164 	 * Converts the data in the message to bytes placed in the
165 	 * message.
166 	 *
167 	 * @data is guaranteed to have enough space to fit the size
168 	 * returned by g_socket_control_message_get_size() on this
169 	 * object.
170 	 *
171 	 * Params:
172 	 *     data = A buffer to write data to
173 	 *
174 	 * Since: 2.22
175 	 */
176 	public void serialize(void* data)
177 	{
178 		g_socket_control_message_serialize(gSocketControlMessage, data);
179 	}
180 }