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