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