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