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.DBusObjectManagerClient; 26 27 private import gio.AsyncInitableIF; 28 private import gio.AsyncInitableT; 29 private import gio.Cancellable; 30 private import gio.DBusConnection; 31 private import gio.DBusObjectManagerIF; 32 private import gio.DBusObjectManagerT; 33 private import gio.DBusObjectProxy; 34 private import gio.DBusProxy; 35 private import gio.InitableIF; 36 private import gio.InitableT; 37 private import glib.ConstructionException; 38 private import glib.ErrorG; 39 private import glib.GException; 40 private import glib.Str; 41 private import glib.Variant; 42 private import gobject.ObjectG; 43 private import gobject.Signals; 44 public import gtkc.gdktypes; 45 private import gtkc.gio; 46 public import gtkc.giotypes; 47 48 49 /** 50 * #GDBusObjectManagerClient is used to create, monitor and delete object 51 * proxies for remote objects exported by a #GDBusObjectManagerServer (or any 52 * code implementing the 53 * [org.freedesktop.DBus.ObjectManager](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) 54 * interface). 55 * 56 * Once an instance of this type has been created, you can connect to 57 * the #GDBusObjectManager::object-added and 58 * #GDBusObjectManager::object-removed signals and inspect the 59 * #GDBusObjectProxy objects returned by 60 * g_dbus_object_manager_get_objects(). 61 * 62 * If the name for a #GDBusObjectManagerClient is not owned by anyone at 63 * object construction time, the default behavior is to request the 64 * message bus to launch an owner for the name. This behavior can be 65 * disabled using the %G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START 66 * flag. It's also worth noting that this only works if the name of 67 * interest is activatable in the first place. E.g. in some cases it 68 * is not possible to launch an owner for the requested name. In this 69 * case, #GDBusObjectManagerClient object construction still succeeds but 70 * there will be no object proxies 71 * (e.g. g_dbus_object_manager_get_objects() returns the empty list) and 72 * the #GDBusObjectManagerClient:name-owner property is %NULL. 73 * 74 * The owner of the requested name can come and go (for example 75 * consider a system service being restarted) – #GDBusObjectManagerClient 76 * handles this case too; simply connect to the #GObject::notify 77 * signal to watch for changes on the #GDBusObjectManagerClient:name-owner 78 * property. When the name owner vanishes, the behavior is that 79 * #GDBusObjectManagerClient:name-owner is set to %NULL (this includes 80 * emission of the #GObject::notify signal) and then 81 * #GDBusObjectManager::object-removed signals are synthesized 82 * for all currently existing object proxies. Since 83 * #GDBusObjectManagerClient:name-owner is %NULL when this happens, you can 84 * use this information to disambiguate a synthesized signal from a 85 * genuine signal caused by object removal on the remote 86 * #GDBusObjectManager. Similarly, when a new name owner appears, 87 * #GDBusObjectManager::object-added signals are synthesized 88 * while #GDBusObjectManagerClient:name-owner is still %NULL. Only when all 89 * object proxies have been added, the #GDBusObjectManagerClient:name-owner 90 * is set to the new name owner (this includes emission of the 91 * #GObject::notify signal). Furthermore, you are guaranteed that 92 * #GDBusObjectManagerClient:name-owner will alternate between a name owner 93 * (e.g. `:1.42`) and %NULL even in the case where 94 * the name of interest is atomically replaced 95 * 96 * Ultimately, #GDBusObjectManagerClient is used to obtain #GDBusProxy 97 * instances. All signals (including the 98 * org.freedesktop.DBus.Properties::PropertiesChanged signal) 99 * delivered to #GDBusProxy instances are guaranteed to originate 100 * from the name owner. This guarantee along with the behavior 101 * described above, means that certain race conditions including the 102 * "half the proxy is from the old owner and the other half is from 103 * the new owner" problem cannot happen. 104 * 105 * To avoid having the application connect to signals on the returned 106 * #GDBusObjectProxy and #GDBusProxy objects, the 107 * #GDBusObject::interface-added, 108 * #GDBusObject::interface-removed, 109 * #GDBusProxy::g-properties-changed and 110 * #GDBusProxy::g-signal signals 111 * are also emitted on the #GDBusObjectManagerClient instance managing these 112 * objects. The signals emitted are 113 * #GDBusObjectManager::interface-added, 114 * #GDBusObjectManager::interface-removed, 115 * #GDBusObjectManagerClient::interface-proxy-properties-changed and 116 * #GDBusObjectManagerClient::interface-proxy-signal. 117 * 118 * Note that all callbacks and signals are emitted in the 119 * [thread-default main context][g-main-context-push-thread-default] 120 * that the #GDBusObjectManagerClient object was constructed 121 * in. Additionally, the #GDBusObjectProxy and #GDBusProxy objects 122 * originating from the #GDBusObjectManagerClient object will be created in 123 * the same context and, consequently, will deliver signals in the 124 * same main loop. 125 * 126 * Since: 2.30 127 */ 128 public class DBusObjectManagerClient : ObjectG, AsyncInitableIF, DBusObjectManagerIF, InitableIF 129 { 130 /** the main Gtk struct */ 131 protected GDBusObjectManagerClient* gDBusObjectManagerClient; 132 133 /** Get the main Gtk struct */ 134 public GDBusObjectManagerClient* getDBusObjectManagerClientStruct() 135 { 136 return gDBusObjectManagerClient; 137 } 138 139 /** the main Gtk struct as a void* */ 140 protected override void* getStruct() 141 { 142 return cast(void*)gDBusObjectManagerClient; 143 } 144 145 protected override void setStruct(GObject* obj) 146 { 147 gDBusObjectManagerClient = cast(GDBusObjectManagerClient*)obj; 148 super.setStruct(obj); 149 } 150 151 /** 152 * Sets our main struct and passes it to the parent class. 153 */ 154 public this (GDBusObjectManagerClient* gDBusObjectManagerClient, bool ownedRef = false) 155 { 156 this.gDBusObjectManagerClient = gDBusObjectManagerClient; 157 super(cast(GObject*)gDBusObjectManagerClient, ownedRef); 158 } 159 160 // add the AsyncInitable capabilities 161 mixin AsyncInitableT!(GDBusObjectManagerClient); 162 163 // add the DBusObjectManager capabilities 164 mixin DBusObjectManagerT!(GDBusObjectManagerClient); 165 166 // add the Initable capabilities 167 mixin InitableT!(GDBusObjectManagerClient); 168 169 /** 170 * Finishes an operation started with g_dbus_object_manager_client_new(). 171 * 172 * Params: 173 * res = A GAsyncResult obtained from the GAsyncReadyCallback passed to the DBusObjectManager constructor. 174 * forBus = If true finish an address. 175 * 176 * Throws: GException on failure. 177 * Throws: ConstructionException GTK+ fails to create the object. 178 * 179 * Since: 2.30 180 */ 181 public this (AsyncResultIF res, bool forBus = false) 182 { 183 GError* err = null; 184 GDBusObjectManager* p; 185 186 if ( forBus ) 187 { 188 p = g_dbus_object_manager_client_new_for_bus_finish((res is null) ? null : res.getAsyncResultStruct(), &err); 189 } 190 else 191 { 192 p = g_dbus_object_manager_client_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err); 193 } 194 195 if (err !is null) 196 { 197 throw new GException( new ErrorG(err) ); 198 } 199 200 if(p is null) 201 { 202 throw new ConstructionException("null returned by g_dbus_object_manager_client_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err)"); 203 } 204 this(cast(GDBusObjectManagerClient*) p, true); 205 } 206 207 /** 208 */ 209 210 /** */ 211 public static GType getType() 212 { 213 return g_dbus_object_manager_client_get_type(); 214 } 215 216 /** 217 * Like g_dbus_object_manager_client_new_sync() but takes a #GBusType instead 218 * of a #GDBusConnection. 219 * 220 * This is a synchronous failable constructor - the calling thread is 221 * blocked until a reply is received. See g_dbus_object_manager_client_new_for_bus() 222 * for the asynchronous version. 223 * 224 * Params: 225 * busType = A #GBusType. 226 * flags = Zero or more flags from the #GDBusObjectManagerClientFlags enumeration. 227 * name = The owner of the control object (unique or well-known name). 228 * objectPath = The object path of the control object. 229 * getProxyTypeFunc = A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies. 230 * getProxyTypeUserData = User data to pass to @get_proxy_type_func. 231 * getProxyTypeDestroyNotify = Free function for @get_proxy_type_user_data or %NULL. 232 * cancellable = A #GCancellable or %NULL 233 * 234 * Return: A 235 * #GDBusObjectManagerClient object or %NULL if @error is set. Free 236 * with g_object_unref(). 237 * 238 * Since: 2.30 239 * 240 * Throws: GException on failure. 241 * Throws: ConstructionException GTK+ fails to create the object. 242 */ 243 public this(GBusType busType, GDBusObjectManagerClientFlags flags, string name, string objectPath, GDBusProxyTypeFunc getProxyTypeFunc, void* getProxyTypeUserData, GDestroyNotify getProxyTypeDestroyNotify, Cancellable cancellable) 244 { 245 GError* err = null; 246 247 auto p = g_dbus_object_manager_client_new_for_bus_sync(busType, flags, Str.toStringz(name), Str.toStringz(objectPath), getProxyTypeFunc, getProxyTypeUserData, getProxyTypeDestroyNotify, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 248 249 if (err !is null) 250 { 251 throw new GException( new ErrorG(err) ); 252 } 253 254 if(p is null) 255 { 256 throw new ConstructionException("null returned by new_for_bus_sync"); 257 } 258 259 this(cast(GDBusObjectManagerClient*) p, true); 260 } 261 262 /** 263 * Creates a new #GDBusObjectManagerClient object. 264 * 265 * This is a synchronous failable constructor - the calling thread is 266 * blocked until a reply is received. See g_dbus_object_manager_client_new() 267 * for the asynchronous version. 268 * 269 * Params: 270 * connection = A #GDBusConnection. 271 * flags = Zero or more flags from the #GDBusObjectManagerClientFlags enumeration. 272 * name = The owner of the control object (unique or well-known name), or %NULL when not using a message bus connection. 273 * objectPath = The object path of the control object. 274 * getProxyTypeFunc = A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies. 275 * getProxyTypeUserData = User data to pass to @get_proxy_type_func. 276 * getProxyTypeDestroyNotify = Free function for @get_proxy_type_user_data or %NULL. 277 * cancellable = A #GCancellable or %NULL 278 * 279 * Return: A 280 * #GDBusObjectManagerClient object or %NULL if @error is set. Free 281 * with g_object_unref(). 282 * 283 * Since: 2.30 284 * 285 * Throws: GException on failure. 286 * Throws: ConstructionException GTK+ fails to create the object. 287 */ 288 public this(DBusConnection connection, GDBusObjectManagerClientFlags flags, string name, string objectPath, GDBusProxyTypeFunc getProxyTypeFunc, void* getProxyTypeUserData, GDestroyNotify getProxyTypeDestroyNotify, Cancellable cancellable) 289 { 290 GError* err = null; 291 292 auto p = g_dbus_object_manager_client_new_sync((connection is null) ? null : connection.getDBusConnectionStruct(), flags, Str.toStringz(name), Str.toStringz(objectPath), getProxyTypeFunc, getProxyTypeUserData, getProxyTypeDestroyNotify, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 293 294 if (err !is null) 295 { 296 throw new GException( new ErrorG(err) ); 297 } 298 299 if(p is null) 300 { 301 throw new ConstructionException("null returned by new_sync"); 302 } 303 304 this(cast(GDBusObjectManagerClient*) p, true); 305 } 306 307 /** 308 * Asynchronously creates a new #GDBusObjectManagerClient object. 309 * 310 * This is an asynchronous failable constructor. When the result is 311 * ready, @callback will be invoked in the 312 * [thread-default main context][g-main-context-push-thread-default] 313 * of the thread you are calling this method from. You can 314 * then call g_dbus_object_manager_client_new_finish() to get the result. See 315 * g_dbus_object_manager_client_new_sync() for the synchronous version. 316 * 317 * Params: 318 * connection = A #GDBusConnection. 319 * flags = Zero or more flags from the #GDBusObjectManagerClientFlags enumeration. 320 * name = The owner of the control object (unique or well-known name). 321 * objectPath = The object path of the control object. 322 * getProxyTypeFunc = A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies. 323 * getProxyTypeUserData = User data to pass to @get_proxy_type_func. 324 * getProxyTypeDestroyNotify = Free function for @get_proxy_type_user_data or %NULL. 325 * cancellable = A #GCancellable or %NULL 326 * callback = A #GAsyncReadyCallback to call when the request is satisfied. 327 * userData = The data to pass to @callback. 328 * 329 * Since: 2.30 330 */ 331 public static void newObjectManagerClient(DBusConnection connection, GDBusObjectManagerClientFlags flags, string name, string objectPath, GDBusProxyTypeFunc getProxyTypeFunc, void* getProxyTypeUserData, GDestroyNotify getProxyTypeDestroyNotify, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 332 { 333 g_dbus_object_manager_client_new((connection is null) ? null : connection.getDBusConnectionStruct(), flags, Str.toStringz(name), Str.toStringz(objectPath), getProxyTypeFunc, getProxyTypeUserData, getProxyTypeDestroyNotify, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 334 } 335 336 /** 337 * Like g_dbus_object_manager_client_new() but takes a #GBusType instead of a 338 * #GDBusConnection. 339 * 340 * This is an asynchronous failable constructor. When the result is 341 * ready, @callback will be invoked in the 342 * [thread-default main loop][g-main-context-push-thread-default] 343 * of the thread you are calling this method from. You can 344 * then call g_dbus_object_manager_client_new_for_bus_finish() to get the result. See 345 * g_dbus_object_manager_client_new_for_bus_sync() for the synchronous version. 346 * 347 * Params: 348 * busType = A #GBusType. 349 * flags = Zero or more flags from the #GDBusObjectManagerClientFlags enumeration. 350 * name = The owner of the control object (unique or well-known name). 351 * objectPath = The object path of the control object. 352 * getProxyTypeFunc = A #GDBusProxyTypeFunc function or %NULL to always construct #GDBusProxy proxies. 353 * getProxyTypeUserData = User data to pass to @get_proxy_type_func. 354 * getProxyTypeDestroyNotify = Free function for @get_proxy_type_user_data or %NULL. 355 * cancellable = A #GCancellable or %NULL 356 * callback = A #GAsyncReadyCallback to call when the request is satisfied. 357 * userData = The data to pass to @callback. 358 * 359 * Since: 2.30 360 */ 361 public static void newForBus(GBusType busType, GDBusObjectManagerClientFlags flags, string name, string objectPath, GDBusProxyTypeFunc getProxyTypeFunc, void* getProxyTypeUserData, GDestroyNotify getProxyTypeDestroyNotify, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 362 { 363 g_dbus_object_manager_client_new_for_bus(busType, flags, Str.toStringz(name), Str.toStringz(objectPath), getProxyTypeFunc, getProxyTypeUserData, getProxyTypeDestroyNotify, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 364 } 365 366 /** 367 * Gets the #GDBusConnection used by @manager. 368 * 369 * Return: A #GDBusConnection object. Do not free, 370 * the object belongs to @manager. 371 * 372 * Since: 2.30 373 */ 374 public DBusConnection getConnection() 375 { 376 auto p = g_dbus_object_manager_client_get_connection(gDBusObjectManagerClient); 377 378 if(p is null) 379 { 380 return null; 381 } 382 383 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p); 384 } 385 386 /** 387 * Gets the flags that @manager was constructed with. 388 * 389 * Return: Zero of more flags from the #GDBusObjectManagerClientFlags 390 * enumeration. 391 * 392 * Since: 2.30 393 */ 394 public GDBusObjectManagerClientFlags getFlags() 395 { 396 return g_dbus_object_manager_client_get_flags(gDBusObjectManagerClient); 397 } 398 399 /** 400 * Gets the name that @manager is for, or %NULL if not a message bus 401 * connection. 402 * 403 * Return: A unique or well-known name. Do not free, the string 404 * belongs to @manager. 405 * 406 * Since: 2.30 407 */ 408 public string getName() 409 { 410 return Str.toString(g_dbus_object_manager_client_get_name(gDBusObjectManagerClient)); 411 } 412 413 /** 414 * The unique name that owns the name that @manager is for or %NULL if 415 * no-one currently owns that name. You can connect to the 416 * #GObject::notify signal to track changes to the 417 * #GDBusObjectManagerClient:name-owner property. 418 * 419 * Return: The name owner or %NULL if no name owner 420 * exists. Free with g_free(). 421 * 422 * Since: 2.30 423 */ 424 public string getNameOwner() 425 { 426 return Str.toString(g_dbus_object_manager_client_get_name_owner(gDBusObjectManagerClient)); 427 } 428 429 int[string] connectedSignals; 430 431 void delegate(DBusObjectProxy, DBusProxy, Variant, string[], DBusObjectManagerClient)[] onInterfaceProxyPropertiesChangedListeners; 432 /** 433 * Emitted when one or more D-Bus properties on proxy changes. The 434 * local cache has already been updated when this signal fires. Note 435 * that both @changed_properties and @invalidated_properties are 436 * guaranteed to never be %NULL (either may be empty though). 437 * 438 * This signal exists purely as a convenience to avoid having to 439 * connect signals to all interface proxies managed by @manager. 440 * 441 * This signal is emitted in the 442 * [thread-default main context][g-main-context-push-thread-default] 443 * that @manager was constructed in. 444 * 445 * Params: 446 * objectProxy = The #GDBusObjectProxy on which an interface has properties that are changing. 447 * interfaceProxy = The #GDBusProxy that has properties that are changing. 448 * changedProperties = A #GVariant containing the properties that changed. 449 * invalidatedProperties = A %NULL terminated array of properties that was invalidated. 450 * 451 * Since: 2.30 452 */ 453 void addOnInterfaceProxyPropertiesChanged(void delegate(DBusObjectProxy, DBusProxy, Variant, string[], DBusObjectManagerClient) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 454 { 455 if ( "interface-proxy-properties-changed" !in connectedSignals ) 456 { 457 Signals.connectData( 458 this, 459 "interface-proxy-properties-changed", 460 cast(GCallback)&callBackInterfaceProxyPropertiesChanged, 461 cast(void*)this, 462 null, 463 connectFlags); 464 connectedSignals["interface-proxy-properties-changed"] = 1; 465 } 466 onInterfaceProxyPropertiesChangedListeners ~= dlg; 467 } 468 extern(C) static void callBackInterfaceProxyPropertiesChanged(GDBusObjectManagerClient* dbusobjectmanagerclientStruct, GDBusObjectProxy* objectProxy, GDBusProxy* interfaceProxy, GVariant* changedProperties, char** invalidatedProperties, DBusObjectManagerClient _dbusobjectmanagerclient) 469 { 470 foreach ( void delegate(DBusObjectProxy, DBusProxy, Variant, string[], DBusObjectManagerClient) dlg; _dbusobjectmanagerclient.onInterfaceProxyPropertiesChangedListeners ) 471 { 472 dlg(ObjectG.getDObject!(DBusObjectProxy)(objectProxy), ObjectG.getDObject!(DBusProxy)(interfaceProxy), new Variant(changedProperties), Str.toStringArray(invalidatedProperties), _dbusobjectmanagerclient); 473 } 474 } 475 476 void delegate(DBusObjectProxy, DBusProxy, string, string, Variant, DBusObjectManagerClient)[] onInterfaceProxySignalListeners; 477 /** 478 * Emitted when a D-Bus signal is received on @interface_proxy. 479 * 480 * This signal exists purely as a convenience to avoid having to 481 * connect signals to all interface proxies managed by @manager. 482 * 483 * This signal is emitted in the 484 * [thread-default main context][g-main-context-push-thread-default] 485 * that @manager was constructed in. 486 * 487 * Params: 488 * objectProxy = The #GDBusObjectProxy on which an interface is emitting a D-Bus signal. 489 * interfaceProxy = The #GDBusProxy that is emitting a D-Bus signal. 490 * senderName = The sender of the signal or NULL if the connection is not a bus connection. 491 * signalName = The signal name. 492 * parameters = A #GVariant tuple with parameters for the signal. 493 * 494 * Since: 2.30 495 */ 496 void addOnInterfaceProxySignal(void delegate(DBusObjectProxy, DBusProxy, string, string, Variant, DBusObjectManagerClient) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 497 { 498 if ( "interface-proxy-signal" !in connectedSignals ) 499 { 500 Signals.connectData( 501 this, 502 "interface-proxy-signal", 503 cast(GCallback)&callBackInterfaceProxySignal, 504 cast(void*)this, 505 null, 506 connectFlags); 507 connectedSignals["interface-proxy-signal"] = 1; 508 } 509 onInterfaceProxySignalListeners ~= dlg; 510 } 511 extern(C) static void callBackInterfaceProxySignal(GDBusObjectManagerClient* dbusobjectmanagerclientStruct, GDBusObjectProxy* objectProxy, GDBusProxy* interfaceProxy, char* senderName, char* signalName, GVariant* parameters, DBusObjectManagerClient _dbusobjectmanagerclient) 512 { 513 foreach ( void delegate(DBusObjectProxy, DBusProxy, string, string, Variant, DBusObjectManagerClient) dlg; _dbusobjectmanagerclient.onInterfaceProxySignalListeners ) 514 { 515 dlg(ObjectG.getDObject!(DBusObjectProxy)(objectProxy), ObjectG.getDObject!(DBusProxy)(interfaceProxy), Str.toString(senderName), Str.toString(signalName), new Variant(parameters), _dbusobjectmanagerclient); 516 } 517 } 518 }