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.TaskPool; 26 27 private import glib.ConstructionException; 28 private import glib.ErrorG; 29 private import glib.GException; 30 private import gobject.ObjectG; 31 private import gstreamer.ObjectGst; 32 private import gstreamer.c.functions; 33 public import gstreamer.c.types; 34 public import gstreamerc.gstreamertypes; 35 36 37 /** 38 * This object provides an abstraction for creating threads. The default 39 * implementation uses a regular GThreadPool to start tasks. 40 * 41 * Subclasses can be made to create custom threads. 42 */ 43 public class TaskPool : ObjectGst 44 { 45 /** the main Gtk struct */ 46 protected GstTaskPool* gstTaskPool; 47 48 /** Get the main Gtk struct */ 49 public GstTaskPool* getTaskPoolStruct(bool transferOwnership = false) 50 { 51 if (transferOwnership) 52 ownedRef = false; 53 return gstTaskPool; 54 } 55 56 /** the main Gtk struct as a void* */ 57 protected override void* getStruct() 58 { 59 return cast(void*)gstTaskPool; 60 } 61 62 protected override void setStruct(GObject* obj) 63 { 64 gstTaskPool = cast(GstTaskPool*)obj; 65 super.setStruct(obj); 66 } 67 68 /** 69 * Sets our main struct and passes it to the parent class. 70 */ 71 public this (GstTaskPool* gstTaskPool, bool ownedRef = false) 72 { 73 this.gstTaskPool = gstTaskPool; 74 super(cast(GstObject*)gstTaskPool, ownedRef); 75 } 76 77 78 /** */ 79 public static GType getType() 80 { 81 return gst_task_pool_get_type(); 82 } 83 84 /** 85 * Create a new default task pool. The default task pool will use a regular 86 * GThreadPool for threads. 87 * 88 * Returns: a new #GstTaskPool. gst_object_unref() after usage. 89 * 90 * Throws: ConstructionException GTK+ fails to create the object. 91 */ 92 public this() 93 { 94 auto p = gst_task_pool_new(); 95 96 if(p is null) 97 { 98 throw new ConstructionException("null returned by new"); 99 } 100 101 this(cast(GstTaskPool*) p, true); 102 } 103 104 /** 105 * Wait for all tasks to be stopped. This is mainly used internally 106 * to ensure proper cleanup of internal data structures in test suites. 107 * 108 * MT safe. 109 */ 110 public void cleanup() 111 { 112 gst_task_pool_cleanup(gstTaskPool); 113 } 114 115 /** 116 * Join a task and/or return it to the pool. @id is the id obtained from 117 * gst_task_pool_push(). 118 * 119 * Params: 120 * id = the id 121 */ 122 public void join(void* id) 123 { 124 gst_task_pool_join(gstTaskPool, id); 125 } 126 127 /** 128 * Prepare the taskpool for accepting gst_task_pool_push() operations. 129 * 130 * MT safe. 131 * 132 * Throws: GException on failure. 133 */ 134 public void prepare() 135 { 136 GError* err = null; 137 138 gst_task_pool_prepare(gstTaskPool, &err); 139 140 if (err !is null) 141 { 142 throw new GException( new ErrorG(err) ); 143 } 144 } 145 146 /** 147 * Start the execution of a new thread from @pool. 148 * 149 * Params: 150 * func = the function to call 151 * userData = data to pass to @func 152 * 153 * Returns: a pointer that should be used 154 * for the gst_task_pool_join function. This pointer can be %NULL, you 155 * must check @error to detect errors. 156 * 157 * Throws: GException on failure. 158 */ 159 public void* push(GstTaskPoolFunction func, void* userData) 160 { 161 GError* err = null; 162 163 auto p = gst_task_pool_push(gstTaskPool, func, userData, &err); 164 165 if (err !is null) 166 { 167 throw new GException( new ErrorG(err) ); 168 } 169 170 return p; 171 } 172 }