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