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.DBusObjectSkeleton; 26 27 private import gio.DBusInterfaceSkeleton; 28 private import gio.DBusMethodInvocation; 29 private import gio.DBusObjectIF; 30 private import gio.DBusObjectT; 31 private import gio.c.functions; 32 public import gio.c.types; 33 private import glib.ConstructionException; 34 private import glib.Str; 35 private import gobject.ObjectG; 36 private import gobject.Signals; 37 public import gtkc.giotypes; 38 private import std.algorithm; 39 40 41 /** 42 * A #GDBusObjectSkeleton instance is essentially a group of D-Bus 43 * interfaces. The set of exported interfaces on the object may be 44 * dynamic and change at runtime. 45 * 46 * This type is intended to be used with #GDBusObjectManager. 47 * 48 * Since: 2.30 49 */ 50 public class DBusObjectSkeleton : ObjectG, DBusObjectIF 51 { 52 /** the main Gtk struct */ 53 protected GDBusObjectSkeleton* gDBusObjectSkeleton; 54 55 /** Get the main Gtk struct */ 56 public GDBusObjectSkeleton* getDBusObjectSkeletonStruct(bool transferOwnership = false) 57 { 58 if (transferOwnership) 59 ownedRef = false; 60 return gDBusObjectSkeleton; 61 } 62 63 /** the main Gtk struct as a void* */ 64 protected override void* getStruct() 65 { 66 return cast(void*)gDBusObjectSkeleton; 67 } 68 69 protected override void setStruct(GObject* obj) 70 { 71 gDBusObjectSkeleton = cast(GDBusObjectSkeleton*)obj; 72 super.setStruct(obj); 73 } 74 75 /** 76 * Sets our main struct and passes it to the parent class. 77 */ 78 public this (GDBusObjectSkeleton* gDBusObjectSkeleton, bool ownedRef = false) 79 { 80 this.gDBusObjectSkeleton = gDBusObjectSkeleton; 81 super(cast(GObject*)gDBusObjectSkeleton, ownedRef); 82 } 83 84 // add the DBusObject capabilities 85 mixin DBusObjectT!(GDBusObjectSkeleton); 86 87 88 /** */ 89 public static GType getType() 90 { 91 return g_dbus_object_skeleton_get_type(); 92 } 93 94 /** 95 * Creates a new #GDBusObjectSkeleton. 96 * 97 * Params: 98 * objectPath = An object path. 99 * 100 * Returns: A #GDBusObjectSkeleton. Free with g_object_unref(). 101 * 102 * Since: 2.30 103 * 104 * Throws: ConstructionException GTK+ fails to create the object. 105 */ 106 public this(string objectPath) 107 { 108 auto p = g_dbus_object_skeleton_new(Str.toStringz(objectPath)); 109 110 if(p is null) 111 { 112 throw new ConstructionException("null returned by new"); 113 } 114 115 this(cast(GDBusObjectSkeleton*) p, true); 116 } 117 118 /** 119 * Adds @interface_ to @object. 120 * 121 * If @object already contains a #GDBusInterfaceSkeleton with the same 122 * interface name, it is removed before @interface_ is added. 123 * 124 * Note that @object takes its own reference on @interface_ and holds 125 * it until removed. 126 * 127 * Params: 128 * iface = A #GDBusInterfaceSkeleton. 129 * 130 * Since: 2.30 131 */ 132 public void addInterface(DBusInterfaceSkeleton iface) 133 { 134 g_dbus_object_skeleton_add_interface(gDBusObjectSkeleton, (iface is null) ? null : iface.getDBusInterfaceSkeletonStruct()); 135 } 136 137 /** 138 * This method simply calls g_dbus_interface_skeleton_flush() on all 139 * interfaces belonging to @object. See that method for when flushing 140 * is useful. 141 * 142 * Since: 2.30 143 */ 144 public void flush() 145 { 146 g_dbus_object_skeleton_flush(gDBusObjectSkeleton); 147 } 148 149 /** 150 * Removes @interface_ from @object. 151 * 152 * Params: 153 * iface = A #GDBusInterfaceSkeleton. 154 * 155 * Since: 2.30 156 */ 157 public void removeInterface(DBusInterfaceSkeleton iface) 158 { 159 g_dbus_object_skeleton_remove_interface(gDBusObjectSkeleton, (iface is null) ? null : iface.getDBusInterfaceSkeletonStruct()); 160 } 161 162 /** 163 * Removes the #GDBusInterface with @interface_name from @object. 164 * 165 * If no D-Bus interface of the given interface exists, this function 166 * does nothing. 167 * 168 * Params: 169 * interfaceName = A D-Bus interface name. 170 * 171 * Since: 2.30 172 */ 173 public void removeInterfaceByName(string interfaceName) 174 { 175 g_dbus_object_skeleton_remove_interface_by_name(gDBusObjectSkeleton, Str.toStringz(interfaceName)); 176 } 177 178 /** 179 * Sets the object path for @object. 180 * 181 * Params: 182 * objectPath = A valid D-Bus object path. 183 * 184 * Since: 2.30 185 */ 186 public void setObjectPath(string objectPath) 187 { 188 g_dbus_object_skeleton_set_object_path(gDBusObjectSkeleton, Str.toStringz(objectPath)); 189 } 190 191 protected class OnAuthorizeMethodDelegateWrapper 192 { 193 bool delegate(DBusInterfaceSkeleton, DBusMethodInvocation, DBusObjectSkeleton) dlg; 194 gulong handlerId; 195 196 this(bool delegate(DBusInterfaceSkeleton, DBusMethodInvocation, DBusObjectSkeleton) dlg) 197 { 198 this.dlg = dlg; 199 onAuthorizeMethodListeners ~= this; 200 } 201 202 void remove(OnAuthorizeMethodDelegateWrapper source) 203 { 204 foreach(index, wrapper; onAuthorizeMethodListeners) 205 { 206 if (wrapper.handlerId == source.handlerId) 207 { 208 onAuthorizeMethodListeners[index] = null; 209 onAuthorizeMethodListeners = std.algorithm.remove(onAuthorizeMethodListeners, index); 210 break; 211 } 212 } 213 } 214 } 215 OnAuthorizeMethodDelegateWrapper[] onAuthorizeMethodListeners; 216 217 /** 218 * Emitted when a method is invoked by a remote caller and used to 219 * determine if the method call is authorized. 220 * 221 * This signal is like #GDBusInterfaceSkeleton's 222 * #GDBusInterfaceSkeleton::g-authorize-method signal, 223 * except that it is for the enclosing object. 224 * 225 * The default class handler just returns %TRUE. 226 * 227 * Params: 228 * iface = The #GDBusInterfaceSkeleton that @invocation is for. 229 * invocation = A #GDBusMethodInvocation. 230 * 231 * Returns: %TRUE if the call is authorized, %FALSE otherwise. 232 * 233 * Since: 2.30 234 */ 235 gulong addOnAuthorizeMethod(bool delegate(DBusInterfaceSkeleton, DBusMethodInvocation, DBusObjectSkeleton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 236 { 237 auto wrapper = new OnAuthorizeMethodDelegateWrapper(dlg); 238 wrapper.handlerId = Signals.connectData( 239 this, 240 "authorize-method", 241 cast(GCallback)&callBackAuthorizeMethod, 242 cast(void*)wrapper, 243 cast(GClosureNotify)&callBackAuthorizeMethodDestroy, 244 connectFlags); 245 return wrapper.handlerId; 246 } 247 248 extern(C) static int callBackAuthorizeMethod(GDBusObjectSkeleton* dbusobjectskeletonStruct, GDBusInterfaceSkeleton* iface, GDBusMethodInvocation* invocation, OnAuthorizeMethodDelegateWrapper wrapper) 249 { 250 return wrapper.dlg(ObjectG.getDObject!(DBusInterfaceSkeleton)(iface), ObjectG.getDObject!(DBusMethodInvocation)(invocation), wrapper.outer); 251 } 252 253 extern(C) static void callBackAuthorizeMethodDestroy(OnAuthorizeMethodDelegateWrapper wrapper, GClosure* closure) 254 { 255 wrapper.remove(wrapper); 256 } 257 }