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