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