Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
PluginManager Class Reference

#include <pluginmanager.hh>

Inheritance diagram for PluginManager:
Inheritance graph
Collaboration diagram for PluginManager:
Collaboration graph

Public Types

using Ptr = std::shared_ptr< PluginManager >
 
- Public Types inherited from ScroomPluginInterface
using Ptr = std::shared_ptr< ScroomPluginInterface >
 

Public Member Functions

bool doWork () override
 
void addHook (bool devMode)
 
void registerNewPresentationInterface (const std::string &identifier, NewPresentationInterface::Ptr newPresentationInterface) override
 
void registerNewAggregateInterface (const std::string &identifier, NewAggregateInterface::Ptr newAggregateInterface) override
 
void registerOpenPresentationInterface (const std::string &extension, OpenPresentationInterface::Ptr openPresentationInterface) override
 
void registerOpenTiledBitmapInterface (const std::string &identifier, std::shared_ptr< Scroom::TiledBitmap::OpenTiledBitmapInterface > openTiledBitmapInterface) override
 
void registerOpenInterface (const std::string &extension, OpenInterface::Ptr openInterface) override
 
void registerViewObserver (const std::string &identifier, ViewObserver::Ptr observer) override
 
void registerPresentationObserver (const std::string &identifier, PresentationObserver::Ptr observer) override
 
const std::map< NewPresentationInterface::Ptr, std::string > & getNewPresentationInterfaces ()
 
const std::map< std::string, NewAggregateInterface::Ptr > & getNewAggregateInterfaces ()
 
const std::map< OpenPresentationInterface::Ptr, std::string > & getOpenPresentationInterfaces ()
 
const std::map< Scroom::TiledBitmap::OpenTiledBitmapInterface::Ptr, std::string > & getOpenTiledBitmapInterfaces ()
 
const std::map< OpenInterface::Ptr, std::string > & getOpenInterfaces ()
 
const std::map< ViewObserver::Ptr, std::string > & getViewObservers ()
 
const std::map< PresentationObserver::Ptr, std::string > & getPresentationObservers ()
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
std::shared_ptr< R > shared_from_this ()
 
template<typename R >
std::shared_ptr< R const > shared_from_this () const
 

Static Public Member Functions

static Ptr create ()
 
static PluginManager::Ptr getInstance ()
 

Private Types

enum  PluginManagerState { FINDING_DIRECTORIES , SCANNING_DIRECTORIES , LOADING_FILES , DONE }
 

Private Member Functions

void setStatusBarMessage (const char *message)
 
 PluginManager ()=default
 

Private Attributes

bool devMode {false}
 
PluginManagerState state {FINDING_DIRECTORIES}
 
std::list< std::string > dirs
 
std::list< std::string >::iterator currentDir
 
std::list< std::string > files
 
std::list< std::string >::iterator currentFile
 
std::list< PluginInformationpluginInformationList
 
std::map< NewPresentationInterface::Ptr, std::string > newPresentationInterfaces
 
std::map< std::string, NewAggregateInterface::PtrnewAggregateInterfaces
 
std::map< OpenPresentationInterface::Ptr, std::string > openPresentationInterfaces
 
std::map< Scroom::TiledBitmap::OpenTiledBitmapInterface::Ptr, std::string > openTiledBitmapInterfaces
 
std::map< OpenInterface::Ptr, std::string > openInterfaces
 
std::map< ViewObserver::Ptr, std::string > viewObservers
 
std::map< PresentationObserver::Ptr, std::string > presentationObservers
 
Scroom::Logger logger
 

Member Typedef Documentation

◆ Ptr

using PluginManager::Ptr = std::shared_ptr<PluginManager>

Member Enumeration Documentation

◆ PluginManagerState

Enumerator
FINDING_DIRECTORIES 
SCANNING_DIRECTORIES 
LOADING_FILES 
DONE 
49 {
53 DONE
54 };
@ FINDING_DIRECTORIES
Definition pluginmanager.hh:50
@ SCANNING_DIRECTORIES
Definition pluginmanager.hh:51
@ DONE
Definition pluginmanager.hh:53
@ LOADING_FILES
Definition pluginmanager.hh:52

Constructor & Destructor Documentation

◆ PluginManager()

PluginManager::PluginManager ( )
privatedefault

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ addHook()

void PluginManager::addHook ( bool  devMode)
246{
247 devMode = devMode_;
248 gdk_threads_add_idle(on_idle, static_cast<WorkInterface*>(this));
249 // progressbar = GTK_PROGRESS_BAR(lookup_widget(scroom, "progressbar"));
250 // statusbar = GTK_STATUSBAR(lookup_widget(scroom, "statusbar"));
251 //
252 // status_context_id = gtk_statusbar_get_context_id(statusbar, "Plugin Manager");
254}
gboolean on_idle(gpointer user_data)
Definition callbacks.cc:278
PluginManagerState state
Definition pluginmanager.hh:58
bool devMode
Definition pluginmanager.hh:57
Definition workinterface.hh:13
Here is the call graph for this function:

◆ create()

PluginManager::Ptr PluginManager::create ( )
static
31{ return Ptr(new PluginManager()); }
std::shared_ptr< PluginManager > Ptr
Definition pluginmanager.hh:45
PluginManager()=default
Here is the call graph for this function:

◆ doWork()

bool PluginManager::doWork ( )
overridevirtual

Implements WorkInterface.

36{
37 bool retval = true;
38
39 switch(state)
40 {
42 {
43 setStatusBarMessage("Locating plugin directories");
44 char* path = getenv(SCROOM_PLUGIN_DIRS.c_str());
45 dirs.clear();
46
47 if(!devMode)
48 {
49#ifdef _WIN32
50 // We want to keep everything portable on windows so we look for the plugin folder in the same directory as the .exe
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 {
60 logger->debug("{} = {}", SCROOM_PLUGIN_DIRS, path);
61
62 for(char* i = path; *i != '\0'; i++)
63 {
64
65// Windows uses semicolons for delimiting environment variables, Linux uses colons
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
84 currentDir = dirs.begin();
85 files.clear();
87 break;
88 }
89
91 {
92 setStatusBarMessage("Scanning plugin directories");
93 if(currentDir == dirs.end())
94 {
96 currentFile = files.begin();
97 break;
98 }
99
100 logger->debug("Scanning directory: {}", *currentDir);
101 const char* folder = currentDir->c_str();
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);
108 currentDir++;
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
120 currentDir++;
121 break;
122 }
123
124 case LOADING_FILES:
125 {
126 setStatusBarMessage("Loading Plugins");
127 if(currentFile == files.end())
128 {
129 state = DONE;
130 break;
131 }
132
133#ifdef _WIN32
134 // Only read .dll files
135 if(currentFile->compare(currentFile->size() - 4, 4, ".dll") == 0)
136 {
137#else
138 // Only read .so files
139 if(currentFile->compare(currentFile->size() - 3, 3, ".so") == 0)
140 {
141#endif
142 logger->debug("Reading file: {}", *currentFile);
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 {
167 if(pi)
168 {
169 if(pi->pluginApiVersion == PLUGIN_API_VERSION)
170 {
171 pluginInformationList.emplace_back(plugin, pi);
172 pi->registerCapabilities(shared_from_this<PluginManager>());
173 plugin = nullptr;
174 gpi = nullptr;
175 pi.reset();
176 }
177 else
178 {
179 logger->error(
180 "Plugin {} has incorrect API version {}, instead of {}", *currentFile, pi->pluginApiVersion, PLUGIN_API_VERSION
181 );
182 }
183 }
184 else
185 {
186 logger->error("GetPluginInformation returned NULL for file {}", *currentFile);
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 }
209 currentFile++;
210 break;
211 }
212 case DONE:
213 {
214 setStatusBarMessage("Done loading plugins");
215
216 std::vector<std::pair<std::string, std::string>> pluginInfo;
217 pluginInfo.reserve(pluginInformationList.size());
218 size_t maxPluginNameLength = 0;
219 for(const auto& plugin: pluginInformationList)
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::shared_ptr< PluginInformationInterface > Ptr
Definition plugininformationinterface.hh:20
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
#define PLUGIN_API_VERSION
Definition plugininformationinterface.hh:15
const std::string SCROOM_PLUGIN_DIRS
Definition pluginmanager.cc:27
ProgressInterface::Ptr const pi
Definition progressinterfaceconversion-tests.cc:23
Here is the call graph for this function:

◆ getInstance()

PluginManager::Ptr PluginManager::getInstance ( )
static

◆ getNewAggregateInterfaces()

const std::map< std::string, NewAggregateInterface::Ptr > & PluginManager::getNewAggregateInterfaces ( )
311{
313}
std::map< std::string, NewAggregateInterface::Ptr > newAggregateInterfaces
Definition pluginmanager.hh:65

◆ getNewPresentationInterfaces()

const std::map< NewPresentationInterface::Ptr, std::string > & PluginManager::getNewPresentationInterfaces ( )
306{
308}
std::map< NewPresentationInterface::Ptr, std::string > newPresentationInterfaces
Definition pluginmanager.hh:64

◆ getOpenInterfaces()

const std::map< OpenInterface::Ptr, std::string > & PluginManager::getOpenInterfaces ( )
325{ return openInterfaces; }
std::map< OpenInterface::Ptr, std::string > openInterfaces
Definition pluginmanager.hh:68

◆ getOpenPresentationInterfaces()

const std::map< OpenPresentationInterface::Ptr, std::string > & PluginManager::getOpenPresentationInterfaces ( )
316{
318}
std::map< OpenPresentationInterface::Ptr, std::string > openPresentationInterfaces
Definition pluginmanager.hh:66

◆ getOpenTiledBitmapInterfaces()

const std::map< Scroom::TiledBitmap::OpenTiledBitmapInterface::Ptr, std::string > & PluginManager::getOpenTiledBitmapInterfaces ( )
321{
323}
std::map< Scroom::TiledBitmap::OpenTiledBitmapInterface::Ptr, std::string > openTiledBitmapInterfaces
Definition pluginmanager.hh:67

◆ getPresentationObservers()

const std::map< PresentationObserver::Ptr, std::string > & PluginManager::getPresentationObservers ( )
330{
332}
std::map< PresentationObserver::Ptr, std::string > presentationObservers
Definition pluginmanager.hh:70

◆ getViewObservers()

const std::map< ViewObserver::Ptr, std::string > & PluginManager::getViewObservers ( )
327{ return viewObservers; }
std::map< ViewObserver::Ptr, std::string > viewObservers
Definition pluginmanager.hh:69

◆ registerNewAggregateInterface()

void PluginManager::registerNewAggregateInterface ( const std::string &  identifier,
NewAggregateInterface::Ptr  newAggregateInterface 
)
overridevirtual

Implements ScroomPluginInterface.

267{
268 newAggregateInterfaces[identifier] = newAggregateInterface;
269}

◆ registerNewPresentationInterface()

void PluginManager::registerNewPresentationInterface ( const std::string &  identifier,
NewPresentationInterface::Ptr  newPresentationInterface 
)
overridevirtual

Implements ScroomPluginInterface.

260{
261 newPresentationInterfaces[newPresentationInterface] = identifier;
262
264}
void on_newPresentationInterfaces_update(const std::map< NewPresentationInterface::Ptr, std::string > &newPresentationInterfaces)
Definition callbacks.cc:626
Here is the call graph for this function:

◆ registerOpenInterface()

void PluginManager::registerOpenInterface ( const std::string &  extension,
OpenInterface::Ptr  openInterface 
)
overridevirtual

Implements ScroomPluginInterface.

289{
290 openInterfaces[openInterface] = extension;
291}

◆ registerOpenPresentationInterface()

void PluginManager::registerOpenPresentationInterface ( const std::string &  extension,
OpenPresentationInterface::Ptr  openPresentationInterface 
)
overridevirtual

Implements ScroomPluginInterface.

275{
276 openPresentationInterfaces[openPresentationInterface] = extension;
277}

◆ registerOpenTiledBitmapInterface()

void PluginManager::registerOpenTiledBitmapInterface ( const std::string &  identifier,
std::shared_ptr< Scroom::TiledBitmap::OpenTiledBitmapInterface openTiledBitmapInterface 
)
overridevirtual

Implements ScroomPluginInterface.

283{
284 openTiledBitmapInterfaces[openTiledBitmapInterface] = extension;
285 openPresentationInterfaces[ToOpenPresentationInterface(openTiledBitmapInterface)] = extension;
286}
OpenPresentationInterface::Ptr ToOpenPresentationInterface(OpenTiledBitmapInterface::Ptr openTiledBitmapInterface)
Definition tiledbitmappresentation.cc:440

◆ registerPresentationObserver()

void PluginManager::registerPresentationObserver ( const std::string &  identifier,
PresentationObserver::Ptr  observer 
)
overridevirtual

Implements ScroomPluginInterface.

301{
302 presentationObservers[observer] = identifier;
303}
TestObserver::Ptr observer
Definition observable-tests.cc:91

◆ registerViewObserver()

void PluginManager::registerViewObserver ( const std::string &  identifier,
ViewObserver::Ptr  observer 
)
overridevirtual

Implements ScroomPluginInterface.

294{
295 viewObservers[observer] = identifier;
296
298}
void on_new_viewobserver(const ViewObserver::Ptr &viewObserver)
Definition callbacks.cc:737
Here is the call graph for this function:

◆ setStatusBarMessage()

void PluginManager::setStatusBarMessage ( const char *  message)
private
240{
241 // gtk_statusbar_pop(statusbar, status_context_id);
242 // gtk_statusbar_push(statusbar, status_context_id, message);
243}

Referenced by doWork().

Here is the caller graph for this function:

Member Data Documentation

◆ currentDir

std::list<std::string>::iterator PluginManager::currentDir
private

Referenced by doWork().

◆ currentFile

std::list<std::string>::iterator PluginManager::currentFile
private

Referenced by doWork().

◆ devMode

bool PluginManager::devMode {false}
private
57{false};

Referenced by addHook(), and doWork().

◆ dirs

std::list<std::string> PluginManager::dirs
private

Referenced by doWork().

◆ files

std::list<std::string> PluginManager::files
private

Referenced by doWork().

◆ logger

Scroom::Logger PluginManager::logger
private

Referenced by doWork().

◆ newAggregateInterfaces

std::map<std::string, NewAggregateInterface::Ptr> PluginManager::newAggregateInterfaces
private

◆ newPresentationInterfaces

std::map<NewPresentationInterface::Ptr, std::string> PluginManager::newPresentationInterfaces
private

◆ openInterfaces

std::map<OpenInterface::Ptr, std::string> PluginManager::openInterfaces
private

◆ openPresentationInterfaces

std::map<OpenPresentationInterface::Ptr, std::string> PluginManager::openPresentationInterfaces
private

◆ openTiledBitmapInterfaces

std::map<Scroom::TiledBitmap::OpenTiledBitmapInterface::Ptr, std::string> PluginManager::openTiledBitmapInterfaces
private

◆ pluginInformationList

std::list<PluginInformation> PluginManager::pluginInformationList
private

Referenced by doWork().

◆ presentationObservers

std::map<PresentationObserver::Ptr, std::string> PluginManager::presentationObservers
private

◆ state

PluginManagerState PluginManager::state {FINDING_DIRECTORIES}
private

Referenced by addHook(), and doWork().

◆ viewObservers

std::map<ViewObserver::Ptr, std::string> PluginManager::viewObservers
private

The documentation for this class was generated from the following files: