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