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.Device;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gstreamer.Caps;
31 private import gstreamer.Element;
32 private import gstreamer.ObjectGst;
33 private import gstreamerc.gstreamer;
34 public  import gstreamerc.gstreamertypes;
35 public  import gtkc.gdktypes;
36 
37 
38 /**
39  * #GstDevice are objects representing a device, they contain
40  * relevant metadata about the device, such as its class and the #GstCaps
41  * representing the media types it can produce or handle.
42  * 
43  * #GstDevice are created by #GstDeviceProvider objects which can be
44  * aggregated by #GstDeviceMonitor objects.
45  *
46  * Since: 1.4
47  */
48 public class Device : ObjectGst
49 {
50 	/** the main Gtk struct */
51 	protected GstDevice* gstDevice;
52 
53 	/** Get the main Gtk struct */
54 	public GstDevice* getDeviceStruct()
55 	{
56 		return gstDevice;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected override void* getStruct()
61 	{
62 		return cast(void*)gstDevice;
63 	}
64 
65 	protected override void setStruct(GObject* obj)
66 	{
67 		gstDevice = cast(GstDevice*)obj;
68 		super.setStruct(obj);
69 	}
70 
71 	/**
72 	 * Sets our main struct and passes it to the parent class.
73 	 */
74 	public this (GstDevice* gstDevice, bool ownedRef = false)
75 	{
76 		this.gstDevice = gstDevice;
77 		super(cast(GstObject*)gstDevice, ownedRef);
78 	}
79 
80 	/**
81 	 */
82 
83 	public static GType getType()
84 	{
85 		return gst_device_get_type();
86 	}
87 
88 	/**
89 	 * Creates the element with all of the required paramaters set to use
90 	 * this device.
91 	 *
92 	 * Params:
93 	 *     name = name of new element, or %NULL to automatically
94 	 *         create a unique name.
95 	 *
96 	 * Return: a new #GstElement configured to use this device
97 	 *
98 	 * Since: 1.4
99 	 */
100 	public Element createElement(string name)
101 	{
102 		auto p = gst_device_create_element(gstDevice, Str.toStringz(name));
103 		
104 		if(p is null)
105 		{
106 			return null;
107 		}
108 		
109 		return ObjectG.getDObject!(Element)(cast(GstElement*) p, true);
110 	}
111 
112 	/**
113 	 * Getter for the #GstCaps that this device supports.
114 	 *
115 	 * Return: The #GstCaps supported by this device. Unref with
116 	 *     gst_caps_unref() when done.
117 	 *
118 	 * Since: 1.4
119 	 */
120 	public Caps getCaps()
121 	{
122 		auto p = gst_device_get_caps(gstDevice);
123 		
124 		if(p is null)
125 		{
126 			return null;
127 		}
128 		
129 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
130 	}
131 
132 	/**
133 	 * Gets the "class" of a device. This is a "/" separated list of
134 	 * classes that represent this device. They are a subset of the
135 	 * classes of the #GstDeviceProvider that produced this device.
136 	 *
137 	 * Return: The device class. Free with g_free() after use.
138 	 *
139 	 * Since: 1.4
140 	 */
141 	public string getDeviceClass()
142 	{
143 		return Str.toString(gst_device_get_device_class(gstDevice));
144 	}
145 
146 	/**
147 	 * Gets the user-friendly name of the device.
148 	 *
149 	 * Return: The device name. Free with g_free() after use.
150 	 *
151 	 * Since: 1.4
152 	 */
153 	public string getDisplayName()
154 	{
155 		return Str.toString(gst_device_get_display_name(gstDevice));
156 	}
157 
158 	/**
159 	 * Check if @device matches all of the given classes
160 	 *
161 	 * Params:
162 	 *     classes = a "/" separate list of device classes to match, only match if
163 	 *         all classes are matched
164 	 *
165 	 * Return: %TRUE if @device matches.
166 	 *
167 	 * Since: 1.4
168 	 */
169 	public bool hasClasses(string classes)
170 	{
171 		return gst_device_has_classes(gstDevice, Str.toStringz(classes)) != 0;
172 	}
173 
174 	/**
175 	 * Check if @factory matches all of the given classes
176 	 *
177 	 * Params:
178 	 *     classes = a %NULL terminated array of classes to match, only match if all
179 	 *         classes are matched
180 	 *
181 	 * Return: %TRUE if @device matches.
182 	 *
183 	 * Since: 1.4
184 	 */
185 	public bool hasClassesv(string[] classes)
186 	{
187 		return gst_device_has_classesv(gstDevice, Str.toStringzArray(classes)) != 0;
188 	}
189 
190 	/**
191 	 * Tries to reconfigure an existing element to use the device. If this
192 	 * function fails, then one must destroy the element and create a new one
193 	 * using gst_device_create_element().
194 	 *
195 	 * Note: This should only be implemented for elements can change their
196 	 * device in the PLAYING state.
197 	 *
198 	 * Params:
199 	 *     element = a #GstElement
200 	 *
201 	 * Return: %TRUE if the element could be reconfigured to use this device,
202 	 *     %FALSE otherwise.
203 	 *
204 	 * Since: 1.4
205 	 */
206 	public bool reconfigureElement(Element element)
207 	{
208 		return gst_device_reconfigure_element(gstDevice, (element is null) ? null : element.getElementStruct()) != 0;
209 	}
210 
211 	int[string] connectedSignals;
212 
213 	void delegate(Device)[] onRemovedListeners;
214 	void addOnRemoved(void delegate(Device) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
215 	{
216 		if ( "removed" !in connectedSignals )
217 		{
218 			Signals.connectData(
219 				this,
220 				"removed",
221 				cast(GCallback)&callBackRemoved,
222 				cast(void*)this,
223 				null,
224 				connectFlags);
225 			connectedSignals["removed"] = 1;
226 		}
227 		onRemovedListeners ~= dlg;
228 	}
229 	extern(C) static void callBackRemoved(GstDevice* deviceStruct, Device _device)
230 	{
231 		foreach ( void delegate(Device) dlg; _device.onRemovedListeners )
232 		{
233 			dlg(_device);
234 		}
235 	}
236 }