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 gio.IOModule;
26 
27 private import gio.IOModuleScope;
28 private import glib.ConstructionException;
29 private import glib.ListG;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gobject.TypeModule;
33 private import gobject.TypePluginIF;
34 private import gobject.TypePluginT;
35 private import gtkc.gio;
36 public  import gtkc.giotypes;
37 
38 
39 /**
40  * Provides an interface and default functions for loading and unloading
41  * modules. This is used internally to make GIO extensible, but can also
42  * be used by others to implement module loading.
43  */
44 public class IOModule : TypeModule
45 {
46 	/** the main Gtk struct */
47 	protected GIOModule* gIOModule;
48 
49 	/** Get the main Gtk struct */
50 	public GIOModule* getIOModuleStruct()
51 	{
52 		return gIOModule;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)gIOModule;
59 	}
60 
61 	protected override void setStruct(GObject* obj)
62 	{
63 		gIOModule = cast(GIOModule*)obj;
64 		super.setStruct(obj);
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (GIOModule* gIOModule, bool ownedRef = false)
71 	{
72 		this.gIOModule = gIOModule;
73 		super(cast(GTypeModule*)gIOModule, ownedRef);
74 	}
75 
76 	/**
77 	 */
78 
79 	public static GType getType()
80 	{
81 		return g_io_module_get_type();
82 	}
83 
84 	/**
85 	 * Creates a new GIOModule that will load the specific
86 	 * shared library when in use.
87 	 *
88 	 * Params:
89 	 *     filename = filename of the shared library module.
90 	 *
91 	 * Return: a #GIOModule from given @filename,
92 	 *     or %NULL on error.
93 	 *
94 	 * Throws: ConstructionException GTK+ fails to create the object.
95 	 */
96 	public this(string filename)
97 	{
98 		auto p = g_io_module_new(Str.toStringz(filename));
99 		
100 		if(p is null)
101 		{
102 			throw new ConstructionException("null returned by new");
103 		}
104 		
105 		this(cast(GIOModule*) p, true);
106 	}
107 
108 	/**
109 	 * Optional API for GIO modules to implement.
110 	 *
111 	 * Should return a list of all the extension points that may be
112 	 * implemented in this module.
113 	 *
114 	 * This method will not be called in normal use, however it may be
115 	 * called when probing existing modules and recording which extension
116 	 * points that this model is used for. This means we won't have to
117 	 * load and initialize this module unless its needed.
118 	 *
119 	 * If this function is not implemented by the module the module will
120 	 * always be loaded, initialized and then unloaded on application
121 	 * startup so that it can register its extension points during init.
122 	 *
123 	 * Note that a module need not actually implement all the extension
124 	 * points that g_io_module_query() returns, since the exact list of
125 	 * extension may depend on runtime issues. However all extension
126 	 * points actually implemented must be returned by g_io_module_query()
127 	 * (if defined).
128 	 *
129 	 * When installing a module that implements g_io_module_query() you must
130 	 * run gio-querymodules in order to build the cache files required for
131 	 * lazy loading.
132 	 *
133 	 * Return: A %NULL-terminated array of strings,
134 	 *     listing the supported extension points of the module. The array
135 	 *     must be suitable for freeing with g_strfreev().
136 	 *
137 	 * Since: 2.24
138 	 */
139 	public static string[] query()
140 	{
141 		return Str.toStringArray(g_io_module_query());
142 	}
143 
144 	/**
145 	 * Required API for GIO modules to implement.
146 	 *
147 	 * This function is run after the module has been loaded into GIO,
148 	 * to initialize the module. Typically, this function will call
149 	 * g_io_extension_point_implement().
150 	 */
151 	public void load()
152 	{
153 		g_io_module_load(gIOModule);
154 	}
155 
156 	/**
157 	 * Required API for GIO modules to implement.
158 	 *
159 	 * This function is run when the module is being unloaded from GIO,
160 	 * to finalize the module.
161 	 */
162 	public void unload()
163 	{
164 		g_io_module_unload(gIOModule);
165 	}
166 
167 	/**
168 	 * Loads all the modules in the specified directory.
169 	 *
170 	 * If don't require all modules to be initialized (and thus registering
171 	 * all gtypes) then you can use g_io_modules_scan_all_in_directory()
172 	 * which allows delayed/lazy loading of modules.
173 	 *
174 	 * Params:
175 	 *     dirname = pathname for a directory containing modules to load.
176 	 *
177 	 * Return: a list of #GIOModules loaded
178 	 *     from the directory,
179 	 *     All the modules are loaded into memory, if you want to
180 	 *     unload them (enabling on-demand loading) you must call
181 	 *     g_type_module_unuse() on all the modules. Free the list
182 	 *     with g_list_free().
183 	 */
184 	public static ListG loadAllInDirectory(string dirname)
185 	{
186 		auto p = g_io_modules_load_all_in_directory(Str.toStringz(dirname));
187 		
188 		if(p is null)
189 		{
190 			return null;
191 		}
192 		
193 		return new ListG(cast(GList*) p);
194 	}
195 
196 	/**
197 	 * Loads all the modules in the specified directory.
198 	 *
199 	 * If don't require all modules to be initialized (and thus registering
200 	 * all gtypes) then you can use g_io_modules_scan_all_in_directory()
201 	 * which allows delayed/lazy loading of modules.
202 	 *
203 	 * Params:
204 	 *     dirname = pathname for a directory containing modules to load.
205 	 *     scop = a scope to use when scanning the modules.
206 	 *
207 	 * Return: a list of #GIOModules loaded
208 	 *     from the directory,
209 	 *     All the modules are loaded into memory, if you want to
210 	 *     unload them (enabling on-demand loading) you must call
211 	 *     g_type_module_unuse() on all the modules. Free the list
212 	 *     with g_list_free().
213 	 *
214 	 * Since: 2.30
215 	 */
216 	public static ListG loadAllInDirectoryWithScope(string dirname, IOModuleScope scop)
217 	{
218 		auto p = g_io_modules_load_all_in_directory_with_scope(Str.toStringz(dirname), (scop is null) ? null : scop.getIOModuleScopeStruct());
219 		
220 		if(p is null)
221 		{
222 			return null;
223 		}
224 		
225 		return new ListG(cast(GList*) p);
226 	}
227 
228 	/**
229 	 * Scans all the modules in the specified directory, ensuring that
230 	 * any extension point implemented by a module is registered.
231 	 *
232 	 * This may not actually load and initialize all the types in each
233 	 * module, some modules may be lazily loaded and initialized when
234 	 * an extension point it implementes is used with e.g.
235 	 * g_io_extension_point_get_extensions() or
236 	 * g_io_extension_point_get_extension_by_name().
237 	 *
238 	 * If you need to guarantee that all types are loaded in all the modules,
239 	 * use g_io_modules_load_all_in_directory().
240 	 *
241 	 * Params:
242 	 *     dirname = pathname for a directory containing modules to scan.
243 	 *
244 	 * Since: 2.24
245 	 */
246 	public static void scanAllInDirectory(string dirname)
247 	{
248 		g_io_modules_scan_all_in_directory(Str.toStringz(dirname));
249 	}
250 
251 	/**
252 	 * Scans all the modules in the specified directory, ensuring that
253 	 * any extension point implemented by a module is registered.
254 	 *
255 	 * This may not actually load and initialize all the types in each
256 	 * module, some modules may be lazily loaded and initialized when
257 	 * an extension point it implementes is used with e.g.
258 	 * g_io_extension_point_get_extensions() or
259 	 * g_io_extension_point_get_extension_by_name().
260 	 *
261 	 * If you need to guarantee that all types are loaded in all the modules,
262 	 * use g_io_modules_load_all_in_directory().
263 	 *
264 	 * Params:
265 	 *     dirname = pathname for a directory containing modules to scan.
266 	 *     scop = a scope to use when scanning the modules
267 	 *
268 	 * Since: 2.30
269 	 */
270 	public static void scanAllInDirectoryWithScope(string dirname, IOModuleScope scop)
271 	{
272 		g_io_modules_scan_all_in_directory_with_scope(Str.toStringz(dirname), (scop is null) ? null : scop.getIOModuleScopeStruct());
273 	}
274 }