ctkCmdLineModuleConcurrentHelpers.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkCmdLineModuleConcurrentHelpers.h"
  16. #include "ctkCmdLineModuleManager.h"
  17. #include "ctkException.h"
  18. #include <QUrl>
  19. #include <QDebug>
  20. //----------------------------------------------------------------------------
  21. ctkCmdLineModuleConcurrentRegister::ctkCmdLineModuleConcurrentRegister(ctkCmdLineModuleManager* manager,
  22. bool debug)
  23. : ModuleManager(manager), Debug(debug)
  24. {}
  25. //----------------------------------------------------------------------------
  26. ctkCmdLineModuleReference ctkCmdLineModuleConcurrentRegister::operator()(const QString& moduleLocation)
  27. {
  28. return this->operator ()(QUrl::fromLocalFile(moduleLocation));
  29. }
  30. //----------------------------------------------------------------------------
  31. ctkCmdLineModuleReference ctkCmdLineModuleConcurrentRegister::operator()(const QUrl& moduleUrl)
  32. {
  33. try
  34. {
  35. return this->ModuleManager->registerModule(moduleUrl);
  36. }
  37. catch (const ctkException& e)
  38. {
  39. if (this->Debug)
  40. {
  41. qDebug() << e;
  42. }
  43. return ctkCmdLineModuleReference();
  44. }
  45. catch (...)
  46. {
  47. if (this->Debug)
  48. {
  49. qDebug() << "Registering module" << moduleUrl << "failed with an unknown exception.";
  50. }
  51. return ctkCmdLineModuleReference();
  52. }
  53. }
  54. //----------------------------------------------------------------------------
  55. ctkCmdLineModuleConcurrentUnRegister::ctkCmdLineModuleConcurrentUnRegister(ctkCmdLineModuleManager* manager)
  56. : ModuleManager(manager)
  57. {}
  58. //----------------------------------------------------------------------------
  59. bool ctkCmdLineModuleConcurrentUnRegister::operator()(const QString& moduleLocation)
  60. {
  61. return this->operator ()(QUrl::fromLocalFile(moduleLocation));
  62. }
  63. //----------------------------------------------------------------------------
  64. bool ctkCmdLineModuleConcurrentUnRegister::operator()(const QUrl& moduleUrl)
  65. {
  66. return this->operator ()(this->ModuleManager->moduleReference(moduleUrl));
  67. }
  68. //----------------------------------------------------------------------------
  69. bool ctkCmdLineModuleConcurrentUnRegister::operator()(const ctkCmdLineModuleReference& moduleRef)
  70. {
  71. if (moduleRef)
  72. {
  73. this->ModuleManager->unregisterModule(moduleRef);
  74. return true;
  75. }
  76. return false;
  77. }