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.UnixFDMessage;
26 
27 private import gio.SocketControlMessage;
28 private import gio.UnixFDList;
29 private import glib.ConstructionException;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import gobject.ObjectG;
33 private import gtkc.gio;
34 public  import gtkc.giotypes;
35 
36 
37 /**
38  * This #GSocketControlMessage contains a #GUnixFDList.
39  * It may be sent using g_socket_send_message() and received using
40  * g_socket_receive_message() over UNIX sockets (ie: sockets in the
41  * %G_SOCKET_ADDRESS_UNIX family). The file descriptors are copied
42  * between processes by the kernel.
43  * 
44  * For an easier way to send and receive file descriptors over
45  * stream-oriented UNIX sockets, see g_unix_connection_send_fd() and
46  * g_unix_connection_receive_fd().
47  * 
48  * Note that `<gio/gunixfdmessage.h>` belongs to the UNIX-specific GIO
49  * interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
50  * file when using it.
51  */
52 public class UnixFDMessage : SocketControlMessage
53 {
54 	/** the main Gtk struct */
55 	protected GUnixFDMessage* gUnixFDMessage;
56 
57 	/** Get the main Gtk struct */
58 	public GUnixFDMessage* getUnixFDMessageStruct()
59 	{
60 		return gUnixFDMessage;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gUnixFDMessage;
67 	}
68 
69 	protected override void setStruct(GObject* obj)
70 	{
71 		gUnixFDMessage = cast(GUnixFDMessage*)obj;
72 		super.setStruct(obj);
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GUnixFDMessage* gUnixFDMessage, bool ownedRef = false)
79 	{
80 		this.gUnixFDMessage = gUnixFDMessage;
81 		super(cast(GSocketControlMessage*)gUnixFDMessage, ownedRef);
82 	}
83 
84 	/**
85 	 */
86 
87 	public static GType getType()
88 	{
89 		return g_unix_fd_message_get_type();
90 	}
91 
92 	/**
93 	 * Creates a new #GUnixFDMessage containing an empty file descriptor
94 	 * list.
95 	 *
96 	 * Return: a new #GUnixFDMessage
97 	 *
98 	 * Since: 2.22
99 	 *
100 	 * Throws: ConstructionException GTK+ fails to create the object.
101 	 */
102 	public this()
103 	{
104 		auto p = g_unix_fd_message_new();
105 		
106 		if(p is null)
107 		{
108 			throw new ConstructionException("null returned by new");
109 		}
110 		
111 		this(cast(GUnixFDMessage*) p, true);
112 	}
113 
114 	/**
115 	 * Creates a new #GUnixFDMessage containing @list.
116 	 *
117 	 * Params:
118 	 *     fdList = a #GUnixFDList
119 	 *
120 	 * Return: a new #GUnixFDMessage
121 	 *
122 	 * Since: 2.24
123 	 *
124 	 * Throws: ConstructionException GTK+ fails to create the object.
125 	 */
126 	public this(UnixFDList fdList)
127 	{
128 		auto p = g_unix_fd_message_new_with_fd_list((fdList is null) ? null : fdList.getUnixFDListStruct());
129 		
130 		if(p is null)
131 		{
132 			throw new ConstructionException("null returned by new_with_fd_list");
133 		}
134 		
135 		this(cast(GUnixFDMessage*) p, true);
136 	}
137 
138 	/**
139 	 * Adds a file descriptor to @message.
140 	 *
141 	 * The file descriptor is duplicated using dup(). You keep your copy
142 	 * of the descriptor and the copy contained in @message will be closed
143 	 * when @message is finalized.
144 	 *
145 	 * A possible cause of failure is exceeding the per-process or
146 	 * system-wide file descriptor limit.
147 	 *
148 	 * Params:
149 	 *     fd = a valid open file descriptor
150 	 *
151 	 * Return: %TRUE in case of success, else %FALSE (and @error is set)
152 	 *
153 	 * Since: 2.22
154 	 *
155 	 * Throws: GException on failure.
156 	 */
157 	public bool appendFd(int fd)
158 	{
159 		GError* err = null;
160 		
161 		auto p = g_unix_fd_message_append_fd(gUnixFDMessage, fd, &err) != 0;
162 		
163 		if (err !is null)
164 		{
165 			throw new GException( new ErrorG(err) );
166 		}
167 		
168 		return p;
169 	}
170 
171 	/**
172 	 * Gets the #GUnixFDList contained in @message.  This function does not
173 	 * return a reference to the caller, but the returned list is valid for
174 	 * the lifetime of @message.
175 	 *
176 	 * Return: the #GUnixFDList from @message
177 	 *
178 	 * Since: 2.24
179 	 */
180 	public UnixFDList getFdList()
181 	{
182 		auto p = g_unix_fd_message_get_fd_list(gUnixFDMessage);
183 		
184 		if(p is null)
185 		{
186 			return null;
187 		}
188 		
189 		return ObjectG.getDObject!(UnixFDList)(cast(GUnixFDList*) p);
190 	}
191 
192 	/**
193 	 * Returns the array of file descriptors that is contained in this
194 	 * object.
195 	 *
196 	 * After this call, the descriptors are no longer contained in
197 	 * @message. Further calls will return an empty list (unless more
198 	 * descriptors have been added).
199 	 *
200 	 * The return result of this function must be freed with g_free().
201 	 * The caller is also responsible for closing all of the file
202 	 * descriptors.
203 	 *
204 	 * If @length is non-%NULL then it is set to the number of file
205 	 * descriptors in the returned array. The returned array is also
206 	 * terminated with -1.
207 	 *
208 	 * This function never returns %NULL. In case there are no file
209 	 * descriptors contained in @message, an empty array is returned.
210 	 *
211 	 * Params:
212 	 *     length = pointer to the length of the returned
213 	 *         array, or %NULL
214 	 *
215 	 * Return: an array of file
216 	 *     descriptors
217 	 *
218 	 * Since: 2.22
219 	 */
220 	public int[] stealFds()
221 	{
222 		int length;
223 		
224 		auto p = g_unix_fd_message_steal_fds(gUnixFDMessage, &length);
225 		
226 		return p[0 .. length];
227 	}
228 }