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 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() 56 { 57 return gDBusInterfaceSkeleton; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected override void* getStruct() 62 { 63 return cast(void*)gDBusInterfaceSkeleton; 64 } 65 66 protected override void setStruct(GObject* obj) 67 { 68 gDBusInterfaceSkeleton = cast(GDBusInterfaceSkeleton*)obj; 69 super.setStruct(obj); 70 } 71 72 /** 73 * Sets our main struct and passes it to the parent class. 74 */ 75 public this (GDBusInterfaceSkeleton* gDBusInterfaceSkeleton, bool ownedRef = false) 76 { 77 this.gDBusInterfaceSkeleton = gDBusInterfaceSkeleton; 78 super(cast(GObject*)gDBusInterfaceSkeleton, ownedRef); 79 } 80 81 // add the DBusInterface capabilities 82 mixin DBusInterfaceT!(GDBusInterfaceSkeleton); 83 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); 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); 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 int[string] connectedSignals; 324 325 bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton)[] onGAuthorizeMethodListeners; 326 /** 327 * Emitted when a method is invoked by a remote caller and used to 328 * determine if the method call is authorized. 329 * 330 * Note that this signal is emitted in a thread dedicated to 331 * handling the method call so handlers are allowed to perform 332 * blocking IO. This means that it is appropriate to call e.g. 333 * [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync) 334 * with the 335 * [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS) 336 * flag set. 337 * 338 * If %FALSE is returned then no further handlers are run and the 339 * signal handler must take a reference to @invocation and finish 340 * handling the call (e.g. return an error via 341 * g_dbus_method_invocation_return_error()). 342 * 343 * Otherwise, if %TRUE is returned, signal emission continues. If no 344 * handlers return %FALSE, then the method is dispatched. If 345 * @interface has an enclosing #GDBusObjectSkeleton, then the 346 * #GDBusObjectSkeleton::authorize-method signal handlers run before 347 * the handlers for this signal. 348 * 349 * The default class handler just returns %TRUE. 350 * 351 * Please note that the common case is optimized: if no signals 352 * handlers are connected and the default class handler isn't 353 * overridden (for both @interface and the enclosing 354 * #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does 355 * not have the 356 * %G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD 357 * flags set, no dedicated thread is ever used and the call will be 358 * handled in the same thread as the object that @interface belongs 359 * to was exported in. 360 * 361 * Params: 362 * invocation = A #GDBusMethodInvocation. 363 * 364 * Return: %TRUE if the call is authorized, %FALSE otherwise. 365 * 366 * Since: 2.30 367 */ 368 void addOnGAuthorizeMethod(bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 369 { 370 if ( "g-authorize-method" !in connectedSignals ) 371 { 372 Signals.connectData( 373 this, 374 "g-authorize-method", 375 cast(GCallback)&callBackGAuthorizeMethod, 376 cast(void*)this, 377 null, 378 connectFlags); 379 connectedSignals["g-authorize-method"] = 1; 380 } 381 onGAuthorizeMethodListeners ~= dlg; 382 } 383 extern(C) static int callBackGAuthorizeMethod(GDBusInterfaceSkeleton* dbusinterfaceskeletonStruct, GDBusMethodInvocation* invocation, DBusInterfaceSkeleton _dbusinterfaceskeleton) 384 { 385 foreach ( bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg; _dbusinterfaceskeleton.onGAuthorizeMethodListeners ) 386 { 387 if ( dlg(ObjectG.getDObject!(DBusMethodInvocation)(invocation), _dbusinterfaceskeleton) ) 388 { 389 return 1; 390 } 391 } 392 393 return 0; 394 } 395 }