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  * 	- gst_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- gthread.StaticRecMutex
49  * structWrap:
50  * 	- GStaticRecMutex* -> StaticRecMutex
51  * 	- GstTask* -> Task
52  * module aliases:
53  * local aliases:
54  * overrides:
55  */
56 
57 module gstreamer.Task;
58 
59 public  import gstreamerc.gstreamertypes;
60 
61 private import gstreamerc.gstreamer;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 
66 private import glib.Str;
67 private import gthread.StaticRecMutex;
68 
69 
70 
71 private import gstreamer.ObjectGst;
72 
73 /**
74  * Description
75  * GstTask is used by GstElement and GstPad to provide the data passing
76  * threads in a GstPipeline.
77  * A GstPad will typically start a GstTask to push or pull data to/from the
78  * peer pads. Most source elements start a GstTask to push data. In some cases
79  * a demuxer element can start a GstTask to pull data from a peer element. This
80  * is typically done when the demuxer can perform random access on the upstream
81  * peer element for improved performance.
82  * Although convenience functions exist on GstPad to start/pause/stop tasks, it
83  * might sometimes be needed to create a GstTask manually if it is not related to
84  * a GstPad.
85  * Before the GstTask can be run, it needs a GStaticRecMutex that can be set with
86  * gst_task_set_lock().
87  * The task can be started, paused and stopped with gst_task_start(), gst_task_pause()
88  * and gst_task_stop() respectively.
89  * A GstTask will repeadedly call the GstTaskFunction with the user data
90  * that was provided when creating the task with gst_task_create(). Before calling
91  * the function it will acquire the provided lock.
92  * Stopping a task with gst_task_stop() will not immediatly make sure the task is
93  * not running anymore. Use gst_task_join() to make sure the task is completely
94  * stopped and the thread is stopped.
95  * After creating a GstTask, use gst_object_unref() to free its resources. This can
96  * only be done it the task is not running anymore.
97  * Last reviewed on 2006-02-13 (0.10.4)
98  */
99 public class Task : ObjectGst
100 {
101 	
102 	/** the main Gtk struct */
103 	protected GstTask* gstTask;
104 	
105 	
106 	public GstTask* getTaskStruct()
107 	{
108 		return gstTask;
109 	}
110 	
111 	
112 	/** the main Gtk struct as a void* */
113 	protected override void* getStruct()
114 	{
115 		return cast(void*)gstTask;
116 	}
117 	
118 	/**
119 	 * Sets our main struct and passes it to the parent class
120 	 */
121 	public this (GstTask* gstTask)
122 	{
123 		super(cast(GstObject*)gstTask);
124 		this.gstTask = gstTask;
125 	}
126 	
127 	protected override void setStruct(GObject* obj)
128 	{
129 		super.setStruct(obj);
130 		gstTask = cast(GstTask*)obj;
131 	}
132 	
133 	/**
134 	 */
135 	
136 	/**
137 	 * Wait for all tasks to be stopped. This is mainly used internally
138 	 * to ensure proper cleanup of internal datastructures in testsuites.
139 	 * MT safe.
140 	 */
141 	public static void cleanupAll()
142 	{
143 		// void gst_task_cleanup_all (void);
144 		gst_task_cleanup_all();
145 	}
146 	
147 	/**
148 	 * Create a new Task that will repeadedly call the provided func
149 	 * with data as a parameter. Typically the task will run in
150 	 * a new thread.
151 	 * The function cannot be changed after the task has been created. You
152 	 * must create a new GstTask to change the function.
153 	 * Params:
154 	 * func = The GstTaskFunction to use
155 	 * data = User data to pass to func
156 	 * Returns: A new GstTask. MT safe.
157 	 */
158 	public static Task create(GstTaskFunction func, void* data)
159 	{
160 		// GstTask* gst_task_create (GstTaskFunction func,  gpointer data);
161 		auto p = gst_task_create(func, data);
162 		
163 		if(p is null)
164 		{
165 			return null;
166 		}
167 		
168 		return ObjectG.getDObject!(Task)(cast(GstTask*) p);
169 	}
170 	
171 	/**
172 	 * Get the current state of the task.
173 	 * Returns: The GstTaskState of the task MT safe.
174 	 */
175 	public GstTaskState getState()
176 	{
177 		// GstTaskState gst_task_get_state (GstTask *task);
178 		return gst_task_get_state(gstTask);
179 	}
180 	
181 	/**
182 	 * Joins task. After this call, it is safe to unref the task
183 	 * and clean up the lock set with gst_task_set_lock().
184 	 * The task will automatically be stopped with this call.
185 	 * This function cannot be called from within a task function as this
186 	 * would cause a deadlock. The function will detect this and print a
187 	 * g_warning.
188 	 * Returns: TRUE if the task could be joined. MT safe.
189 	 */
190 	public int join()
191 	{
192 		// gboolean gst_task_join (GstTask *task);
193 		return gst_task_join(gstTask);
194 	}
195 	
196 	/**
197 	 * Pauses task. This method can also be called on a task in the
198 	 * stopped state, in which case a thread will be started and will remain
199 	 * in the paused state. This function does not wait for the task to complete
200 	 * the paused state.
201 	 * Returns: TRUE if the task could be paused. MT safe.
202 	 */
203 	public int pause()
204 	{
205 		// gboolean gst_task_pause (GstTask *task);
206 		return gst_task_pause(gstTask);
207 	}
208 	
209 	/**
210 	 * Set the mutex used by the task. The mutex will be acquired before
211 	 * calling the GstTaskFunction.
212 	 * This function has to be called before calling gst_task_pause() or
213 	 * gst_task_start().
214 	 * MT safe.
215 	 * Params:
216 	 * mutex = The GMutex to use
217 	 */
218 	public void setLock(StaticRecMutex mutex)
219 	{
220 		// void gst_task_set_lock (GstTask *task,  GStaticRecMutex *mutex);
221 		gst_task_set_lock(gstTask, (mutex is null) ? null : mutex.getStaticRecMutexStruct());
222 	}
223 	
224 	/**
225 	 * Starts task. The task must have a lock associated with it using
226 	 * gst_task_set_lock() or thsi function will return FALSE.
227 	 * Returns: TRUE if the task could be started. MT safe.
228 	 */
229 	public int start()
230 	{
231 		// gboolean gst_task_start (GstTask *task);
232 		return gst_task_start(gstTask);
233 	}
234 	
235 	/**
236 	 * Stops task. This method merely schedules the task to stop and
237 	 * will not wait for the task to have completely stopped. Use
238 	 * gst_task_join() to stop and wait for completion.
239 	 * Returns: TRUE if the task could be stopped. MT safe.
240 	 */
241 	public int stop()
242 	{
243 		// gboolean gst_task_stop (GstTask *task);
244 		return gst_task_stop(gstTask);
245 	}
246 }