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