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 glib.c.functions;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gstreamer.Bus;
33 private import gstreamer.Device;
34 private import gstreamer.DeviceProviderFactory;
35 private import gstreamer.ObjectGst;
36 private import gstreamer.Plugin;
37 private import gstreamer.c.functions;
38 public  import gstreamer.c.types;
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 programmatically 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 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GstDeviceProvider* gstDeviceProvider, bool ownedRef = false)
78 	{
79 		this.gstDeviceProvider = gstDeviceProvider;
80 		super(cast(GstObject*)gstDeviceProvider, ownedRef);
81 	}
82 
83 
84 	/** */
85 	public static GType getType()
86 	{
87 		return gst_device_provider_get_type();
88 	}
89 
90 	/**
91 	 * Create a new device providerfactory capable of instantiating objects of the
92 	 * @type and add the factory to @plugin.
93 	 *
94 	 * Params:
95 	 *     plugin = #GstPlugin to register the device provider with, or %NULL for
96 	 *         a static device provider.
97 	 *     name = name of device providers of this type
98 	 *     rank = rank of device provider (higher rank means more importance when autoplugging)
99 	 *     type = GType of device provider to register
100 	 *
101 	 * Returns: %TRUE, if the registering succeeded, %FALSE on error
102 	 *
103 	 * Since: 1.4
104 	 */
105 	public static bool register(Plugin plugin, string name, uint rank, GType type)
106 	{
107 		return gst_device_provider_register((plugin is null) ? null : plugin.getPluginStruct(), Str.toStringz(name), rank, type) != 0;
108 	}
109 
110 	/** */
111 	public bool canMonitor()
112 	{
113 		return gst_device_provider_can_monitor(gstDeviceProvider) != 0;
114 	}
115 
116 	/**
117 	 * Posts a message on the provider's #GstBus to inform applications that
118 	 * a new device has been added.
119 	 *
120 	 * This is for use by subclasses.
121 	 *
122 	 * @device's reference count will be incremented, and any floating reference
123 	 * will be removed (see gst_object_ref_sink()).
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 	 * This function is used when @changed_device was modified into its new form
137 	 * @device. This will post a `DEVICE_CHANGED` message on the bus to let
138 	 * the application know that the device was modified. #GstDevice is immutable
139 	 * for MT. safety purposes so this is an "atomic" way of letting the application
140 	 * know when a device was modified.
141 	 *
142 	 * Params:
143 	 *     device = the new version of @changed_device
144 	 *     changedDevice = the old version of the device that has been updated
145 	 *
146 	 * Since: 1.16
147 	 */
148 	public void deviceChanged(Device device, Device changedDevice)
149 	{
150 		gst_device_provider_device_changed(gstDeviceProvider, (device is null) ? null : device.getDeviceStruct(), (changedDevice is null) ? null : changedDevice.getDeviceStruct());
151 	}
152 
153 	/**
154 	 * Posts a message on the provider's #GstBus to inform applications that
155 	 * a device has been removed.
156 	 *
157 	 * This is for use by subclasses.
158 	 *
159 	 * Params:
160 	 *     device = a #GstDevice that has been removed
161 	 *
162 	 * Since: 1.4
163 	 */
164 	public void deviceRemove(Device device)
165 	{
166 		gst_device_provider_device_remove(gstDeviceProvider, (device is null) ? null : device.getDeviceStruct());
167 	}
168 
169 	/**
170 	 * Gets the #GstBus of this #GstDeviceProvider
171 	 *
172 	 * Returns: a #GstBus
173 	 *
174 	 * Since: 1.4
175 	 */
176 	public Bus getBus()
177 	{
178 		auto __p = gst_device_provider_get_bus(gstDeviceProvider);
179 
180 		if(__p is null)
181 		{
182 			return null;
183 		}
184 
185 		return ObjectG.getDObject!(Bus)(cast(GstBus*) __p, true);
186 	}
187 
188 	/**
189 	 * Gets a list of devices that this provider understands. This may actually
190 	 * probe the hardware if the provider is not currently started.
191 	 *
192 	 * If the provider has been started, this will returned the same #GstDevice
193 	 * objedcts that have been returned by the #GST_MESSAGE_DEVICE_ADDED messages.
194 	 *
195 	 * Returns: a #GList of
196 	 *     #GstDevice
197 	 *
198 	 * Since: 1.4
199 	 */
200 	public ListG getDevices()
201 	{
202 		auto __p = gst_device_provider_get_devices(gstDeviceProvider);
203 
204 		if(__p is null)
205 		{
206 			return null;
207 		}
208 
209 		return new ListG(cast(GList*) __p, true);
210 	}
211 
212 	/**
213 	 * Retrieves the factory that was used to create this device provider.
214 	 *
215 	 * Returns: the #GstDeviceProviderFactory used for
216 	 *     creating this device provider. no refcounting is needed.
217 	 *
218 	 * Since: 1.4
219 	 */
220 	public DeviceProviderFactory getFactory()
221 	{
222 		auto __p = gst_device_provider_get_factory(gstDeviceProvider);
223 
224 		if(__p is null)
225 		{
226 			return null;
227 		}
228 
229 		return ObjectG.getDObject!(DeviceProviderFactory)(cast(GstDeviceProviderFactory*) __p);
230 	}
231 
232 	/**
233 	 * Get the provider factory names of the #GstDeviceProvider instances that
234 	 * are hidden by @provider.
235 	 *
236 	 * Returns: a list of hidden providers factory names or %NULL when
237 	 *     nothing is hidden by @provider. Free with g_strfreev.
238 	 *
239 	 * Since: 1.6
240 	 */
241 	public string[] getHiddenProviders()
242 	{
243 		auto retStr = gst_device_provider_get_hidden_providers(gstDeviceProvider);
244 
245 		scope(exit) Str.freeStringArray(retStr);
246 		return Str.toStringArray(retStr);
247 	}
248 
249 	/**
250 	 * Get metadata with @key in @provider.
251 	 *
252 	 * Params:
253 	 *     key = the key to get
254 	 *
255 	 * Returns: the metadata for @key.
256 	 *
257 	 * Since: 1.14
258 	 */
259 	public string getMetadata(string key)
260 	{
261 		return Str.toString(gst_device_provider_get_metadata(gstDeviceProvider, Str.toStringz(key)));
262 	}
263 
264 	/**
265 	 * Make @provider hide the devices from the factory with @name.
266 	 *
267 	 * This function is used when @provider will also provide the devices reported
268 	 * by provider factory @name. A monitor should stop monitoring the
269 	 * device provider with @name to avoid duplicate devices.
270 	 *
271 	 * Params:
272 	 *     name = a provider factory name
273 	 *
274 	 * Since: 1.6
275 	 */
276 	public void hideProvider(string name)
277 	{
278 		gst_device_provider_hide_provider(gstDeviceProvider, Str.toStringz(name));
279 	}
280 
281 	/**
282 	 * Starts providering the devices. This will cause #GST_MESSAGE_DEVICE_ADDED
283 	 * and #GST_MESSAGE_DEVICE_REMOVED messages to be posted on the provider's bus
284 	 * when devices are added or removed from the system.
285 	 *
286 	 * Since the #GstDeviceProvider is a singleton,
287 	 * gst_device_provider_start() may already have been called by another
288 	 * user of the object, gst_device_provider_stop() needs to be called the same
289 	 * number of times.
290 	 *
291 	 * After this function has been called, gst_device_provider_get_devices() will
292 	 * return the same objects that have been received from the
293 	 * #GST_MESSAGE_DEVICE_ADDED messages and will no longer probe.
294 	 *
295 	 * Returns: %TRUE if the device providering could be started
296 	 *
297 	 * Since: 1.4
298 	 */
299 	public bool start()
300 	{
301 		return gst_device_provider_start(gstDeviceProvider) != 0;
302 	}
303 
304 	/**
305 	 * Decreases the use-count by one. If the use count reaches zero, this
306 	 * #GstDeviceProvider will stop providering the devices. This needs to be
307 	 * called the same number of times that gst_device_provider_start() was called.
308 	 *
309 	 * Since: 1.4
310 	 */
311 	public void stop()
312 	{
313 		gst_device_provider_stop(gstDeviceProvider);
314 	}
315 
316 	/**
317 	 * Make @provider unhide the devices from factory @name.
318 	 *
319 	 * This function is used when @provider will no longer provide the devices
320 	 * reported by provider factory @name. A monitor should start
321 	 * monitoring the devices from provider factory @name in order to see
322 	 * all devices again.
323 	 *
324 	 * Params:
325 	 *     name = a provider factory name
326 	 *
327 	 * Since: 1.6
328 	 */
329 	public void unhideProvider(string name)
330 	{
331 		gst_device_provider_unhide_provider(gstDeviceProvider, Str.toStringz(name));
332 	}
333 
334 	/** */
335 	gulong addOnProviderHidden(void delegate(string, DeviceProvider) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
336 	{
337 		return Signals.connect(this, "provider-hidden", dlg, connectFlags ^ ConnectFlags.SWAPPED);
338 	}
339 
340 	/** */
341 	gulong addOnProviderUnhidden(void delegate(string, DeviceProvider) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
342 	{
343 		return Signals.connect(this, "provider-unhidden", dlg, connectFlags ^ ConnectFlags.SWAPPED);
344 	}
345 }