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