alternative to assert
[gtkD.git] / src / glib / Module.d
blobb513c6330ba81b0126eff4272067d23305627b36
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Dynamic-Loading-of-Modules.html
26 * outPack = glib
27 * outFile = Module
28 * strct = GModule
29 * realStrct=
30 * ctorStrct=
31 * clss = Module
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_module_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Module
45 * - glib.Str
46 * structWrap:
47 * - GModule* -> Module
48 * local aliases:
51 module glib.Module;
53 private import glib.glibtypes;
55 private import lib.glib;
57 private import glib.Module;
58 private import glib.Str;
60 /**
61 * Description
62 * These functions provide a portable way to dynamically load object files
63 * (commonly known as 'plug-ins').
64 * The current implementation supports all systems that provide
65 * an implementation of dlopen() (e.g. Linux/Sun), as well as HP-UX via its
66 * shl_load() mechanism, and Windows platforms via DLLs.
67 * A program which wants to use these functions must be linked to the
68 * libraries output by the command pkg-config --libs gmodule-2.0.
69 * To use them you must first determine whether dynamic loading
70 * is supported on the platform by calling g_module_supported().
71 * If it is, you can open a module with g_module_open(),
72 * find the module's symbols (e.g. function names) with g_module_symbol(),
73 * and later close the module with g_module_close().
74 * g_module_name() will return the file name of a currently opened module.
75 * If any of the above functions fail, the error status can be found with
76 * g_module_error().
77 * The GModule implementation features reference counting for opened modules,
78 * and supports hook functions within a module which are called when the
79 * module is loaded and unloaded (see GModuleCheckInit and GModuleUnload).
80 * If your module introduces static data to common subsystems in the running
81 * program, e.g. through calling g_quark_from_static_string ("my-module-stuff"),
82 * it must ensure that it is never unloaded, by calling g_module_make_resident().
83 * Example12.Calling a function defined in a GModule
84 * /+* the function signature for 'say_hello' +/
85 * typedef void (* SayHelloFunc) (const char *message);
86 * gboolean
87 * just_say_hello (const char *filename, GError **error)
88 * {
89 * SayHelloFunc say_hello;
90 * GModule *module;
91 * module = g_module_open (filename, G_MODULE_BIND_LAZY);
92 * if (!module)
93 * {
94 * g_set_error (error, FOO_ERROR, FOO_ERROR_BLAH,
95 * "%s", g_module_error ());
96 * return FALSE;
97 * }
98 * if (!g_module_symbol (module, "say_hello", (gpointer *)say_hello))
99 * {
100 * g_set_error (error, SAY_ERROR, SAY_ERROR_OPEN,
101 * "%s: %s", filename, g_module_error ());
102 * if (!g_module_close (module))
103 * g_warning ("%s: %s", filename, g_module_error ());
104 * return FALSE;
106 * /+* call our function in the module +/
107 * say_hello ("Hello world!");
108 * if (!g_module_close (module))
109 * g_warning ("%s: %s", filename, g_module_error ());
110 * return TRUE;
113 public class Module
116 /** the main Gtk struct */
117 protected GModule* gModule;
120 public GModule* getModuleStruct()
122 return gModule;
126 /** the main Gtk struct as a void* */
127 protected void* getStruct()
129 return cast(void*)gModule;
133 * Sets our main struct and passes it to the parent class
135 public this (GModule* gModule)
137 this.gModule = gModule;
145 * Checks if modules are supported on the current platform.
146 * Returns:
147 * TRUE if modules are supported.
149 public static int supported()
151 // gboolean g_module_supported (void);
152 return g_module_supported();
156 * A portable way to build the filename of a module. The platform-specific
157 * prefix and suffix are added to the filename, if needed, and the result is
158 * added to the directory, using the correct separator character.
159 * The directory should specify the directory where the module can be found.
160 * It can be NULL or an empty string to indicate that the module is in a standard
161 * platform-specific directory, though this is not recommended since the
162 * wrong module may be found.
163 * For example, calling g_module_build_path() on a Linux system with a directory
164 * of /lib and a module_name of "mylibrary" will return
165 * /lib/libmylibrary.so. On a Windows system, using
166 * \Windows as the directory it will return
167 * \Windows\mylibrary.dll.
168 * directory:
169 * the directory where the module is. This can be NULL or the empty
170 * string to indicate that the standard platform-specific directories will be
171 * used, though that is not recommended.
172 * module_name:
173 * the name of the module.
174 * Returns:
175 * the complete path of the module, including the standard library
176 * prefix and suffix. This should be freed when no longer needed.
178 public static char[] buildPath(char[] directory, char[] moduleName)
180 // gchar* g_module_build_path (const gchar *directory, const gchar *module_name);
181 return Str.toString(g_module_build_path(Str.toStringz(directory), Str.toStringz(moduleName)) );
185 * Opens a module. If the module has already been opened, its reference
186 * count is incremented.
187 * First of all g_module_open() tries to open file_name as a module. If
188 * that fails and file_name has the ".la"-suffix (and is a libtool archive)
189 * it tries to open the corresponding module. If that fails and it doesn't
190 * have the proper module suffix for the platform (G_MODULE_SUFFIX), this
191 * suffix will be appended and the corresponding module will be opended. If
192 * that fails and file_name doesn't have the ".la"-suffix, this suffix is
193 * appended and g_module_open() tries to open the corresponding module. If
194 * eventually that fails as well, NULL is returned.
195 * file_name:
196 * the name of the file containing the module, or NULL to obtain
197 * a GModule representing the main program itself.
198 * flags:
199 * the flags used for opening the module. This can be the logical
200 * OR of any of the GModuleFlags.
201 * Returns:
202 * a GModule on success, or NULL on failure.
204 public static Module open(char[] fileName, GModuleFlags flags)
206 // GModule* g_module_open (const gchar *file_name, GModuleFlags flags);
207 return new Module( g_module_open(Str.toStringz(fileName), flags) );
212 * Gets a symbol pointer from a module.
213 * module:
214 * a GModule.
215 * symbol_name:
216 * the name of the symbol to find.
217 * symbol:
218 * returns the pointer to the symbol value.
219 * Returns:
220 * TRUE on success.
222 public int symbol(char[] symbolName, void** symbol)
224 // gboolean g_module_symbol (GModule *module, const gchar *symbol_name, gpointer *symbol);
225 return g_module_symbol(gModule, Str.toStringz(symbolName), symbol);
229 * Gets the filename from a GModule.
230 * module:
231 * a GModule.
232 * Returns:
233 * the filename of the module, or "main" if the module is the main
234 * program itself.
236 public char[] name()
238 // const gchar* g_module_name (GModule *module);
239 return Str.toString(g_module_name(gModule) );
243 * Ensures that a module will never be unloaded.
244 * Any future g_module_close() calls on the module will be ignored.
245 * module:
246 * a GModule to make permanently resident.
248 public void makeResident()
250 // void g_module_make_resident (GModule *module);
251 g_module_make_resident(gModule);
255 * Closes a module.
256 * module:
257 * a GModule to close.
258 * Returns:
259 * TRUE on success.
261 public int close()
263 // gboolean g_module_close (GModule *module);
264 return g_module_close(gModule);
268 * Gets a string describing the last module error.
269 * Returns:
270 * a string describing the last module error.
272 public static char[] error()
274 // const gchar* g_module_error (void);
275 return Str.toString(g_module_error() );