36{
37 bool retval = true;
38
40 {
42 {
46
48 {
49#ifdef _WIN32
50
51 std::string plugin_path = (boost::dll::program_location().parent_path() / "plugins").generic_string();
52 dirs.push_back(plugin_path);
53#else
54 dirs.emplace_back(PLUGIN_DIR);
55#endif
56 }
57
58 if(path != nullptr)
59 {
61
62 for(char* i = path; *i != '\0'; i++)
63 {
64
65
66#ifdef _WIN32
67 const char envDelim = ';';
68#else
69 const char envDelim = ':';
70#endif
71 if(*i != envDelim)
72 {
73 continue;
74 }
75
76 *i = '\0';
77 dirs.emplace_back(path);
78 path = i + 1;
79 }
80
81 dirs.emplace_back(path);
82 }
83
87 break;
88 }
89
91 {
94 {
97 break;
98 }
99
102 namespace fs = boost::filesystem;
103 boost::system::error_code ec;
104
105 if(!fs::is_directory(folder, ec))
106 {
107 logger->error(
"Can't open directory: {}", folder);
109 break;
110 }
111
112 for(const auto& entry: fs::directory_iterator(folder))
113 {
114 if(fs::is_regular_file(entry) || fs::is_symlink(entry) || fs::is_other(entry))
115 {
116 files.push_back(entry.path().generic_string());
117 }
118 }
119
121 break;
122 }
123
125 {
128 {
130 break;
131 }
132
133#ifdef _WIN32
134
136 {
137#else
138
140 {
141#endif
143 GModule* plugin = g_module_open(
currentFile->c_str(),
static_cast<GModuleFlags
>(0));
144 if(plugin)
145 {
146 gpointer pgpi = nullptr;
147 bool symbol_found = false;
148
149 if(g_module_symbol(plugin, "_Z20getPluginInformationv", &pgpi))
150 {
151 symbol_found = true;
152 }
153 else if(g_module_symbol(plugin, "getPluginInformation", &pgpi))
154 {
155 symbol_found = true;
156 logger->warn(
"Plugin {} uses C-style GetPluginInformation - You need to recompile it", *
currentFile);
157 }
158
159 if(symbol_found)
160 {
161 using PluginFunc = std::shared_ptr<PluginInformationInterface> (*)();
162
163 auto gpi = reinterpret_cast<PluginFunc>(pgpi);
164 if(gpi)
165 {
168 {
170 {
172 pi->registerCapabilities(shared_from_this<PluginManager>());
173 plugin = nullptr;
174 gpi = nullptr;
176 }
177 else
178 {
181 );
182 }
183 }
184 else
185 {
187 }
188 }
189 else
190 {
191 logger->error(
"Can't find the getPluginInterface function in file {}: {}", *
currentFile, g_module_error());
192 }
193 }
194 else
195 {
196 logger->warn(
"Can't lookup symbols in file {}: {}", *
currentFile, g_module_error());
197 }
198
199 if(plugin)
200 {
201 g_module_close(plugin);
202 }
203 }
204 else
205 {
206 logger->error(
"Something went wrong for file {}: {}", *
currentFile, g_module_error());
207 }
208 }
210 break;
211 }
213 {
215
216 std::vector<std::pair<std::string, std::string>> pluginInfo;
218 size_t maxPluginNameLength = 0;
220 {
221 pluginInfo.emplace_back(plugin.pluginInformation->getPluginName(), plugin.pluginInformation->getPluginVersion());
222 maxPluginNameLength = std::max(maxPluginNameLength, plugin.pluginInformation->getPluginName().size());
223 }
224 std::sort(pluginInfo.begin(), pluginInfo.end());
225 logger->info(
"Loaded plugins:");
226 for(const auto& [name, version]: pluginInfo)
227 {
228 logger->info(
" {:{}} : {}", name, maxPluginNameLength, version);
229 }
230
232 retval = false;
233 break;
234 }
235 }
236 return retval;
237}
void on_done_loading_plugins()
Definition callbacks.cc:288
std::list< std::string > dirs
Definition pluginmanager.hh:59
std::list< std::string >::iterator currentDir
Definition pluginmanager.hh:60
std::list< std::string >::iterator currentFile
Definition pluginmanager.hh:62
void setStatusBarMessage(const char *message)
Definition pluginmanager.cc:239
std::list< PluginInformation > pluginInformationList
Definition pluginmanager.hh:63
Scroom::Logger logger
Definition pluginmanager.hh:71
std::list< std::string > files
Definition pluginmanager.hh:61
const std::string SCROOM_PLUGIN_DIRS
Definition pluginmanager.cc:27
ProgressInterface::Ptr const pi
Definition progressinterfaceconversion-tests.cc:23