8 #include "addonloader.h" 13 #include <string_view> 21 #include "addoninfo.h" 23 #include "addonloader_p.h" 28 AddonLoader::~AddonLoader() {}
30 SharedLibraryLoader::~SharedLibraryLoader() {}
32 AddonInstance *SharedLibraryLoader::load(
const AddonInfo &info,
33 AddonManager *manager) {
34 auto iter = registry_.find(info.uniqueName());
35 if (iter == registry_.end()) {
36 std::vector<std::string> libnames =
39 if (libnames.empty()) {
40 FCITX_ERROR() <<
"Failed to parse Library field: " << info.library()
41 <<
" for addon " << info.uniqueName();
45 std::vector<Library> libraries;
46 for (std::string_view libname : libnames) {
47 Flags<LibraryLoadHint> flag = LibraryLoadHint::DefaultHint;
49 flag |= LibraryLoadHint::ExportExternalSymbolsHint;
52 stringutils::concat(libname, FCITX_LIBRARY_SUFFIX);
54 StandardPathsType::Addon, file);
55 if (libraryPaths.empty()) {
56 FCITX_ERROR() <<
"Could not locate library " << file
57 <<
" for addon " << info.uniqueName() <<
".";
60 for (
const auto &libraryPath : libraryPaths) {
61 Library library(libraryPath);
62 if (library.load(flag)) {
63 libraries.push_back(std::move(library));
68 <<
"Failed to load library for addon " << info.uniqueName()
69 <<
" on " << libraryPath <<
". Error: " << library.error();
76 if (libraries.size() == libnames.size()) {
78 registry_.emplace(info.uniqueName(),
79 std::make_unique<SharedLibraryFactory>(
80 info, std::move(libraries)));
81 }
catch (
const std::exception &e) {
82 FCITX_ERROR() <<
"Failed to initialize addon factory for addon " 83 << info.uniqueName() <<
". Error: " << e.what();
85 iter = registry_.find(info.uniqueName());
89 if (iter == registry_.end()) {
94 return iter->second->factory()->create(manager);
95 }
catch (
const std::exception &e) {
96 FCITX_ERROR() <<
"Failed to create addon: " << info.uniqueName() <<
" " 99 FCITX_ERROR() <<
"Failed to create addon: " << info.uniqueName();
104 StaticLibraryLoader::StaticLibraryLoader(StaticAddonRegistry *registry_)
105 : registry(registry_) {}
107 AddonInstance *StaticLibraryLoader::load(
const AddonInfo &info,
108 AddonManager *manager) {
109 auto iter = registry->find(info.uniqueName());
110 if (iter == registry->end()) {
114 return iter->second->create(manager);
115 }
catch (
const std::exception &e) {
116 FCITX_ERROR() <<
"Failed to create addon: " << info.uniqueName() <<
" " 119 FCITX_ERROR() <<
"Failed to create addon: " << info.uniqueName();
static const StandardPaths & global()
Return the global instance of StandardPath.
std::vector< std::filesystem::path > locateAll(StandardPathsType type, const std::filesystem::path &path, StandardPathsModes modes=StandardPathsMode::Default) const
Check if path exists in all directories.
bool consumePrefix(std::string_view &str, std::string_view prefix)
Return a substring of input str if str starts with given prefix.
Class to handler dynamic library.
std::vector< std::string > split(std::string_view str, std::string_view delim, SplitBehavior behavior)
Split the string by delim.
New Utility classes to handle application specific path.
Helper template class to make easier to use type safe enum flags.