ctkCommandLineModuleAppPlugin.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // Qt includes
  16. #include <QtPlugin>
  17. #include <QStringList>
  18. #include <QString>
  19. // CTK includes
  20. #include "ctkCommandLineModuleAppPlugin_p.h"
  21. #include "ctkCommandLineModuleAppLogic_p.h"
  22. #include <ctkCommandLineParser.h>
  23. ctkPluginContext* ctkCommandLineModuleAppPlugin::Context = 0;
  24. //----------------------------------------------------------------------------
  25. ctkCommandLineModuleAppPlugin::ctkCommandLineModuleAppPlugin()
  26. : AppLogic(0)
  27. {
  28. }
  29. //----------------------------------------------------------------------------
  30. ctkCommandLineModuleAppPlugin::~ctkCommandLineModuleAppPlugin()
  31. {
  32. qDebug()<< "delete applogic";
  33. delete this->AppLogic;
  34. this->AppLogic = 0;
  35. }
  36. //----------------------------------------------------------------------------
  37. void ctkCommandLineModuleAppPlugin::start(ctkPluginContext* context)
  38. {
  39. ctkCommandLineModuleAppPlugin::Context = context;
  40. delete this->AppLogic;
  41. ctkCommandLineParser cmdLineParser;
  42. cmdLineParser.setArgumentPrefix("--", "-");
  43. cmdLineParser.setStrictModeEnabled(true);
  44. cmdLineParser.addArgument("module", "", QVariant::String, "Path to a CLI module (executable)", "CLIModuleBlur2dImage");
  45. QString argsstring("pluginname ");
  46. argsstring.append(context->getProperty("dah.args").toString());
  47. QStringList argslist = argsstring.split(" ");
  48. bool parseOkay = false;
  49. QHash<QString, QVariant> args = cmdLineParser.parseArguments(argslist, &parseOkay);
  50. bool canStart = true;
  51. if(!args.contains("module"))
  52. {
  53. qDebug() << "ctkCommandLineModuleAppPlugin: The plugin framework does not contain a valid \"dah.args\" property that specifies a CLModule as \"--module <modulename>\".";
  54. canStart = false;
  55. }
  56. if(canStart)
  57. {
  58. this->AppLogic = new ctkCommandLineModuleAppLogic(args["module"].toString());
  59. context->registerService<ctkDicomAppInterface>(this->AppLogic);
  60. }
  61. }
  62. //----------------------------------------------------------------------------
  63. void ctkCommandLineModuleAppPlugin::stop(ctkPluginContext* context)
  64. {
  65. Q_UNUSED(context)
  66. ctkCommandLineModuleAppPlugin::Context = 0;
  67. }
  68. //----------------------------------------------------------------------------
  69. ctkPluginContext* ctkCommandLineModuleAppPlugin::getPluginContext()
  70. {
  71. return ctkCommandLineModuleAppPlugin::Context;
  72. }
  73. #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
  74. Q_EXPORT_PLUGIN2(org_commontk_dah_cmdlinemoduleapp, ctkCommandLineModuleAppPlugin)
  75. #endif