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.DBusConnection; 26 27 private import gio.ActionGroupIF; 28 private import gio.AsyncInitableIF; 29 private import gio.AsyncInitableT; 30 private import gio.AsyncResultIF; 31 private import gio.Cancellable; 32 private import gio.Credentials; 33 private import gio.DBusAuthObserver; 34 private import gio.DBusInterfaceInfo; 35 private import gio.DBusMessage; 36 private import gio.IOStream; 37 private import gio.InitableIF; 38 private import gio.InitableT; 39 private import gio.MenuModel; 40 private import gio.UnixFDList; 41 private import glib.ConstructionException; 42 private import glib.ErrorG; 43 private import glib.GException; 44 private import glib.Str; 45 private import glib.Variant; 46 private import glib.VariantType; 47 private import gobject.ObjectG; 48 private import gobject.Signals; 49 public import gtkc.gdktypes; 50 private import gtkc.gio; 51 public import gtkc.giotypes; 52 53 54 /** 55 * The #GDBusConnection type is used for D-Bus connections to remote 56 * peers such as a message buses. It is a low-level API that offers a 57 * lot of flexibility. For instance, it lets you establish a connection 58 * over any transport that can by represented as an #GIOStream. 59 * 60 * This class is rarely used directly in D-Bus clients. If you are writing 61 * a D-Bus client, it is often easier to use the g_bus_own_name(), 62 * g_bus_watch_name() or g_dbus_proxy_new_for_bus() APIs. 63 * 64 * As an exception to the usual GLib rule that a particular object must not 65 * be used by two threads at the same time, #GDBusConnection's methods may be 66 * called from any thread. This is so that g_bus_get() and g_bus_get_sync() 67 * can safely return the same #GDBusConnection when called from any thread. 68 * 69 * Most of the ways to obtain a #GDBusConnection automatically initialize it 70 * (i.e. connect to D-Bus): for instance, g_dbus_connection_new() and 71 * g_bus_get(), and the synchronous versions of those methods, give you an 72 * initialized connection. Language bindings for GIO should use 73 * g_initable_new() or g_async_initable_new_async(), which also initialize the 74 * connection. 75 * 76 * If you construct an uninitialized #GDBusConnection, such as via 77 * g_object_new(), you must initialize it via g_initable_init() or 78 * g_async_initable_init_async() before using its methods or properties. 79 * Calling methods or accessing properties on a #GDBusConnection that has not 80 * completed initialization successfully is considered to be invalid, and leads 81 * to undefined behaviour. In particular, if initialization fails with a 82 * #GError, the only valid thing you can do with that #GDBusConnection is to 83 * free it with g_object_unref(). 84 * 85 * ## An example D-Bus server # {#gdbus-server} 86 * 87 * Here is an example for a D-Bus server: 88 * [gdbus-example-server.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-server.c) 89 * 90 * ## An example for exporting a subtree # {#gdbus-subtree-server} 91 * 92 * Here is an example for exporting a subtree: 93 * [gdbus-example-subtree.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-subtree.c) 94 * 95 * ## An example for file descriptor passing # {#gdbus-unix-fd-client} 96 * 97 * Here is an example for passing UNIX file descriptors: 98 * [gdbus-unix-fd-client.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-unix-fd-client.c) 99 * 100 * ## An example for exporting a GObject # {#gdbus-export} 101 * 102 * Here is an example for exporting a #GObject: 103 * [gdbus-example-export.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-export.c) 104 * 105 * Since: 2.26 106 */ 107 public class DBusConnection : ObjectG, AsyncInitableIF, InitableIF 108 { 109 /** the main Gtk struct */ 110 protected GDBusConnection* gDBusConnection; 111 112 /** Get the main Gtk struct */ 113 public GDBusConnection* getDBusConnectionStruct() 114 { 115 return gDBusConnection; 116 } 117 118 /** the main Gtk struct as a void* */ 119 protected override void* getStruct() 120 { 121 return cast(void*)gDBusConnection; 122 } 123 124 protected override void setStruct(GObject* obj) 125 { 126 gDBusConnection = cast(GDBusConnection*)obj; 127 super.setStruct(obj); 128 } 129 130 /** 131 * Sets our main struct and passes it to the parent class. 132 */ 133 public this (GDBusConnection* gDBusConnection, bool ownedRef = false) 134 { 135 this.gDBusConnection = gDBusConnection; 136 super(cast(GObject*)gDBusConnection, ownedRef); 137 } 138 139 // add the AsyncInitable capabilities 140 mixin AsyncInitableT!(GDBusConnection); 141 142 // add the Initable capabilities 143 mixin InitableT!(GDBusConnection); 144 145 /** 146 * Finishes an operation started with g_dbus_connection_new(). 147 * 148 * Params: 149 * res = A GAsyncResult obtained from the GAsyncReadyCallback 150 * passed to g_dbus_connection_new(). 151 * address = If true finish an address. 152 * 153 * Throws: GException on failure. 154 * Throws: ConstructionException GTK+ fails to create the object. 155 * 156 * Since: 2.26 157 */ 158 public this (AsyncResultIF res, bool address = false) 159 { 160 GError* err = null; 161 GDBusConnection* p; 162 163 if ( address ) 164 { 165 p = g_dbus_connection_new_for_address_finish((res is null) ? null : res.getAsyncResultStruct(), &err); 166 } 167 else 168 { 169 p = g_dbus_connection_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err); 170 } 171 172 if (err !is null) 173 { 174 throw new GException( new ErrorG(err) ); 175 } 176 177 if(p is null) 178 { 179 throw new ConstructionException("null returned by g_dbus_connection_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err)"); 180 } 181 this(p, true); 182 } 183 184 /** 185 */ 186 187 public static GType getType() 188 { 189 return g_dbus_connection_get_type(); 190 } 191 192 /** 193 * Synchronously connects and sets up a D-Bus client connection for 194 * exchanging D-Bus messages with an endpoint specified by @address 195 * which must be in the D-Bus address format. 196 * 197 * This constructor can only be used to initiate client-side 198 * connections - use g_dbus_connection_new_sync() if you need to act 199 * as the server. In particular, @flags cannot contain the 200 * %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER or 201 * %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS flags. 202 * 203 * This is a synchronous failable constructor. See 204 * g_dbus_connection_new_for_address() for the asynchronous version. 205 * 206 * If @observer is not %NULL it may be used to control the 207 * authentication process. 208 * 209 * Params: 210 * address = a D-Bus address 211 * flags = flags describing how to make the connection 212 * observer = a #GDBusAuthObserver or %NULL 213 * cancellable = a #GCancellable or %NULL 214 * 215 * Return: a #GDBusConnection or %NULL if @error is set. Free with 216 * g_object_unref(). 217 * 218 * Since: 2.26 219 * 220 * Throws: GException on failure. 221 * Throws: ConstructionException GTK+ fails to create the object. 222 */ 223 public this(string address, GDBusConnectionFlags flags, DBusAuthObserver observer, Cancellable cancellable) 224 { 225 GError* err = null; 226 227 auto p = g_dbus_connection_new_for_address_sync(Str.toStringz(address), flags, (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 228 229 if(p is null) 230 { 231 throw new ConstructionException("null returned by new_for_address_sync"); 232 } 233 234 if (err !is null) 235 { 236 throw new GException( new ErrorG(err) ); 237 } 238 239 this(cast(GDBusConnection*) p, true); 240 } 241 242 /** 243 * Synchronously sets up a D-Bus connection for exchanging D-Bus messages 244 * with the end represented by @stream. 245 * 246 * If @stream is a #GSocketConnection, then the corresponding #GSocket 247 * will be put into non-blocking mode. 248 * 249 * The D-Bus connection will interact with @stream from a worker thread. 250 * As a result, the caller should not interact with @stream after this 251 * method has been called, except by calling g_object_unref() on it. 252 * 253 * If @observer is not %NULL it may be used to control the 254 * authentication process. 255 * 256 * This is a synchronous failable constructor. See 257 * g_dbus_connection_new() for the asynchronous version. 258 * 259 * Params: 260 * stream = a #GIOStream 261 * guid = the GUID to use if a authenticating as a server or %NULL 262 * flags = flags describing how to make the connection 263 * observer = a #GDBusAuthObserver or %NULL 264 * cancellable = a #GCancellable or %NULL 265 * 266 * Return: a #GDBusConnection or %NULL if @error is set. Free with g_object_unref(). 267 * 268 * Since: 2.26 269 * 270 * Throws: GException on failure. 271 * Throws: ConstructionException GTK+ fails to create the object. 272 */ 273 public this(IOStream stream, string guid, GDBusConnectionFlags flags, DBusAuthObserver observer, Cancellable cancellable) 274 { 275 GError* err = null; 276 277 auto p = g_dbus_connection_new_sync((stream is null) ? null : stream.getIOStreamStruct(), Str.toStringz(guid), flags, (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 278 279 if(p is null) 280 { 281 throw new ConstructionException("null returned by new_sync"); 282 } 283 284 if (err !is null) 285 { 286 throw new GException( new ErrorG(err) ); 287 } 288 289 this(cast(GDBusConnection*) p, true); 290 } 291 292 /** 293 * Asynchronously sets up a D-Bus connection for exchanging D-Bus messages 294 * with the end represented by @stream. 295 * 296 * If @stream is a #GSocketConnection, then the corresponding #GSocket 297 * will be put into non-blocking mode. 298 * 299 * The D-Bus connection will interact with @stream from a worker thread. 300 * As a result, the caller should not interact with @stream after this 301 * method has been called, except by calling g_object_unref() on it. 302 * 303 * If @observer is not %NULL it may be used to control the 304 * authentication process. 305 * 306 * When the operation is finished, @callback will be invoked. You can 307 * then call g_dbus_connection_new_finish() to get the result of the 308 * operation. 309 * 310 * This is a asynchronous failable constructor. See 311 * g_dbus_connection_new_sync() for the synchronous 312 * version. 313 * 314 * Params: 315 * stream = a #GIOStream 316 * guid = the GUID to use if a authenticating as a server or %NULL 317 * flags = flags describing how to make the connection 318 * observer = a #GDBusAuthObserver or %NULL 319 * cancellable = a #GCancellable or %NULL 320 * callback = a #GAsyncReadyCallback to call when the request is satisfied 321 * userData = the data to pass to @callback 322 * 323 * Since: 2.26 324 */ 325 public static void newConnection(IOStream stream, string guid, GDBusConnectionFlags flags, DBusAuthObserver observer, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 326 { 327 g_dbus_connection_new((stream is null) ? null : stream.getIOStreamStruct(), Str.toStringz(guid), flags, (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 328 } 329 330 /** 331 * Asynchronously connects and sets up a D-Bus client connection for 332 * exchanging D-Bus messages with an endpoint specified by @address 333 * which must be in the D-Bus address format. 334 * 335 * This constructor can only be used to initiate client-side 336 * connections - use g_dbus_connection_new() if you need to act as the 337 * server. In particular, @flags cannot contain the 338 * %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER or 339 * %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS flags. 340 * 341 * When the operation is finished, @callback will be invoked. You can 342 * then call g_dbus_connection_new_finish() to get the result of the 343 * operation. 344 * 345 * If @observer is not %NULL it may be used to control the 346 * authentication process. 347 * 348 * This is a asynchronous failable constructor. See 349 * g_dbus_connection_new_for_address_sync() for the synchronous 350 * version. 351 * 352 * Params: 353 * address = a D-Bus address 354 * flags = flags describing how to make the connection 355 * observer = a #GDBusAuthObserver or %NULL 356 * cancellable = a #GCancellable or %NULL 357 * callback = a #GAsyncReadyCallback to call when the request is satisfied 358 * userData = the data to pass to @callback 359 * 360 * Since: 2.26 361 */ 362 public static void newForAddress(string address, GDBusConnectionFlags flags, DBusAuthObserver observer, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 363 { 364 g_dbus_connection_new_for_address(Str.toStringz(address), flags, (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 365 } 366 367 /** 368 * Adds a message filter. Filters are handlers that are run on all 369 * incoming and outgoing messages, prior to standard dispatch. Filters 370 * are run in the order that they were added. The same handler can be 371 * added as a filter more than once, in which case it will be run more 372 * than once. Filters added during a filter callback won't be run on 373 * the message being processed. Filter functions are allowed to modify 374 * and even drop messages. 375 * 376 * Note that filters are run in a dedicated message handling thread so 377 * they can't block and, generally, can't do anything but signal a 378 * worker thread. Also note that filters are rarely needed - use API 379 * such as g_dbus_connection_send_message_with_reply(), 380 * g_dbus_connection_signal_subscribe() or g_dbus_connection_call() instead. 381 * 382 * If a filter consumes an incoming message the message is not 383 * dispatched anywhere else - not even the standard dispatch machinery 384 * (that API such as g_dbus_connection_signal_subscribe() and 385 * g_dbus_connection_send_message_with_reply() relies on) will see the 386 * message. Similary, if a filter consumes an outgoing message, the 387 * message will not be sent to the other peer. 388 * 389 * Params: 390 * filterFunction = a filter function 391 * userData = user data to pass to @filter_function 392 * userDataFreeFunc = function to free @user_data with when filter 393 * is removed or %NULL 394 * 395 * Return: a filter identifier that can be used with 396 * g_dbus_connection_remove_filter() 397 * 398 * Since: 2.26 399 */ 400 public uint addFilter(GDBusMessageFilterFunction filterFunction, void* userData, GDestroyNotify userDataFreeFunc) 401 { 402 return g_dbus_connection_add_filter(gDBusConnection, filterFunction, userData, userDataFreeFunc); 403 } 404 405 /** 406 * Asynchronously invokes the @method_name method on the 407 * @interface_name D-Bus interface on the remote object at 408 * @object_path owned by @bus_name. 409 * 410 * If @connection is closed then the operation will fail with 411 * %G_IO_ERROR_CLOSED. If @cancellable is canceled, the operation will 412 * fail with %G_IO_ERROR_CANCELLED. If @parameters contains a value 413 * not compatible with the D-Bus protocol, the operation fails with 414 * %G_IO_ERROR_INVALID_ARGUMENT. 415 * 416 * If @reply_type is non-%NULL then the reply will be checked for having this type and an 417 * error will be raised if it does not match. Said another way, if you give a @reply_type 418 * then any non-%NULL return value will be of this type. 419 * 420 * If the @parameters #GVariant is floating, it is consumed. This allows 421 * convenient 'inline' use of g_variant_new(), e.g.: 422 * |[<!-- language="C" --> 423 * g_dbus_connection_call (connection, 424 * "org.freedesktop.StringThings", 425 * "/org/freedesktop/StringThings", 426 * "org.freedesktop.StringThings", 427 * "TwoStrings", 428 * g_variant_new ("(ss)", 429 * "Thing One", 430 * "Thing Two"), 431 * NULL, 432 * G_DBUS_CALL_FLAGS_NONE, 433 * -1, 434 * NULL, 435 * (GAsyncReadyCallback) two_strings_done, 436 * NULL); 437 * ]| 438 * 439 * This is an asynchronous method. When the operation is finished, 440 * @callback will be invoked in the 441 * [thread-default main context][g-main-context-push-thread-default] 442 * of the thread you are calling this method from. You can then call 443 * g_dbus_connection_call_finish() to get the result of the operation. 444 * See g_dbus_connection_call_sync() for the synchronous version of this 445 * function. 446 * 447 * If @callback is %NULL then the D-Bus method call message will be sent with 448 * the %G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED flag set. 449 * 450 * Params: 451 * busName = a unique or well-known bus name or %NULL if 452 * @connection is not a message bus connection 453 * objectPath = path of remote object 454 * interfaceName = D-Bus interface to invoke method on 455 * methodName = the name of the method to invoke 456 * parameters = a #GVariant tuple with parameters for the method 457 * or %NULL if not passing parameters 458 * replyType = the expected type of the reply, or %NULL 459 * flags = flags from the #GDBusCallFlags enumeration 460 * timeoutMsec = the timeout in milliseconds, -1 to use the default 461 * timeout or %G_MAXINT for no timeout 462 * cancellable = a #GCancellable or %NULL 463 * callback = a #GAsyncReadyCallback to call when the request 464 * is satisfied or %NULL if you don't care about the result of the 465 * method invocation 466 * userData = the data to pass to @callback 467 * 468 * Since: 2.26 469 */ 470 public void call(string busName, string objectPath, string interfaceName, string methodName, Variant parameters, VariantType replyType, GDBusCallFlags flags, int timeoutMsec, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 471 { 472 g_dbus_connection_call(gDBusConnection, Str.toStringz(busName), Str.toStringz(objectPath), Str.toStringz(interfaceName), Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), (replyType is null) ? null : replyType.getVariantTypeStruct(), flags, timeoutMsec, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 473 } 474 475 /** 476 * Finishes an operation started with g_dbus_connection_call(). 477 * 478 * Params: 479 * res = a #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_connection_call() 480 * 481 * Return: %NULL if @error is set. Otherwise a #GVariant tuple with 482 * return values. Free with g_variant_unref(). 483 * 484 * Since: 2.26 485 * 486 * Throws: GException on failure. 487 */ 488 public Variant callFinish(AsyncResultIF res) 489 { 490 GError* err = null; 491 492 auto p = g_dbus_connection_call_finish(gDBusConnection, (res is null) ? null : res.getAsyncResultStruct(), &err); 493 494 if (err !is null) 495 { 496 throw new GException( new ErrorG(err) ); 497 } 498 499 if(p is null) 500 { 501 return null; 502 } 503 504 return new Variant(cast(GVariant*) p); 505 } 506 507 /** 508 * Synchronously invokes the @method_name method on the 509 * @interface_name D-Bus interface on the remote object at 510 * @object_path owned by @bus_name. 511 * 512 * If @connection is closed then the operation will fail with 513 * %G_IO_ERROR_CLOSED. If @cancellable is canceled, the 514 * operation will fail with %G_IO_ERROR_CANCELLED. If @parameters 515 * contains a value not compatible with the D-Bus protocol, the operation 516 * fails with %G_IO_ERROR_INVALID_ARGUMENT. 517 * 518 * If @reply_type is non-%NULL then the reply will be checked for having 519 * this type and an error will be raised if it does not match. Said 520 * another way, if you give a @reply_type then any non-%NULL return 521 * value will be of this type. 522 * 523 * If the @parameters #GVariant is floating, it is consumed. 524 * This allows convenient 'inline' use of g_variant_new(), e.g.: 525 * |[<!-- language="C" --> 526 * g_dbus_connection_call_sync (connection, 527 * "org.freedesktop.StringThings", 528 * "/org/freedesktop/StringThings", 529 * "org.freedesktop.StringThings", 530 * "TwoStrings", 531 * g_variant_new ("(ss)", 532 * "Thing One", 533 * "Thing Two"), 534 * NULL, 535 * G_DBUS_CALL_FLAGS_NONE, 536 * -1, 537 * NULL, 538 * &error); 539 * ]| 540 * 541 * The calling thread is blocked until a reply is received. See 542 * g_dbus_connection_call() for the asynchronous version of 543 * this method. 544 * 545 * Params: 546 * busName = a unique or well-known bus name or %NULL if 547 * @connection is not a message bus connection 548 * objectPath = path of remote object 549 * interfaceName = D-Bus interface to invoke method on 550 * methodName = the name of the method to invoke 551 * parameters = a #GVariant tuple with parameters for the method 552 * or %NULL if not passing parameters 553 * replyType = the expected type of the reply, or %NULL 554 * flags = flags from the #GDBusCallFlags enumeration 555 * timeoutMsec = the timeout in milliseconds, -1 to use the default 556 * timeout or %G_MAXINT for no timeout 557 * cancellable = a #GCancellable or %NULL 558 * 559 * Return: %NULL if @error is set. Otherwise a #GVariant tuple with 560 * return values. Free with g_variant_unref(). 561 * 562 * Since: 2.26 563 * 564 * Throws: GException on failure. 565 */ 566 public Variant callSync(string busName, string objectPath, string interfaceName, string methodName, Variant parameters, VariantType replyType, GDBusCallFlags flags, int timeoutMsec, Cancellable cancellable) 567 { 568 GError* err = null; 569 570 auto p = g_dbus_connection_call_sync(gDBusConnection, Str.toStringz(busName), Str.toStringz(objectPath), Str.toStringz(interfaceName), Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), (replyType is null) ? null : replyType.getVariantTypeStruct(), flags, timeoutMsec, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 571 572 if (err !is null) 573 { 574 throw new GException( new ErrorG(err) ); 575 } 576 577 if(p is null) 578 { 579 return null; 580 } 581 582 return new Variant(cast(GVariant*) p); 583 } 584 585 /** 586 * Like g_dbus_connection_call() but also takes a #GUnixFDList object. 587 * 588 * This method is only available on UNIX. 589 * 590 * Params: 591 * busName = a unique or well-known bus name or %NULL if 592 * @connection is not a message bus connection 593 * objectPath = path of remote object 594 * interfaceName = D-Bus interface to invoke method on 595 * methodName = the name of the method to invoke 596 * parameters = a #GVariant tuple with parameters for the method 597 * or %NULL if not passing parameters 598 * replyType = the expected type of the reply, or %NULL 599 * flags = flags from the #GDBusCallFlags enumeration 600 * timeoutMsec = the timeout in milliseconds, -1 to use the default 601 * timeout or %G_MAXINT for no timeout 602 * fdList = a #GUnixFDList or %NULL 603 * cancellable = a #GCancellable or %NULL 604 * callback = a #GAsyncReadyCallback to call when the request is 605 * satisfied or %NULL if you don't * care about the result of the 606 * method invocation 607 * userData = The data to pass to @callback. 608 * 609 * Since: 2.30 610 */ 611 public void callWithUnixFdList(string busName, string objectPath, string interfaceName, string methodName, Variant parameters, VariantType replyType, GDBusCallFlags flags, int timeoutMsec, UnixFDList fdList, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 612 { 613 g_dbus_connection_call_with_unix_fd_list(gDBusConnection, Str.toStringz(busName), Str.toStringz(objectPath), Str.toStringz(interfaceName), Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), (replyType is null) ? null : replyType.getVariantTypeStruct(), flags, timeoutMsec, (fdList is null) ? null : fdList.getUnixFDListStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 614 } 615 616 /** 617 * Finishes an operation started with g_dbus_connection_call_with_unix_fd_list(). 618 * 619 * Params: 620 * outFdList = return location for a #GUnixFDList or %NULL 621 * res = a #GAsyncResult obtained from the #GAsyncReadyCallback passed to 622 * g_dbus_connection_call_with_unix_fd_list() 623 * 624 * Return: %NULL if @error is set. Otherwise a #GVariant tuple with 625 * return values. Free with g_variant_unref(). 626 * 627 * Since: 2.30 628 * 629 * Throws: GException on failure. 630 */ 631 public Variant callWithUnixFdListFinish(out UnixFDList outFdList, AsyncResultIF res) 632 { 633 GUnixFDList* outoutFdList = null; 634 GError* err = null; 635 636 auto p = g_dbus_connection_call_with_unix_fd_list_finish(gDBusConnection, &outoutFdList, (res is null) ? null : res.getAsyncResultStruct(), &err); 637 638 if (err !is null) 639 { 640 throw new GException( new ErrorG(err) ); 641 } 642 643 outFdList = ObjectG.getDObject!(UnixFDList)(outoutFdList); 644 645 if(p is null) 646 { 647 return null; 648 } 649 650 return new Variant(cast(GVariant*) p); 651 } 652 653 /** 654 * Like g_dbus_connection_call_sync() but also takes and returns #GUnixFDList objects. 655 * 656 * This method is only available on UNIX. 657 * 658 * Params: 659 * busName = a unique or well-known bus name or %NULL 660 * if @connection is not a message bus connection 661 * objectPath = path of remote object 662 * interfaceName = D-Bus interface to invoke method on 663 * methodName = the name of the method to invoke 664 * parameters = a #GVariant tuple with parameters for 665 * the method or %NULL if not passing parameters 666 * replyType = the expected type of the reply, or %NULL 667 * flags = flags from the #GDBusCallFlags enumeration 668 * timeoutMsec = the timeout in milliseconds, -1 to use the default 669 * timeout or %G_MAXINT for no timeout 670 * fdList = a #GUnixFDList or %NULL 671 * outFdList = return location for a #GUnixFDList or %NULL 672 * cancellable = a #GCancellable or %NULL 673 * 674 * Return: %NULL if @error is set. Otherwise a #GVariant tuple with 675 * return values. Free with g_variant_unref(). 676 * 677 * Since: 2.30 678 * 679 * Throws: GException on failure. 680 */ 681 public Variant callWithUnixFdListSync(string busName, string objectPath, string interfaceName, string methodName, Variant parameters, VariantType replyType, GDBusCallFlags flags, int timeoutMsec, UnixFDList fdList, out UnixFDList outFdList, Cancellable cancellable) 682 { 683 GUnixFDList* outoutFdList = null; 684 GError* err = null; 685 686 auto p = g_dbus_connection_call_with_unix_fd_list_sync(gDBusConnection, Str.toStringz(busName), Str.toStringz(objectPath), Str.toStringz(interfaceName), Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), (replyType is null) ? null : replyType.getVariantTypeStruct(), flags, timeoutMsec, (fdList is null) ? null : fdList.getUnixFDListStruct(), &outoutFdList, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 687 688 if (err !is null) 689 { 690 throw new GException( new ErrorG(err) ); 691 } 692 693 outFdList = ObjectG.getDObject!(UnixFDList)(outoutFdList); 694 695 if(p is null) 696 { 697 return null; 698 } 699 700 return new Variant(cast(GVariant*) p); 701 } 702 703 /** 704 * Closes @connection. Note that this never causes the process to 705 * exit (this might only happen if the other end of a shared message 706 * bus connection disconnects, see #GDBusConnection:exit-on-close). 707 * 708 * Once the connection is closed, operations such as sending a message 709 * will return with the error %G_IO_ERROR_CLOSED. Closing a connection 710 * will not automatically flush the connection so queued messages may 711 * be lost. Use g_dbus_connection_flush() if you need such guarantees. 712 * 713 * If @connection is already closed, this method fails with 714 * %G_IO_ERROR_CLOSED. 715 * 716 * When @connection has been closed, the #GDBusConnection::closed 717 * signal is emitted in the 718 * [thread-default main context][g-main-context-push-thread-default] 719 * of the thread that @connection was constructed in. 720 * 721 * This is an asynchronous method. When the operation is finished, 722 * @callback will be invoked in the 723 * [thread-default main context][g-main-context-push-thread-default] 724 * of the thread you are calling this method from. You can 725 * then call g_dbus_connection_close_finish() to get the result of the 726 * operation. See g_dbus_connection_close_sync() for the synchronous 727 * version. 728 * 729 * Params: 730 * cancellable = a #GCancellable or %NULL 731 * callback = a #GAsyncReadyCallback to call when the request is 732 * satisfied or %NULL if you don't care about the result 733 * userData = The data to pass to @callback 734 * 735 * Since: 2.26 736 */ 737 public void close(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 738 { 739 g_dbus_connection_close(gDBusConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 740 } 741 742 /** 743 * Finishes an operation started with g_dbus_connection_close(). 744 * 745 * Params: 746 * res = a #GAsyncResult obtained from the #GAsyncReadyCallback passed 747 * to g_dbus_connection_close() 748 * 749 * Return: %TRUE if the operation succeeded, %FALSE if @error is set 750 * 751 * Since: 2.26 752 * 753 * Throws: GException on failure. 754 */ 755 public bool closeFinish(AsyncResultIF res) 756 { 757 GError* err = null; 758 759 auto p = g_dbus_connection_close_finish(gDBusConnection, (res is null) ? null : res.getAsyncResultStruct(), &err) != 0; 760 761 if (err !is null) 762 { 763 throw new GException( new ErrorG(err) ); 764 } 765 766 return p; 767 } 768 769 /** 770 * Synchronously closees @connection. The calling thread is blocked 771 * until this is done. See g_dbus_connection_close() for the 772 * asynchronous version of this method and more details about what it 773 * does. 774 * 775 * Params: 776 * cancellable = a #GCancellable or %NULL 777 * 778 * Return: %TRUE if the operation succeeded, %FALSE if @error is set 779 * 780 * Since: 2.26 781 * 782 * Throws: GException on failure. 783 */ 784 public bool closeSync(Cancellable cancellable) 785 { 786 GError* err = null; 787 788 auto p = g_dbus_connection_close_sync(gDBusConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 789 790 if (err !is null) 791 { 792 throw new GException( new ErrorG(err) ); 793 } 794 795 return p; 796 } 797 798 /** 799 * Emits a signal. 800 * 801 * If the parameters GVariant is floating, it is consumed. 802 * 803 * This can only fail if @parameters is not compatible with the D-Bus protocol. 804 * 805 * Params: 806 * destinationBusName = the unique bus name for the destination 807 * for the signal or %NULL to emit to all listeners 808 * objectPath = path of remote object 809 * interfaceName = D-Bus interface to emit a signal on 810 * signalName = the name of the signal to emit 811 * parameters = a #GVariant tuple with parameters for the signal 812 * or %NULL if not passing parameters 813 * 814 * Return: %TRUE unless @error is set 815 * 816 * Since: 2.26 817 * 818 * Throws: GException on failure. 819 */ 820 public bool emitSignal(string destinationBusName, string objectPath, string interfaceName, string signalName, Variant parameters) 821 { 822 GError* err = null; 823 824 auto p = g_dbus_connection_emit_signal(gDBusConnection, Str.toStringz(destinationBusName), Str.toStringz(objectPath), Str.toStringz(interfaceName), Str.toStringz(signalName), (parameters is null) ? null : parameters.getVariantStruct(), &err) != 0; 825 826 if (err !is null) 827 { 828 throw new GException( new ErrorG(err) ); 829 } 830 831 return p; 832 } 833 834 /** 835 * Exports @action_group on @connection at @object_path. 836 * 837 * The implemented D-Bus API should be considered private. It is 838 * subject to change in the future. 839 * 840 * A given object path can only have one action group exported on it. 841 * If this constraint is violated, the export will fail and 0 will be 842 * returned (with @error set accordingly). 843 * 844 * You can unexport the action group using 845 * g_dbus_connection_unexport_action_group() with the return value of 846 * this function. 847 * 848 * The thread default main context is taken at the time of this call. 849 * All incoming action activations and state change requests are 850 * reported from this context. Any changes on the action group that 851 * cause it to emit signals must also come from this same context. 852 * Since incoming action activations and state change requests are 853 * rather likely to cause changes on the action group, this effectively 854 * limits a given action group to being exported from only one main 855 * context. 856 * 857 * Params: 858 * objectPath = a D-Bus object path 859 * actionGroup = a #GActionGroup 860 * 861 * Return: the ID of the export (never zero), or 0 in case of failure 862 * 863 * Since: 2.32 864 * 865 * Throws: GException on failure. 866 */ 867 public uint exportActionGroup(string objectPath, ActionGroupIF actionGroup) 868 { 869 GError* err = null; 870 871 auto p = g_dbus_connection_export_action_group(gDBusConnection, Str.toStringz(objectPath), (actionGroup is null) ? null : actionGroup.getActionGroupStruct(), &err); 872 873 if (err !is null) 874 { 875 throw new GException( new ErrorG(err) ); 876 } 877 878 return p; 879 } 880 881 /** 882 * Exports @menu on @connection at @object_path. 883 * 884 * The implemented D-Bus API should be considered private. 885 * It is subject to change in the future. 886 * 887 * An object path can only have one menu model exported on it. If this 888 * constraint is violated, the export will fail and 0 will be 889 * returned (with @error set accordingly). 890 * 891 * You can unexport the menu model using 892 * g_dbus_connection_unexport_menu_model() with the return value of 893 * this function. 894 * 895 * Params: 896 * objectPath = a D-Bus object path 897 * menu = a #GMenuModel 898 * 899 * Return: the ID of the export (never zero), or 0 in case of failure 900 * 901 * Since: 2.32 902 * 903 * Throws: GException on failure. 904 */ 905 public uint exportMenuModel(string objectPath, MenuModel menu) 906 { 907 GError* err = null; 908 909 auto p = g_dbus_connection_export_menu_model(gDBusConnection, Str.toStringz(objectPath), (menu is null) ? null : menu.getMenuModelStruct(), &err); 910 911 if (err !is null) 912 { 913 throw new GException( new ErrorG(err) ); 914 } 915 916 return p; 917 } 918 919 /** 920 * Asynchronously flushes @connection, that is, writes all queued 921 * outgoing message to the transport and then flushes the transport 922 * (using g_output_stream_flush_async()). This is useful in programs 923 * that wants to emit a D-Bus signal and then exit immediately. Without 924 * flushing the connection, there is no guaranteed that the message has 925 * been sent to the networking buffers in the OS kernel. 926 * 927 * This is an asynchronous method. When the operation is finished, 928 * @callback will be invoked in the 929 * [thread-default main context][g-main-context-push-thread-default] 930 * of the thread you are calling this method from. You can 931 * then call g_dbus_connection_flush_finish() to get the result of the 932 * operation. See g_dbus_connection_flush_sync() for the synchronous 933 * version. 934 * 935 * Params: 936 * cancellable = a #GCancellable or %NULL 937 * callback = a #GAsyncReadyCallback to call when the 938 * request is satisfied or %NULL if you don't care about the result 939 * userData = The data to pass to @callback 940 * 941 * Since: 2.26 942 */ 943 public void flush(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 944 { 945 g_dbus_connection_flush(gDBusConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 946 } 947 948 /** 949 * Finishes an operation started with g_dbus_connection_flush(). 950 * 951 * Params: 952 * res = a #GAsyncResult obtained from the #GAsyncReadyCallback passed 953 * to g_dbus_connection_flush() 954 * 955 * Return: %TRUE if the operation succeeded, %FALSE if @error is set 956 * 957 * Since: 2.26 958 * 959 * Throws: GException on failure. 960 */ 961 public bool flushFinish(AsyncResultIF res) 962 { 963 GError* err = null; 964 965 auto p = g_dbus_connection_flush_finish(gDBusConnection, (res is null) ? null : res.getAsyncResultStruct(), &err) != 0; 966 967 if (err !is null) 968 { 969 throw new GException( new ErrorG(err) ); 970 } 971 972 return p; 973 } 974 975 /** 976 * Synchronously flushes @connection. The calling thread is blocked 977 * until this is done. See g_dbus_connection_flush() for the 978 * asynchronous version of this method and more details about what it 979 * does. 980 * 981 * Params: 982 * cancellable = a #GCancellable or %NULL 983 * 984 * Return: %TRUE if the operation succeeded, %FALSE if @error is set 985 * 986 * Since: 2.26 987 * 988 * Throws: GException on failure. 989 */ 990 public bool flushSync(Cancellable cancellable) 991 { 992 GError* err = null; 993 994 auto p = g_dbus_connection_flush_sync(gDBusConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 995 996 if (err !is null) 997 { 998 throw new GException( new ErrorG(err) ); 999 } 1000 1001 return p; 1002 } 1003 1004 /** 1005 * Gets the capabilities negotiated with the remote peer 1006 * 1007 * Return: zero or more flags from the #GDBusCapabilityFlags enumeration 1008 * 1009 * Since: 2.26 1010 */ 1011 public GDBusCapabilityFlags getCapabilities() 1012 { 1013 return g_dbus_connection_get_capabilities(gDBusConnection); 1014 } 1015 1016 /** 1017 * Gets whether the process is terminated when @connection is 1018 * closed by the remote peer. See 1019 * #GDBusConnection:exit-on-close for more details. 1020 * 1021 * Return: whether the process is terminated when @connection is 1022 * closed by the remote peer 1023 * 1024 * Since: 2.26 1025 */ 1026 public bool getExitOnClose() 1027 { 1028 return g_dbus_connection_get_exit_on_close(gDBusConnection) != 0; 1029 } 1030 1031 /** 1032 * The GUID of the peer performing the role of server when 1033 * authenticating. See #GDBusConnection:guid for more details. 1034 * 1035 * Return: The GUID. Do not free this string, it is owned by 1036 * @connection. 1037 * 1038 * Since: 2.26 1039 */ 1040 public string getGuid() 1041 { 1042 return Str.toString(g_dbus_connection_get_guid(gDBusConnection)); 1043 } 1044 1045 /** 1046 * Retrieves the last serial number assigned to a #GDBusMessage on 1047 * the current thread. This includes messages sent via both low-level 1048 * API such as g_dbus_connection_send_message() as well as 1049 * high-level API such as g_dbus_connection_emit_signal(), 1050 * g_dbus_connection_call() or g_dbus_proxy_call(). 1051 * 1052 * Return: the last used serial or zero when no message has been sent 1053 * within the current thread 1054 * 1055 * Since: 2.34 1056 */ 1057 public uint getLastSerial() 1058 { 1059 return g_dbus_connection_get_last_serial(gDBusConnection); 1060 } 1061 1062 /** 1063 * Gets the credentials of the authenticated peer. This will always 1064 * return %NULL unless @connection acted as a server 1065 * (e.g. %G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_SERVER was passed) 1066 * when set up and the client passed credentials as part of the 1067 * authentication process. 1068 * 1069 * In a message bus setup, the message bus is always the server and 1070 * each application is a client. So this method will always return 1071 * %NULL for message bus clients. 1072 * 1073 * Return: a #GCredentials or %NULL if not available. 1074 * Do not free this object, it is owned by @connection. 1075 * 1076 * Since: 2.26 1077 */ 1078 public Credentials getPeerCredentials() 1079 { 1080 auto p = g_dbus_connection_get_peer_credentials(gDBusConnection); 1081 1082 if(p is null) 1083 { 1084 return null; 1085 } 1086 1087 return ObjectG.getDObject!(Credentials)(cast(GCredentials*) p); 1088 } 1089 1090 /** 1091 * Gets the underlying stream used for IO. 1092 * 1093 * While the #GDBusConnection is active, it will interact with this 1094 * stream from a worker thread, so it is not safe to interact with 1095 * the stream directly. 1096 * 1097 * Return: the stream used for IO 1098 * 1099 * Since: 2.26 1100 */ 1101 public IOStream getStream() 1102 { 1103 auto p = g_dbus_connection_get_stream(gDBusConnection); 1104 1105 if(p is null) 1106 { 1107 return null; 1108 } 1109 1110 return ObjectG.getDObject!(IOStream)(cast(GIOStream*) p); 1111 } 1112 1113 /** 1114 * Gets the unique name of @connection as assigned by the message 1115 * bus. This can also be used to figure out if @connection is a 1116 * message bus connection. 1117 * 1118 * Return: the unique name or %NULL if @connection is not a message 1119 * bus connection. Do not free this string, it is owned by 1120 * @connection. 1121 * 1122 * Since: 2.26 1123 */ 1124 public string getUniqueName() 1125 { 1126 return Str.toString(g_dbus_connection_get_unique_name(gDBusConnection)); 1127 } 1128 1129 /** 1130 * Gets whether @connection is closed. 1131 * 1132 * Return: %TRUE if the connection is closed, %FALSE otherwise 1133 * 1134 * Since: 2.26 1135 */ 1136 public bool isClosed() 1137 { 1138 return g_dbus_connection_is_closed(gDBusConnection) != 0; 1139 } 1140 1141 /** 1142 * Registers callbacks for exported objects at @object_path with the 1143 * D-Bus interface that is described in @interface_info. 1144 * 1145 * Calls to functions in @vtable (and @user_data_free_func) will happen 1146 * in the 1147 * [thread-default main context][g-main-context-push-thread-default] 1148 * of the thread you are calling this method from. 1149 * 1150 * Note that all #GVariant values passed to functions in @vtable will match 1151 * the signature given in @interface_info - if a remote caller passes 1152 * incorrect values, the `org.freedesktop.DBus.Error.InvalidArgs` 1153 * is returned to the remote caller. 1154 * 1155 * Additionally, if the remote caller attempts to invoke methods or 1156 * access properties not mentioned in @interface_info the 1157 * `org.freedesktop.DBus.Error.UnknownMethod` resp. 1158 * `org.freedesktop.DBus.Error.InvalidArgs` errors 1159 * are returned to the caller. 1160 * 1161 * It is considered a programming error if the 1162 * #GDBusInterfaceGetPropertyFunc function in @vtable returns a 1163 * #GVariant of incorrect type. 1164 * 1165 * If an existing callback is already registered at @object_path and 1166 * @interface_name, then @error is set to #G_IO_ERROR_EXISTS. 1167 * 1168 * GDBus automatically implements the standard D-Bus interfaces 1169 * org.freedesktop.DBus.Properties, org.freedesktop.DBus.Introspectable 1170 * and org.freedesktop.Peer, so you don't have to implement those for the 1171 * objects you export. You can implement org.freedesktop.DBus.Properties 1172 * yourself, e.g. to handle getting and setting of properties asynchronously. 1173 * 1174 * Note that the reference count on @interface_info will be 1175 * incremented by 1 (unless allocated statically, e.g. if the 1176 * reference count is -1, see g_dbus_interface_info_ref()) for as long 1177 * as the object is exported. Also note that @vtable will be copied. 1178 * 1179 * See this [server][gdbus-server] for an example of how to use this method. 1180 * 1181 * Params: 1182 * objectPath = the object path to register at 1183 * interfaceInfo = introspection data for the interface 1184 * vtable = a #GDBusInterfaceVTable to call into or %NULL 1185 * userData = data to pass to functions in @vtable 1186 * userDataFreeFunc = function to call when the object path is unregistered 1187 * 1188 * Return: 0 if @error is set, otherwise a registration id (never 0) 1189 * that can be used with g_dbus_connection_unregister_object() 1190 * 1191 * Since: 2.26 1192 * 1193 * Throws: GException on failure. 1194 */ 1195 public uint registerObject(string objectPath, DBusInterfaceInfo interfaceInfo, GDBusInterfaceVTable* vtable, void* userData, GDestroyNotify userDataFreeFunc) 1196 { 1197 GError* err = null; 1198 1199 auto p = g_dbus_connection_register_object(gDBusConnection, Str.toStringz(objectPath), (interfaceInfo is null) ? null : interfaceInfo.getDBusInterfaceInfoStruct(), vtable, userData, userDataFreeFunc, &err); 1200 1201 if (err !is null) 1202 { 1203 throw new GException( new ErrorG(err) ); 1204 } 1205 1206 return p; 1207 } 1208 1209 /** 1210 * Registers a whole subtree of dynamic objects. 1211 * 1212 * The @enumerate and @introspection functions in @vtable are used to 1213 * convey, to remote callers, what nodes exist in the subtree rooted 1214 * by @object_path. 1215 * 1216 * When handling remote calls into any node in the subtree, first the 1217 * @enumerate function is used to check if the node exists. If the node exists 1218 * or the #G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES flag is set 1219 * the @introspection function is used to check if the node supports the 1220 * requested method. If so, the @dispatch function is used to determine 1221 * where to dispatch the call. The collected #GDBusInterfaceVTable and 1222 * #gpointer will be used to call into the interface vtable for processing 1223 * the request. 1224 * 1225 * All calls into user-provided code will be invoked in the 1226 * [thread-default main context][g-main-context-push-thread-default] 1227 * of the thread you are calling this method from. 1228 * 1229 * If an existing subtree is already registered at @object_path or 1230 * then @error is set to #G_IO_ERROR_EXISTS. 1231 * 1232 * Note that it is valid to register regular objects (using 1233 * g_dbus_connection_register_object()) in a subtree registered with 1234 * g_dbus_connection_register_subtree() - if so, the subtree handler 1235 * is tried as the last resort. One way to think about a subtree 1236 * handler is to consider it a fallback handler for object paths not 1237 * registered via g_dbus_connection_register_object() or other bindings. 1238 * 1239 * Note that @vtable will be copied so you cannot change it after 1240 * registration. 1241 * 1242 * See this [server][gdbus-subtree-server] for an example of how to use 1243 * this method. 1244 * 1245 * Params: 1246 * objectPath = the object path to register the subtree at 1247 * vtable = a #GDBusSubtreeVTable to enumerate, introspect and 1248 * dispatch nodes in the subtree 1249 * flags = flags used to fine tune the behavior of the subtree 1250 * userData = data to pass to functions in @vtable 1251 * userDataFreeFunc = function to call when the subtree is unregistered 1252 * 1253 * Return: 0 if @error is set, otherwise a subtree registration id (never 0) 1254 * that can be used with g_dbus_connection_unregister_subtree() . 1255 * 1256 * Since: 2.26 1257 * 1258 * Throws: GException on failure. 1259 */ 1260 public uint registerSubtree(string objectPath, GDBusSubtreeVTable* vtable, GDBusSubtreeFlags flags, void* userData, GDestroyNotify userDataFreeFunc) 1261 { 1262 GError* err = null; 1263 1264 auto p = g_dbus_connection_register_subtree(gDBusConnection, Str.toStringz(objectPath), vtable, flags, userData, userDataFreeFunc, &err); 1265 1266 if (err !is null) 1267 { 1268 throw new GException( new ErrorG(err) ); 1269 } 1270 1271 return p; 1272 } 1273 1274 /** 1275 * Removes a filter. 1276 * 1277 * Params: 1278 * filterId = an identifier obtained from g_dbus_connection_add_filter() 1279 * 1280 * Since: 2.26 1281 */ 1282 public void removeFilter(uint filterId) 1283 { 1284 g_dbus_connection_remove_filter(gDBusConnection, filterId); 1285 } 1286 1287 /** 1288 * Asynchronously sends @message to the peer represented by @connection. 1289 * 1290 * Unless @flags contain the 1291 * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag, the serial number 1292 * will be assigned by @connection and set on @message via 1293 * g_dbus_message_set_serial(). If @out_serial is not %NULL, then the 1294 * serial number used will be written to this location prior to 1295 * submitting the message to the underlying transport. 1296 * 1297 * If @connection is closed then the operation will fail with 1298 * %G_IO_ERROR_CLOSED. If @message is not well-formed, 1299 * the operation fails with %G_IO_ERROR_INVALID_ARGUMENT. 1300 * 1301 * See this [server][gdbus-server] and [client][gdbus-unix-fd-client] 1302 * for an example of how to use this low-level API to send and receive 1303 * UNIX file descriptors. 1304 * 1305 * Note that @message must be unlocked, unless @flags contain the 1306 * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag. 1307 * 1308 * Params: 1309 * message = a #GDBusMessage 1310 * flags = flags affecting how the message is sent 1311 * outSerial = return location for serial number assigned 1312 * to @message when sending it or %NULL 1313 * 1314 * Return: %TRUE if the message was well-formed and queued for 1315 * transmission, %FALSE if @error is set 1316 * 1317 * Since: 2.26 1318 * 1319 * Throws: GException on failure. 1320 */ 1321 public bool sendMessage(DBusMessage message, GDBusSendMessageFlags flags, out uint outSerial) 1322 { 1323 GError* err = null; 1324 1325 auto p = g_dbus_connection_send_message(gDBusConnection, (message is null) ? null : message.getDBusMessageStruct(), flags, &outSerial, &err) != 0; 1326 1327 if (err !is null) 1328 { 1329 throw new GException( new ErrorG(err) ); 1330 } 1331 1332 return p; 1333 } 1334 1335 /** 1336 * Asynchronously sends @message to the peer represented by @connection. 1337 * 1338 * Unless @flags contain the 1339 * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag, the serial number 1340 * will be assigned by @connection and set on @message via 1341 * g_dbus_message_set_serial(). If @out_serial is not %NULL, then the 1342 * serial number used will be written to this location prior to 1343 * submitting the message to the underlying transport. 1344 * 1345 * If @connection is closed then the operation will fail with 1346 * %G_IO_ERROR_CLOSED. If @cancellable is canceled, the operation will 1347 * fail with %G_IO_ERROR_CANCELLED. If @message is not well-formed, 1348 * the operation fails with %G_IO_ERROR_INVALID_ARGUMENT. 1349 * 1350 * This is an asynchronous method. When the operation is finished, @callback 1351 * will be invoked in the 1352 * [thread-default main context][g-main-context-push-thread-default] 1353 * of the thread you are calling this method from. You can then call 1354 * g_dbus_connection_send_message_with_reply_finish() to get the result of the operation. 1355 * See g_dbus_connection_send_message_with_reply_sync() for the synchronous version. 1356 * 1357 * Note that @message must be unlocked, unless @flags contain the 1358 * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag. 1359 * 1360 * See this [server][gdbus-server] and [client][gdbus-unix-fd-client] 1361 * for an example of how to use this low-level API to send and receive 1362 * UNIX file descriptors. 1363 * 1364 * Params: 1365 * message = a #GDBusMessage 1366 * flags = flags affecting how the message is sent 1367 * timeoutMsec = the timeout in milliseconds, -1 to use the default 1368 * timeout or %G_MAXINT for no timeout 1369 * outSerial = return location for serial number assigned 1370 * to @message when sending it or %NULL 1371 * cancellable = a #GCancellable or %NULL 1372 * callback = a #GAsyncReadyCallback to call when the request 1373 * is satisfied or %NULL if you don't care about the result 1374 * userData = The data to pass to @callback 1375 * 1376 * Since: 2.26 1377 */ 1378 public void sendMessageWithReply(DBusMessage message, GDBusSendMessageFlags flags, int timeoutMsec, out uint outSerial, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1379 { 1380 g_dbus_connection_send_message_with_reply(gDBusConnection, (message is null) ? null : message.getDBusMessageStruct(), flags, timeoutMsec, &outSerial, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1381 } 1382 1383 /** 1384 * Finishes an operation started with g_dbus_connection_send_message_with_reply(). 1385 * 1386 * Note that @error is only set if a local in-process error 1387 * occurred. That is to say that the returned #GDBusMessage object may 1388 * be of type %G_DBUS_MESSAGE_TYPE_ERROR. Use 1389 * g_dbus_message_to_gerror() to transcode this to a #GError. 1390 * 1391 * See this [server][gdbus-server] and [client][gdbus-unix-fd-client] 1392 * for an example of how to use this low-level API to send and receive 1393 * UNIX file descriptors. 1394 * 1395 * Params: 1396 * res = a #GAsyncResult obtained from the #GAsyncReadyCallback passed to 1397 * g_dbus_connection_send_message_with_reply() 1398 * 1399 * Return: a locked #GDBusMessage or %NULL if @error is set 1400 * 1401 * Since: 2.26 1402 * 1403 * Throws: GException on failure. 1404 */ 1405 public DBusMessage sendMessageWithReplyFinish(AsyncResultIF res) 1406 { 1407 GError* err = null; 1408 1409 auto p = g_dbus_connection_send_message_with_reply_finish(gDBusConnection, (res is null) ? null : res.getAsyncResultStruct(), &err); 1410 1411 if (err !is null) 1412 { 1413 throw new GException( new ErrorG(err) ); 1414 } 1415 1416 if(p is null) 1417 { 1418 return null; 1419 } 1420 1421 return ObjectG.getDObject!(DBusMessage)(cast(GDBusMessage*) p, true); 1422 } 1423 1424 /** 1425 * Synchronously sends @message to the peer represented by @connection 1426 * and blocks the calling thread until a reply is received or the 1427 * timeout is reached. See g_dbus_connection_send_message_with_reply() 1428 * for the asynchronous version of this method. 1429 * 1430 * Unless @flags contain the 1431 * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag, the serial number 1432 * will be assigned by @connection and set on @message via 1433 * g_dbus_message_set_serial(). If @out_serial is not %NULL, then the 1434 * serial number used will be written to this location prior to 1435 * submitting the message to the underlying transport. 1436 * 1437 * If @connection is closed then the operation will fail with 1438 * %G_IO_ERROR_CLOSED. If @cancellable is canceled, the operation will 1439 * fail with %G_IO_ERROR_CANCELLED. If @message is not well-formed, 1440 * the operation fails with %G_IO_ERROR_INVALID_ARGUMENT. 1441 * 1442 * Note that @error is only set if a local in-process error 1443 * occurred. That is to say that the returned #GDBusMessage object may 1444 * be of type %G_DBUS_MESSAGE_TYPE_ERROR. Use 1445 * g_dbus_message_to_gerror() to transcode this to a #GError. 1446 * 1447 * See this [server][gdbus-server] and [client][gdbus-unix-fd-client] 1448 * for an example of how to use this low-level API to send and receive 1449 * UNIX file descriptors. 1450 * 1451 * Note that @message must be unlocked, unless @flags contain the 1452 * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag. 1453 * 1454 * Params: 1455 * message = a #GDBusMessage 1456 * flags = flags affecting how the message is sent. 1457 * timeoutMsec = the timeout in milliseconds, -1 to use the default 1458 * timeout or %G_MAXINT for no timeout 1459 * outSerial = return location for serial number 1460 * assigned to @message when sending it or %NULL 1461 * cancellable = a #GCancellable or %NULL 1462 * 1463 * Return: a locked #GDBusMessage that is the reply 1464 * to @message or %NULL if @error is set 1465 * 1466 * Since: 2.26 1467 * 1468 * Throws: GException on failure. 1469 */ 1470 public DBusMessage sendMessageWithReplySync(DBusMessage message, GDBusSendMessageFlags flags, int timeoutMsec, out uint outSerial, Cancellable cancellable) 1471 { 1472 GError* err = null; 1473 1474 auto p = g_dbus_connection_send_message_with_reply_sync(gDBusConnection, (message is null) ? null : message.getDBusMessageStruct(), flags, timeoutMsec, &outSerial, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1475 1476 if (err !is null) 1477 { 1478 throw new GException( new ErrorG(err) ); 1479 } 1480 1481 if(p is null) 1482 { 1483 return null; 1484 } 1485 1486 return ObjectG.getDObject!(DBusMessage)(cast(GDBusMessage*) p, true); 1487 } 1488 1489 /** 1490 * Sets whether the process should be terminated when @connection is 1491 * closed by the remote peer. See #GDBusConnection:exit-on-close for 1492 * more details. 1493 * 1494 * Note that this function should be used with care. Most modern UNIX 1495 * desktops tie the notion of a user session the session bus, and expect 1496 * all of a users applications to quit when their bus connection goes away. 1497 * If you are setting @exit_on_close to %FALSE for the shared session 1498 * bus connection, you should make sure that your application exits 1499 * when the user session ends. 1500 * 1501 * Params: 1502 * exitOnClose = whether the process should be terminated 1503 * when @connection is closed by the remote peer 1504 * 1505 * Since: 2.26 1506 */ 1507 public void setExitOnClose(bool exitOnClose) 1508 { 1509 g_dbus_connection_set_exit_on_close(gDBusConnection, exitOnClose); 1510 } 1511 1512 /** 1513 * Subscribes to signals on @connection and invokes @callback with a whenever 1514 * the signal is received. Note that @callback will be invoked in the 1515 * [thread-default main context][g-main-context-push-thread-default] 1516 * of the thread you are calling this method from. 1517 * 1518 * If @connection is not a message bus connection, @sender must be 1519 * %NULL. 1520 * 1521 * If @sender is a well-known name note that @callback is invoked with 1522 * the unique name for the owner of @sender, not the well-known name 1523 * as one would expect. This is because the message bus rewrites the 1524 * name. As such, to avoid certain race conditions, users should be 1525 * tracking the name owner of the well-known name and use that when 1526 * processing the received signal. 1527 * 1528 * If one of %G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE or 1529 * %G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH are given, @arg0 is 1530 * interpreted as part of a namespace or path. The first argument 1531 * of a signal is matched against that part as specified by D-Bus. 1532 * 1533 * Params: 1534 * sender = sender name to match on (unique or well-known name) 1535 * or %NULL to listen from all senders 1536 * interfaceName = D-Bus interface name to match on or %NULL to 1537 * match on all interfaces 1538 * member = D-Bus signal name to match on or %NULL to match on 1539 * all signals 1540 * objectPath = object path to match on or %NULL to match on 1541 * all object paths 1542 * arg0 = contents of first string argument to match on or %NULL 1543 * to match on all kinds of arguments 1544 * flags = flags describing how to subscribe to the signal (currently unused) 1545 * callback = callback to invoke when there is a signal matching the requested data 1546 * userData = user data to pass to @callback 1547 * userDataFreeFunc = function to free @user_data with when 1548 * subscription is removed or %NULL 1549 * 1550 * Return: a subscription identifier that can be used with g_dbus_connection_signal_unsubscribe() 1551 * 1552 * Since: 2.26 1553 */ 1554 public uint signalSubscribe(string sender, string interfaceName, string member, string objectPath, string arg0, GDBusSignalFlags flags, GDBusSignalCallback callback, void* userData, GDestroyNotify userDataFreeFunc) 1555 { 1556 return g_dbus_connection_signal_subscribe(gDBusConnection, Str.toStringz(sender), Str.toStringz(interfaceName), Str.toStringz(member), Str.toStringz(objectPath), Str.toStringz(arg0), flags, callback, userData, userDataFreeFunc); 1557 } 1558 1559 /** 1560 * Unsubscribes from signals. 1561 * 1562 * Params: 1563 * subscriptionId = a subscription id obtained from 1564 * g_dbus_connection_signal_subscribe() 1565 * 1566 * Since: 2.26 1567 */ 1568 public void signalUnsubscribe(uint subscriptionId) 1569 { 1570 g_dbus_connection_signal_unsubscribe(gDBusConnection, subscriptionId); 1571 } 1572 1573 /** 1574 * If @connection was created with 1575 * %G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING, this method 1576 * starts processing messages. Does nothing on if @connection wasn't 1577 * created with this flag or if the method has already been called. 1578 * 1579 * Since: 2.26 1580 */ 1581 public void startMessageProcessing() 1582 { 1583 g_dbus_connection_start_message_processing(gDBusConnection); 1584 } 1585 1586 /** 1587 * Reverses the effect of a previous call to 1588 * g_dbus_connection_export_action_group(). 1589 * 1590 * It is an error to call this function with an ID that wasn't returned 1591 * from g_dbus_connection_export_action_group() or to call it with the 1592 * same ID more than once. 1593 * 1594 * Params: 1595 * exportId = the ID from g_dbus_connection_export_action_group() 1596 * 1597 * Since: 2.32 1598 */ 1599 public void unexportActionGroup(uint exportId) 1600 { 1601 g_dbus_connection_unexport_action_group(gDBusConnection, exportId); 1602 } 1603 1604 /** 1605 * Reverses the effect of a previous call to 1606 * g_dbus_connection_export_menu_model(). 1607 * 1608 * It is an error to call this function with an ID that wasn't returned 1609 * from g_dbus_connection_export_menu_model() or to call it with the 1610 * same ID more than once. 1611 * 1612 * Params: 1613 * exportId = the ID from g_dbus_connection_export_menu_model() 1614 * 1615 * Since: 2.32 1616 */ 1617 public void unexportMenuModel(uint exportId) 1618 { 1619 g_dbus_connection_unexport_menu_model(gDBusConnection, exportId); 1620 } 1621 1622 /** 1623 * Unregisters an object. 1624 * 1625 * Params: 1626 * registrationId = a registration id obtained from 1627 * g_dbus_connection_register_object() 1628 * 1629 * Return: %TRUE if the object was unregistered, %FALSE otherwise 1630 * 1631 * Since: 2.26 1632 */ 1633 public bool unregisterObject(uint registrationId) 1634 { 1635 return g_dbus_connection_unregister_object(gDBusConnection, registrationId) != 0; 1636 } 1637 1638 /** 1639 * Unregisters a subtree. 1640 * 1641 * Params: 1642 * registrationId = a subtree registration id obtained from 1643 * g_dbus_connection_register_subtree() 1644 * 1645 * Return: %TRUE if the subtree was unregistered, %FALSE otherwise 1646 * 1647 * Since: 2.26 1648 */ 1649 public bool unregisterSubtree(uint registrationId) 1650 { 1651 return g_dbus_connection_unregister_subtree(gDBusConnection, registrationId) != 0; 1652 } 1653 1654 int[string] connectedSignals; 1655 1656 void delegate(bool, ErrorG, DBusConnection)[] onClosedListeners; 1657 /** 1658 * Emitted when the connection is closed. 1659 * 1660 * The cause of this event can be 1661 * 1662 * - If g_dbus_connection_close() is called. In this case 1663 * @remote_peer_vanished is set to %FALSE and @error is %NULL. 1664 * 1665 * - If the remote peer closes the connection. In this case 1666 * @remote_peer_vanished is set to %TRUE and @error is set. 1667 * 1668 * - If the remote peer sends invalid or malformed data. In this 1669 * case @remote_peer_vanished is set to %FALSE and @error is set. 1670 * 1671 * Upon receiving this signal, you should give up your reference to 1672 * @connection. You are guaranteed that this signal is emitted only 1673 * once. 1674 * 1675 * Params: 1676 * remotePeerVanished = %TRUE if @connection is closed because the 1677 * remote peer closed its end of the connection 1678 * error = a #GError with more details about the event or %NULL 1679 * 1680 * Since: 2.26 1681 */ 1682 void addOnClosed(void delegate(bool, ErrorG, DBusConnection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1683 { 1684 if ( "closed" !in connectedSignals ) 1685 { 1686 Signals.connectData( 1687 this, 1688 "closed", 1689 cast(GCallback)&callBackClosed, 1690 cast(void*)this, 1691 null, 1692 connectFlags); 1693 connectedSignals["closed"] = 1; 1694 } 1695 onClosedListeners ~= dlg; 1696 } 1697 extern(C) static void callBackClosed(GDBusConnection* dbusconnectionStruct, bool remotePeerVanished, GError* error, DBusConnection _dbusconnection) 1698 { 1699 foreach ( void delegate(bool, ErrorG, DBusConnection) dlg; _dbusconnection.onClosedListeners ) 1700 { 1701 dlg(remotePeerVanished, new ErrorG(error), _dbusconnection); 1702 } 1703 } 1704 1705 /** 1706 * Asynchronously connects to the message bus specified by @bus_type. 1707 * 1708 * When the operation is finished, @callback will be invoked. You can 1709 * then call g_bus_get_finish() to get the result of the operation. 1710 * 1711 * This is a asynchronous failable function. See g_bus_get_sync() for 1712 * the synchronous version. 1713 * 1714 * Params: 1715 * busType = a #GBusType 1716 * cancellable = a #GCancellable or %NULL 1717 * callback = a #GAsyncReadyCallback to call when the request is satisfied 1718 * userData = the data to pass to @callback 1719 * 1720 * Since: 2.26 1721 */ 1722 public static void get(GBusType busType, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1723 { 1724 g_bus_get(busType, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1725 } 1726 1727 /** 1728 * Finishes an operation started with g_bus_get(). 1729 * 1730 * The returned object is a singleton, that is, shared with other 1731 * callers of g_bus_get() and g_bus_get_sync() for @bus_type. In the 1732 * event that you need a private message bus connection, use 1733 * g_dbus_address_get_for_bus_sync() and 1734 * g_dbus_connection_new_for_address(). 1735 * 1736 * Note that the returned #GDBusConnection object will (usually) have 1737 * the #GDBusConnection:exit-on-close property set to %TRUE. 1738 * 1739 * Params: 1740 * res = a #GAsyncResult obtained from the #GAsyncReadyCallback passed 1741 * to g_bus_get() 1742 * 1743 * Return: a #GDBusConnection or %NULL if @error is set. 1744 * Free with g_object_unref(). 1745 * 1746 * Since: 2.26 1747 * 1748 * Throws: GException on failure. 1749 */ 1750 public static DBusConnection getFinish(AsyncResultIF res) 1751 { 1752 GError* err = null; 1753 1754 auto p = g_bus_get_finish((res is null) ? null : res.getAsyncResultStruct(), &err); 1755 1756 if (err !is null) 1757 { 1758 throw new GException( new ErrorG(err) ); 1759 } 1760 1761 if(p is null) 1762 { 1763 return null; 1764 } 1765 1766 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p, true); 1767 } 1768 1769 /** 1770 * Synchronously connects to the message bus specified by @bus_type. 1771 * Note that the returned object may shared with other callers, 1772 * e.g. if two separate parts of a process calls this function with 1773 * the same @bus_type, they will share the same object. 1774 * 1775 * This is a synchronous failable function. See g_bus_get() and 1776 * g_bus_get_finish() for the asynchronous version. 1777 * 1778 * The returned object is a singleton, that is, shared with other 1779 * callers of g_bus_get() and g_bus_get_sync() for @bus_type. In the 1780 * event that you need a private message bus connection, use 1781 * g_dbus_address_get_for_bus_sync() and 1782 * g_dbus_connection_new_for_address(). 1783 * 1784 * Note that the returned #GDBusConnection object will (usually) have 1785 * the #GDBusConnection:exit-on-close property set to %TRUE. 1786 * 1787 * Params: 1788 * busType = a #GBusType 1789 * cancellable = a #GCancellable or %NULL 1790 * 1791 * Return: a #GDBusConnection or %NULL if @error is set. 1792 * Free with g_object_unref(). 1793 * 1794 * Since: 2.26 1795 * 1796 * Throws: GException on failure. 1797 */ 1798 public static DBusConnection getSync(GBusType busType, Cancellable cancellable) 1799 { 1800 GError* err = null; 1801 1802 auto p = g_bus_get_sync(busType, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1803 1804 if (err !is null) 1805 { 1806 throw new GException( new ErrorG(err) ); 1807 } 1808 1809 if(p is null) 1810 { 1811 return null; 1812 } 1813 1814 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p, true); 1815 } 1816 }