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