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 	public static GType getType()
87 	{
88 		return g_unix_fd_message_get_type();
89 	}
90 
91 	/**
92 	 * Creates a new #GUnixFDMessage containing an empty file descriptor
93 	 * list.
94 	 *
95 	 * Return: a new #GUnixFDMessage
96 	 *
97 	 * Since: 2.22
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this()
102 	{
103 		auto p = g_unix_fd_message_new();
104 		
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 		
110 		this(cast(GUnixFDMessage*) p, true);
111 	}
112 
113 	/**
114 	 * Creates a new #GUnixFDMessage containing @list.
115 	 *
116 	 * Params:
117 	 *     fdList = a #GUnixFDList
118 	 *
119 	 * Return: a new #GUnixFDMessage
120 	 *
121 	 * Since: 2.24
122 	 *
123 	 * Throws: ConstructionException GTK+ fails to create the object.
124 	 */
125 	public this(UnixFDList fdList)
126 	{
127 		auto p = g_unix_fd_message_new_with_fd_list((fdList is null) ? null : fdList.getUnixFDListStruct());
128 		
129 		if(p is null)
130 		{
131 			throw new ConstructionException("null returned by new_with_fd_list");
132 		}
133 		
134 		this(cast(GUnixFDMessage*) p, true);
135 	}
136 
137 	/**
138 	 * Adds a file descriptor to @message.
139 	 *
140 	 * The file descriptor is duplicated using dup(). You keep your copy
141 	 * of the descriptor and the copy contained in @message will be closed
142 	 * when @message is finalized.
143 	 *
144 	 * A possible cause of failure is exceeding the per-process or
145 	 * system-wide file descriptor limit.
146 	 *
147 	 * Params:
148 	 *     fd = a valid open file descriptor
149 	 *
150 	 * Return: %TRUE in case of success, else %FALSE (and @error is set)
151 	 *
152 	 * Since: 2.22
153 	 *
154 	 * Throws: GException on failure.
155 	 */
156 	public bool appendFd(int fd)
157 	{
158 		GError* err = null;
159 		
160 		auto p = g_unix_fd_message_append_fd(gUnixFDMessage, fd, &err) != 0;
161 		
162 		if (err !is null)
163 		{
164 			throw new GException( new ErrorG(err) );
165 		}
166 		
167 		return p;
168 	}
169 
170 	/**
171 	 * Gets the #GUnixFDList contained in @message.  This function does not
172 	 * return a reference to the caller, but the returned list is valid for
173 	 * the lifetime of @message.
174 	 *
175 	 * Return: the #GUnixFDList from @message
176 	 *
177 	 * Since: 2.24
178 	 */
179 	public UnixFDList getFdList()
180 	{
181 		auto p = g_unix_fd_message_get_fd_list(gUnixFDMessage);
182 		
183 		if(p is null)
184 		{
185 			return null;
186 		}
187 		
188 		return ObjectG.getDObject!(UnixFDList)(cast(GUnixFDList*) p);
189 	}
190 
191 	/**
192 	 * Returns the array of file descriptors that is contained in this
193 	 * object.
194 	 *
195 	 * After this call, the descriptors are no longer contained in
196 	 * @message. Further calls will return an empty list (unless more
197 	 * descriptors have been added).
198 	 *
199 	 * The return result of this function must be freed with g_free().
200 	 * The caller is also responsible for closing all of the file
201 	 * descriptors.
202 	 *
203 	 * If @length is non-%NULL then it is set to the number of file
204 	 * descriptors in the returned array. The returned array is also
205 	 * terminated with -1.
206 	 *
207 	 * This function never returns %NULL. In case there are no file
208 	 * descriptors contained in @message, an empty array is returned.
209 	 *
210 	 * Return: an array of file
211 	 *     descriptors
212 	 *
213 	 * Since: 2.22
214 	 */
215 	public int[] stealFds()
216 	{
217 		int length;
218 		
219 		auto p = g_unix_fd_message_steal_fds(gUnixFDMessage, &length);
220 		
221 		return p[0 .. length];
222 	}
223 }