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