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