ctkPluginFramework.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 "ctkPluginFramework.h"
  16. #include "ctkPluginFrameworkPrivate_p.h"
  17. #include "ctkPluginPrivate_p.h"
  18. #include "ctkPluginFrameworkContextPrivate_p.h"
  19. #include "ctkPluginConstants.h"
  20. namespace ctk {
  21. PluginFramework::PluginFramework(PluginFrameworkContextPrivate* fw)
  22. : Plugin(*new PluginFrameworkPrivate(*this, fw))
  23. {
  24. }
  25. void PluginFramework::init()
  26. {
  27. Q_D(PluginFramework);
  28. QMutexLocker sync(&d->lock);
  29. // waitOnActivation(d->lock, "Framework.ini", true);
  30. switch (d->state)
  31. {
  32. case Plugin::INSTALLED:
  33. case Plugin::RESOLVED:
  34. break;
  35. case Plugin::STARTING:
  36. case Plugin::ACTIVE:
  37. return;
  38. default:
  39. throw std::logic_error("INTERNAL ERROR, Illegal state");
  40. }
  41. d->init();
  42. }
  43. QStringList PluginFramework::getResourceList(const QString& path) const
  44. {
  45. QString resourcePath = QString(":/") + PluginConstants::SYSTEM_PLUGIN_SYMBOLICNAME;
  46. if (path.startsWith('/'))
  47. resourcePath += path;
  48. else
  49. resourcePath += QString("/") + path;
  50. QStringList paths;
  51. QFileInfoList entryInfoList = QDir(resourcePath).entryInfoList();
  52. QListIterator<QFileInfo> infoIter(entryInfoList);
  53. while (infoIter.hasNext())
  54. {
  55. const QFileInfo& resInfo = infoIter.next();
  56. QString entry = resInfo.canonicalFilePath().mid(resourcePath.size());
  57. if (resInfo.isDir())
  58. entry += "/";
  59. paths << entry;
  60. }
  61. return paths;
  62. }
  63. QByteArray PluginFramework::getResource(const QString& path) const
  64. {
  65. QString resourcePath = QString(":/") + PluginConstants::SYSTEM_PLUGIN_SYMBOLICNAME;
  66. if (path.startsWith('/'))
  67. resourcePath += path;
  68. else
  69. resourcePath += QString("/") + path;
  70. QFile resourceFile(resourcePath);
  71. resourceFile.open(QIODevice::ReadOnly);
  72. return resourceFile.readAll();
  73. }
  74. void waitForStop(int timeout)
  75. {
  76. // TODO implement
  77. }
  78. }