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