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