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.DBusInterfaceSkeleton; 26 27 private import gio.DBusConnection; 28 private import gio.DBusInterfaceIF; 29 private import gio.DBusInterfaceInfo; 30 private import gio.DBusInterfaceT; 31 private import gio.DBusMethodInvocation; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import glib.ListG; 35 private import glib.Str; 36 private import glib.Variant; 37 private import gobject.ObjectG; 38 private import gobject.Signals; 39 private import gtkc.gio; 40 public import gtkc.giotypes; 41 private import std.algorithm; 42 43 44 /** 45 * Abstract base class for D-Bus interfaces on the service side. 46 * 47 * Since: 2.30 48 */ 49 public class DBusInterfaceSkeleton : ObjectG, DBusInterfaceIF 50 { 51 /** the main Gtk struct */ 52 protected GDBusInterfaceSkeleton* gDBusInterfaceSkeleton; 53 54 /** Get the main Gtk struct */ 55 public GDBusInterfaceSkeleton* getDBusInterfaceSkeletonStruct(bool transferOwnership = false) 56 { 57 if (transferOwnership) 58 ownedRef = false; 59 return gDBusInterfaceSkeleton; 60 } 61 62 /** the main Gtk struct as a void* */ 63 protected override void* getStruct() 64 { 65 return cast(void*)gDBusInterfaceSkeleton; 66 } 67 68 protected override void setStruct(GObject* obj) 69 { 70 gDBusInterfaceSkeleton = cast(GDBusInterfaceSkeleton*)obj; 71 super.setStruct(obj); 72 } 73 74 /** 75 * Sets our main struct and passes it to the parent class. 76 */ 77 public this (GDBusInterfaceSkeleton* gDBusInterfaceSkeleton, bool ownedRef = false) 78 { 79 this.gDBusInterfaceSkeleton = gDBusInterfaceSkeleton; 80 super(cast(GObject*)gDBusInterfaceSkeleton, ownedRef); 81 } 82 83 // add the DBusInterface capabilities 84 mixin DBusInterfaceT!(GDBusInterfaceSkeleton); 85 86 87 /** */ 88 public static GType getType() 89 { 90 return g_dbus_interface_skeleton_get_type(); 91 } 92 93 /** 94 * Exports @interface_ at @object_path on @connection. 95 * 96 * This can be called multiple times to export the same @interface_ 97 * onto multiple connections however the @object_path provided must be 98 * the same for all connections. 99 * 100 * Use g_dbus_interface_skeleton_unexport() to unexport the object. 101 * 102 * Params: 103 * connection = A #GDBusConnection to export @interface_ on. 104 * objectPath = The path to export the interface at. 105 * 106 * Returns: %TRUE if the interface was exported on @connection, otherwise %FALSE with 107 * @error set. 108 * 109 * Since: 2.30 110 * 111 * Throws: GException on failure. 112 */ 113 public bool expor(DBusConnection connection, string objectPath) 114 { 115 GError* err = null; 116 117 auto p = g_dbus_interface_skeleton_export(gDBusInterfaceSkeleton, (connection is null) ? null : connection.getDBusConnectionStruct(), Str.toStringz(objectPath), &err) != 0; 118 119 if (err !is null) 120 { 121 throw new GException( new ErrorG(err) ); 122 } 123 124 return p; 125 } 126 127 /** 128 * If @interface_ has outstanding changes, request for these changes to be 129 * emitted immediately. 130 * 131 * For example, an exported D-Bus interface may queue up property 132 * changes and emit the 133 * `org.freedesktop.DBus.Properties::Propert`` 134 * signal later (e.g. in an idle handler). This technique is useful 135 * for collapsing multiple property changes into one. 136 * 137 * Since: 2.30 138 */ 139 public void flush() 140 { 141 g_dbus_interface_skeleton_flush(gDBusInterfaceSkeleton); 142 } 143 144 /** 145 * Gets the first connection that @interface_ is exported on, if any. 146 * 147 * Returns: A #GDBusConnection or %NULL if @interface_ is 148 * not exported anywhere. Do not free, the object belongs to @interface_. 149 * 150 * Since: 2.30 151 */ 152 public DBusConnection getConnection() 153 { 154 auto p = g_dbus_interface_skeleton_get_connection(gDBusInterfaceSkeleton); 155 156 if(p is null) 157 { 158 return null; 159 } 160 161 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p); 162 } 163 164 /** 165 * Gets a list of the connections that @interface_ is exported on. 166 * 167 * Returns: A list of 168 * all the connections that @interface_ is exported on. The returned 169 * list should be freed with g_list_free() after each element has 170 * been freed with g_object_unref(). 171 * 172 * Since: 2.32 173 */ 174 public ListG getConnections() 175 { 176 auto p = g_dbus_interface_skeleton_get_connections(gDBusInterfaceSkeleton); 177 178 if(p is null) 179 { 180 return null; 181 } 182 183 return new ListG(cast(GList*) p, true); 184 } 185 186 /** 187 * Gets the #GDBusInterfaceSkeletonFlags that describes what the behavior 188 * of @interface_ 189 * 190 * Returns: One or more flags from the #GDBusInterfaceSkeletonFlags enumeration. 191 * 192 * Since: 2.30 193 */ 194 public GDBusInterfaceSkeletonFlags getFlags() 195 { 196 return g_dbus_interface_skeleton_get_flags(gDBusInterfaceSkeleton); 197 } 198 199 /** 200 * Gets D-Bus introspection information for the D-Bus interface 201 * implemented by @interface_. 202 * 203 * Returns: A #GDBusInterfaceInfo (never %NULL). Do not free. 204 * 205 * Since: 2.30 206 */ 207 public DBusInterfaceInfo getInfo() 208 { 209 auto p = g_dbus_interface_skeleton_get_info(gDBusInterfaceSkeleton); 210 211 if(p is null) 212 { 213 return null; 214 } 215 216 return ObjectG.getDObject!(DBusInterfaceInfo)(cast(GDBusInterfaceInfo*) p); 217 } 218 219 /** 220 * Gets the object path that @interface_ is exported on, if any. 221 * 222 * Returns: A string owned by @interface_ or %NULL if @interface_ is not exported 223 * anywhere. Do not free, the string belongs to @interface_. 224 * 225 * Since: 2.30 226 */ 227 public string getObjectPath() 228 { 229 return Str.toString(g_dbus_interface_skeleton_get_object_path(gDBusInterfaceSkeleton)); 230 } 231 232 /** 233 * Gets all D-Bus properties for @interface_. 234 * 235 * Returns: A #GVariant of type 236 * ['a{sv}'][G-VARIANT-TYPE-VARDICT:CAPS]. 237 * Free with g_variant_unref(). 238 * 239 * Since: 2.30 240 */ 241 public Variant getProperties() 242 { 243 auto p = g_dbus_interface_skeleton_get_properties(gDBusInterfaceSkeleton); 244 245 if(p is null) 246 { 247 return null; 248 } 249 250 return new Variant(cast(GVariant*) p, true); 251 } 252 253 /** 254 * Gets the interface vtable for the D-Bus interface implemented by 255 * @interface_. The returned function pointers should expect @interface_ 256 * itself to be passed as @user_data. 257 * 258 * Returns: A #GDBusInterfaceVTable (never %NULL). 259 * 260 * Since: 2.30 261 */ 262 public GDBusInterfaceVTable* getVtable() 263 { 264 return g_dbus_interface_skeleton_get_vtable(gDBusInterfaceSkeleton); 265 } 266 267 /** 268 * Checks if @interface_ is exported on @connection. 269 * 270 * Params: 271 * connection = A #GDBusConnection. 272 * 273 * Returns: %TRUE if @interface_ is exported on @connection, %FALSE otherwise. 274 * 275 * Since: 2.32 276 */ 277 public bool hasConnection(DBusConnection connection) 278 { 279 return g_dbus_interface_skeleton_has_connection(gDBusInterfaceSkeleton, (connection is null) ? null : connection.getDBusConnectionStruct()) != 0; 280 } 281 282 /** 283 * Sets flags describing what the behavior of @skeleton should be. 284 * 285 * Params: 286 * flags = Flags from the #GDBusInterfaceSkeletonFlags enumeration. 287 * 288 * Since: 2.30 289 */ 290 public void setFlags(GDBusInterfaceSkeletonFlags flags) 291 { 292 g_dbus_interface_skeleton_set_flags(gDBusInterfaceSkeleton, flags); 293 } 294 295 /** 296 * Stops exporting @interface_ on all connections it is exported on. 297 * 298 * To unexport @interface_ from only a single connection, use 299 * g_dbus_interface_skeleton_unexport_from_connection() 300 * 301 * Since: 2.30 302 */ 303 public void unexport() 304 { 305 g_dbus_interface_skeleton_unexport(gDBusInterfaceSkeleton); 306 } 307 308 /** 309 * Stops exporting @interface_ on @connection. 310 * 311 * To stop exporting on all connections the interface is exported on, 312 * use g_dbus_interface_skeleton_unexport(). 313 * 314 * Params: 315 * connection = A #GDBusConnection. 316 * 317 * Since: 2.32 318 */ 319 public void unexportFromConnection(DBusConnection connection) 320 { 321 g_dbus_interface_skeleton_unexport_from_connection(gDBusInterfaceSkeleton, (connection is null) ? null : connection.getDBusConnectionStruct()); 322 } 323 324 protected class OnGAuthorizeMethodDelegateWrapper 325 { 326 bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg; 327 gulong handlerId; 328 329 this(bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg) 330 { 331 this.dlg = dlg; 332 onGAuthorizeMethodListeners ~= this; 333 } 334 335 void remove(OnGAuthorizeMethodDelegateWrapper source) 336 { 337 foreach(index, wrapper; onGAuthorizeMethodListeners) 338 { 339 if (wrapper.handlerId == source.handlerId) 340 { 341 onGAuthorizeMethodListeners[index] = null; 342 onGAuthorizeMethodListeners = std.algorithm.remove(onGAuthorizeMethodListeners, index); 343 break; 344 } 345 } 346 } 347 } 348 OnGAuthorizeMethodDelegateWrapper[] onGAuthorizeMethodListeners; 349 350 /** 351 * Emitted when a method is invoked by a remote caller and used to 352 * determine if the method call is authorized. 353 * 354 * Note that this signal is emitted in a thread dedicated to 355 * handling the method call so handlers are allowed to perform 356 * blocking IO. This means that it is appropriate to call e.g. 357 * [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync) 358 * with the 359 * [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS) 360 * flag set. 361 * 362 * If %FALSE is returned then no further handlers are run and the 363 * signal handler must take a reference to @invocation and finish 364 * handling the call (e.g. return an error via 365 * g_dbus_method_invocation_return_error()). 366 * 367 * Otherwise, if %TRUE is returned, signal emission continues. If no 368 * handlers return %FALSE, then the method is dispatched. If 369 * @interface has an enclosing #GDBusObjectSkeleton, then the 370 * #GDBusObjectSkeleton::authorize-method signal handlers run before 371 * the handlers for this signal. 372 * 373 * The default class handler just returns %TRUE. 374 * 375 * Please note that the common case is optimized: if no signals 376 * handlers are connected and the default class handler isn't 377 * overridden (for both @interface and the enclosing 378 * #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does 379 * not have the 380 * %G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD 381 * flags set, no dedicated thread is ever used and the call will be 382 * handled in the same thread as the object that @interface belongs 383 * to was exported in. 384 * 385 * Params: 386 * invocation = A #GDBusMethodInvocation. 387 * 388 * Returns: %TRUE if the call is authorized, %FALSE otherwise. 389 * 390 * Since: 2.30 391 */ 392 gulong addOnGAuthorizeMethod(bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 393 { 394 auto wrapper = new OnGAuthorizeMethodDelegateWrapper(dlg); 395 wrapper.handlerId = Signals.connectData( 396 this, 397 "g-authorize-method", 398 cast(GCallback)&callBackGAuthorizeMethod, 399 cast(void*)wrapper, 400 cast(GClosureNotify)&callBackGAuthorizeMethodDestroy, 401 connectFlags); 402 return wrapper.handlerId; 403 } 404 405 extern(C) static int callBackGAuthorizeMethod(GDBusInterfaceSkeleton* dbusinterfaceskeletonStruct, GDBusMethodInvocation* invocation, OnGAuthorizeMethodDelegateWrapper wrapper) 406 { 407 return wrapper.dlg(ObjectG.getDObject!(DBusMethodInvocation)(invocation), wrapper.outer); 408 } 409 410 extern(C) static void callBackGAuthorizeMethodDestroy(OnGAuthorizeMethodDelegateWrapper wrapper, GClosure* closure) 411 { 412 wrapper.remove(wrapper); 413 } 414 }