Plasma Engine  2.0
Loading...
Searching...
No Matches
Plugin_Posix.h
1#include <Foundation/FoundationInternal.h>
2PL_FOUNDATION_INTERNAL_HEADER
3
4#include <dlfcn.h>
5
6#include <Foundation/Configuration/Plugin.h>
7#include <Foundation/IO/OSFile.h>
8#include <Foundation/Logging/Log.h>
9#include <Foundation/Strings/StringBuilder.h>
10#include <Foundation/System/Process.h>
11
12using plPluginModule = void*;
13
14bool plPlugin::PlatformNeedsPluginCopy()
15{
16 return false;
17}
18
19void plPlugin::GetPluginPaths(plStringView sPluginName, plStringBuilder& sOriginalFile, plStringBuilder& sCopiedFile, plUInt8 uiFileCopyNumber)
20{
21 sOriginalFile = plOSFile::GetApplicationDirectory();
22 sOriginalFile.AppendPath(sPluginName);
23 sOriginalFile.Append(".so");
24
26 sCopiedFile.AppendPath(sPluginName);
27
28 if (uiFileCopyNumber > 0)
29 sCopiedFile.AppendFormat("{0}", uiFileCopyNumber);
30
31 sCopiedFile.Append(".loaded");
32}
33
34plResult UnloadPluginModule(plPluginModule& Module, plStringView sPluginFile)
35{
36 if (dlclose(Module) != 0)
37 {
39 plLog::Error("Could not unload plugin '{0}'. Error {1}", sPluginFile.GetData(tmp), static_cast<const char*>(dlerror()));
40 return PL_FAILURE;
41 }
42
43 return PL_SUCCESS;
44}
45
46plResult LoadPluginModule(plStringView sFileToLoad, plPluginModule& Module, plStringView sPluginFile)
47{
49 Module = dlopen(sFileToLoad.GetData(tmp), RTLD_NOW | RTLD_GLOBAL);
50 if (Module == nullptr)
51 {
52 plLog::Error("Could not load plugin '{0}'. Error {1}.\nSet the environment variable LD_DEBUG=all to get more information.", sPluginFile.GetData(tmp), static_cast<const char*>(dlerror()));
53 return PL_FAILURE;
54 }
55 return PL_SUCCESS;
56}
static void Error(plLogInterface *pInterface, const plFormatString &string)
An error that needs to be fixed as soon as possible.
Definition Log.cpp:375
static plStringView GetApplicationDirectory()
Returns the path to the directory in which the application binary is located.
Definition OSFile.cpp:331
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
void Append(plUInt32 uiChar)
Appends a single Utf32 character.
Definition StringBuilder_inl.h:94
void AppendFormat(const plFormatString &string)
Appends a formatted string. Uses '{}' formatting placeholders, see plFormatString for details.
Definition StringBuilder.cpp:1251
void AppendPath(plStringView sPath1, plStringView sPath2={}, plStringView sPath3={}, plStringView sPath4={})
Appends several path pieces. Makes sure they are always properly separated by a slash.
Definition StringBuilder.cpp:866
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
const char * GetData(plStringBuilder &ref_sTempStorage) const
Returns the data as a zero-terminated string.
Definition StringView.cpp:15
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54