![]() |
CTK
0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
|
Main manager class to handle loading and unloading of modules. More...
#include <Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h>
Public Types | |
enum | ValidationMode { STRICT_VALIDATION , SKIP_VALIDATION , WEAK_VALIDATION } |
Signals | |
void | moduleRegistered (const ctkCmdLineModuleReference &) |
This signal is emitted whenever a module is registered. More... | |
void | moduleUnregistered (const ctkCmdLineModuleReference &) |
This signal is emitted whenever a module is un-registered. More... | |
Public Member Functions | |
ctkCmdLineModuleBackend * | backend (const QString &scheme) const |
Get the registered backend for a scheme. More... | |
QList< ctkCmdLineModuleBackend * > | backends () const |
Get a list of all registered backends. More... | |
void | clearCache () |
Clears the XML/timestamp cache. More... | |
ctkCmdLineModuleManager (ValidationMode validationMode=STRICT_VALIDATION, const QString &cacheDir=QString()) | |
Create a module manager instance. More... | |
ctkCmdLineModuleReference | moduleReference (const QUrl &location) const |
Returns a ctkCmdLineModuleReference object for the given URL. More... | |
QList< ctkCmdLineModuleReference > | moduleReferences () const |
Returns module references for all currently registered modules. More... | |
void | registerBackend (ctkCmdLineModuleBackend *backend) |
Registers a new back-end. More... | |
ctkCmdLineModuleReference | registerModule (const QUrl &location) |
Registers a module, identified by the given URL. More... | |
ctkCmdLineModuleFuture | run (ctkCmdLineModuleFrontend *frontend) |
Run a module front-end. More... | |
void | setTimeOutForXMLRetrieval (int timeout) |
Set the timeout for retrieving the XML parameter description from a module. More... | |
void | setValidationMode (const ValidationMode &mode) |
Set the validation mode. More... | |
int | timeOutForXMLRetrieval () const |
Get the timeout for retrieving the XML parameter description from a module. More... | |
void | unregisterModule (const ctkCmdLineModuleReference &moduleRef) |
Unregister a previously registered module. More... | |
ValidationMode | validationMode () const |
Get the validation mode. More... | |
~ctkCmdLineModuleManager () | |
Main manager class to handle loading and unloading of modules.
This is the central managing class for CTK "command line modules". To register modules, you need a command line module back-end which is capable of handling the URL scheme under which you want to register your modules.
A default back-end for handling "file" URLs which runs local executables is available in ctkCmdLineModuleBackendLocalProcess.
To create and run a specific front-end for a given module, you need a concrete ctkCmdLineModuleFrontend implementation. The implementation provided in ctkCmdLineModuleFrontendQtGui creates a default Qt widgets based GUI for a given ctkCmdLineModuleReference instance.
Here is an example how this and related classes could be used:
First, we create ctkCmdLineModuleManager instance.
Then we need at least one back-end which can handle registering modules.
Finally, we can register a module.
Definition at line 71 of file ctkCmdLineModuleManager.h.
Enumerator | |
---|---|
STRICT_VALIDATION | registerModule() will throw an exception if the XML is invalid |
SKIP_VALIDATION | no XML schema validation at all |
WEAK_VALIDATION | registerModule() will validate the XML description but proceed with registration on validation error. |
Definition at line 77 of file ctkCmdLineModuleManager.h.
ctkCmdLineModuleManager::ctkCmdLineModuleManager | ( | ValidationMode | validationMode = STRICT_VALIDATION , |
const QString & | cacheDir = QString() |
||
) |
Create a module manager instance.
validationMode | The validation mode for the XML description of the module parameters. |
cacheDir | The directory where to cache information about registered modules. |
If the validationMode
argument is set to SKIP_VALIDATION
, no XML validation takes place and certain front-ends might fail to generate a GUI. If it is set to WEAK_VALIDATION
, module registrations will proceed on error but the error status is available via ctkCmdLineModuleReference::xmlValidationErrorString().
ctkCmdLineModuleManager::~ctkCmdLineModuleManager | ( | ) |
ctkCmdLineModuleBackend* ctkCmdLineModuleManager::backend | ( | const QString & | scheme | ) | const |
Get the registered backend for a scheme.
scheme | The scheme the backend was registered with |
scheme
is unknown. QList<ctkCmdLineModuleBackend*> ctkCmdLineModuleManager::backends | ( | ) | const |
Get a list of all registered backends.
void ctkCmdLineModuleManager::clearCache | ( | ) |
Clears the XML/timestamp cache.
ctkCmdLineModuleReference ctkCmdLineModuleManager::moduleReference | ( | const QUrl & | location | ) | const |
Returns a ctkCmdLineModuleReference object for the given URL.
location | The location URL for which to get a module reference. |
QList<ctkCmdLineModuleReference> ctkCmdLineModuleManager::moduleReferences | ( | ) | const |
Returns module references for all currently registered modules.
|
signal |
This signal is emitted whenever a module is registered.
|
signal |
This signal is emitted whenever a module is un-registered.
void ctkCmdLineModuleManager::registerBackend | ( | ctkCmdLineModuleBackend * | backend | ) |
Registers a new back-end.
backend | The new back-end. |
ctkInvalidArgumentException | if another back-end was already registered handling one of the URL schemes this back-end claims to handle. |
ctkCmdLineModuleReference ctkCmdLineModuleManager::registerModule | ( | const QUrl & | location | ) |
Registers a module, identified by the given URL.
location | The URL for the new module. |
ctkInvalidArgumentException | if no back-end for the given URL scheme was registered or the XML description for the module is invalid. |
ctkCmdLineModuleTimeoutException | if a time-out occured when retrieving the XML description from the module. |
ctkCmdLineModuleRunException | if a general error occurred when running the module. |
ctkCmdLineModuleFuture ctkCmdLineModuleManager::run | ( | ctkCmdLineModuleFrontend * | frontend | ) |
Run a module front-end.
frontend | The module front-end to run. |
This method takes a ctkCmdLineModuleFrontend pointer and uses the registered back-end for this module's location URL scheme to run it asynchronously. The returned future object is the only way to interact with the task started by the specific back-end.
void ctkCmdLineModuleManager::setTimeOutForXMLRetrieval | ( | int | timeout | ) |
Set the timeout for retrieving the XML parameter description from a module.
The default time-out is 30 seconds.
timeout | The timeout in milli seconds. |
void ctkCmdLineModuleManager::setValidationMode | ( | const ValidationMode & | mode | ) |
Set the validation mode.
int ctkCmdLineModuleManager::timeOutForXMLRetrieval | ( | ) | const |
Get the timeout for retrieving the XML parameter description from a module.
void ctkCmdLineModuleManager::unregisterModule | ( | const ctkCmdLineModuleReference & | moduleRef | ) |
Unregister a previously registered module.
moduleRef | The reference for the module to unregister. |
This method does nothing if the module reference moduleRef
is invalid or reference an un-registered module.
ValidationMode ctkCmdLineModuleManager::validationMode | ( | ) | const |
Get the validation mode.