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