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