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