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.DeviceProvider;
26 
27 private import glib.ListG;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gstreamer.Bus;
32 private import gstreamer.Device;
33 private import gstreamer.DeviceProviderFactory;
34 private import gstreamer.ObjectGst;
35 private import gstreamer.Plugin;
36 private import gstreamerc.gstreamer;
37 public  import gstreamerc.gstreamertypes;
38 public  import gtkc.gdktypes;
39 private import std.algorithm;
40 
41 
42 /**
43  * A #GstDeviceProvider subclass is provided by a plugin that handles devices
44  * if there is a way to programatically list connected devices. It can also
45  * optionally provide updates to the list of connected devices.
46  * 
47  * Each #GstDeviceProvider subclass is a singleton, a plugin should
48  * normally provide a single subclass for all devices.
49  * 
50  * Applications would normally use a #GstDeviceMonitor to monitor devices
51  * from all relevant providers.
52  *
53  * Since: 1.4
54  */
55 public class DeviceProvider : ObjectGst
56 {
57 	/** the main Gtk struct */
58 	protected GstDeviceProvider* gstDeviceProvider;
59 
60 	/** Get the main Gtk struct */
61 	public GstDeviceProvider* getDeviceProviderStruct()
62 	{
63 		return gstDeviceProvider;
64 	}
65 
66 	/** the main Gtk struct as a void* */
67 	protected override void* getStruct()
68 	{
69 		return cast(void*)gstDeviceProvider;
70 	}
71 
72 	protected override void setStruct(GObject* obj)
73 	{
74 		gstDeviceProvider = cast(GstDeviceProvider*)obj;
75 		super.setStruct(obj);
76 	}
77 
78 	/**
79 	 * Sets our main struct and passes it to the parent class.
80 	 */
81 	public this (GstDeviceProvider* gstDeviceProvider, bool ownedRef = false)
82 	{
83 		this.gstDeviceProvider = gstDeviceProvider;
84 		super(cast(GstObject*)gstDeviceProvider, ownedRef);
85 	}
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return gst_device_provider_get_type();
92 	}
93 
94 	/**
95 	 * Create a new device providerfactory capable of instantiating objects of the
96 	 * @type and add the factory to @plugin.
97 	 *
98 	 * Params:
99 	 *     plugin = #GstPlugin to register the device provider with, or %NULL for
100 	 *         a static device provider.
101 	 *     name = name of device providers of this type
102 	 *     rank = rank of device provider (higher rank means more importance when autoplugging)
103 	 *     type = GType of device provider to register
104 	 *
105 	 * Return: %TRUE, if the registering succeeded, %FALSE on error
106 	 *
107 	 * Since: 1.4
108 	 */
109 	public static bool register(Plugin plugin, string name, uint rank, GType type)
110 	{
111 		return gst_device_provider_register((plugin is null) ? null : plugin.getPluginStruct(), Str.toStringz(name), rank, type) != 0;
112 	}
113 
114 	/** */
115 	public bool canMonitor()
116 	{
117 		return gst_device_provider_can_monitor(gstDeviceProvider) != 0;
118 	}
119 
120 	/**
121 	 * Posts a message on the provider's #GstBus to inform applications that
122 	 * a new device has been added.
123 	 *
124 	 * This is for use by subclasses.
125 	 *
126 	 * Params:
127 	 *     device = a #GstDevice that has been added
128 	 *
129 	 * Since: 1.4
130 	 */
131 	public void deviceAdd(Device device)
132 	{
133 		gst_device_provider_device_add(gstDeviceProvider, (device is null) ? null : device.getDeviceStruct());
134 	}
135 
136 	/**
137 	 * Posts a message on the provider's #GstBus to inform applications that
138 	 * a device has been removed.
139 	 *
140 	 * This is for use by subclasses.
141 	 *
142 	 * Params:
143 	 *     device = a #GstDevice that has been removed
144 	 *
145 	 * Since: 1.4
146 	 */
147 	public void deviceRemove(Device device)
148 	{
149 		gst_device_provider_device_remove(gstDeviceProvider, (device is null) ? null : device.getDeviceStruct());
150 	}
151 
152 	/**
153 	 * Gets the #GstBus of this #GstDeviceProvider
154 	 *
155 	 * Return: a #GstBus
156 	 *
157 	 * Since: 1.4
158 	 */
159 	public Bus getBus()
160 	{
161 		auto p = gst_device_provider_get_bus(gstDeviceProvider);
162 		
163 		if(p is null)
164 		{
165 			return null;
166 		}
167 		
168 		return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true);
169 	}
170 
171 	/**
172 	 * Gets a list of devices that this provider understands. This may actually
173 	 * probe the hardware if the provider is not currently started.
174 	 *
175 	 * Return: a #GList of
176 	 *     #GstDevice
177 	 *
178 	 * Since: 1.4
179 	 */
180 	public ListG getDevices()
181 	{
182 		auto p = gst_device_provider_get_devices(gstDeviceProvider);
183 		
184 		if(p is null)
185 		{
186 			return null;
187 		}
188 		
189 		return new ListG(cast(GList*) p, true);
190 	}
191 
192 	/**
193 	 * Retrieves the factory that was used to create this device provider.
194 	 *
195 	 * Return: the #GstDeviceProviderFactory used for
196 	 *     creating this device provider. no refcounting is needed.
197 	 *
198 	 * Since: 1.4
199 	 */
200 	public DeviceProviderFactory getFactory()
201 	{
202 		auto p = gst_device_provider_get_factory(gstDeviceProvider);
203 		
204 		if(p is null)
205 		{
206 			return null;
207 		}
208 		
209 		return ObjectG.getDObject!(DeviceProviderFactory)(cast(GstDeviceProviderFactory*) p);
210 	}
211 
212 	/**
213 	 * Get the provider factory names of the #GstDeviceProvider instances that
214 	 * are hidden by @provider.
215 	 *
216 	 * Return: a list of hidden providers factory names or %NULL when
217 	 *     nothing is hidden by @provider. Free with g_strfreev.
218 	 *
219 	 * Since: 1.6
220 	 */
221 	public string[] getHiddenProviders()
222 	{
223 		auto retStr = gst_device_provider_get_hidden_providers(gstDeviceProvider);
224 		
225 		scope(exit) Str.freeStringArray(retStr);
226 		return Str.toStringArray(retStr);
227 	}
228 
229 	/**
230 	 * Make @provider hide the devices from the factory with @name.
231 	 *
232 	 * This function is used when @provider will also provide the devices reported
233 	 * by provider factory @name. A monitor should stop monitoring the
234 	 * device provider with @name to avoid duplicate devices.
235 	 *
236 	 * Params:
237 	 *     name = a provider factory name
238 	 *
239 	 * Since: 1.6
240 	 */
241 	public void hideProvider(string name)
242 	{
243 		gst_device_provider_hide_provider(gstDeviceProvider, Str.toStringz(name));
244 	}
245 
246 	/**
247 	 * Starts providering the devices. This will cause #GST_MESSAGE_DEVICE_ADDED
248 	 * and #GST_MESSAGE_DEVICE_REMOVED messages to be posted on the provider's bus
249 	 * when devices are added or removed from the system.
250 	 *
251 	 * Since the #GstDeviceProvider is a singleton,
252 	 * gst_device_provider_start() may already have been called by another
253 	 * user of the object, gst_device_provider_stop() needs to be called the same
254 	 * number of times.
255 	 *
256 	 * Return: %TRUE if the device providering could be started
257 	 *
258 	 * Since: 1.4
259 	 */
260 	public bool start()
261 	{
262 		return gst_device_provider_start(gstDeviceProvider) != 0;
263 	}
264 
265 	/**
266 	 * Decreases the use-count by one. If the use count reaches zero, this
267 	 * #GstDeviceProvider will stop providering the devices. This needs to be
268 	 * called the same number of times that gst_device_provider_start() was called.
269 	 *
270 	 * Since: 1.4
271 	 */
272 	public void stop()
273 	{
274 		gst_device_provider_stop(gstDeviceProvider);
275 	}
276 
277 	/**
278 	 * Make @provider unhide the devices from factory @name.
279 	 *
280 	 * This function is used when @provider will no longer provide the devices
281 	 * reported by provider factory @name. A monitor should start
282 	 * monitoring the devices from provider factory @name in order to see
283 	 * all devices again.
284 	 *
285 	 * Params:
286 	 *     name = a provider factory name
287 	 *
288 	 * Since: 1.6
289 	 */
290 	public void unhideProvider(string name)
291 	{
292 		gst_device_provider_unhide_provider(gstDeviceProvider, Str.toStringz(name));
293 	}
294 
295 	protected class OnProviderHiddenDelegateWrapper
296 	{
297 		void delegate(string, DeviceProvider) dlg;
298 		gulong handlerId;
299 		ConnectFlags flags;
300 		this(void delegate(string, DeviceProvider) dlg, gulong handlerId, ConnectFlags flags)
301 		{
302 			this.dlg = dlg;
303 			this.handlerId = handlerId;
304 			this.flags = flags;
305 		}
306 	}
307 	protected OnProviderHiddenDelegateWrapper[] onProviderHiddenListeners;
308 
309 	/** */
310 	gulong addOnProviderHidden(void delegate(string, DeviceProvider) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
311 	{
312 		onProviderHiddenListeners ~= new OnProviderHiddenDelegateWrapper(dlg, 0, connectFlags);
313 		onProviderHiddenListeners[onProviderHiddenListeners.length - 1].handlerId = Signals.connectData(
314 			this,
315 			"provider-hidden",
316 			cast(GCallback)&callBackProviderHidden,
317 			cast(void*)onProviderHiddenListeners[onProviderHiddenListeners.length - 1],
318 			cast(GClosureNotify)&callBackProviderHiddenDestroy,
319 			connectFlags);
320 		return onProviderHiddenListeners[onProviderHiddenListeners.length - 1].handlerId;
321 	}
322 	
323 	extern(C) static void callBackProviderHidden(GstDeviceProvider* deviceproviderStruct, char* object,OnProviderHiddenDelegateWrapper wrapper)
324 	{
325 		wrapper.dlg(Str.toString(object), wrapper.outer);
326 	}
327 	
328 	extern(C) static void callBackProviderHiddenDestroy(OnProviderHiddenDelegateWrapper wrapper, GClosure* closure)
329 	{
330 		wrapper.outer.internalRemoveOnProviderHidden(wrapper);
331 	}
332 
333 	protected void internalRemoveOnProviderHidden(OnProviderHiddenDelegateWrapper source)
334 	{
335 		foreach(index, wrapper; onProviderHiddenListeners)
336 		{
337 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
338 			{
339 				onProviderHiddenListeners[index] = null;
340 				onProviderHiddenListeners = std.algorithm.remove(onProviderHiddenListeners, index);
341 				break;
342 			}
343 		}
344 	}
345 	
346 
347 	protected class OnProviderUnhiddenDelegateWrapper
348 	{
349 		void delegate(string, DeviceProvider) dlg;
350 		gulong handlerId;
351 		ConnectFlags flags;
352 		this(void delegate(string, DeviceProvider) dlg, gulong handlerId, ConnectFlags flags)
353 		{
354 			this.dlg = dlg;
355 			this.handlerId = handlerId;
356 			this.flags = flags;
357 		}
358 	}
359 	protected OnProviderUnhiddenDelegateWrapper[] onProviderUnhiddenListeners;
360 
361 	/** */
362 	gulong addOnProviderUnhidden(void delegate(string, DeviceProvider) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
363 	{
364 		onProviderUnhiddenListeners ~= new OnProviderUnhiddenDelegateWrapper(dlg, 0, connectFlags);
365 		onProviderUnhiddenListeners[onProviderUnhiddenListeners.length - 1].handlerId = Signals.connectData(
366 			this,
367 			"provider-unhidden",
368 			cast(GCallback)&callBackProviderUnhidden,
369 			cast(void*)onProviderUnhiddenListeners[onProviderUnhiddenListeners.length - 1],
370 			cast(GClosureNotify)&callBackProviderUnhiddenDestroy,
371 			connectFlags);
372 		return onProviderUnhiddenListeners[onProviderUnhiddenListeners.length - 1].handlerId;
373 	}
374 	
375 	extern(C) static void callBackProviderUnhidden(GstDeviceProvider* deviceproviderStruct, char* object,OnProviderUnhiddenDelegateWrapper wrapper)
376 	{
377 		wrapper.dlg(Str.toString(object), wrapper.outer);
378 	}
379 	
380 	extern(C) static void callBackProviderUnhiddenDestroy(OnProviderUnhiddenDelegateWrapper wrapper, GClosure* closure)
381 	{
382 		wrapper.outer.internalRemoveOnProviderUnhidden(wrapper);
383 	}
384 
385 	protected void internalRemoveOnProviderUnhidden(OnProviderUnhiddenDelegateWrapper source)
386 	{
387 		foreach(index, wrapper; onProviderUnhiddenListeners)
388 		{
389 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
390 			{
391 				onProviderUnhiddenListeners[index] = null;
392 				onProviderUnhiddenListeners = std.algorithm.remove(onProviderUnhiddenListeners, index);
393 				break;
394 			}
395 		}
396 	}
397 	
398 }