Computer Assited Medical Intervention Tool Kit  version 5.0
ExtensionManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 
27 #ifndef EXTENSIONS_MANAGER_H
28 #define EXTENSIONS_MANAGER_H
29 
30 // -- Core stuff
31 #include "ComponentExtension.h"
32 #include "ActionExtension.h"
33 #include "ViewerExtension.h"
34 #include "CamiTKAPI.h"
35 #include "AbortException.h"
36 
37 // -- QT stuff
38 #include <QtPlugin>
39 #include <QPluginLoader>
40 #include <QStringList>
41 #include <QMap>
42 #include <QDir>
43 
44 namespace camitk {
58 class CAMITK_API ExtensionManager : public QObject {
59 
60 public:
65  enum ExtensionType {
66  ACTION,
67  COMPONENT,
68  APPLICATION,
69  VIEWER
70  };
71 
73  static void autoload();
74 
87  static void autoload(ExtensionType type);
88 
96  static bool loadExtension(ExtensionType type, QString file);
97 
114  static QString getInstallationString(QString file, const QString& globalInstallDir, const QString& userInstallDir, const QString& currentWorkingDir);
115 
118 
122  static ComponentExtension* getComponentExtension(QString);
123 
134  static const QList<ComponentExtension*> getComponentExtensionsList();
135 
139  static ComponentExtension* getDataDirectoryComponentExtension(QString);
140 
151  static const QList<ComponentExtension*> getDataDirectoryComponentsList();
152 
154  static QStringList getFileExtensions();
155 
157  static QStringList getDataDirectoryExtNames();
158 
163  static void registerFileExtension(QString fileExtension);
164 
168  static bool unloadComponentExtension(QString);
170 
171 
174 
176  static void unloadAllActionExtensions();
177 
188  static const QList<ActionExtension*> getActionExtensionsList();
189 
198  static ActionExtension* getActionExtension(QString);
199 
203  static bool unloadActionExtension(QString);
205 
208 
210  static void unloadAllViewerExtensions();
211 
222  static const QList<ViewerExtension*> getViewerExtensionsList();
223 
232  static ViewerExtension* getViewerExtension(QString);
233 
237  static bool unloadViewerExtension(QString);
239 
240 private:
248  static QMap<QString, ComponentExtension*>& getComponentExtensionMap();
249 
257  static QMap<QString, ComponentExtension*>& getDataDirectoryComponentExtensionMap();
258 
266  static QMap<QString, ActionExtension*>& getActionExtensionMap();
267 
275  static QMap<QString, ViewerExtension*>& getViewerExtensionMap();
276 
278  static QStringList getExtensionFilter();
279 
281  static QStringList getPluginFileNames(QDir);
282 
291  static void initPrivateLibDirs();
292 
298  static void addLibraryPath(QDir potentialPath, QString potentialLibDir);
299 
302 
312  static bool componentExtensionLessThan(const ComponentExtension* left, const ComponentExtension* right);
313 
329  static bool actionExtensionLessThan(ActionExtension* left, ActionExtension* right);
330 
336  static bool viewerExtensionLessThan(ViewerExtension* left, ViewerExtension* right);
338 };
339 
340 }
341 
342 
343 #endif //EXTENSIONS_MANAGER_H
camitk::ExtensionManager::getExtensionFilter
static QStringList getExtensionFilter()
return the extensions file filter
Definition: ExtensionManager.cpp:598
camitk::Core::shortVersion
static const char * shortVersion
short version string (all in lower case, without the patch number)
Definition: Core.h:210
camitk::Core::getGlobalInstallDir
static const QString getGlobalInstallDir()
get the CAMITK_DIR (where camitk-config is installed)
Definition: Core.cpp:376
camitk::ExtensionManager::unloadViewerExtension
static bool unloadViewerExtension(QString)
Unload an viewer extension using its .dll/.so/.dylib filename.
Definition: ExtensionManager.cpp:549
camitk::ExtensionManager::getViewerExtensionMap
static QMap< QString, ViewerExtension * > & getViewerExtensionMap()
get the singleton map of loaded viewer plugins (the key is the shared object/dll/dylib filename) This...
Definition: ExtensionManager.cpp:520
camitk::ExtensionManager::initPrivateLibDirs
static void initPrivateLibDirs()
Add the private library directories (lib/camitk-version) in the current session PATH:
Definition: ExtensionManager.cpp:741
camitk::ExtensionManager::actionExtensionLessThan
static bool actionExtensionLessThan(ActionExtension *left, ActionExtension *right)
Custom comparaison method between two ActionExtension* This method uses the QString::<() (less than o...
Definition: ExtensionManager.cpp:774
camitk::ExtensionManager::getActionExtensionMap
static QMap< QString, ActionExtension * > & getActionExtensionMap()
get the singleton map of loaded action plugins (the key is the shared object/dll/dylib filename) This...
Definition: ExtensionManager.cpp:491
camitk::ExtensionManager::unloadComponentExtension
static bool unloadComponentExtension(QString)
Unload a plugin corresponding to a given extension or component name.
Definition: ExtensionManager.cpp:661
CamiTKAPI.h
camitk::ExtensionManager::addLibraryPath
static void addLibraryPath(QDir potentialPath, QString potentialLibDir)
check if the given directory contains an extension repository and if it does update PATH (on windows)...
Definition: ExtensionManager.cpp:714
camitk::Application::getSettings
static QSettings & getSettings()
Get the Core wide settings.
Definition: Application.cpp:309
AbortException.h
camitk::ExtensionManager::getFileExtensions
static QStringList getFileExtensions()
get the list of all the suffixes managed by registered component extensions (all possible file suffix...
Definition: ExtensionManager.cpp:480
camitk::ExtensionManager::autoload
static void autoload()
Autoload component and action extensions.
Definition: ExtensionManager.cpp:68
camitk::ComponentExtension
This class describes what is a generic Component extension. To add a ComponentExtension to CamiTK cor...
Definition: ComponentExtension.h:83
camitk::Core::libDir
static const char * libDir
library folder set depending on the compiler and environement choice (it could be lib/ or lib64/ on L...
Definition: Core.h:222
camitk::ExtensionManager::unloadAllViewerExtensions
static void unloadAllViewerExtensions()
unload all viewer extensions and delete instantiated actions
Definition: ExtensionManager.cpp:527
camitk::Application::registerAllViewers
static int registerAllViewers(ViewerExtension *)
register all viewers from the given ViewerExtension
Definition: Application.cpp:918
camitk::Application::unregisterAllActions
static int unregisterAllActions(ActionExtension *)
unregister all actions from the given ActionExtension
Definition: Application.cpp:766
CAMITK_TRACE_ALT
#define CAMITK_TRACE_ALT(MSG)
Definition: Log.h:257
camitk::ExtensionManager::loadExtension
static bool loadExtension(ExtensionType type, QString file)
Load a specific extension from a file.
Definition: ExtensionManager.cpp:216
Action.h
camitk::ExtensionManager::unloadActionExtension
static bool unloadActionExtension(QString)
Unload an action extension using its .dll/.so/.dylib filename.
Definition: ExtensionManager.cpp:643
camitk::Core::getViewerDirectories
static const QStringList getViewerDirectories()
get all the viewers directories.
Definition: Core.cpp:356
camitk::Core::soVersion
static const char * soVersion
version used for so name
Definition: Core.h:212
ActionExtension.h
Log.h
camitk::ExtensionManager::getComponentExtension
static ComponentExtension * getComponentExtension(QString)
get the plugin corresponding to a given extension or name.
Definition: ExtensionManager.cpp:440
camitk::Core::getCurrentWorkingDir
static const QString getCurrentWorkingDir()
get the current working directory (during dev, this should be the build directory,...
Definition: Core.cpp:423
camitk::ExtensionManager::componentExtensionLessThan
static bool componentExtensionLessThan(const ComponentExtension *left, const ComponentExtension *right)
Custom comparaison method between two ComponentExtension* This method uses the QString::<() (less tha...
Definition: ExtensionManager.cpp:769
camitk::ExtensionManager::getDataDirectoryComponentExtension
static ComponentExtension * getDataDirectoryComponentExtension(QString)
get the plugin corresponding to a given data directory component extension's name.
Definition: ExtensionManager.cpp:428
camitk::ExtensionManager::getPluginFileNames
static QStringList getPluginFileNames(QDir)
return the list of shared objects in a directory considering debug/release on MSVC
Definition: ExtensionManager.cpp:615
camitk::ExtensionManager::getViewerExtensionsList
static const QList< ViewerExtension * > getViewerExtensionsList()
Get the list of registered ViewerExtension.
Definition: ExtensionManager.cpp:536
camitk::ExtensionManager::ExtensionType
ExtensionType
Definition: ExtensionManager.h:111
camitk::Core::getUserInstallDir
static const QString getUserInstallDir()
get the user config directory (this is the local installation directory)
Definition: Core.cpp:417
camitk::Core::isDebugBuild
static const bool isDebugBuild()
Definition: Core.cpp:452
ComponentExtension.h
camitk::Core::debugPostfix
static const char * debugPostfix
debug postfix used on MSVC to distinguished between release and debug version
Definition: Core.h:214
ViewerExtension.h
camitk::ExtensionManager::getComponentExtensionsList
static const QList< ComponentExtension * > getComponentExtensionsList()
Get the list of registered ComponentExtension.
Definition: ExtensionManager.cpp:464
camitk::ExtensionManager::getDataDirectoryExtNames
static QStringList getDataDirectoryExtNames()
get the list of all the name of the registered Component data directory
Definition: ExtensionManager.cpp:485
camitk::ExtensionManager::COMPONENT
@ COMPONENT
Component extensions: manages the data logic.
Definition: ExtensionManager.h:113
camitk::Core::getComponentDirectories
static const QStringList getComponentDirectories()
get all the component directories.
Definition: Core.cpp:351
camitk::ExtensionManager::getDataDirectoryComponentsList
static const QList< ComponentExtension * > getDataDirectoryComponentsList()
Get the list of registered ComponentExtension working on directory.
Definition: ExtensionManager.cpp:472
camitk::ActionExtension
This class describes what is a generic Action extension. To add a ActionExtension to CamiTK core,...
Definition: ActionExtension.h:80
camitk::ExtensionManager::getActionExtension
static ActionExtension * getActionExtension(QString)
Get the ActionExtension corresponding to the given shared library file.
Definition: ExtensionManager.cpp:506
camitk::Application::registerAllActions
static int registerAllActions(ActionExtension *)
register all actions from the given ActionExtension
Definition: Application.cpp:742
camitk::ExtensionManager::ACTION
@ ACTION
Action extensions: manages the processing logic.
Definition: ExtensionManager.h:112
CAMITK_INFO_ALT
#define CAMITK_INFO_ALT(MSG)
Definition: Log.h:262
camitk::ExtensionManager::getDataDirectoryComponentExtensionMap
static QMap< QString, ComponentExtension * > & getDataDirectoryComponentExtensionMap()
get the singleton map of loaded component plugins for data directory (the key is the name) This is th...
Definition: ExtensionManager.cpp:433
Viewer.h
CAMITK_ERROR_ALT
#define CAMITK_ERROR_ALT(MSG)
Definition: Log.h:277
camitk::ExtensionManager::getViewerExtension
static ViewerExtension * getViewerExtension(QString)
Get the Viewer Extension corresponding to the given shared library file.
Definition: ExtensionManager.cpp:544
camitk::ExtensionManager::viewerExtensionLessThan
static bool viewerExtensionLessThan(ViewerExtension *left, ViewerExtension *right)
Custom comparaison method between two ViewerExtension* based on the same principle as actionExtension...
Definition: ExtensionManager.cpp:779
camitk::ExtensionManager::getInstallationString
static QString getInstallationString(QString file, const QString &globalInstallDir, const QString &userInstallDir, const QString &currentWorkingDir)
Returns a three char string that corresponds to the installation directory of a given shared library.
Definition: ExtensionManager.cpp:363
camitk::ExtensionManager::unloadAllActionExtensions
static void unloadAllActionExtensions()
unload all action extensions and delete instantiated actions
Definition: ExtensionManager.cpp:511
camitk::ViewerExtension
This class describes what is a generic Action extension. To add a ActionExtension to CamiTK core,...
Definition: ViewerExtension.h:108
Core.h
camitk::ExtensionManager::getActionExtensionsList
static const QList< ActionExtension * > getActionExtensionsList()
Get the list of registered ActionExtension.
Definition: ExtensionManager.cpp:498
camitk::ExtensionManager::VIEWER
@ VIEWER
Viewer extensions: manages the presentation and user interaction logic.
Definition: ExtensionManager.h:115
ExtensionManager.h
camitk::ExtensionManager::registerFileExtension
static void registerFileExtension(QString fileExtension)
Register the file extension with the current application for opening This function is called by regis...
Definition: ExtensionManager.cpp:567
camitk::Core::getActionDirectories
static const QStringList getActionDirectories()
get all the action directories.
Definition: Core.cpp:346
camitk::Application::unregisterAllViewers
static int unregisterAllViewers(ViewerExtension *)
unregister all viewers from the given ViewerExtension
Definition: Application.cpp:985
camitk::ExtensionManager::getComponentExtensionMap
static QMap< QString, ComponentExtension * > & getComponentExtensionMap()
get the singleton map of loaded component plugins for files (the key is the file extension) This is t...
Definition: ExtensionManager.cpp:421
Application.h
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:49
camitk
Definition: Action.cpp:35