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