2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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
47 * - GModule* -> Module
58 import tango
.io
.Stdout
; // use the tango loging?
62 private import gtkc
.glibtypes
;
64 private import gtkc
.glib
;
67 private import glib
.Module
;
68 private import glib
.Str
;
75 * These functions provide a portable way to dynamically load object files
76 * (commonly known as 'plug-ins').
77 * The current implementation supports all systems that provide
78 * an implementation of dlopen() (e.g. Linux/Sun), as well as HP-UX via its
79 * shl_load() mechanism, and Windows platforms via DLLs.
80 * A program which wants to use these functions must be linked to the
81 * libraries output by the command pkg-config --libs gmodule-2.0.
82 * To use them you must first determine whether dynamic loading
83 * is supported on the platform by calling g_module_supported().
84 * If it is, you can open a module with g_module_open(),
85 * find the module's symbols (e.g. function names) with g_module_symbol(),
86 * and later close the module with g_module_close().
87 * g_module_name() will return the file name of a currently opened module.
88 * If any of the above functions fail, the error status can be found with
90 * The GModule implementation features reference counting for opened modules,
91 * and supports hook functions within a module which are called when the
92 * module is loaded and unloaded (see GModuleCheckInit and GModuleUnload).
93 * If your module introduces static data to common subsystems in the running
94 * program, e.g. through calling g_quark_from_static_string ("my-module-stuff"),
95 * it must ensure that it is never unloaded, by calling g_module_make_resident().
96 * Example12.Calling a function defined in a GModule
97 * /+* the function signature for 'say_hello' +/
98 * typedef void (* SayHelloFunc) (const char *message);
100 * just_say_hello (const char *filename, GError **error)
102 * SayHelloFunc say_hello;
104 * module = g_module_open (filename, G_MODULE_BIND_LAZY);
107 * g_set_error (error, FOO_ERROR, FOO_ERROR_BLAH,
108 * "%s", g_module_error ());
111 * if (!g_module_symbol (module, "say_hello", (gpointer *)say_hello))
113 * g_set_error (error, SAY_ERROR, SAY_ERROR_OPEN,
114 * "%s: %s", filename, g_module_error ());
115 * if (!g_module_close (module))
116 * g_warning ("%s: %s", filename, g_module_error ());
119 * if (say_hello == NULL)
121 * g_set_error (error, SAY_ERROR, SAY_ERROR_OPEN, "symbol say_hello is NULL");
122 * if (!g_module_close (module))
123 * g_warning ("%s: %s", filename, g_module_error ());
126 * if (say_hello == NULL)
128 * g_set_error (error, SAY_ERROR, SAY_ERROR_OPEN, "symbol say_hello is NULL");
129 * if (!g_module_close (module))
130 * g_warning ("%s: %s", filename, g_module_error ());
133 * /+* call our function in the module +/
134 * say_hello ("Hello world!");
135 * if (!g_module_close (module))
136 * g_warning ("%s: %s", filename, g_module_error ());
143 /** the main Gtk struct */
144 protected GModule
* gModule
;
147 public GModule
* getModuleStruct()
153 /** the main Gtk struct as a void* */
154 protected void* getStruct()
156 return cast(void*)gModule
;
160 * Sets our main struct and passes it to the parent class
162 public this (GModule
* gModule
)
166 if ( gModule
is null )
171 Stdout("struct gModule is null on constructor").newline
;
175 printf("struct gModule is null on constructor");
182 assert(gModule
!is null, "struct gModule is null on constructor");
184 this.gModule
= gModule
;
192 * Checks if modules are supported on the current platform.
194 * TRUE if modules are supported.
196 public static int supported()
198 // gboolean g_module_supported (void);
199 return g_module_supported();
203 * A portable way to build the filename of a module. The platform-specific
204 * prefix and suffix are added to the filename, if needed, and the result is
205 * added to the directory, using the correct separator character.
206 * The directory should specify the directory where the module can be found.
207 * It can be NULL or an empty string to indicate that the module is in a standard
208 * platform-specific directory, though this is not recommended since the
209 * wrong module may be found.
210 * For example, calling g_module_build_path() on a Linux system with a directory
211 * of /lib and a module_name of "mylibrary" will return
212 * /lib/libmylibrary.so. On a Windows system, using
213 * \Windows as the directory it will return
214 * \Windows\mylibrary.dll.
216 * the directory where the module is. This can be NULL or the empty
217 * string to indicate that the standard platform-specific directories will be
218 * used, though that is not recommended.
220 * the name of the module.
222 * the complete path of the module, including the standard library
223 * prefix and suffix. This should be freed when no longer needed.
225 public static char[] buildPath(char[] directory
, char[] moduleName
)
227 // gchar* g_module_build_path (const gchar *directory, const gchar *module_name);
228 return Str
.toString(g_module_build_path(Str
.toStringz(directory
), Str
.toStringz(moduleName
)) );
232 * Opens a module. If the module has already been opened, its reference
233 * count is incremented.
234 * First of all g_module_open() tries to open file_name as a module. If
235 * that fails and file_name has the ".la"-suffix (and is a libtool archive)
236 * it tries to open the corresponding module. If that fails and it doesn't
237 * have the proper module suffix for the platform (G_MODULE_SUFFIX), this
238 * suffix will be appended and the corresponding module will be opended. If
239 * that fails and file_name doesn't have the ".la"-suffix, this suffix is
240 * appended and g_module_open() tries to open the corresponding module. If
241 * eventually that fails as well, NULL is returned.
243 * the name of the file containing the module, or NULL to obtain
244 * a GModule representing the main program itself.
246 * the flags used for opening the module. This can be the logical
247 * OR of any of the GModuleFlags.
249 * a GModule on success, or NULL on failure.
251 public static Module
open(char[] fileName
, GModuleFlags flags
)
253 // GModule* g_module_open (const gchar *file_name, GModuleFlags flags);
254 return new Module( g_module_open(Str
.toStringz(fileName
), flags
) );
259 * Gets a symbol pointer from a module.
260 * Note that a valid symbol can be NULL.
261 * Note that a valid symbol can be NULL.
265 * the name of the symbol to find.
267 * returns the pointer to the symbol value.
271 public int symbol(char[] symbolName
, void** symbol
)
273 // gboolean g_module_symbol (GModule *module, const gchar *symbol_name, gpointer *symbol);
274 return g_module_symbol(gModule
, Str
.toStringz(symbolName
), symbol
);
278 * Gets the filename from a GModule.
282 * the filename of the module, or "main" if the module is the main
287 // const gchar* g_module_name (GModule *module);
288 return Str
.toString(g_module_name(gModule
) );
292 * Ensures that a module will never be unloaded.
293 * Any future g_module_close() calls on the module will be ignored.
295 * a GModule to make permanently resident.
297 public void makeResident()
299 // void g_module_make_resident (GModule *module);
300 g_module_make_resident(gModule
);
306 * a GModule to close.
312 // gboolean g_module_close (GModule *module);
313 return g_module_close(gModule
);
317 * Gets a string describing the last module error.
319 * a string describing the last module error.
321 public static char[] error()
323 // const gchar* g_module_error (void);
324 return Str
.toString(g_module_error() );