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