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