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