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