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