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