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.DBusObjectT; 26 27 public import gio.DBusInterface; 28 public import gio.DBusInterfaceIF; 29 public import glib.ListG; 30 public import glib.Str; 31 public import gobject.ObjectG; 32 public import gobject.Signals; 33 public import gtkc.gdktypes; 34 public import gtkc.gio; 35 public import gtkc.giotypes; 36 public import std.algorithm; 37 38 39 /** 40 * The #GDBusObject type is the base type for D-Bus objects on both 41 * the service side (see #GDBusObjectSkeleton) and the client side 42 * (see #GDBusObjectProxy). It is essentially just a container of 43 * interfaces. 44 */ 45 public template DBusObjectT(TStruct) 46 { 47 /** Get the main Gtk struct */ 48 public GDBusObject* getDBusObjectStruct() 49 { 50 return cast(GDBusObject*)getStruct(); 51 } 52 53 54 /** 55 * Gets the D-Bus interface with name @interface_name associated with 56 * @object, if any. 57 * 58 * Params: 59 * interfaceName = A D-Bus interface name. 60 * 61 * Return: %NULL if not found, otherwise a 62 * #GDBusInterface that must be freed with g_object_unref(). 63 * 64 * Since: 2.30 65 */ 66 public DBusInterfaceIF getInterface(string interfaceName) 67 { 68 auto p = g_dbus_object_get_interface(getDBusObjectStruct(), Str.toStringz(interfaceName)); 69 70 if(p is null) 71 { 72 return null; 73 } 74 75 return ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(cast(GDBusInterface*) p, true); 76 } 77 78 /** 79 * Gets the D-Bus interfaces associated with @object. 80 * 81 * Return: A list of #GDBusInterface instances. 82 * The returned list must be freed by g_list_free() after each element has been freed 83 * with g_object_unref(). 84 * 85 * Since: 2.30 86 */ 87 public ListG getInterfaces() 88 { 89 auto p = g_dbus_object_get_interfaces(getDBusObjectStruct()); 90 91 if(p is null) 92 { 93 return null; 94 } 95 96 return new ListG(cast(GList*) p, true); 97 } 98 99 /** 100 * Gets the object path for @object. 101 * 102 * Return: A string owned by @object. Do not free. 103 * 104 * Since: 2.30 105 */ 106 public string getObjectPath() 107 { 108 return Str.toString(g_dbus_object_get_object_path(getDBusObjectStruct())); 109 } 110 111 protected class OnInterfaceAddedDelegateWrapper 112 { 113 void delegate(DBusInterfaceIF, DBusObjectIF) dlg; 114 gulong handlerId; 115 ConnectFlags flags; 116 this(void delegate(DBusInterfaceIF, DBusObjectIF) dlg, gulong handlerId, ConnectFlags flags) 117 { 118 this.dlg = dlg; 119 this.handlerId = handlerId; 120 this.flags = flags; 121 } 122 } 123 protected OnInterfaceAddedDelegateWrapper[] onInterfaceAddedListeners; 124 125 /** 126 * Emitted when @interface is added to @object. 127 * 128 * Params: 129 * iface = The #GDBusInterface that was added. 130 * 131 * Since: 2.30 132 */ 133 gulong addOnInterfaceAdded(void delegate(DBusInterfaceIF, DBusObjectIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 134 { 135 onInterfaceAddedListeners ~= new OnInterfaceAddedDelegateWrapper(dlg, 0, connectFlags); 136 onInterfaceAddedListeners[onInterfaceAddedListeners.length - 1].handlerId = Signals.connectData( 137 this, 138 "interface-added", 139 cast(GCallback)&callBackInterfaceAdded, 140 cast(void*)onInterfaceAddedListeners[onInterfaceAddedListeners.length - 1], 141 cast(GClosureNotify)&callBackInterfaceAddedDestroy, 142 connectFlags); 143 return onInterfaceAddedListeners[onInterfaceAddedListeners.length - 1].handlerId; 144 } 145 146 extern(C) static void callBackInterfaceAdded(GDBusObject* dbusobjectStruct, GDBusInterface* iface,OnInterfaceAddedDelegateWrapper wrapper) 147 { 148 wrapper.dlg(ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), wrapper.outer); 149 } 150 151 extern(C) static void callBackInterfaceAddedDestroy(OnInterfaceAddedDelegateWrapper wrapper, GClosure* closure) 152 { 153 wrapper.outer.internalRemoveOnInterfaceAdded(wrapper); 154 } 155 156 protected void internalRemoveOnInterfaceAdded(OnInterfaceAddedDelegateWrapper source) 157 { 158 foreach(index, wrapper; onInterfaceAddedListeners) 159 { 160 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 161 { 162 onInterfaceAddedListeners[index] = null; 163 onInterfaceAddedListeners = std.algorithm.remove(onInterfaceAddedListeners, index); 164 break; 165 } 166 } 167 } 168 169 170 protected class OnInterfaceRemovedDelegateWrapper 171 { 172 void delegate(DBusInterfaceIF, DBusObjectIF) dlg; 173 gulong handlerId; 174 ConnectFlags flags; 175 this(void delegate(DBusInterfaceIF, DBusObjectIF) dlg, gulong handlerId, ConnectFlags flags) 176 { 177 this.dlg = dlg; 178 this.handlerId = handlerId; 179 this.flags = flags; 180 } 181 } 182 protected OnInterfaceRemovedDelegateWrapper[] onInterfaceRemovedListeners; 183 184 /** 185 * Emitted when @interface is removed from @object. 186 * 187 * Params: 188 * iface = The #GDBusInterface that was removed. 189 * 190 * Since: 2.30 191 */ 192 gulong addOnInterfaceRemoved(void delegate(DBusInterfaceIF, DBusObjectIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 193 { 194 onInterfaceRemovedListeners ~= new OnInterfaceRemovedDelegateWrapper(dlg, 0, connectFlags); 195 onInterfaceRemovedListeners[onInterfaceRemovedListeners.length - 1].handlerId = Signals.connectData( 196 this, 197 "interface-removed", 198 cast(GCallback)&callBackInterfaceRemoved, 199 cast(void*)onInterfaceRemovedListeners[onInterfaceRemovedListeners.length - 1], 200 cast(GClosureNotify)&callBackInterfaceRemovedDestroy, 201 connectFlags); 202 return onInterfaceRemovedListeners[onInterfaceRemovedListeners.length - 1].handlerId; 203 } 204 205 extern(C) static void callBackInterfaceRemoved(GDBusObject* dbusobjectStruct, GDBusInterface* iface,OnInterfaceRemovedDelegateWrapper wrapper) 206 { 207 wrapper.dlg(ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), wrapper.outer); 208 } 209 210 extern(C) static void callBackInterfaceRemovedDestroy(OnInterfaceRemovedDelegateWrapper wrapper, GClosure* closure) 211 { 212 wrapper.outer.internalRemoveOnInterfaceRemoved(wrapper); 213 } 214 215 protected void internalRemoveOnInterfaceRemoved(OnInterfaceRemovedDelegateWrapper source) 216 { 217 foreach(index, wrapper; onInterfaceRemovedListeners) 218 { 219 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 220 { 221 onInterfaceRemovedListeners[index] = null; 222 onInterfaceRemovedListeners = std.algorithm.remove(onInterfaceRemovedListeners, index); 223 break; 224 } 225 } 226 } 227 228 }