source: appstream-generator/build/girepo/glib/Module.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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