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