Computer Assited Medical Intervention Tool Kit  version 4.1
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-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
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 "CamiTKAPI.h"
34 #include "AbortException.h"
35 
36 // -- QT stuff
37 #include <QtPlugin>
38 #include <QPluginLoader>
39 #include <QStringList>
40 #include <QMap>
41 #include <QDir>
42 
43 namespace camitk {
57 class CAMITK_API ExtensionManager : public QObject {
58 
59 public:
64  enum ExtensionType {
65  ACTION,
66  COMPONENT,
67  APPLICATION,
68  VIEWER
69  };
70 
72  static void autoload();
73 
86  static void autoload(ExtensionType type);
87 
95  static bool loadExtension(ExtensionType type, QString file);
96 
113  static QString getInstallationString(QString file, const QString& globalInstallDir, const QString& userInstallDir, const QString& currentWorkingDir);
114 
117 
121  static ComponentExtension* getComponentExtension(QString);
122 
133  static const QList<ComponentExtension*> getComponentExtensionsList();
134 
138  static ComponentExtension* getDataDirectoryComponentExtension(QString);
139 
150  static const QList<ComponentExtension*> getDataDirectoryComponentsList();
151 
153  static QStringList getFileExtensions();
154 
156  static QStringList getDataDirectoryExtNames();
157 
162  static void registerFileExtension(QString fileExtension);
163 
167  static bool unloadComponentExtension(QString);
169 
170 
173 
175  static void unloadAllActionExtensions();
176 
187  static const QList<ActionExtension*> getActionExtensionsList();
188 
197  static ActionExtension* getActionExtension(QString);
198 
202  static bool unloadActionExtension(QString);
204 
205 private:
213  static QMap<QString, ComponentExtension*>& getComponentExtensionMap();
214 
222  static QMap<QString, ComponentExtension*>& getDataDirectoryComponentExtensionMap();
223 
231  static QMap<QString, ActionExtension*>& getActionExtensionMap();
232 
234  static QStringList getExtensionFilter();
235 
237  static QStringList getPluginFileNames(QDir);
238 
245  static void initPrivateLibDirs();
246 
249 
259  static bool componentExtensionLessThan(const ComponentExtension* left, const ComponentExtension* right);
260 
276  static bool actionExtensionLessThan(ActionExtension* left, ActionExtension* right);
278 };
279 
280 }
281 
282 
283 #endif //EXTENSIONS_MANAGER_H
camitk::ExtensionManager::getExtensionFilter
static QStringList getExtensionFilter()
return the extensions file filter
Definition: ExtensionManager.cpp:435
camitk::Core::shortVersion
static const char * shortVersion
short version string (all in lower case, without the patch number)
Definition: Core.h:172
camitk::Core::getGlobalInstallDir
static const QString getGlobalInstallDir()
get the CAMITK_DIR (where camitk-config is installed)
Definition: Core.cpp:311
camitk::ExtensionManager::initPrivateLibDirs
static void initPrivateLibDirs()
Add the private library directories (lib/camitk-version) in the current session PATH:
Definition: ExtensionManager.cpp:550
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:626
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:376
camitk::ExtensionManager::unloadComponentExtension
static bool unloadComponentExtension(QString)
Unload a plugin corresponding to a given extension or component name.
Definition: ExtensionManager.cpp:497
CamiTKAPI.h
camitk::Application::getSettings
static QSettings & getSettings()
Get the Core wide settings.
Definition: Application.cpp:300
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:365
camitk::ExtensionManager::autoload
static void autoload()
Autoload component and action extensions.
Definition: ExtensionManager.cpp:65
camitk::ComponentExtension
This class describes what is a generic Component extension. To add a ComponentExtension to CamiTK cor...
Definition: ComponentExtension.h:78
camitk::Application::unregisterAllActions
static int unregisterAllActions(ActionExtension *)
unregister all actions from the given ActionExtension
Definition: Application.cpp:735
CAMITK_TRACE_ALT
#define CAMITK_TRACE_ALT(MSG)
Definition: Log.h:252
camitk::ExtensionManager::loadExtension
static bool loadExtension(ExtensionType type, QString file)
Load a specific extension from a file.
Definition: ExtensionManager.cpp:184
camitk::Action::getName
QString getName() const
get the name of the action
Definition: Action.h:332
Action.h
camitk::ExtensionManager::unloadActionExtension
static bool unloadActionExtension(QString)
Unload an action extension using its .dll/.so/.dylib filename.
Definition: ExtensionManager.cpp:476
camitk::Core::soVersion
static const char * soVersion
version used for so name
Definition: Core.h:174
ActionExtension.h
Log.h
camitk::ExtensionManager::getComponentExtension
static ComponentExtension * getComponentExtension(QString)
get the plugin corresponding to a given extension or name.
Definition: ExtensionManager.cpp:325
camitk::Core::getCurrentWorkingDir
static const QString getCurrentWorkingDir()
get the current working directory (during dev, this should be the build directory,...
Definition: Core.cpp:358
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:621
camitk::Action
Action class is an abstract class that enables you to build a action (generally on a component)....
Definition: Action.h:228
camitk::ExtensionManager::getDataDirectoryComponentExtension
static ComponentExtension * getDataDirectoryComponentExtension(QString)
get the plugin corresponding to a given data directory component extension's name.
Definition: ExtensionManager.cpp:313
camitk::ExtensionManager::getPluginFileNames
static QStringList getPluginFileNames(QDir)
return the list of shared objects in a directory considering debug/release on MSVC
Definition: ExtensionManager.cpp:450
camitk::ExtensionManager::ExtensionType
ExtensionType
Definition: ExtensionManager.h:107
camitk::Core::getUserInstallDir
static const QString getUserInstallDir()
get the user config directory (this is the local installation directory)
Definition: Core.cpp:352
camitk::Core::isDebugBuild
static const bool isDebugBuild()
Definition: Core.cpp:387
ComponentExtension.h
camitk::Core::debugPostfix
static const char * debugPostfix
debug postfix used on MSVC to distinguished between release and debug version
Definition: Core.h:176
camitk::ExtensionManager::getComponentExtensionsList
static const QList< ComponentExtension * > getComponentExtensionsList()
Get the list of registered ComponentExtension.
Definition: ExtensionManager.cpp:349
camitk::ExtensionManager::getDataDirectoryExtNames
static QStringList getDataDirectoryExtNames()
get the list of all the name of the registered Component data directory
Definition: ExtensionManager.cpp:370
camitk::ExtensionManager::COMPONENT
Component extensions: manages the data logic.
Definition: ExtensionManager.h:109
camitk::Core::getComponentDirectories
static const QStringList getComponentDirectories()
get all the component directories.
Definition: Core.cpp:292
camitk::ExtensionManager::getDataDirectoryComponentsList
static const QList< ComponentExtension * > getDataDirectoryComponentsList()
Get the list of registered ComponentExtension working on directory.
Definition: ExtensionManager.cpp:357
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:391
camitk::Application::registerAllActions
static int registerAllActions(ActionExtension *)
register all actions from the given ActionExtension
Definition: Application.cpp:711
camitk::ExtensionManager::ACTION
Action extensions: manages the processing logic.
Definition: ExtensionManager.h:108
CAMITK_INFO_ALT
#define CAMITK_INFO_ALT(MSG)
Definition: Log.h:257
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:318
CAMITK_ERROR_ALT
#define CAMITK_ERROR_ALT(MSG)
Definition: Log.h:272
camitk::ActionExtension::getActions
const ActionList & getActions()
get the list of actions registered y this extension
Definition: ActionExtension.cpp:103
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:280
camitk::ComponentExtension::getLocation
QString getLocation() const
get the file path (location of the .dll/.so/.dylib) of this plugin
Definition: ComponentExtension.h:160
camitk::ExtensionManager::unloadAllActionExtensions
static void unloadAllActionExtensions()
unload all action extensions and delete instantiated actions
Definition: ExtensionManager.cpp:396
Core.h
camitk::ExtensionManager::getActionExtensionsList
static const QList< ActionExtension * > getActionExtensionsList()
Get the list of registered ActionExtension.
Definition: ExtensionManager.cpp:383
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:405
camitk::Core::getActionDirectories
static const QStringList getActionDirectories()
get all the action directories.
Definition: Core.cpp:287
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:306
Application.h
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:48
camitk
Definition: Action.cpp:36