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.DBusUtilities;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.IOStream;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import glib.Str;
33 private import glib.Variant;
34 private import glib.VariantType;
35 private import gobject.ObjectG;
36 private import gobject.Value;
37 private import gtkc.gio;
38 public  import gtkc.giotypes;
39 
40 
41 /** */
42 public struct DBusUtilities
43 {
44 
45 	/**
46 	 * Escape @string so it can appear in a D-Bus address as the value
47 	 * part of a key-value pair.
48 	 *
49 	 * For instance, if @string is "/run/bus-for-:0",
50 	 * this function would return "/run/bus-for-%3A0",
51 	 * which could be used in a D-Bus address like
52 	 * "unix:nonce-tcp:host=127.0.0.1,port=42,noncefile=/run/bus-for-%3A0".
53 	 *
54 	 * Params:
55 	 *     str = an unescaped string to be included in a D-Bus address
56 	 *         as the value in a key-value pair
57 	 *
58 	 * Return: a copy of @string with all
59 	 *     non-optionally-escaped bytes escaped
60 	 *
61 	 * Since: 2.36
62 	 */
63 	public static string addressEscapeValue(string str)
64 	{
65 		return Str.toString(g_dbus_address_escape_value(Str.toStringz(str)));
66 	}
67 
68 	/**
69 	 * Synchronously looks up the D-Bus address for the well-known message
70 	 * bus instance specified by @bus_type. This may involve using various
71 	 * platform specific mechanisms.
72 	 *
73 	 * Params:
74 	 *     busType = a #GBusType
75 	 *     cancellable = a #GCancellable or %NULL
76 	 *
77 	 * Return: a valid D-Bus address string for @bus_type or %NULL if
78 	 *     @error is set
79 	 *
80 	 * Since: 2.26
81 	 *
82 	 * Throws: GException on failure.
83 	 */
84 	public static string addressGetForBusSync(GBusType busType, Cancellable cancellable)
85 	{
86 		GError* err = null;
87 		
88 		auto p = g_dbus_address_get_for_bus_sync(busType, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
89 		
90 		if (err !is null)
91 		{
92 			throw new GException( new ErrorG(err) );
93 		}
94 		
95 		return Str.toString(p);
96 	}
97 
98 	/**
99 	 * Asynchronously connects to an endpoint specified by @address and
100 	 * sets up the connection so it is in a state to run the client-side
101 	 * of the D-Bus authentication conversation.
102 	 *
103 	 * When the operation is finished, @callback will be invoked. You can
104 	 * then call g_dbus_address_get_stream_finish() to get the result of
105 	 * the operation.
106 	 *
107 	 * This is an asynchronous failable function. See
108 	 * g_dbus_address_get_stream_sync() for the synchronous version.
109 	 *
110 	 * Params:
111 	 *     address = A valid D-Bus address.
112 	 *     cancellable = A #GCancellable or %NULL.
113 	 *     callback = A #GAsyncReadyCallback to call when the request is satisfied.
114 	 *     userData = Data to pass to @callback.
115 	 *
116 	 * Since: 2.26
117 	 */
118 	public static void addressGetStream(string address, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
119 	{
120 		g_dbus_address_get_stream(Str.toStringz(address), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
121 	}
122 
123 	/**
124 	 * Finishes an operation started with g_dbus_address_get_stream().
125 	 *
126 	 * Params:
127 	 *     res = A #GAsyncResult obtained from the GAsyncReadyCallback passed to g_dbus_address_get_stream().
128 	 *     outGuid = %NULL or return location to store the GUID extracted from @address, if any.
129 	 *
130 	 * Return: A #GIOStream or %NULL if @error is set.
131 	 *
132 	 * Since: 2.26
133 	 *
134 	 * Throws: GException on failure.
135 	 */
136 	public static IOStream addressGetStreamFinish(AsyncResultIF res, out string outGuid)
137 	{
138 		char* outoutGuid = null;
139 		GError* err = null;
140 		
141 		auto p = g_dbus_address_get_stream_finish((res is null) ? null : res.getAsyncResultStruct(), &outoutGuid, &err);
142 		
143 		if (err !is null)
144 		{
145 			throw new GException( new ErrorG(err) );
146 		}
147 		
148 		outGuid = Str.toString(outoutGuid);
149 		
150 		if(p is null)
151 		{
152 			return null;
153 		}
154 		
155 		return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p, true);
156 	}
157 
158 	/**
159 	 * Synchronously connects to an endpoint specified by @address and
160 	 * sets up the connection so it is in a state to run the client-side
161 	 * of the D-Bus authentication conversation.
162 	 *
163 	 * This is a synchronous failable function. See
164 	 * g_dbus_address_get_stream() for the asynchronous version.
165 	 *
166 	 * Params:
167 	 *     address = A valid D-Bus address.
168 	 *     outGuid = %NULL or return location to store the GUID extracted from @address, if any.
169 	 *     cancellable = A #GCancellable or %NULL.
170 	 *
171 	 * Return: A #GIOStream or %NULL if @error is set.
172 	 *
173 	 * Since: 2.26
174 	 *
175 	 * Throws: GException on failure.
176 	 */
177 	public static IOStream addressGetStreamSync(string address, out string outGuid, Cancellable cancellable)
178 	{
179 		char* outoutGuid = null;
180 		GError* err = null;
181 		
182 		auto p = g_dbus_address_get_stream_sync(Str.toStringz(address), &outoutGuid, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
183 		
184 		if (err !is null)
185 		{
186 			throw new GException( new ErrorG(err) );
187 		}
188 		
189 		outGuid = Str.toString(outoutGuid);
190 		
191 		if(p is null)
192 		{
193 			return null;
194 		}
195 		
196 		return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p, true);
197 	}
198 
199 	/**
200 	 * Generate a D-Bus GUID that can be used with
201 	 * e.g. g_dbus_connection_new().
202 	 *
203 	 * See the D-Bus specification regarding what strings are valid D-Bus
204 	 * GUID (for example, D-Bus GUIDs are not RFC-4122 compliant).
205 	 *
206 	 * Return: A valid D-Bus GUID. Free with g_free().
207 	 *
208 	 * Since: 2.26
209 	 */
210 	public static string generateGuid()
211 	{
212 		return Str.toString(g_dbus_generate_guid());
213 	}
214 
215 	/**
216 	 * Converts a #GValue to a #GVariant of the type indicated by the @type
217 	 * parameter.
218 	 *
219 	 * The conversion is using the following rules:
220 	 *
221 	 * - #G_TYPE_STRING: 's', 'o', 'g' or 'ay'
222 	 * - #G_TYPE_STRV: 'as', 'ao' or 'aay'
223 	 * - #G_TYPE_BOOLEAN: 'b'
224 	 * - #G_TYPE_UCHAR: 'y'
225 	 * - #G_TYPE_INT: 'i', 'n'
226 	 * - #G_TYPE_UINT: 'u', 'q'
227 	 * - #G_TYPE_INT64 'x'
228 	 * - #G_TYPE_UINT64: 't'
229 	 * - #G_TYPE_DOUBLE: 'd'
230 	 * - #G_TYPE_VARIANT: Any #GVariantType
231 	 *
232 	 * This can fail if e.g. @gvalue is of type #G_TYPE_STRING and @type
233 	 * is ['i'][G-VARIANT-TYPE-INT32:CAPS]. It will also fail for any #GType
234 	 * (including e.g. #G_TYPE_OBJECT and #G_TYPE_BOXED derived-types) not
235 	 * in the table above.
236 	 *
237 	 * Note that if @gvalue is of type #G_TYPE_VARIANT and its value is
238 	 * %NULL, the empty #GVariant instance (never %NULL) for @type is
239 	 * returned (e.g. 0 for scalar types, the empty string for string types,
240 	 * '/' for object path types, the empty array for any array type and so on).
241 	 *
242 	 * See the g_dbus_gvariant_to_gvalue() function for how to convert a
243 	 * #GVariant to a #GValue.
244 	 *
245 	 * Params:
246 	 *     gvalue = A #GValue to convert to a #GVariant
247 	 *     type = A #GVariantType
248 	 *
249 	 * Return: A #GVariant (never floating) of #GVariantType @type holding
250 	 *     the data from @gvalue or %NULL in case of failure. Free with
251 	 *     g_variant_unref().
252 	 *
253 	 * Since: 2.30
254 	 */
255 	public static Variant gvalueToGvariant(Value gvalue, VariantType type)
256 	{
257 		auto p = g_dbus_gvalue_to_gvariant((gvalue is null) ? null : gvalue.getValueStruct(), (type is null) ? null : type.getVariantTypeStruct());
258 		
259 		if(p is null)
260 		{
261 			return null;
262 		}
263 		
264 		return new Variant(cast(GVariant*) p);
265 	}
266 
267 	/**
268 	 * Converts a #GVariant to a #GValue. If @value is floating, it is consumed.
269 	 *
270 	 * The rules specified in the g_dbus_gvalue_to_gvariant() function are
271 	 * used - this function is essentially its reverse form.
272 	 *
273 	 * The conversion never fails - a valid #GValue is always returned in
274 	 * @out_gvalue.
275 	 *
276 	 * Params:
277 	 *     value = A #GVariant.
278 	 *     outGvalue = Return location pointing to a zero-filled (uninitialized) #GValue.
279 	 *
280 	 * Since: 2.30
281 	 */
282 	public static void gvariantToGvalue(Variant value, out Value outGvalue)
283 	{
284 		GValue* outoutGvalue = gMalloc!GValue();
285 		
286 		g_dbus_gvariant_to_gvalue((value is null) ? null : value.getVariantStruct(), outoutGvalue);
287 		
288 		outGvalue = ObjectG.getDObject!(Value)(outoutGvalue);
289 	}
290 
291 	/**
292 	 * Checks if @string is a D-Bus address.
293 	 *
294 	 * This doesn't check if @string is actually supported by #GDBusServer
295 	 * or #GDBusConnection - use g_dbus_is_supported_address() to do more
296 	 * checks.
297 	 *
298 	 * Params:
299 	 *     str = A string.
300 	 *
301 	 * Return: %TRUE if @string is a valid D-Bus address, %FALSE otherwise.
302 	 *
303 	 * Since: 2.26
304 	 */
305 	public static bool isAddress(string str)
306 	{
307 		return g_dbus_is_address(Str.toStringz(str)) != 0;
308 	}
309 
310 	/**
311 	 * Checks if @string is a D-Bus GUID.
312 	 *
313 	 * See the D-Bus specification regarding what strings are valid D-Bus
314 	 * GUID (for example, D-Bus GUIDs are not RFC-4122 compliant).
315 	 *
316 	 * Params:
317 	 *     str = The string to check.
318 	 *
319 	 * Return: %TRUE if @string is a guid, %FALSE otherwise.
320 	 *
321 	 * Since: 2.26
322 	 */
323 	public static bool isGuid(string str)
324 	{
325 		return g_dbus_is_guid(Str.toStringz(str)) != 0;
326 	}
327 
328 	/**
329 	 * Checks if @string is a valid D-Bus interface name.
330 	 *
331 	 * Params:
332 	 *     str = The string to check.
333 	 *
334 	 * Return: %TRUE if valid, %FALSE otherwise.
335 	 *
336 	 * Since: 2.26
337 	 */
338 	public static bool isInterfaceName(string str)
339 	{
340 		return g_dbus_is_interface_name(Str.toStringz(str)) != 0;
341 	}
342 
343 	/**
344 	 * Checks if @string is a valid D-Bus member (e.g. signal or method) name.
345 	 *
346 	 * Params:
347 	 *     str = The string to check.
348 	 *
349 	 * Return: %TRUE if valid, %FALSE otherwise.
350 	 *
351 	 * Since: 2.26
352 	 */
353 	public static bool isMemberName(string str)
354 	{
355 		return g_dbus_is_member_name(Str.toStringz(str)) != 0;
356 	}
357 
358 	/**
359 	 * Checks if @string is a valid D-Bus bus name (either unique or well-known).
360 	 *
361 	 * Params:
362 	 *     str = The string to check.
363 	 *
364 	 * Return: %TRUE if valid, %FALSE otherwise.
365 	 *
366 	 * Since: 2.26
367 	 */
368 	public static bool isName(string str)
369 	{
370 		return g_dbus_is_name(Str.toStringz(str)) != 0;
371 	}
372 
373 	/**
374 	 * Like g_dbus_is_address() but also checks if the library suppors the
375 	 * transports in @string and that key/value pairs for each transport
376 	 * are valid.
377 	 *
378 	 * Params:
379 	 *     str = A string.
380 	 *
381 	 * Return: %TRUE if @string is a valid D-Bus address that is
382 	 *     supported by this library, %FALSE if @error is set.
383 	 *
384 	 * Since: 2.26
385 	 *
386 	 * Throws: GException on failure.
387 	 */
388 	public static bool isSupportedAddress(string str)
389 	{
390 		GError* err = null;
391 		
392 		auto p = g_dbus_is_supported_address(Str.toStringz(str), &err) != 0;
393 		
394 		if (err !is null)
395 		{
396 			throw new GException( new ErrorG(err) );
397 		}
398 		
399 		return p;
400 	}
401 
402 	/**
403 	 * Checks if @string is a valid D-Bus unique bus name.
404 	 *
405 	 * Params:
406 	 *     str = The string to check.
407 	 *
408 	 * Return: %TRUE if valid, %FALSE otherwise.
409 	 *
410 	 * Since: 2.26
411 	 */
412 	public static bool isUniqueName(string str)
413 	{
414 		return g_dbus_is_unique_name(Str.toStringz(str)) != 0;
415 	}
416 }