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