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  * Conversion parameters:
26  * inFile  = GstRegistry.html
27  * outPack = gstreamer
28  * outFile = Registry
29  * strct   = GstRegistry
30  * realStrct=
31  * ctorStrct=
32  * clss    = Registry
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_registry_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ListG
48  * 	- gstreamer.Plugin
49  * 	- gstreamer.PluginFeature
50  * structWrap:
51  * 	- GList* -> ListG
52  * 	- GstPlugin* -> Plugin
53  * 	- GstPluginFeature* -> PluginFeature
54  * 	- GstRegistry* -> Registry
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module gstreamer.Registry;
61 
62 public  import gstreamerc.gstreamertypes;
63 
64 private import gstreamerc.gstreamer;
65 private import glib.ConstructionException;
66 private import gobject.ObjectG;
67 
68 private import gobject.Signals;
69 public  import gtkc.gdktypes;
70 private import glib.Str;
71 private import glib.ListG;
72 private import gstreamer.Plugin;
73 private import gstreamer.PluginFeature;
74 
75 
76 private import gstreamer.ObjectGst;
77 
78 /**
79  * One registry holds the metadata of a set of plugins.
80  *
81  * Design:
82  *
83  * The GstRegistry object is a list of plugins and some functions for dealing
84  * with them. Each GstPlugin is matched 1-1 with a file on disk, and may or may
85  * not be loaded at a given time.
86  *
87  * The primary source, at all times, of plugin information is each plugin file
88  * itself. Thus, if an application wants information about a particular plugin,
89  * or wants to search for a feature that satisfies given criteria, the primary
90  * means of doing so is to load every plugin and look at the resulting
91  * information that is gathered in the default registry. Clearly, this is a time
92  * consuming process, so we cache information in the registry file. The format
93  * and location of the cache file is internal to gstreamer.
94  *
95  * On startup, plugins are searched for in the plugin search path. The following
96  * locations are checked in this order:
97  *
98  * location from --gst-plugin-path commandline option.
99  *
100  * the GST_PLUGIN_PATH environment variable.
101  *
102  * the GST_PLUGIN_SYSTEM_PATH environment variable.
103  *
104  * default locations (if GST_PLUGIN_SYSTEM_PATH is not set). Those
105  *  default locations are:
106  *  ~/.gstreamer-$GST_API_VERSION/plugins/
107  *  and $prefix/libs/gstreamer-$GST_API_VERSION/.
108  *
109  * The registry cache file is loaded from
110  * ~/.gstreamer-$GST_API_VERSION/registry-$ARCH.bin or the
111  * file listed in the GST_REGISTRY env var. One reason to change the registry
112  * location is for testing.
113  *
114  * For each plugin that is found in the plugin search path, there could be 3
115  * possibilities for cached information:
116  *
117  * the cache may not contain information about a given file.
118  *
119  * the cache may have stale information.
120  *
121  * the cache may have current information.
122  *
123  * In the first two cases, the plugin is loaded and the cache updated. In
124  * addition to these cases, the cache may have entries for plugins that are not
125  * relevant to the current process. These are marked as not available to the
126  * current process. If the cache is updated for whatever reason, it is marked
127  * dirty.
128  *
129  * A dirty cache is written out at the end of initialization. Each entry is
130  * checked to make sure the information is minimally valid. If not, the entry is
131  * simply dropped.
132  *
133  * Implementation notes:
134  *
135  * The "cache" and "registry" are different concepts and can represent
136  * different sets of plugins. For various reasons, at init time, the cache is
137  * stored in the default registry, and plugins not relevant to the current
138  * process are marked with the GST_PLUGIN_FLAG_CACHED bit. These plugins are
139  * removed at the end of initialization.
140  *
141  * Last reviewed on 2012-03-29 (0.11.3)
142  */
143 public class Registry : ObjectGst
144 {
145 	
146 	/** the main Gtk struct */
147 	protected GstRegistry* gstRegistry;
148 	
149 	
150 	/** Get the main Gtk struct */
151 	public GstRegistry* getRegistryStruct()
152 	{
153 		return gstRegistry;
154 	}
155 	
156 	
157 	/** the main Gtk struct as a void* */
158 	protected override void* getStruct()
159 	{
160 		return cast(void*)gstRegistry;
161 	}
162 	
163 	/**
164 	 * Sets our main struct and passes it to the parent class
165 	 */
166 	public this (GstRegistry* gstRegistry)
167 	{
168 		super(cast(GstObject*)gstRegistry);
169 		this.gstRegistry = gstRegistry;
170 	}
171 	
172 	protected override void setStruct(GObject* obj)
173 	{
174 		super.setStruct(obj);
175 		gstRegistry = cast(GstRegistry*)obj;
176 	}
177 	
178 	/**
179 	 */
180 	int[string] connectedSignals;
181 	
182 	void delegate(PluginFeature, Registry)[] onFeatureAddedListeners;
183 	/**
184 	 * Signals that a feature has been added to the registry (possibly
185 	 * replacing a previously-added one by the same name)
186 	 */
187 	void addOnFeatureAdded(void delegate(PluginFeature, Registry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
188 	{
189 		if ( !("feature-added" in connectedSignals) )
190 		{
191 			Signals.connectData(
192 			getStruct(),
193 			"feature-added",
194 			cast(GCallback)&callBackFeatureAdded,
195 			cast(void*)this,
196 			null,
197 			connectFlags);
198 			connectedSignals["feature-added"] = 1;
199 		}
200 		onFeatureAddedListeners ~= dlg;
201 	}
202 	extern(C) static void callBackFeatureAdded(GstRegistry* registryStruct, GstPluginFeature* feature, Registry _registry)
203 	{
204 		foreach ( void delegate(PluginFeature, Registry) dlg ; _registry.onFeatureAddedListeners )
205 		{
206 			dlg(ObjectG.getDObject!(PluginFeature)(feature), _registry);
207 		}
208 	}
209 	
210 	void delegate(Plugin, Registry)[] onPluginAddedListeners;
211 	/**
212 	 * Signals that a plugin has been added to the registry (possibly
213 	 * replacing a previously-added one by the same name)
214 	 * See Also
215 	 * GstPlugin, GstPluginFeature
216 	 */
217 	void addOnPluginAdded(void delegate(Plugin, Registry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
218 	{
219 		if ( !("plugin-added" in connectedSignals) )
220 		{
221 			Signals.connectData(
222 			getStruct(),
223 			"plugin-added",
224 			cast(GCallback)&callBackPluginAdded,
225 			cast(void*)this,
226 			null,
227 			connectFlags);
228 			connectedSignals["plugin-added"] = 1;
229 		}
230 		onPluginAddedListeners ~= dlg;
231 	}
232 	extern(C) static void callBackPluginAdded(GstRegistry* registryStruct, GstPlugin* plugin, Registry _registry)
233 	{
234 		foreach ( void delegate(Plugin, Registry) dlg ; _registry.onPluginAddedListeners )
235 		{
236 			dlg(ObjectG.getDObject!(Plugin)(plugin), _registry);
237 		}
238 	}
239 	
240 	
241 	/**
242 	 * Retrieves the singleton plugin registry. The caller does not own a
243 	 * reference on the registry, as it is alive as long as GStreamer is
244 	 * initialized.
245 	 * Returns: the GstRegistry. [transfer none]
246 	 */
247 	public static Registry get()
248 	{
249 		// GstRegistry * gst_registry_get (void);
250 		auto p = gst_registry_get();
251 		
252 		if(p is null)
253 		{
254 			return null;
255 		}
256 		
257 		return ObjectG.getDObject!(Registry)(cast(GstRegistry*) p);
258 	}
259 	
260 	/**
261 	 * Retrieves a GList of GstPluginFeature of type.
262 	 * Params:
263 	 * type = a GType.
264 	 * Returns: a GList of GstPluginFeature of type. Use gst_plugin_feature_list_free() after use MT safe. [transfer full][element-type Gst.PluginFeature]
265 	 */
266 	public ListG getFeatureList(GType type)
267 	{
268 		// GList * gst_registry_get_feature_list (GstRegistry *registry,  GType type);
269 		auto p = gst_registry_get_feature_list(gstRegistry, type);
270 		
271 		if(p is null)
272 		{
273 			return null;
274 		}
275 		
276 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
277 	}
278 	
279 	/**
280 	 * Returns the registrys feature list cookie. This changes
281 	 * every time a feature is added or removed from the registry.
282 	 * Returns: the feature list cookie.
283 	 */
284 	public uint getFeatureListCookie()
285 	{
286 		// guint32 gst_registry_get_feature_list_cookie  (GstRegistry *registry);
287 		return gst_registry_get_feature_list_cookie(gstRegistry);
288 	}
289 	
290 	/**
291 	 * Retrieves a GList of features of the plugin with name name.
292 	 * Params:
293 	 * name = a plugin name.
294 	 * Returns: a GList of GstPluginFeature. Use gst_plugin_feature_list_free() after usage. [transfer full][element-type Gst.PluginFeature]
295 	 */
296 	public ListG getFeatureListByPlugin(string name)
297 	{
298 		// GList * gst_registry_get_feature_list_by_plugin  (GstRegistry *registry,  const gchar *name);
299 		auto p = gst_registry_get_feature_list_by_plugin(gstRegistry, Str.toStringz(name));
300 		
301 		if(p is null)
302 		{
303 			return null;
304 		}
305 		
306 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
307 	}
308 	
309 	/**
310 	 * Get a copy of all plugins registered in the given registry. The refcount
311 	 * of each element in the list in incremented.
312 	 * Returns: a GList of GstPlugin. Use gst_plugin_list_free() after usage. MT safe. [transfer full][element-type Gst.Plugin]
313 	 */
314 	public ListG getPluginList()
315 	{
316 		// GList * gst_registry_get_plugin_list (GstRegistry *registry);
317 		auto p = gst_registry_get_plugin_list(gstRegistry);
318 		
319 		if(p is null)
320 		{
321 			return null;
322 		}
323 		
324 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
325 	}
326 	
327 	/**
328 	 * Add the plugin to the registry. The plugin-added signal will be emitted.
329 	 * This function will sink plugin.
330 	 * Params:
331 	 * plugin = the plugin to add. [transfer full]
332 	 * Returns: TRUE on success. MT safe.
333 	 */
334 	public int addPlugin(Plugin plugin)
335 	{
336 		// gboolean gst_registry_add_plugin (GstRegistry *registry,  GstPlugin *plugin);
337 		return gst_registry_add_plugin(gstRegistry, (plugin is null) ? null : plugin.getPluginStruct());
338 	}
339 	
340 	/**
341 	 * Remove the plugin from the registry.
342 	 * MT safe.
343 	 * Params:
344 	 * plugin = the plugin to remove. [transfer none]
345 	 */
346 	public void removePlugin(Plugin plugin)
347 	{
348 		// void gst_registry_remove_plugin (GstRegistry *registry,  GstPlugin *plugin);
349 		gst_registry_remove_plugin(gstRegistry, (plugin is null) ? null : plugin.getPluginStruct());
350 	}
351 	
352 	/**
353 	 * Runs a filter against all plugins in the registry and returns a GList with
354 	 * the results. If the first flag is set, only the first match is
355 	 * returned (as a list with a single object).
356 	 * Every plugin is reffed; use gst_plugin_list_free() after use, which
357 	 * will unref again.
358 	 * Params:
359 	 * filter = the filter to use. [scope call]
360 	 * first = only return first match
361 	 * userData = user data passed to the filter function. [closure]
362 	 * Returns: a GList of GstPlugin. Use gst_plugin_list_free() after usage. MT safe. [transfer full][element-type Gst.Plugin]
363 	 */
364 	public ListG pluginFilter(GstPluginFilter filter, int first, void* userData)
365 	{
366 		// GList * gst_registry_plugin_filter (GstRegistry *registry,  GstPluginFilter filter,  gboolean first,  gpointer user_data);
367 		auto p = gst_registry_plugin_filter(gstRegistry, filter, first, userData);
368 		
369 		if(p is null)
370 		{
371 			return null;
372 		}
373 		
374 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
375 	}
376 	
377 	/**
378 	 * Runs a filter against all features of the plugins in the registry
379 	 * and returns a GList with the results.
380 	 * If the first flag is set, only the first match is
381 	 * returned (as a list with a single object).
382 	 * Params:
383 	 * filter = the filter to use. [scope call]
384 	 * first = only return first match
385 	 * userData = user data passed to the filter function. [closure]
386 	 * Returns: a GList of GstPluginFeature. Use gst_plugin_feature_list_free() after usage. MT safe. [transfer full][element-type Gst.PluginFeature]
387 	 */
388 	public ListG featureFilter(GstPluginFeatureFilter filter, int first, void* userData)
389 	{
390 		// GList * gst_registry_feature_filter (GstRegistry *registry,  GstPluginFeatureFilter filter,  gboolean first,  gpointer user_data);
391 		auto p = gst_registry_feature_filter(gstRegistry, filter, first, userData);
392 		
393 		if(p is null)
394 		{
395 			return null;
396 		}
397 		
398 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
399 	}
400 	
401 	/**
402 	 * Find the plugin with the given name in the registry.
403 	 * The plugin will be reffed; caller is responsible for unreffing.
404 	 * Params:
405 	 * name = the plugin name to find
406 	 * Returns: the plugin with the given name or NULL if the plugin was not found. gst_object_unref() after usage. MT safe. [transfer full]
407 	 */
408 	public Plugin findPlugin(string name)
409 	{
410 		// GstPlugin * gst_registry_find_plugin (GstRegistry *registry,  const gchar *name);
411 		auto p = gst_registry_find_plugin(gstRegistry, Str.toStringz(name));
412 		
413 		if(p is null)
414 		{
415 			return null;
416 		}
417 		
418 		return ObjectG.getDObject!(Plugin)(cast(GstPlugin*) p);
419 	}
420 	
421 	/**
422 	 * Find the pluginfeature with the given name and type in the registry.
423 	 * Params:
424 	 * name = the pluginfeature name to find
425 	 * type = the pluginfeature type to find
426 	 * Returns: the pluginfeature with the given name and type or NULL if the plugin was not found. gst_object_unref() after usage. MT safe. [transfer full]
427 	 */
428 	public PluginFeature findFeature(string name, GType type)
429 	{
430 		// GstPluginFeature * gst_registry_find_feature (GstRegistry *registry,  const gchar *name,  GType type);
431 		auto p = gst_registry_find_feature(gstRegistry, Str.toStringz(name), type);
432 		
433 		if(p is null)
434 		{
435 			return null;
436 		}
437 		
438 		return ObjectG.getDObject!(PluginFeature)(cast(GstPluginFeature*) p);
439 	}
440 	
441 	/**
442 	 * Find a GstPluginFeature with name in registry.
443 	 * Params:
444 	 * name = a GstPluginFeature name
445 	 * Returns: a GstPluginFeature with its refcount incremented, use gst_object_unref() after usage. MT safe. [transfer full]
446 	 */
447 	public PluginFeature lookupFeature(string name)
448 	{
449 		// GstPluginFeature * gst_registry_lookup_feature (GstRegistry *registry,  const char *name);
450 		auto p = gst_registry_lookup_feature(gstRegistry, Str.toStringz(name));
451 		
452 		if(p is null)
453 		{
454 			return null;
455 		}
456 		
457 		return ObjectG.getDObject!(PluginFeature)(cast(GstPluginFeature*) p);
458 	}
459 	
460 	/**
461 	 * Scan the given path for plugins to add to the registry. The syntax of the
462 	 * path is specific to the registry.
463 	 * Params:
464 	 * path = the path to scan
465 	 * Returns: TRUE if registry changed
466 	 */
467 	public int scanPath(string path)
468 	{
469 		// gboolean gst_registry_scan_path (GstRegistry *registry,  const gchar *path);
470 		return gst_registry_scan_path(gstRegistry, Str.toStringz(path));
471 	}
472 	
473 	/**
474 	 * Look up a plugin in the given registry with the given filename.
475 	 * If found, plugin is reffed.
476 	 * Params:
477 	 * filename = the name of the file to look up
478 	 * Returns: the GstPlugin if found, or NULL if not. gst_object_unref() after usage. [transfer full]
479 	 */
480 	public Plugin lookup(string filename)
481 	{
482 		// GstPlugin * gst_registry_lookup (GstRegistry *registry,  const char *filename);
483 		auto p = gst_registry_lookup(gstRegistry, Str.toStringz(filename));
484 		
485 		if(p is null)
486 		{
487 			return null;
488 		}
489 		
490 		return ObjectG.getDObject!(Plugin)(cast(GstPlugin*) p);
491 	}
492 	
493 	/**
494 	 * Remove the feature from the registry.
495 	 * MT safe.
496 	 * Params:
497 	 * feature = the feature to remove. [transfer none]
498 	 */
499 	public void removeFeature(PluginFeature feature)
500 	{
501 		// void gst_registry_remove_feature (GstRegistry *registry,  GstPluginFeature *feature);
502 		gst_registry_remove_feature(gstRegistry, (feature is null) ? null : feature.getPluginFeatureStruct());
503 	}
504 	
505 	/**
506 	 * Add the feature to the registry. The feature-added signal will be emitted.
507 	 * This function sinks feature.
508 	 * Params:
509 	 * feature = the feature to add. [transfer full]
510 	 * Returns: TRUE on success. MT safe.
511 	 */
512 	public int addFeature(PluginFeature feature)
513 	{
514 		// gboolean gst_registry_add_feature (GstRegistry *registry,  GstPluginFeature *feature);
515 		return gst_registry_add_feature(gstRegistry, (feature is null) ? null : feature.getPluginFeatureStruct());
516 	}
517 	
518 	/**
519 	 * Checks whether a plugin feature by the given name exists in
520 	 * registry and whether its version is at least the
521 	 * version required.
522 	 * Params:
523 	 * featureName = the name of the feature (e.g. "oggdemux")
524 	 * minMajor = the minimum major version number
525 	 * minMinor = the minimum minor version number
526 	 * minMicro = the minimum micro version number
527 	 * feature = the feature that has been added
528 	 * Returns: TRUE if the feature could be found and the version is the same as the required version or newer, and FALSE otherwise. Signal Details The "feature-added" signal void user_function (GstRegistry *registry, GstPluginFeature *feature, gpointer user_data) : Run Last Signals that a feature has been added to the registry (possibly replacing a previously-added one by the same name)
529 	 */
530 	public int checkFeatureVersion(string featureName, uint minMajor, uint minMinor, uint minMicro)
531 	{
532 		// gboolean gst_registry_check_feature_version (GstRegistry *registry,  const gchar *feature_name,  guint min_major,  guint min_minor,  guint min_micro);
533 		return gst_registry_check_feature_version(gstRegistry, Str.toStringz(featureName), minMajor, minMinor, minMicro);
534 	}
535 }