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  = glib-Dynamic-Loading-of-Modules.html
27  * outPack = glib
28  * outFile = Module
29  * strct   = GModule
30  * realStrct=
31  * ctorStrct=
32  * clss    = Module
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_module_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * 	- GModule* -> Module
49  * module aliases:
50  * local aliases:
51  * overrides:
52  */
53 
54 module glib.Module;
55 
56 public  import gtkc.glibtypes;
57 
58 private import gtkc.glib;
59 private import glib.ConstructionException;
60 
61 
62 private import glib.Str;
63 
64 
65 
66 
67 /**
68  * These functions provide a portable way to dynamically load object files
69  * (commonly known as 'plug-ins'). The current implementation supports all
70  * systems that provide an implementation of dlopen() (e.g. Linux/Sun), as
71  * well as HP-UX via its shl_load() mechanism, and Windows platforms via DLLs.
72  *
73  * A program which wants to use these functions must be linked to the
74  * libraries output by the command
75  * pkg-config --libs gmodule-2.0.
76  *
77  * To use them you must first determine whether dynamic loading
78  * is supported on the platform by calling g_module_supported().
79  * If it is, you can open a module with g_module_open(),
80  * find the module's symbols (e.g. function names) with g_module_symbol(),
81  * and later close the module with g_module_close().
82  * g_module_name() will return the file name of a currently opened module.
83  *
84  * If any of the above functions fail, the error status can be found with
85  * g_module_error().
86  *
87  * The GModule implementation features reference counting for opened modules,
88  * and supports hook functions within a module which are called when the
89  * module is loaded and unloaded (see GModuleCheckInit and GModuleUnload).
90  *
91  * If your module introduces static data to common subsystems in the running
92  * program, e.g. through calling
93  * g_quark_from_static_string ("my-module-stuff"),
94  * it must ensure that it is never unloaded, by calling g_module_make_resident().
95  *
96  * $(DDOC_COMMENT example)
97  */
98 public class Module
99 {
100 	
101 	/** the main Gtk struct */
102 	protected GModule* gModule;
103 	
104 	
105 	public GModule* getModuleStruct()
106 	{
107 		return gModule;
108 	}
109 	
110 	
111 	/** the main Gtk struct as a void* */
112 	protected void* getStruct()
113 	{
114 		return cast(void*)gModule;
115 	}
116 	
117 	/**
118 	 * Sets our main struct and passes it to the parent class
119 	 */
120 	public this (GModule* gModule)
121 	{
122 		this.gModule = gModule;
123 	}
124 	
125 	/**
126 	 */
127 	
128 	/**
129 	 * Checks if modules are supported on the current platform.
130 	 * Returns: TRUE if modules are supported
131 	 */
132 	public static int supported()
133 	{
134 		// gboolean g_module_supported (void);
135 		return g_module_supported();
136 	}
137 	
138 	/**
139 	 * A portable way to build the filename of a module. The platform-specific
140 	 * prefix and suffix are added to the filename, if needed, and the result
141 	 * is added to the directory, using the correct separator character.
142 	 * The directory should specify the directory where the module can be found.
143 	 * It can be NULL or an empty string to indicate that the module is in a
144 	 * standard platform-specific directory, though this is not recommended
145 	 * since the wrong module may be found.
146 	 * For example, calling g_module_build_path() on a Linux system with a
147 	 * directory of /lib and a module_name of "mylibrary"
148 	 * will return /lib/libmylibrary.so. On a Windows system,
149 	 * using \Windows as the directory it will return
150 	 * \Windows\mylibrary.dll.
151 	 * Params:
152 	 * directory = the directory where the module is. This can be NULL
153 	 * or the empty string to indicate that the standard platform-specific
154 	 * directories will be used, though that is not recommended. [allow-none]
155 	 * moduleName = the name of the module
156 	 * Returns: the complete path of the module, including the standard library prefix and suffix. This should be freed when no longer needed
157 	 */
158 	public static string buildPath(string directory, string moduleName)
159 	{
160 		// gchar * g_module_build_path (const gchar *directory,  const gchar *module_name);
161 		return Str.toString(g_module_build_path(Str.toStringz(directory), Str.toStringz(moduleName)));
162 	}
163 	
164 	/**
165 	 * Opens a module. If the module has already been opened,
166 	 * its reference count is incremented.
167 	 * First of all g_module_open() tries to open file_name as a module.
168 	 * If that fails and file_name has the ".la"-suffix (and is a libtool
169 	 * archive) it tries to open the corresponding module. If that fails
170 	 * and it doesn't have the proper module suffix for the platform
171 	 * (G_MODULE_SUFFIX), this suffix will be appended and the corresponding
172 	 * module will be opended. If that fails and file_name doesn't have the
173 	 * ".la"-suffix, this suffix is appended and g_module_open() tries to open
174 	 * the corresponding module. If eventually that fails as well, NULL is
175 	 * returned.
176 	 * Params:
177 	 * fileName = the name of the file containing the module, or NULL
178 	 * to obtain a GModule representing the main program itself. [allow-none]
179 	 * flags = the flags used for opening the module. This can be the
180 	 * logical OR of any of the GModuleFlags
181 	 * Returns: a GModule on success, or NULL on failure
182 	 */
183 	public static Module open(string fileName, GModuleFlags flags)
184 	{
185 		// GModule * g_module_open (const gchar *file_name,  GModuleFlags flags);
186 		auto p = g_module_open(Str.toStringz(fileName), flags);
187 		
188 		if(p is null)
189 		{
190 			return null;
191 		}
192 		
193 		return new Module(cast(GModule*) p);
194 	}
195 	
196 	/**
197 	 * Gets a symbol pointer from a module, such as one exported
198 	 * by G_MODULE_EXPORT. Note that a valid symbol can be NULL.
199 	 * Params:
200 	 * symbolName = the name of the symbol to find
201 	 * symbol = returns the pointer to the symbol value. [out]
202 	 * Returns: TRUE on success
203 	 */
204 	public int symbol(string symbolName, void** symbol)
205 	{
206 		// gboolean g_module_symbol (GModule *module,  const gchar *symbol_name,  gpointer *symbol);
207 		return g_module_symbol(gModule, Str.toStringz(symbolName), symbol);
208 	}
209 	
210 	/**
211 	 * Returns the filename that the module was opened with.
212 	 * If module refers to the application itself, "main" is returned.
213 	 * Returns: the filename of the module. [transfer none]
214 	 */
215 	public string name()
216 	{
217 		// const gchar * g_module_name (GModule *module);
218 		return Str.toString(g_module_name(gModule));
219 	}
220 	
221 	/**
222 	 * Ensures that a module will never be unloaded.
223 	 * Any future g_module_close() calls on the module will be ignored.
224 	 */
225 	public void makeResident()
226 	{
227 		// void g_module_make_resident (GModule *module);
228 		g_module_make_resident(gModule);
229 	}
230 	
231 	/**
232 	 * Closes a module.
233 	 * Returns: TRUE on success
234 	 */
235 	public int close()
236 	{
237 		// gboolean g_module_close (GModule *module);
238 		return g_module_close(gModule);
239 	}
240 	
241 	/**
242 	 * Gets a string describing the last module error.
243 	 * Returns: a string describing the last module error
244 	 */
245 	public static string error()
246 	{
247 		// const gchar * g_module_error (void);
248 		return Str.toString(g_module_error());
249 	}
250 }