Class Module
- All Implemented Interfaces:
Proxy
GModule
struct is an opaque data structure to represent a
[dynamically-loaded module][glib-Dynamic-Loading-of-Modules].
It should only be accessed via the following functions.-
Constructor Summary
ConstructorDescriptionModule
(MemorySegment address) Create a Module proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Deprecated.boolean
close()
Closes a module.static String
error()
Gets a string describing the last module error.static Quark
void
Ensures that a module will never be unloaded.name()
Returns the filename that the module was opened with.static Module
open
(@Nullable String fileName, Set<ModuleFlags> flags) A thin wrapper function around g_module_open_full()static Module
open
(@Nullable String fileName, ModuleFlags... flags) A thin wrapper function around g_module_open_full()static Module
openFull
(@Nullable String fileName, Set<ModuleFlags> flags) Opens a module.static Module
openFull
(@Nullable String fileName, ModuleFlags... flags) Opens a module.static boolean
Checks if modules are supported on the current platform.boolean
symbol
(String symbolName, @Nullable Out<MemorySegment> symbol) Gets a symbol pointer from a module, such as one exported byG_MODULE_EXPORT
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Module
Create a Module proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
buildPath
Deprecated.Use g_module_open() instead withmoduleName
as the basename of the file_name argument. SeeG_MODULE_SUFFIX
for why.A portable way to build the filename of a module. The platform-specific prefix and suffix are added to the filename, if needed, and the result is added to the directory, using the correct separator character.The directory should specify the directory where the module can be found. It can be
null
or an empty string to indicate that the module is in a standard platform-specific directory, though this is not recommended since the wrong module may be found.For example, calling g_module_build_path() on a Linux system with a
directory
of/lib
and amoduleName
of "mylibrary" will return/lib/libmylibrary.so
. On a Windows system, using\\Windows
as the directory it will return\\Windows\\mylibrary.dll
.- Parameters:
directory
- the directory where the module is. This can benull
or the empty string to indicate that the standard platform-specific directories will be used, though that is not recommendedmoduleName
- the name of the module- Returns:
- the complete path of the module, including the standard library prefix and suffix. This should be freed when no longer needed
-
error
Gets a string describing the last module error.- Returns:
- a string describing the last module error
-
errorQuark
-
open
A thin wrapper function around g_module_open_full()- Parameters:
fileName
- the name or path to the file containing the module, ornull
to obtain aGModule
representing the main program itselfflags
- the flags used for opening the module. This can be the logical OR of any of theGModuleFlags
.- Returns:
- a
GModule
on success, ornull
on failure
-
open
A thin wrapper function around g_module_open_full()- Parameters:
fileName
- the name or path to the file containing the module, ornull
to obtain aGModule
representing the main program itselfflags
- the flags used for opening the module. This can be the logical OR of any of theGModuleFlags
.- Returns:
- a
GModule
on success, ornull
on failure
-
openFull
public static Module openFull(@Nullable @Nullable String fileName, Set<ModuleFlags> flags) throws GErrorException Opens a module. If the module has already been opened, its reference count is incremented. If not, the module is searched usingfileName
.Since 2.76, the search order/behavior is as follows:
1. If
fileName
exists as a regular file, it is used as-is; else 2. IffileName
doesn't have the correct suffix and/or prefix for the platform, then possible suffixes and prefixes will be added to the basename till a file is found and whatever is found will be used; else 3. IffileName
doesn't have the ".la"-suffix, ".la" is appended. Either way, if a matching .la file exists (and is a libtool archive) the libtool archive is parsed to find the actual file name, and that is used.If, at the end of all this, we have a file path that we can access on disk, it is opened as a module. If not,
fileName
is attempted to be opened as a module verbatim in the hopes that the system implementation will somehow be able to access it. If that is not possible,null
is returned.Note that this behaviour was different prior to 2.76, but there is some overlap in functionality. If backwards compatibility is an issue, kindly consult earlier
GModule
documentation for the prior search order/behavior offileName
.- Parameters:
fileName
- the name or path to the file containing the module, ornull
to obtain aGModule
representing the main program itselfflags
- the flags used for opening the module. This can be the logical OR of any of theGModuleFlags
- Returns:
- a
GModule
on success, ornull
on failure - Throws:
GErrorException
- seeGError
-
openFull
public static Module openFull(@Nullable @Nullable String fileName, ModuleFlags... flags) throws GErrorException Opens a module. If the module has already been opened, its reference count is incremented. If not, the module is searched usingfileName
.Since 2.76, the search order/behavior is as follows:
1. If
fileName
exists as a regular file, it is used as-is; else 2. IffileName
doesn't have the correct suffix and/or prefix for the platform, then possible suffixes and prefixes will be added to the basename till a file is found and whatever is found will be used; else 3. IffileName
doesn't have the ".la"-suffix, ".la" is appended. Either way, if a matching .la file exists (and is a libtool archive) the libtool archive is parsed to find the actual file name, and that is used.If, at the end of all this, we have a file path that we can access on disk, it is opened as a module. If not,
fileName
is attempted to be opened as a module verbatim in the hopes that the system implementation will somehow be able to access it. If that is not possible,null
is returned.Note that this behaviour was different prior to 2.76, but there is some overlap in functionality. If backwards compatibility is an issue, kindly consult earlier
GModule
documentation for the prior search order/behavior offileName
.- Parameters:
fileName
- the name or path to the file containing the module, ornull
to obtain aGModule
representing the main program itselfflags
- the flags used for opening the module. This can be the logical OR of any of theGModuleFlags
- Returns:
- a
GModule
on success, ornull
on failure - Throws:
GErrorException
- seeGError
-
supported
public static boolean supported()Checks if modules are supported on the current platform.- Returns:
true
if modules are supported
-
close
public boolean close()Closes a module.- Returns:
true
on success
-
makeResident
public void makeResident()Ensures that a module will never be unloaded. Any future g_module_close() calls on the module will be ignored. -
name
Returns the filename that the module was opened with.If this Module refers to the application itself, "main" is returned.
- Returns:
- the filename of the module
-
symbol
Gets a symbol pointer from a module, such as one exported byG_MODULE_EXPORT
. Note that a valid symbol can benull
.- Parameters:
symbolName
- the name of the symbol to findsymbol
- returns the pointer to the symbol value- Returns:
true
on success
-
moduleName
as the basename of the file_name argument.