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  * Conversion parameters:
26  * inFile  = GstTask.html
27  * outPack = gstreamer
28  * outFile = Task
29  * strct   = GstTask
30  * realStrct=
31  * ctorStrct=
32  * clss    = Task
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_task_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gthread.RecMutex
48  * 	- gthread.Thread
49  * 	- gstreamer.TaskPool
50  * structWrap:
51  * 	- GRecMutex* -> RecMutex
52  * 	- GThread* -> Thread
53  * 	- GstTaskPool* -> TaskPool
54  * module aliases:
55  * local aliases:
56  * overrides:
57  */
58 
59 module gstreamer.Task;
60 
61 public  import gstreamerc.gstreamertypes;
62 
63 private import gstreamerc.gstreamer;
64 private import glib.ConstructionException;
65 private import gobject.ObjectG;
66 
67 
68 private import glib.Str;
69 private import gthread.RecMutex;
70 private import gthread.Thread;
71 private import gstreamer.TaskPool;
72 
73 
74 
75 private import gstreamer.ObjectGst;
76 
77 /**
78  * GstTask is used by GstElement and GstPad to provide the data passing
79  * threads in a GstPipeline.
80  *
81  * A GstPad will typically start a GstTask to push or pull data to/from the
82  * peer pads. Most source elements start a GstTask to push data. In some cases
83  * a demuxer element can start a GstTask to pull data from a peer element. This
84  * is typically done when the demuxer can perform random access on the upstream
85  * peer element for improved performance.
86  *
87  * Although convenience functions exist on GstPad to start/pause/stop tasks, it
88  * might sometimes be needed to create a GstTask manually if it is not related to
89  * a GstPad.
90  *
91  * Before the GstTask can be run, it needs a GRecMutex that can be set with
92  * gst_task_set_lock().
93  *
94  * The task can be started, paused and stopped with gst_task_start(), gst_task_pause()
95  * and gst_task_stop() respectively or with the gst_task_set_state() function.
96  *
97  * A GstTask will repeatedly call the GstTaskFunction with the user data
98  * that was provided when creating the task with gst_task_new(). While calling
99  * the function it will acquire the provided lock. The provided lock is released
100  * when the task pauses or stops.
101  *
102  * Stopping a task with gst_task_stop() will not immediately make sure the task is
103  * not running anymore. Use gst_task_join() to make sure the task is completely
104  * stopped and the thread is stopped.
105  *
106  * After creating a GstTask, use gst_object_unref() to free its resources. This can
107  * only be done when the task is not running anymore.
108  *
109  * Task functions can send a GstMessage to send out-of-band data to the
110  * application. The application can receive messages from the GstBus in its
111  * mainloop.
112  *
113  * For debugging purposes, the task will configure its object name as the thread
114  * name on Linux. Please note that the object name should be configured before the
115  * task is started; changing the object name after the task has been started, has
116  * no effect on the thread name.
117  *
118  * Last reviewed on 2012-03-29 (0.11.3)
119  */
120 public class Task : ObjectGst
121 {
122 	
123 	/** the main Gtk struct */
124 	protected GstTask* gstTask;
125 	
126 	
127 	public GstTask* getTaskStruct()
128 	{
129 		return gstTask;
130 	}
131 	
132 	
133 	/** the main Gtk struct as a void* */
134 	protected override void* getStruct()
135 	{
136 		return cast(void*)gstTask;
137 	}
138 	
139 	/**
140 	 * Sets our main struct and passes it to the parent class
141 	 */
142 	public this (GstTask* gstTask)
143 	{
144 		super(cast(GstObject*)gstTask);
145 		this.gstTask = gstTask;
146 	}
147 	
148 	protected override void setStruct(GObject* obj)
149 	{
150 		super.setStruct(obj);
151 		gstTask = cast(GstTask*)obj;
152 	}
153 	
154 	/**
155 	 */
156 	
157 	/**
158 	 * Create a new Task that will repeatedly call the provided func
159 	 * with user_data as a parameter. Typically the task will run in
160 	 * a new thread.
161 	 * The function cannot be changed after the task has been created. You
162 	 * must create a new GstTask to change the function.
163 	 * This function will not yet create and start a thread. Use gst_task_start() or
164 	 * gst_task_pause() to create and start the GThread.
165 	 * Before the task can be used, a GRecMutex must be configured using the
166 	 * gst_task_set_lock() function. This lock will always be acquired while
167 	 * func is called.
168 	 * Params:
169 	 * func = The GstTaskFunction to use
170 	 * userData = User data to pass to func
171 	 * notify = the function to call when user_data is no longer needed.
172 	 * Throws: ConstructionException GTK+ fails to create the object.
173 	 */
174 	public this (GstTaskFunction func, void* userData, GDestroyNotify notify)
175 	{
176 		// GstTask * gst_task_new (GstTaskFunction func,  gpointer user_data,  GDestroyNotify notify);
177 		auto p = gst_task_new(func, userData, notify);
178 		if(p is null)
179 		{
180 			throw new ConstructionException("null returned by gst_task_new(func, userData, notify)");
181 		}
182 		this(cast(GstTask*) p);
183 	}
184 	
185 	/**
186 	 * Set the mutex used by the task. The mutex will be acquired before
187 	 * calling the GstTaskFunction.
188 	 * This function has to be called before calling gst_task_pause() or
189 	 * gst_task_start().
190 	 * MT safe.
191 	 * Params:
192 	 * mutex = The GRecMutex to use
193 	 */
194 	public void setLock(RecMutex mutex)
195 	{
196 		// void gst_task_set_lock (GstTask *task,  GRecMutex *mutex);
197 		gst_task_set_lock(gstTask, (mutex is null) ? null : mutex.getRecMutexStruct());
198 	}
199 	
200 	/**
201 	 * Set pool as the new GstTaskPool for task. Any new streaming threads that
202 	 * will be created by task will now use pool.
203 	 * MT safe.
204 	 * Params:
205 	 * pool = a GstTaskPool. [transfer none]
206 	 */
207 	public void setPool(TaskPool pool)
208 	{
209 		// void gst_task_set_pool (GstTask *task,  GstTaskPool *pool);
210 		gst_task_set_pool(gstTask, (pool is null) ? null : pool.getTaskPoolStruct());
211 	}
212 	
213 	/**
214 	 * Get the GstTaskPool that this task will use for its streaming
215 	 * threads.
216 	 * MT safe.
217 	 * Returns: the GstTaskPool used by task. gst_object_unref() after usage. [transfer full]
218 	 */
219 	public TaskPool getPool()
220 	{
221 		// GstTaskPool * gst_task_get_pool (GstTask *task);
222 		auto p = gst_task_get_pool(gstTask);
223 		
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 		
229 		return ObjectG.getDObject!(TaskPool)(cast(GstTaskPool*) p);
230 	}
231 	
232 	/**
233 	 * Call enter_func when the task function of task is entered. user_data will
234 	 * be passed to enter_func and notify will be called when user_data is no
235 	 * longer referenced.
236 	 * Params:
237 	 * enterFunc = a GstTaskThreadFunc. [in]
238 	 * userData = user data passed to enter_func
239 	 * notify = called when user_data is no longer referenced
240 	 */
241 	public void setEnterCallback(GstTaskThreadFunc enterFunc, void* userData, GDestroyNotify notify)
242 	{
243 		// void gst_task_set_enter_callback (GstTask *task,  GstTaskThreadFunc enter_func,  gpointer user_data,  GDestroyNotify notify);
244 		gst_task_set_enter_callback(gstTask, enterFunc, userData, notify);
245 	}
246 	
247 	/**
248 	 * Call leave_func when the task function of task is left. user_data will
249 	 * be passed to leave_func and notify will be called when user_data is no
250 	 * longer referenced.
251 	 * Params:
252 	 * leaveFunc = a GstTaskThreadFunc. [in]
253 	 * userData = user data passed to leave_func
254 	 * notify = called when user_data is no longer referenced
255 	 */
256 	public void setLeaveCallback(GstTaskThreadFunc leaveFunc, void* userData, GDestroyNotify notify)
257 	{
258 		// void gst_task_set_leave_callback (GstTask *task,  GstTaskThreadFunc leave_func,  gpointer user_data,  GDestroyNotify notify);
259 		gst_task_set_leave_callback(gstTask, leaveFunc, userData, notify);
260 	}
261 	
262 	/**
263 	 * Get the current state of the task.
264 	 * Returns: The GstTaskState of the task MT safe.
265 	 */
266 	public GstTaskState getState()
267 	{
268 		// GstTaskState gst_task_get_state (GstTask *task);
269 		return gst_task_get_state(gstTask);
270 	}
271 	
272 	/**
273 	 * Sets the state of task to state.
274 	 * The task must have a lock associated with it using
275 	 * gst_task_set_lock() when going to GST_TASK_STARTED or GST_TASK_PAUSED or
276 	 * this function will return FALSE.
277 	 * MT safe.
278 	 * Params:
279 	 * state = the new task state
280 	 * Returns: TRUE if the state could be changed.
281 	 */
282 	public int setState(GstTaskState state)
283 	{
284 		// gboolean gst_task_set_state (GstTask *task,  GstTaskState state);
285 		return gst_task_set_state(gstTask, state);
286 	}
287 	
288 	/**
289 	 * Pauses task. This method can also be called on a task in the
290 	 * stopped state, in which case a thread will be started and will remain
291 	 * in the paused state. This function does not wait for the task to complete
292 	 * the paused state.
293 	 * Returns: TRUE if the task could be paused. MT safe.
294 	 */
295 	public int pause()
296 	{
297 		// gboolean gst_task_pause (GstTask *task);
298 		return gst_task_pause(gstTask);
299 	}
300 	
301 	/**
302 	 * Starts task. The task must have a lock associated with it using
303 	 * gst_task_set_lock() or this function will return FALSE.
304 	 * Returns: TRUE if the task could be started. MT safe.
305 	 */
306 	public int start()
307 	{
308 		// gboolean gst_task_start (GstTask *task);
309 		return gst_task_start(gstTask);
310 	}
311 	
312 	/**
313 	 * Stops task. This method merely schedules the task to stop and
314 	 * will not wait for the task to have completely stopped. Use
315 	 * gst_task_join() to stop and wait for completion.
316 	 * Returns: TRUE if the task could be stopped. MT safe.
317 	 */
318 	public int stop()
319 	{
320 		// gboolean gst_task_stop (GstTask *task);
321 		return gst_task_stop(gstTask);
322 	}
323 	
324 	/**
325 	 * Joins task. After this call, it is safe to unref the task
326 	 * and clean up the lock set with gst_task_set_lock().
327 	 * The task will automatically be stopped with this call.
328 	 * This function cannot be called from within a task function as this
329 	 * would cause a deadlock. The function will detect this and print a
330 	 * g_warning.
331 	 * Returns: TRUE if the task could be joined. MT safe.
332 	 */
333 	public int join()
334 	{
335 		// gboolean gst_task_join (GstTask *task);
336 		return gst_task_join(gstTask);
337 	}
338 	
339 	/**
340 	 * Wait for all tasks to be stopped. This is mainly used internally
341 	 * to ensure proper cleanup of internal data structures in test suites.
342 	 * MT safe.
343 	 */
344 	public static void cleanupAll()
345 	{
346 		// void gst_task_cleanup_all (void);
347 		gst_task_cleanup_all();
348 	}
349 }