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 	public static GType getType()
77 	{
78 		return gst_task_pool_get_type();
79 	}
80 
81 	/**
82 	 * Create a new default task pool. The default task pool will use a regular
83 	 * GThreadPool for threads.
84 	 *
85 	 * Returns: a new #GstTaskPool. gst_object_unref() after usage.
86 	 *
87 	 * Throws: ConstructionException GTK+ fails to create the object.
88 	 */
89 	public this()
90 	{
91 		auto p = gst_task_pool_new();
92 		
93 		if(p is null)
94 		{
95 			throw new ConstructionException("null returned by new");
96 		}
97 		
98 		this(cast(GstTaskPool*) p, true);
99 	}
100 
101 	/**
102 	 * Wait for all tasks to be stopped. This is mainly used internally
103 	 * to ensure proper cleanup of internal data structures in test suites.
104 	 *
105 	 * MT safe.
106 	 */
107 	public void cleanup()
108 	{
109 		gst_task_pool_cleanup(gstTaskPool);
110 	}
111 
112 	/**
113 	 * Join a task and/or return it to the pool. @id is the id obtained from
114 	 * gst_task_pool_push().
115 	 *
116 	 * Params:
117 	 *     id = the id
118 	 */
119 	public void join(void* id)
120 	{
121 		gst_task_pool_join(gstTaskPool, id);
122 	}
123 
124 	/**
125 	 * Prepare the taskpool for accepting gst_task_pool_push() operations.
126 	 *
127 	 * MT safe.
128 	 *
129 	 * Throws: GException on failure.
130 	 */
131 	public void prepare()
132 	{
133 		GError* err = null;
134 		
135 		gst_task_pool_prepare(gstTaskPool, &err);
136 		
137 		if (err !is null)
138 		{
139 			throw new GException( new ErrorG(err) );
140 		}
141 	}
142 
143 	/**
144 	 * Start the execution of a new thread from @pool.
145 	 *
146 	 * Params:
147 	 *     func = the function to call
148 	 *     userData = data to pass to @func
149 	 *
150 	 * Returns: a pointer that should be used
151 	 *     for the gst_task_pool_join function. This pointer can be %NULL, you
152 	 *     must check @error to detect errors.
153 	 *
154 	 * Throws: GException on failure.
155 	 */
156 	public void* push(GstTaskPoolFunction func, void* userData)
157 	{
158 		GError* err = null;
159 		
160 		auto p = gst_task_pool_push(gstTaskPool, func, userData, &err);
161 		
162 		if (err !is null)
163 		{
164 			throw new GException( new ErrorG(err) );
165 		}
166 		
167 		return p;
168 	}
169 }