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 gstreamer.ChildProxyT; 26 27 public import glib.Str; 28 public import gobject.ObjectG; 29 public import gobject.ParamSpec; 30 public import gobject.Signals; 31 public import gobject.Value; 32 public import gstreamer.c.functions; 33 public import gstreamer.c.types; 34 public import gstreamerc.gstreamertypes; 35 public import std.algorithm; 36 37 38 /** 39 * This interface abstracts handling of property sets for elements with 40 * children. Imagine elements such as mixers or polyphonic generators. They all 41 * have multiple #GstPad or some kind of voice objects. Another use case are 42 * container elements like #GstBin. 43 * The element implementing the interface acts as a parent for those child 44 * objects. 45 * 46 * By implementing this interface the child properties can be accessed from the 47 * parent element by using gst_child_proxy_get() and gst_child_proxy_set(). 48 * 49 * Property names are written as "child-name::property-name". The whole naming 50 * scheme is recursive. Thus "child1::child2::property" is valid too, if 51 * "child1" and "child2" implement the #GstChildProxy interface. 52 */ 53 public template ChildProxyT(TStruct) 54 { 55 /** Get the main Gtk struct */ 56 public GstChildProxy* getChildProxyStruct(bool transferOwnership = false) 57 { 58 if (transferOwnership) 59 ownedRef = false; 60 return cast(GstChildProxy*)getStruct(); 61 } 62 63 64 /** 65 * Emits the "child-added" signal. 66 * 67 * Params: 68 * child = the newly added child 69 * name = the name of the new child 70 */ 71 public void childAdded(ObjectG child, string name) 72 { 73 gst_child_proxy_child_added(getChildProxyStruct(), (child is null) ? null : child.getObjectGStruct(), Str.toStringz(name)); 74 } 75 76 /** 77 * Emits the "child-removed" signal. 78 * 79 * Params: 80 * child = the removed child 81 * name = the name of the old child 82 */ 83 public void childRemoved(ObjectG child, string name) 84 { 85 gst_child_proxy_child_removed(getChildProxyStruct(), (child is null) ? null : child.getObjectGStruct(), Str.toStringz(name)); 86 } 87 88 /** 89 * Fetches a child by its number. 90 * 91 * Params: 92 * index = the child's position in the child list 93 * 94 * Returns: the child object or %NULL if 95 * not found (index too high). Unref after usage. 96 * 97 * MT safe. 98 */ 99 public ObjectG getChildByIndex(uint index) 100 { 101 auto p = gst_child_proxy_get_child_by_index(getChildProxyStruct(), index); 102 103 if(p is null) 104 { 105 return null; 106 } 107 108 return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true); 109 } 110 111 /** 112 * Looks up a child element by the given name. 113 * 114 * This virtual method has a default implementation that uses #GstObject 115 * together with gst_object_get_name(). If the interface is to be used with 116 * #GObjects, this methods needs to be overridden. 117 * 118 * Params: 119 * name = the child's name 120 * 121 * Returns: the child object or %NULL if 122 * not found. Unref after usage. 123 * 124 * MT safe. 125 */ 126 public ObjectG getChildByName(string name) 127 { 128 auto p = gst_child_proxy_get_child_by_name(getChildProxyStruct(), Str.toStringz(name)); 129 130 if(p is null) 131 { 132 return null; 133 } 134 135 return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true); 136 } 137 138 /** 139 * Gets the number of child objects this parent contains. 140 * 141 * Returns: the number of child objects 142 * 143 * MT safe. 144 */ 145 public uint getChildrenCount() 146 { 147 return gst_child_proxy_get_children_count(getChildProxyStruct()); 148 } 149 150 /** 151 * Gets a single property using the GstChildProxy mechanism. 152 * You are responsible for freeing it by calling g_value_unset() 153 * 154 * Params: 155 * name = name of the property 156 * value = a #GValue that should take the result. 157 */ 158 public void childGetProperty(string name, out Value value) 159 { 160 GValue* outvalue = gMalloc!GValue(); 161 162 gst_child_proxy_get_property(getChildProxyStruct(), Str.toStringz(name), outvalue); 163 164 value = ObjectG.getDObject!(Value)(outvalue, true); 165 } 166 167 /** 168 * Gets properties of the parent object and its children. 169 * 170 * Params: 171 * firstPropertyName = name of the first property to get 172 * varArgs = return location for the first property, followed optionally by more name/return location pairs, followed by %NULL 173 */ 174 public void childGetValist(string firstPropertyName, void* varArgs) 175 { 176 gst_child_proxy_get_valist(getChildProxyStruct(), Str.toStringz(firstPropertyName), varArgs); 177 } 178 179 /** 180 * Looks up which object and #GParamSpec would be effected by the given @name. 181 * 182 * MT safe. 183 * 184 * Params: 185 * name = name of the property to look up 186 * target = pointer to a #GObject that 187 * takes the real object to set property on 188 * pspec = pointer to take the #GParamSpec 189 * describing the property 190 * 191 * Returns: %TRUE if @target and @pspec could be found. %FALSE otherwise. In that 192 * case the values for @pspec and @target are not modified. Unref @target after 193 * usage. For plain GObjects @target is the same as @object. 194 */ 195 public bool lookup(string name, out ObjectG target, out ParamSpec pspec) 196 { 197 GObject* outtarget = null; 198 GParamSpec* outpspec = null; 199 200 auto p = gst_child_proxy_lookup(getChildProxyStruct(), Str.toStringz(name), &outtarget, &outpspec) != 0; 201 202 target = ObjectG.getDObject!(ObjectG)(outtarget); 203 pspec = ObjectG.getDObject!(ParamSpec)(outpspec); 204 205 return p; 206 } 207 208 /** 209 * Sets a single property using the GstChildProxy mechanism. 210 * 211 * Params: 212 * name = name of the property to set 213 * value = new #GValue for the property 214 */ 215 public void childSetProperty(string name, Value value) 216 { 217 gst_child_proxy_set_property(getChildProxyStruct(), Str.toStringz(name), (value is null) ? null : value.getValueStruct()); 218 } 219 220 /** 221 * Sets properties of the parent object and its children. 222 * 223 * Params: 224 * firstPropertyName = name of the first property to set 225 * varArgs = value for the first property, followed optionally by more name/value pairs, followed by %NULL 226 */ 227 public void childSetValist(string firstPropertyName, void* varArgs) 228 { 229 gst_child_proxy_set_valist(getChildProxyStruct(), Str.toStringz(firstPropertyName), varArgs); 230 } 231 232 protected class OnChildAddedDelegateWrapper 233 { 234 void delegate(ObjectG, string, ChildProxyIF) dlg; 235 gulong handlerId; 236 237 this(void delegate(ObjectG, string, ChildProxyIF) dlg) 238 { 239 this.dlg = dlg; 240 onChildAddedListeners ~= this; 241 } 242 243 void remove(OnChildAddedDelegateWrapper source) 244 { 245 foreach(index, wrapper; onChildAddedListeners) 246 { 247 if (wrapper.handlerId == source.handlerId) 248 { 249 onChildAddedListeners[index] = null; 250 onChildAddedListeners = std.algorithm.remove(onChildAddedListeners, index); 251 break; 252 } 253 } 254 } 255 } 256 OnChildAddedDelegateWrapper[] onChildAddedListeners; 257 258 /** 259 * Will be emitted after the @object was added to the @child_proxy. 260 * 261 * Params: 262 * object = the #GObject that was added 263 * name = the name of the new child 264 */ 265 gulong addOnChildAdded(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 266 { 267 auto wrapper = new OnChildAddedDelegateWrapper(dlg); 268 wrapper.handlerId = Signals.connectData( 269 this, 270 "child-added", 271 cast(GCallback)&callBackChildAdded, 272 cast(void*)wrapper, 273 cast(GClosureNotify)&callBackChildAddedDestroy, 274 connectFlags); 275 return wrapper.handlerId; 276 } 277 278 extern(C) static void callBackChildAdded(GstChildProxy* childproxyStruct, GObject* object, char* name, OnChildAddedDelegateWrapper wrapper) 279 { 280 wrapper.dlg(ObjectG.getDObject!(ObjectG)(object), Str.toString(name), wrapper.outer); 281 } 282 283 extern(C) static void callBackChildAddedDestroy(OnChildAddedDelegateWrapper wrapper, GClosure* closure) 284 { 285 wrapper.remove(wrapper); 286 } 287 288 protected class OnChildRemovedDelegateWrapper 289 { 290 void delegate(ObjectG, string, ChildProxyIF) dlg; 291 gulong handlerId; 292 293 this(void delegate(ObjectG, string, ChildProxyIF) dlg) 294 { 295 this.dlg = dlg; 296 onChildRemovedListeners ~= this; 297 } 298 299 void remove(OnChildRemovedDelegateWrapper source) 300 { 301 foreach(index, wrapper; onChildRemovedListeners) 302 { 303 if (wrapper.handlerId == source.handlerId) 304 { 305 onChildRemovedListeners[index] = null; 306 onChildRemovedListeners = std.algorithm.remove(onChildRemovedListeners, index); 307 break; 308 } 309 } 310 } 311 } 312 OnChildRemovedDelegateWrapper[] onChildRemovedListeners; 313 314 /** 315 * Will be emitted after the @object was removed from the @child_proxy. 316 * 317 * Params: 318 * object = the #GObject that was removed 319 * name = the name of the old child 320 */ 321 gulong addOnChildRemoved(void delegate(ObjectG, string, ChildProxyIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 322 { 323 auto wrapper = new OnChildRemovedDelegateWrapper(dlg); 324 wrapper.handlerId = Signals.connectData( 325 this, 326 "child-removed", 327 cast(GCallback)&callBackChildRemoved, 328 cast(void*)wrapper, 329 cast(GClosureNotify)&callBackChildRemovedDestroy, 330 connectFlags); 331 return wrapper.handlerId; 332 } 333 334 extern(C) static void callBackChildRemoved(GstChildProxy* childproxyStruct, GObject* object, char* name, OnChildRemovedDelegateWrapper wrapper) 335 { 336 wrapper.dlg(ObjectG.getDObject!(ObjectG)(object), Str.toString(name), wrapper.outer); 337 } 338 339 extern(C) static void callBackChildRemovedDestroy(OnChildRemovedDelegateWrapper wrapper, GClosure* closure) 340 { 341 wrapper.remove(wrapper); 342 } 343 }