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 module glib.Module;
26 
27 private import glib.Str;
28 private import gtkc.glib;
29 public  import gtkc.glibtypes;
30 
31 
32 /**
33  * The #GModule struct is an opaque data structure to represent a
34  * [dynamically-loaded module][glib-Dynamic-Loading-of-Modules].
35  * It should only be accessed via the following functions.
36  */
37 public class Module
38 {
39 	/** the main Gtk struct */
40 	protected GModule* gModule;
41 
42 	/** Get the main Gtk struct */
43 	public GModule* getModuleStruct()
44 	{
45 		return gModule;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected void* getStruct()
50 	{
51 		return cast(void*)gModule;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (GModule* gModule)
58 	{
59 		this.gModule = gModule;
60 	}
61 
62 
63 	/**
64 	 * Closes a module.
65 	 *
66 	 * Return: %TRUE on success
67 	 */
68 	public bool close()
69 	{
70 		return g_module_close(gModule) != 0;
71 	}
72 
73 	/**
74 	 * Ensures that a module will never be unloaded.
75 	 * Any future g_module_close() calls on the module will be ignored.
76 	 */
77 	public void makeResident()
78 	{
79 		g_module_make_resident(gModule);
80 	}
81 
82 	/**
83 	 * Returns the filename that the module was opened with.
84 	 *
85 	 * If @module refers to the application itself, "main" is returned.
86 	 *
87 	 * Return: the filename of the module
88 	 */
89 	public string name()
90 	{
91 		return Str.toString(g_module_name(gModule));
92 	}
93 
94 	/**
95 	 * Gets a symbol pointer from a module, such as one exported
96 	 * by #G_MODULE_EXPORT. Note that a valid symbol can be %NULL.
97 	 *
98 	 * Params:
99 	 *     symbolName = the name of the symbol to find
100 	 *     symbol = returns the pointer to the symbol value
101 	 *
102 	 * Return: %TRUE on success
103 	 */
104 	public bool symbol(string symbolName, void** symbol)
105 	{
106 		return g_module_symbol(gModule, Str.toStringz(symbolName), symbol) != 0;
107 	}
108 
109 	/**
110 	 * A portable way to build the filename of a module. The platform-specific
111 	 * prefix and suffix are added to the filename, if needed, and the result
112 	 * is added to the directory, using the correct separator character.
113 	 *
114 	 * The directory should specify the directory where the module can be found.
115 	 * It can be %NULL or an empty string to indicate that the module is in a
116 	 * standard platform-specific directory, though this is not recommended
117 	 * since the wrong module may be found.
118 	 *
119 	 * For example, calling g_module_build_path() on a Linux system with a
120 	 * @directory of `/lib` and a @module_name of "mylibrary" will return
121 	 * `/lib/libmylibrary.so`. On a Windows system, using `\Windows` as the
122 	 * directory it will return `\Windows\mylibrary.dll`.
123 	 *
124 	 * Params:
125 	 *     directory = the directory where the module is. This can be
126 	 *         %NULL or the empty string to indicate that the standard platform-specific
127 	 *         directories will be used, though that is not recommended
128 	 *     moduleName = the name of the module
129 	 *
130 	 * Return: the complete path of the module, including the standard library
131 	 *     prefix and suffix. This should be freed when no longer needed
132 	 */
133 	public static string buildPath(string directory, string moduleName)
134 	{
135 		return Str.toString(g_module_build_path(Str.toStringz(directory), Str.toStringz(moduleName)));
136 	}
137 
138 	/**
139 	 * Gets a string describing the last module error.
140 	 *
141 	 * Return: a string describing the last module error
142 	 */
143 	public static string error()
144 	{
145 		return Str.toString(g_module_error());
146 	}
147 
148 	/**
149 	 * Opens a module. If the module has already been opened,
150 	 * its reference count is incremented.
151 	 *
152 	 * First of all g_module_open() tries to open @file_name as a module.
153 	 * If that fails and @file_name has the ".la"-suffix (and is a libtool
154 	 * archive) it tries to open the corresponding module. If that fails
155 	 * and it doesn't have the proper module suffix for the platform
156 	 * (#G_MODULE_SUFFIX), this suffix will be appended and the corresponding
157 	 * module will be opended. If that fails and @file_name doesn't have the
158 	 * ".la"-suffix, this suffix is appended and g_module_open() tries to open
159 	 * the corresponding module. If eventually that fails as well, %NULL is
160 	 * returned.
161 	 *
162 	 * Params:
163 	 *     fileName = the name of the file containing the module, or %NULL
164 	 *         to obtain a #GModule representing the main program itself
165 	 *     flags = the flags used for opening the module. This can be the
166 	 *         logical OR of any of the #GModuleFlags
167 	 *
168 	 * Return: a #GModule on success, or %NULL on failure
169 	 */
170 	public static Module open(string fileName, GModuleFlags flags)
171 	{
172 		auto p = g_module_open(Str.toStringz(fileName), flags);
173 		
174 		if(p is null)
175 		{
176 			return null;
177 		}
178 		
179 		return new Module(cast(GModule*) p);
180 	}
181 
182 	/**
183 	 * Checks if modules are supported on the current platform.
184 	 *
185 	 * Return: %TRUE if modules are supported
186 	 */
187 	public static bool supported()
188 	{
189 		return g_module_supported() != 0;
190 	}
191 }