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 * Conversion parameters: 26 * inFile = gio-D-Bus-Utilities.html 27 * outPack = gio 28 * outFile = DBusUtilities 29 * strct = 30 * realStrct= 31 * ctorStrct= 32 * clss = DBusUtilities 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_dbus_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - glib.ErrorG 48 * - glib.GException 49 * - glib.Variant 50 * - glib.VariantType 51 * - gobject.Value 52 * - gio.AsyncResultIF 53 * - gio.Cancellable 54 * - gio.IOStream 55 * structWrap: 56 * - GValue* -> Value 57 * - GVariant* -> Variant 58 * - GVariantType* -> VariantType 59 * module aliases: 60 * local aliases: 61 * overrides: 62 */ 63 64 module gio.DBusUtilities; 65 66 public import gtkc.giotypes; 67 68 private import gtkc.gio; 69 private import glib.ConstructionException; 70 private import gobject.ObjectG; 71 72 private import glib.Str; 73 private import glib.ErrorG; 74 private import glib.GException; 75 private import glib.Variant; 76 private import glib.VariantType; 77 private import gobject.Value; 78 private import gio.AsyncResultIF; 79 private import gio.Cancellable; 80 private import gio.IOStream; 81 82 83 84 /** 85 * Various utility routines related to D-Bus. 86 */ 87 public class DBusUtilities 88 { 89 90 /** 91 * Routines for working with D-Bus addresses. A D-Bus address is a string 92 * like "unix:tmpdir=/tmp/my-app-name". The exact format of addresses 93 * is explained in detail in the D-Bus specification. 94 */ 95 96 /** 97 * Generate a D-Bus GUID that can be used with 98 * e.g. g_dbus_connection_new(). 99 * See the D-Bus specification regarding what strings are valid D-Bus 100 * GUID (for example, D-Bus GUIDs are not RFC-4122 compliant). 101 * Since 2.26 102 * Returns: A valid D-Bus GUID. Free with g_free(). 103 */ 104 public static string generateGuid() 105 { 106 // gchar * g_dbus_generate_guid (void); 107 return Str.toString(g_dbus_generate_guid()); 108 } 109 110 /** 111 * Checks if string is a D-Bus GUID. 112 * See the D-Bus specification regarding what strings are valid D-Bus 113 * GUID (for example, D-Bus GUIDs are not RFC-4122 compliant). 114 * Since 2.26 115 * Params: 116 * string = The string to check. 117 * Returns: TRUE if string is a guid, FALSE otherwise. 118 */ 119 public static int isGuid(string string) 120 { 121 // gboolean g_dbus_is_guid (const gchar *string); 122 return g_dbus_is_guid(Str.toStringz(string)); 123 } 124 125 /** 126 * Checks if string is a valid D-Bus bus name (either unique or well-known). 127 * Since 2.26 128 * Params: 129 * string = The string to check. 130 * Returns: TRUE if valid, FALSE otherwise. 131 */ 132 public static int isName(string string) 133 { 134 // gboolean g_dbus_is_name (const gchar *string); 135 return g_dbus_is_name(Str.toStringz(string)); 136 } 137 138 /** 139 * Checks if string is a valid D-Bus unique bus name. 140 * Since 2.26 141 * Params: 142 * string = The string to check. 143 * Returns: TRUE if valid, FALSE otherwise. 144 */ 145 public static int isUniqueName(string string) 146 { 147 // gboolean g_dbus_is_unique_name (const gchar *string); 148 return g_dbus_is_unique_name(Str.toStringz(string)); 149 } 150 151 /** 152 * Checks if string is a valid D-Bus member (e.g. signal or method) name. 153 * Since 2.26 154 * Params: 155 * string = The string to check. 156 * Returns: TRUE if valid, FALSE otherwise. 157 */ 158 public static int isMemberName(string string) 159 { 160 // gboolean g_dbus_is_member_name (const gchar *string); 161 return g_dbus_is_member_name(Str.toStringz(string)); 162 } 163 164 /** 165 * Checks if string is a valid D-Bus interface name. 166 * Since 2.26 167 * Params: 168 * string = The string to check. 169 * Returns: TRUE if valid, FALSE otherwise. 170 */ 171 public static int isInterfaceName(string string) 172 { 173 // gboolean g_dbus_is_interface_name (const gchar *string); 174 return g_dbus_is_interface_name(Str.toStringz(string)); 175 } 176 177 /** 178 * Converts a GValue to a GVariant of the type indicated by the type parameter. 179 * Since 2.30 180 * Params: 181 * gvalue = A GValue to convert to a GVariant. 182 * type = A GVariantType. 183 * Returns: A GVariant (never floating) of GVariantType type holding the data from gvalue or NULL in case of failure. Free with g_variant_unref(). 184 */ 185 public static Variant gvalueToGvariant(Value gvalue, VariantType type) 186 { 187 // GVariant * g_dbus_gvalue_to_gvariant (const GValue *gvalue, const GVariantType *type); 188 auto p = g_dbus_gvalue_to_gvariant((gvalue is null) ? null : gvalue.getValueStruct(), (type is null) ? null : type.getVariantTypeStruct()); 189 190 if(p is null) 191 { 192 return null; 193 } 194 195 return ObjectG.getDObject!(Variant)(cast(GVariant*) p); 196 } 197 198 /** 199 * Converts a GVariant to a GValue. If value is floating, it is consumed. 200 * The rules specified in the g_dbus_gvalue_to_gvariant() function are 201 * used - this function is essentially its reverse form. 202 * The conversion never fails - a valid GValue is always returned in 203 * out_gvalue. 204 * Since 2.30 205 * Params: 206 * value = A GVariant. 207 * outGvalue = Return location pointing to a zero-filled (uninitialized) GValue. [out] 208 */ 209 public static void gvariantToGvalue(Variant value, Value outGvalue) 210 { 211 // void g_dbus_gvariant_to_gvalue (GVariant *value, GValue *out_gvalue); 212 g_dbus_gvariant_to_gvalue((value is null) ? null : value.getVariantStruct(), (outGvalue is null) ? null : outGvalue.getValueStruct()); 213 } 214 215 /** 216 * Checks if string is a D-Bus address. 217 * This doesn't check if string is actually supported by GDBusServer 218 * or GDBusConnection - use g_dbus_is_supported_address() to do more 219 * checks. 220 * Since 2.26 221 * Params: 222 * string = A string. 223 * Returns: TRUE if string is a valid D-Bus address, FALSE otherwise. 224 */ 225 public static int isAddress(string string) 226 { 227 // gboolean g_dbus_is_address (const gchar *string); 228 return g_dbus_is_address(Str.toStringz(string)); 229 } 230 231 /** 232 * Like g_dbus_is_address() but also checks if the library suppors the 233 * transports in string and that key/value pairs for each transport 234 * are valid. 235 * Since 2.26 236 * Params: 237 * string = A string. 238 * Returns: TRUE if string is a valid D-Bus address that is supported by this library, FALSE if error is set. 239 * Throws: GException on failure. 240 */ 241 public static int isSupportedAddress(string string) 242 { 243 // gboolean g_dbus_is_supported_address (const gchar *string, GError **error); 244 GError* err = null; 245 246 auto p = g_dbus_is_supported_address(Str.toStringz(string), &err); 247 248 if (err !is null) 249 { 250 throw new GException( new ErrorG(err) ); 251 } 252 253 return p; 254 } 255 256 /** 257 * Asynchronously connects to an endpoint specified by address and 258 * sets up the connection so it is in a state to run the client-side 259 * of the D-Bus authentication conversation. 260 * When the operation is finished, callback will be invoked. You can 261 * then call g_dbus_address_get_stream_finish() to get the result of 262 * the operation. 263 * This is an asynchronous failable function. See 264 * g_dbus_address_get_stream_sync() for the synchronous version. 265 * Since 2.26 266 * Params: 267 * address = A valid D-Bus address. 268 * cancellable = A GCancellable or NULL. [allow-none] 269 * callback = A GAsyncReadyCallback to call when the request is satisfied. 270 * userData = Data to pass to callback. 271 */ 272 public static void addressGetStream(string address, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 273 { 274 // void g_dbus_address_get_stream (const gchar *address, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 275 g_dbus_address_get_stream(Str.toStringz(address), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 276 } 277 278 /** 279 * Finishes an operation started with g_dbus_address_get_stream(). 280 * Since 2.26 281 * Params: 282 * res = A GAsyncResult obtained from the GAsyncReadyCallback passed to g_dbus_address_get_stream(). 283 * outGuid = NULL or return location to store the GUID extracted from address, if any. 284 * Returns: A GIOStream or NULL if error is set. [transfer full] 285 * Throws: GException on failure. 286 */ 287 public static IOStream addressGetStreamFinish(AsyncResultIF res, out string outGuid) 288 { 289 // GIOStream * g_dbus_address_get_stream_finish (GAsyncResult *res, gchar **out_guid, GError **error); 290 char* outoutGuid = null; 291 GError* err = null; 292 293 auto p = g_dbus_address_get_stream_finish((res is null) ? null : res.getAsyncResultTStruct(), &outoutGuid, &err); 294 295 if (err !is null) 296 { 297 throw new GException( new ErrorG(err) ); 298 } 299 300 outGuid = Str.toString(outoutGuid); 301 302 if(p is null) 303 { 304 return null; 305 } 306 307 return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p); 308 } 309 310 /** 311 * Synchronously connects to an endpoint specified by address and 312 * sets up the connection so it is in a state to run the client-side 313 * of the D-Bus authentication conversation. 314 * This is a synchronous failable function. See 315 * g_dbus_address_get_stream() for the asynchronous version. 316 * Since 2.26 317 * Params: 318 * address = A valid D-Bus address. 319 * outGuid = NULL or return location to store the GUID extracted from address, if any. 320 * cancellable = A GCancellable or NULL. [allow-none] 321 * Returns: A GIOStream or NULL if error is set. [transfer full] 322 * Throws: GException on failure. 323 */ 324 public static IOStream addressGetStreamSync(string address, out string outGuid, Cancellable cancellable) 325 { 326 // GIOStream * g_dbus_address_get_stream_sync (const gchar *address, gchar **out_guid, GCancellable *cancellable, GError **error); 327 char* outoutGuid = null; 328 GError* err = null; 329 330 auto p = g_dbus_address_get_stream_sync(Str.toStringz(address), &outoutGuid, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 331 332 if (err !is null) 333 { 334 throw new GException( new ErrorG(err) ); 335 } 336 337 outGuid = Str.toString(outoutGuid); 338 339 if(p is null) 340 { 341 return null; 342 } 343 344 return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p); 345 } 346 347 /** 348 * Synchronously looks up the D-Bus address for the well-known message 349 * bus instance specified by bus_type. This may involve using various 350 * platform specific mechanisms. 351 * Since 2.26 352 * Params: 353 * busType = A GBusType. 354 * cancellable = A GCancellable or NULL. [allow-none] 355 * Returns: A valid D-Bus address string for bus_type or NULL if error is set. 356 * Throws: GException on failure. 357 */ 358 public static string addressGetForBusSync(GBusType busType, Cancellable cancellable) 359 { 360 // gchar * g_dbus_address_get_for_bus_sync (GBusType bus_type, GCancellable *cancellable, GError **error); 361 GError* err = null; 362 363 auto p = g_dbus_address_get_for_bus_sync(busType, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 364 365 if (err !is null) 366 { 367 throw new GException( new ErrorG(err) ); 368 } 369 370 return Str.toString(p); 371 } 372 }