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