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.DBusProxy; 26 27 private import gio.AsyncInitableIF; 28 private import gio.AsyncInitableT; 29 private import gio.AsyncResultIF; 30 private import gio.Cancellable; 31 private import gio.DBusConnection; 32 private import gio.DBusInterfaceIF; 33 private import gio.DBusInterfaceInfo; 34 private import gio.DBusInterfaceT; 35 private import gio.InitableIF; 36 private import gio.InitableT; 37 private import gio.UnixFDList; 38 private import gio.c.functions; 39 public import gio.c.types; 40 private import glib.ConstructionException; 41 private import glib.ErrorG; 42 private import glib.GException; 43 private import glib.Str; 44 private import glib.Variant; 45 private import gobject.ObjectG; 46 private import gobject.Signals; 47 public import gtkc.giotypes; 48 private import std.algorithm; 49 50 51 /** 52 * #GDBusProxy is a base class used for proxies to access a D-Bus 53 * interface on a remote object. A #GDBusProxy can be constructed for 54 * both well-known and unique names. 55 * 56 * By default, #GDBusProxy will cache all properties (and listen to 57 * changes) of the remote object, and proxy all signals that gets 58 * emitted. This behaviour can be changed by passing suitable 59 * #GDBusProxyFlags when the proxy is created. If the proxy is for a 60 * well-known name, the property cache is flushed when the name owner 61 * vanishes and reloaded when a name owner appears. 62 * 63 * If a #GDBusProxy is used for a well-known name, the owner of the 64 * name is tracked and can be read from 65 * #GDBusProxy:g-name-owner. Connect to the #GObject::notify signal to 66 * get notified of changes. Additionally, only signals and property 67 * changes emitted from the current name owner are considered and 68 * calls are always sent to the current name owner. This avoids a 69 * number of race conditions when the name is lost by one owner and 70 * claimed by another. However, if no name owner currently exists, 71 * then calls will be sent to the well-known name which may result in 72 * the message bus launching an owner (unless 73 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START is set). 74 * 75 * The generic #GDBusProxy::g-properties-changed and 76 * #GDBusProxy::g-signal signals are not very convenient to work with. 77 * Therefore, the recommended way of working with proxies is to subclass 78 * #GDBusProxy, and have more natural properties and signals in your derived 79 * class. This [example][gdbus-example-gdbus-codegen] shows how this can 80 * easily be done using the [gdbus-codegen][gdbus-codegen] tool. 81 * 82 * A #GDBusProxy instance can be used from multiple threads but note 83 * that all signals (e.g. #GDBusProxy::g-signal, #GDBusProxy::g-properties-changed 84 * and #GObject::notify) are emitted in the 85 * [thread-default main context][g-main-context-push-thread-default] 86 * of the thread where the instance was constructed. 87 * 88 * An example using a proxy for a well-known name can be found in 89 * [gdbus-example-watch-proxy.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-watch-proxy.c) 90 * 91 * Since: 2.26 92 */ 93 public class DBusProxy : ObjectG, AsyncInitableIF, DBusInterfaceIF, InitableIF 94 { 95 /** the main Gtk struct */ 96 protected GDBusProxy* gDBusProxy; 97 98 /** Get the main Gtk struct */ 99 public GDBusProxy* getDBusProxyStruct(bool transferOwnership = false) 100 { 101 if (transferOwnership) 102 ownedRef = false; 103 return gDBusProxy; 104 } 105 106 /** the main Gtk struct as a void* */ 107 protected override void* getStruct() 108 { 109 return cast(void*)gDBusProxy; 110 } 111 112 /** 113 * Sets our main struct and passes it to the parent class. 114 */ 115 public this (GDBusProxy* gDBusProxy, bool ownedRef = false) 116 { 117 this.gDBusProxy = gDBusProxy; 118 super(cast(GObject*)gDBusProxy, ownedRef); 119 } 120 121 // add the AsyncInitable capabilities 122 mixin AsyncInitableT!(GDBusProxy); 123 124 // add the DBusInterface capabilities 125 mixin DBusInterfaceT!(GDBusProxy); 126 127 // add the Initable capabilities 128 mixin InitableT!(GDBusProxy); 129 130 /** 131 * Finishes creating a GDBusProxy. 132 * 133 * Params: 134 * res = A GAsyncResult obtained from the GAsyncReadyCallback 135 * function passed to g_dbus_proxy_new(). 136 * forBus = If true finish an address. 137 * 138 * Throws: GException on failure. 139 * Throws: ConstructionException GTK+ fails to create the object. 140 * 141 * Since: 2.26 142 */ 143 public this (AsyncResultIF res, bool forBus = false) 144 { 145 GError* err = null; 146 GDBusProxy* p; 147 148 if ( forBus ) 149 { 150 p = g_dbus_proxy_new_for_bus_finish((res is null) ? null : res.getAsyncResultStruct(), &err); 151 } 152 else 153 { 154 p = g_dbus_proxy_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err); 155 } 156 157 if (err !is null) 158 { 159 throw new GException( new ErrorG(err) ); 160 } 161 162 if(p is null) 163 { 164 throw new ConstructionException("null returned by g_dbus_proxy_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err)"); 165 } 166 this(p, true); 167 } 168 169 /** 170 */ 171 172 /** */ 173 public static GType getType() 174 { 175 return g_dbus_proxy_get_type(); 176 } 177 178 /** 179 * Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection. 180 * 181 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy]. 182 * 183 * Params: 184 * busType = A #GBusType. 185 * flags = Flags used when constructing the proxy. 186 * info = A #GDBusInterfaceInfo specifying the minimal interface 187 * that @proxy conforms to or %NULL. 188 * name = A bus name (well-known or unique). 189 * objectPath = An object path. 190 * interfaceName = A D-Bus interface name. 191 * cancellable = A #GCancellable or %NULL. 192 * 193 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref(). 194 * 195 * Since: 2.26 196 * 197 * Throws: GException on failure. 198 * Throws: ConstructionException GTK+ fails to create the object. 199 */ 200 public this(GBusType busType, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable) 201 { 202 GError* err = null; 203 204 auto p = g_dbus_proxy_new_for_bus_sync(busType, flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 205 206 if (err !is null) 207 { 208 throw new GException( new ErrorG(err) ); 209 } 210 211 if(p is null) 212 { 213 throw new ConstructionException("null returned by new_for_bus_sync"); 214 } 215 216 this(cast(GDBusProxy*) p, true); 217 } 218 219 /** 220 * Creates a proxy for accessing @interface_name on the remote object 221 * at @object_path owned by @name at @connection and synchronously 222 * loads D-Bus properties unless the 223 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. 224 * 225 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up 226 * match rules for signals. Connect to the #GDBusProxy::g-signal signal 227 * to handle signals from the remote object. 228 * 229 * If @name is a well-known name and the 230 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION 231 * flags aren't set and no name owner currently exists, the message bus 232 * will be requested to launch a name owner for the name. 233 * 234 * This is a synchronous failable constructor. See g_dbus_proxy_new() 235 * and g_dbus_proxy_new_finish() for the asynchronous version. 236 * 237 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy]. 238 * 239 * Params: 240 * connection = A #GDBusConnection. 241 * flags = Flags used when constructing the proxy. 242 * info = A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL. 243 * name = A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. 244 * objectPath = An object path. 245 * interfaceName = A D-Bus interface name. 246 * cancellable = A #GCancellable or %NULL. 247 * 248 * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref(). 249 * 250 * Since: 2.26 251 * 252 * Throws: GException on failure. 253 * Throws: ConstructionException GTK+ fails to create the object. 254 */ 255 public this(DBusConnection connection, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable) 256 { 257 GError* err = null; 258 259 auto p = g_dbus_proxy_new_sync((connection is null) ? null : connection.getDBusConnectionStruct(), flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 260 261 if (err !is null) 262 { 263 throw new GException( new ErrorG(err) ); 264 } 265 266 if(p is null) 267 { 268 throw new ConstructionException("null returned by new_sync"); 269 } 270 271 this(cast(GDBusProxy*) p, true); 272 } 273 274 /** 275 * Creates a proxy for accessing @interface_name on the remote object 276 * at @object_path owned by @name at @connection and asynchronously 277 * loads D-Bus properties unless the 278 * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to 279 * the #GDBusProxy::g-properties-changed signal to get notified about 280 * property changes. 281 * 282 * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up 283 * match rules for signals. Connect to the #GDBusProxy::g-signal signal 284 * to handle signals from the remote object. 285 * 286 * If @name is a well-known name and the 287 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION 288 * flags aren't set and no name owner currently exists, the message bus 289 * will be requested to launch a name owner for the name. 290 * 291 * This is a failable asynchronous constructor - when the proxy is 292 * ready, @callback will be invoked and you can use 293 * g_dbus_proxy_new_finish() to get the result. 294 * 295 * See g_dbus_proxy_new_sync() and for a synchronous version of this constructor. 296 * 297 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy]. 298 * 299 * Params: 300 * connection = A #GDBusConnection. 301 * flags = Flags used when constructing the proxy. 302 * info = A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL. 303 * name = A bus name (well-known or unique) or %NULL if @connection is not a message bus connection. 304 * objectPath = An object path. 305 * interfaceName = A D-Bus interface name. 306 * cancellable = A #GCancellable or %NULL. 307 * callback = Callback function to invoke when the proxy is ready. 308 * userData = User data to pass to @callback. 309 * 310 * Since: 2.26 311 */ 312 public static void newProxy(DBusConnection connection, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 313 { 314 g_dbus_proxy_new((connection is null) ? null : connection.getDBusConnectionStruct(), flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 315 } 316 317 /** 318 * Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection. 319 * 320 * #GDBusProxy is used in this [example][gdbus-wellknown-proxy]. 321 * 322 * Params: 323 * busType = A #GBusType. 324 * flags = Flags used when constructing the proxy. 325 * info = A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL. 326 * name = A bus name (well-known or unique). 327 * objectPath = An object path. 328 * interfaceName = A D-Bus interface name. 329 * cancellable = A #GCancellable or %NULL. 330 * callback = Callback function to invoke when the proxy is ready. 331 * userData = User data to pass to @callback. 332 * 333 * Since: 2.26 334 */ 335 public static void newForBus(GBusType busType, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 336 { 337 g_dbus_proxy_new_for_bus(busType, flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 338 } 339 340 /** 341 * Asynchronously invokes the @method_name method on @proxy. 342 * 343 * If @method_name contains any dots, then @name is split into interface and 344 * method name parts. This allows using @proxy for invoking methods on 345 * other interfaces. 346 * 347 * If the #GDBusConnection associated with @proxy is closed then 348 * the operation will fail with %G_IO_ERROR_CLOSED. If 349 * @cancellable is canceled, the operation will fail with 350 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not 351 * compatible with the D-Bus protocol, the operation fails with 352 * %G_IO_ERROR_INVALID_ARGUMENT. 353 * 354 * If the @parameters #GVariant is floating, it is consumed. This allows 355 * convenient 'inline' use of g_variant_new(), e.g.: 356 * |[<!-- language="C" --> 357 * g_dbus_proxy_call (proxy, 358 * "TwoStrings", 359 * g_variant_new ("(ss)", 360 * "Thing One", 361 * "Thing Two"), 362 * G_DBUS_CALL_FLAGS_NONE, 363 * -1, 364 * NULL, 365 * (GAsyncReadyCallback) two_strings_done, 366 * &data); 367 * ]| 368 * 369 * If @proxy has an expected interface (see 370 * #GDBusProxy:g-interface-info) and @method_name is referenced by it, 371 * then the return value is checked against the return type. 372 * 373 * This is an asynchronous method. When the operation is finished, 374 * @callback will be invoked in the 375 * [thread-default main context][g-main-context-push-thread-default] 376 * of the thread you are calling this method from. 377 * You can then call g_dbus_proxy_call_finish() to get the result of 378 * the operation. See g_dbus_proxy_call_sync() for the synchronous 379 * version of this method. 380 * 381 * If @callback is %NULL then the D-Bus method call message will be sent with 382 * the %G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED flag set. 383 * 384 * Params: 385 * methodName = Name of method to invoke. 386 * parameters = A #GVariant tuple with parameters for the signal or %NULL if not passing parameters. 387 * flags = Flags from the #GDBusCallFlags enumeration. 388 * timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning 389 * "infinite") or -1 to use the proxy default timeout. 390 * cancellable = A #GCancellable or %NULL. 391 * callback = A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't 392 * care about the result of the method invocation. 393 * userData = The data to pass to @callback. 394 * 395 * Since: 2.26 396 */ 397 public void call(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 398 { 399 g_dbus_proxy_call(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 400 } 401 402 /** 403 * Finishes an operation started with g_dbus_proxy_call(). 404 * 405 * Params: 406 * res = A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call(). 407 * 408 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with 409 * return values. Free with g_variant_unref(). 410 * 411 * Since: 2.26 412 * 413 * Throws: GException on failure. 414 */ 415 public Variant callFinish(AsyncResultIF res) 416 { 417 GError* err = null; 418 419 auto p = g_dbus_proxy_call_finish(gDBusProxy, (res is null) ? null : res.getAsyncResultStruct(), &err); 420 421 if (err !is null) 422 { 423 throw new GException( new ErrorG(err) ); 424 } 425 426 if(p is null) 427 { 428 return null; 429 } 430 431 return new Variant(cast(GVariant*) p, true); 432 } 433 434 /** 435 * Synchronously invokes the @method_name method on @proxy. 436 * 437 * If @method_name contains any dots, then @name is split into interface and 438 * method name parts. This allows using @proxy for invoking methods on 439 * other interfaces. 440 * 441 * If the #GDBusConnection associated with @proxy is disconnected then 442 * the operation will fail with %G_IO_ERROR_CLOSED. If 443 * @cancellable is canceled, the operation will fail with 444 * %G_IO_ERROR_CANCELLED. If @parameters contains a value not 445 * compatible with the D-Bus protocol, the operation fails with 446 * %G_IO_ERROR_INVALID_ARGUMENT. 447 * 448 * If the @parameters #GVariant is floating, it is consumed. This allows 449 * convenient 'inline' use of g_variant_new(), e.g.: 450 * |[<!-- language="C" --> 451 * g_dbus_proxy_call_sync (proxy, 452 * "TwoStrings", 453 * g_variant_new ("(ss)", 454 * "Thing One", 455 * "Thing Two"), 456 * G_DBUS_CALL_FLAGS_NONE, 457 * -1, 458 * NULL, 459 * &error); 460 * ]| 461 * 462 * The calling thread is blocked until a reply is received. See 463 * g_dbus_proxy_call() for the asynchronous version of this 464 * method. 465 * 466 * If @proxy has an expected interface (see 467 * #GDBusProxy:g-interface-info) and @method_name is referenced by it, 468 * then the return value is checked against the return type. 469 * 470 * Params: 471 * methodName = Name of method to invoke. 472 * parameters = A #GVariant tuple with parameters for the signal 473 * or %NULL if not passing parameters. 474 * flags = Flags from the #GDBusCallFlags enumeration. 475 * timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning 476 * "infinite") or -1 to use the proxy default timeout. 477 * cancellable = A #GCancellable or %NULL. 478 * 479 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with 480 * return values. Free with g_variant_unref(). 481 * 482 * Since: 2.26 483 * 484 * Throws: GException on failure. 485 */ 486 public Variant callSync(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, Cancellable cancellable) 487 { 488 GError* err = null; 489 490 auto p = g_dbus_proxy_call_sync(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 491 492 if (err !is null) 493 { 494 throw new GException( new ErrorG(err) ); 495 } 496 497 if(p is null) 498 { 499 return null; 500 } 501 502 return new Variant(cast(GVariant*) p, true); 503 } 504 505 /** 506 * Like g_dbus_proxy_call() but also takes a #GUnixFDList object. 507 * 508 * This method is only available on UNIX. 509 * 510 * Params: 511 * methodName = Name of method to invoke. 512 * parameters = A #GVariant tuple with parameters for the signal or %NULL if not passing parameters. 513 * flags = Flags from the #GDBusCallFlags enumeration. 514 * timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning 515 * "infinite") or -1 to use the proxy default timeout. 516 * fdList = A #GUnixFDList or %NULL. 517 * cancellable = A #GCancellable or %NULL. 518 * callback = A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't 519 * care about the result of the method invocation. 520 * userData = The data to pass to @callback. 521 * 522 * Since: 2.30 523 */ 524 public void callWithUnixFdList(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, UnixFDList fdList, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 525 { 526 g_dbus_proxy_call_with_unix_fd_list(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (fdList is null) ? null : fdList.getUnixFDListStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 527 } 528 529 /** 530 * Finishes an operation started with g_dbus_proxy_call_with_unix_fd_list(). 531 * 532 * Params: 533 * outFdList = Return location for a #GUnixFDList or %NULL. 534 * res = A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call_with_unix_fd_list(). 535 * 536 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with 537 * return values. Free with g_variant_unref(). 538 * 539 * Since: 2.30 540 * 541 * Throws: GException on failure. 542 */ 543 public Variant callWithUnixFdListFinish(out UnixFDList outFdList, AsyncResultIF res) 544 { 545 GUnixFDList* outoutFdList = null; 546 GError* err = null; 547 548 auto p = g_dbus_proxy_call_with_unix_fd_list_finish(gDBusProxy, &outoutFdList, (res is null) ? null : res.getAsyncResultStruct(), &err); 549 550 if (err !is null) 551 { 552 throw new GException( new ErrorG(err) ); 553 } 554 555 outFdList = ObjectG.getDObject!(UnixFDList)(outoutFdList); 556 557 if(p is null) 558 { 559 return null; 560 } 561 562 return new Variant(cast(GVariant*) p, true); 563 } 564 565 /** 566 * Like g_dbus_proxy_call_sync() but also takes and returns #GUnixFDList objects. 567 * 568 * This method is only available on UNIX. 569 * 570 * Params: 571 * methodName = Name of method to invoke. 572 * parameters = A #GVariant tuple with parameters for the signal 573 * or %NULL if not passing parameters. 574 * flags = Flags from the #GDBusCallFlags enumeration. 575 * timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning 576 * "infinite") or -1 to use the proxy default timeout. 577 * fdList = A #GUnixFDList or %NULL. 578 * outFdList = Return location for a #GUnixFDList or %NULL. 579 * cancellable = A #GCancellable or %NULL. 580 * 581 * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with 582 * return values. Free with g_variant_unref(). 583 * 584 * Since: 2.30 585 * 586 * Throws: GException on failure. 587 */ 588 public Variant callWithUnixFdListSync(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, UnixFDList fdList, out UnixFDList outFdList, Cancellable cancellable) 589 { 590 GUnixFDList* outoutFdList = null; 591 GError* err = null; 592 593 auto p = g_dbus_proxy_call_with_unix_fd_list_sync(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (fdList is null) ? null : fdList.getUnixFDListStruct(), &outoutFdList, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 594 595 if (err !is null) 596 { 597 throw new GException( new ErrorG(err) ); 598 } 599 600 outFdList = ObjectG.getDObject!(UnixFDList)(outoutFdList); 601 602 if(p is null) 603 { 604 return null; 605 } 606 607 return new Variant(cast(GVariant*) p, true); 608 } 609 610 /** 611 * Looks up the value for a property from the cache. This call does no 612 * blocking IO. 613 * 614 * If @proxy has an expected interface (see 615 * #GDBusProxy:g-interface-info) and @property_name is referenced by 616 * it, then @value is checked against the type of the property. 617 * 618 * Params: 619 * propertyName = Property name. 620 * 621 * Returns: A reference to the #GVariant instance that holds the value 622 * for @property_name or %NULL if the value is not in the cache. The 623 * returned reference must be freed with g_variant_unref(). 624 * 625 * Since: 2.26 626 */ 627 public Variant getCachedProperty(string propertyName) 628 { 629 auto p = g_dbus_proxy_get_cached_property(gDBusProxy, Str.toStringz(propertyName)); 630 631 if(p is null) 632 { 633 return null; 634 } 635 636 return new Variant(cast(GVariant*) p, true); 637 } 638 639 /** 640 * Gets the names of all cached properties on @proxy. 641 * 642 * Returns: A %NULL-terminated array of strings or %NULL if 643 * @proxy has no cached properties. Free the returned array with 644 * g_strfreev(). 645 * 646 * Since: 2.26 647 */ 648 public string[] getCachedPropertyNames() 649 { 650 auto retStr = g_dbus_proxy_get_cached_property_names(gDBusProxy); 651 652 scope(exit) Str.freeStringArray(retStr); 653 return Str.toStringArray(retStr); 654 } 655 656 /** 657 * Gets the connection @proxy is for. 658 * 659 * Returns: A #GDBusConnection owned by @proxy. Do not free. 660 * 661 * Since: 2.26 662 */ 663 public DBusConnection getConnection() 664 { 665 auto p = g_dbus_proxy_get_connection(gDBusProxy); 666 667 if(p is null) 668 { 669 return null; 670 } 671 672 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p); 673 } 674 675 /** 676 * Gets the timeout to use if -1 (specifying default timeout) is 677 * passed as @timeout_msec in the g_dbus_proxy_call() and 678 * g_dbus_proxy_call_sync() functions. 679 * 680 * See the #GDBusProxy:g-default-timeout property for more details. 681 * 682 * Returns: Timeout to use for @proxy. 683 * 684 * Since: 2.26 685 */ 686 public int getDefaultTimeout() 687 { 688 return g_dbus_proxy_get_default_timeout(gDBusProxy); 689 } 690 691 /** 692 * Gets the flags that @proxy was constructed with. 693 * 694 * Returns: Flags from the #GDBusProxyFlags enumeration. 695 * 696 * Since: 2.26 697 */ 698 public GDBusProxyFlags getFlags() 699 { 700 return g_dbus_proxy_get_flags(gDBusProxy); 701 } 702 703 /** 704 * Returns the #GDBusInterfaceInfo, if any, specifying the interface 705 * that @proxy conforms to. See the #GDBusProxy:g-interface-info 706 * property for more details. 707 * 708 * Returns: A #GDBusInterfaceInfo or %NULL. Do not unref the returned 709 * object, it is owned by @proxy. 710 * 711 * Since: 2.26 712 */ 713 public DBusInterfaceInfo getInterfaceInfo() 714 { 715 auto p = g_dbus_proxy_get_interface_info(gDBusProxy); 716 717 if(p is null) 718 { 719 return null; 720 } 721 722 return ObjectG.getDObject!(DBusInterfaceInfo)(cast(GDBusInterfaceInfo*) p, true); 723 } 724 725 /** 726 * Gets the D-Bus interface name @proxy is for. 727 * 728 * Returns: A string owned by @proxy. Do not free. 729 * 730 * Since: 2.26 731 */ 732 public string getInterfaceName() 733 { 734 return Str.toString(g_dbus_proxy_get_interface_name(gDBusProxy)); 735 } 736 737 /** 738 * Gets the name that @proxy was constructed for. 739 * 740 * Returns: A string owned by @proxy. Do not free. 741 * 742 * Since: 2.26 743 */ 744 public string getName() 745 { 746 return Str.toString(g_dbus_proxy_get_name(gDBusProxy)); 747 } 748 749 /** 750 * The unique name that owns the name that @proxy is for or %NULL if 751 * no-one currently owns that name. You may connect to the 752 * #GObject::notify signal to track changes to the 753 * #GDBusProxy:g-name-owner property. 754 * 755 * Returns: The name owner or %NULL if no name owner exists. Free with g_free(). 756 * 757 * Since: 2.26 758 */ 759 public string getNameOwner() 760 { 761 auto retStr = g_dbus_proxy_get_name_owner(gDBusProxy); 762 763 scope(exit) Str.freeString(retStr); 764 return Str.toString(retStr); 765 } 766 767 /** 768 * Gets the object path @proxy is for. 769 * 770 * Returns: A string owned by @proxy. Do not free. 771 * 772 * Since: 2.26 773 */ 774 public string getObjectPath() 775 { 776 return Str.toString(g_dbus_proxy_get_object_path(gDBusProxy)); 777 } 778 779 /** 780 * If @value is not %NULL, sets the cached value for the property with 781 * name @property_name to the value in @value. 782 * 783 * If @value is %NULL, then the cached value is removed from the 784 * property cache. 785 * 786 * If @proxy has an expected interface (see 787 * #GDBusProxy:g-interface-info) and @property_name is referenced by 788 * it, then @value is checked against the type of the property. 789 * 790 * If the @value #GVariant is floating, it is consumed. This allows 791 * convenient 'inline' use of g_variant_new(), e.g. 792 * |[<!-- language="C" --> 793 * g_dbus_proxy_set_cached_property (proxy, 794 * "SomeProperty", 795 * g_variant_new ("(si)", 796 * "A String", 797 * 42)); 798 * ]| 799 * 800 * Normally you will not need to use this method since @proxy 801 * is tracking changes using the 802 * `org.freedesktop.DBus.Properties.PropertiesChanged` 803 * D-Bus signal. However, for performance reasons an object may 804 * decide to not use this signal for some properties and instead 805 * use a proprietary out-of-band mechanism to transmit changes. 806 * 807 * As a concrete example, consider an object with a property 808 * `ChatroomParticipants` which is an array of strings. Instead of 809 * transmitting the same (long) array every time the property changes, 810 * it is more efficient to only transmit the delta using e.g. signals 811 * `ChatroomParticipantJoined(String name)` and 812 * `ChatroomParticipantParted(String name)`. 813 * 814 * Params: 815 * propertyName = Property name. 816 * value = Value for the property or %NULL to remove it from the cache. 817 * 818 * Since: 2.26 819 */ 820 public void setCachedProperty(string propertyName, Variant value) 821 { 822 g_dbus_proxy_set_cached_property(gDBusProxy, Str.toStringz(propertyName), (value is null) ? null : value.getVariantStruct()); 823 } 824 825 /** 826 * Sets the timeout to use if -1 (specifying default timeout) is 827 * passed as @timeout_msec in the g_dbus_proxy_call() and 828 * g_dbus_proxy_call_sync() functions. 829 * 830 * See the #GDBusProxy:g-default-timeout property for more details. 831 * 832 * Params: 833 * timeoutMsec = Timeout in milliseconds. 834 * 835 * Since: 2.26 836 */ 837 public void setDefaultTimeout(int timeoutMsec) 838 { 839 g_dbus_proxy_set_default_timeout(gDBusProxy, timeoutMsec); 840 } 841 842 /** 843 * Ensure that interactions with @proxy conform to the given 844 * interface. See the #GDBusProxy:g-interface-info property for more 845 * details. 846 * 847 * Params: 848 * info = Minimum interface this proxy conforms to or %NULL to unset. 849 * 850 * Since: 2.26 851 */ 852 public void setInterfaceInfo(DBusInterfaceInfo info) 853 { 854 g_dbus_proxy_set_interface_info(gDBusProxy, (info is null) ? null : info.getDBusInterfaceInfoStruct()); 855 } 856 857 protected class OnGPropertiesChangedDelegateWrapper 858 { 859 void delegate(Variant, string[], DBusProxy) dlg; 860 gulong handlerId; 861 862 this(void delegate(Variant, string[], DBusProxy) dlg) 863 { 864 this.dlg = dlg; 865 onGPropertiesChangedListeners ~= this; 866 } 867 868 void remove(OnGPropertiesChangedDelegateWrapper source) 869 { 870 foreach(index, wrapper; onGPropertiesChangedListeners) 871 { 872 if (wrapper.handlerId == source.handlerId) 873 { 874 onGPropertiesChangedListeners[index] = null; 875 onGPropertiesChangedListeners = std.algorithm.remove(onGPropertiesChangedListeners, index); 876 break; 877 } 878 } 879 } 880 } 881 OnGPropertiesChangedDelegateWrapper[] onGPropertiesChangedListeners; 882 883 /** 884 * Emitted when one or more D-Bus properties on @proxy changes. The 885 * local cache has already been updated when this signal fires. Note 886 * that both @changed_properties and @invalidated_properties are 887 * guaranteed to never be %NULL (either may be empty though). 888 * 889 * If the proxy has the flag 890 * %G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES set, then 891 * @invalidated_properties will always be empty. 892 * 893 * This signal corresponds to the 894 * `PropertiesChanged` D-Bus signal on the 895 * `org.freedesktop.DBus.Properties` interface. 896 * 897 * Params: 898 * changedProperties = A #GVariant containing the properties that changed 899 * invalidatedProperties = A %NULL terminated array of properties that was invalidated 900 * 901 * Since: 2.26 902 */ 903 gulong addOnGPropertiesChanged(void delegate(Variant, string[], DBusProxy) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 904 { 905 auto wrapper = new OnGPropertiesChangedDelegateWrapper(dlg); 906 wrapper.handlerId = Signals.connectData( 907 this, 908 "g-properties-changed", 909 cast(GCallback)&callBackGPropertiesChanged, 910 cast(void*)wrapper, 911 cast(GClosureNotify)&callBackGPropertiesChangedDestroy, 912 connectFlags); 913 return wrapper.handlerId; 914 } 915 916 extern(C) static void callBackGPropertiesChanged(GDBusProxy* dbusproxyStruct, GVariant* changedProperties, char** invalidatedProperties, OnGPropertiesChangedDelegateWrapper wrapper) 917 { 918 wrapper.dlg(new Variant(changedProperties), Str.toStringArray(invalidatedProperties), wrapper.outer); 919 } 920 921 extern(C) static void callBackGPropertiesChangedDestroy(OnGPropertiesChangedDelegateWrapper wrapper, GClosure* closure) 922 { 923 wrapper.remove(wrapper); 924 } 925 926 protected class OnGSignalDelegateWrapper 927 { 928 void delegate(string, string, Variant, DBusProxy) dlg; 929 gulong handlerId; 930 931 this(void delegate(string, string, Variant, DBusProxy) dlg) 932 { 933 this.dlg = dlg; 934 onGSignalListeners ~= this; 935 } 936 937 void remove(OnGSignalDelegateWrapper source) 938 { 939 foreach(index, wrapper; onGSignalListeners) 940 { 941 if (wrapper.handlerId == source.handlerId) 942 { 943 onGSignalListeners[index] = null; 944 onGSignalListeners = std.algorithm.remove(onGSignalListeners, index); 945 break; 946 } 947 } 948 } 949 } 950 OnGSignalDelegateWrapper[] onGSignalListeners; 951 952 /** 953 * Emitted when a signal from the remote object and interface that @proxy is for, has been received. 954 * 955 * Params: 956 * senderName = The sender of the signal or %NULL if the connection is not a bus connection. 957 * signalName = The name of the signal. 958 * parameters = A #GVariant tuple with parameters for the signal. 959 * 960 * Since: 2.26 961 */ 962 gulong addOnGSignal(void delegate(string, string, Variant, DBusProxy) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 963 { 964 auto wrapper = new OnGSignalDelegateWrapper(dlg); 965 wrapper.handlerId = Signals.connectData( 966 this, 967 "g-signal", 968 cast(GCallback)&callBackGSignal, 969 cast(void*)wrapper, 970 cast(GClosureNotify)&callBackGSignalDestroy, 971 connectFlags); 972 return wrapper.handlerId; 973 } 974 975 extern(C) static void callBackGSignal(GDBusProxy* dbusproxyStruct, char* senderName, char* signalName, GVariant* parameters, OnGSignalDelegateWrapper wrapper) 976 { 977 wrapper.dlg(Str.toString(senderName), Str.toString(signalName), new Variant(parameters), wrapper.outer); 978 } 979 980 extern(C) static void callBackGSignalDestroy(OnGSignalDelegateWrapper wrapper, GClosure* closure) 981 { 982 wrapper.remove(wrapper); 983 } 984 }