ctkTestApp_p.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #ifndef CTKTESTAPP_P_H
  16. #define CTKTESTAPP_P_H
  17. #include <service/application/ctkApplicationDescriptor.h>
  18. #include <service/application/ctkApplicationHandle.h>
  19. #include <ctkApplicationRunnable.h>
  20. #include <ctkServiceRegistration.h>
  21. #include <service/application/ctkApplicationLauncher.h>
  22. #include <ctkServiceTracker.h>
  23. #include <ctkServiceTrackerCustomizer.h>
  24. #include <QObject>
  25. class ctkPluginContext;
  26. class MyAppHandle;
  27. class MyAppDescriptor;
  28. class MyAppContainer : private ctkServiceTrackerCustomizer<ctkApplicationLauncher*>
  29. {
  30. public:
  31. MyAppContainer(ctkPluginContext* context);
  32. ~MyAppContainer();
  33. void start();
  34. void stop();
  35. void launch(MyAppHandle* handle);
  36. void registerHandle(MyAppHandle* handle);
  37. private:
  38. Q_DISABLE_COPY(MyAppContainer)
  39. virtual ctkApplicationLauncher* addingService(const ctkServiceReference& reference);
  40. virtual void modifiedService(const ctkServiceReference& reference, ctkApplicationLauncher* service);
  41. virtual void removedService(const ctkServiceReference& reference, ctkApplicationLauncher* service);
  42. ctkPluginContext* context;
  43. ctkApplicationLauncher* appLauncher;
  44. ctkServiceTracker<ctkApplicationLauncher*> launcherTracker;
  45. ctkApplicationRunnable* defaultMainThreadAppHandle;
  46. QHash<MyAppHandle*, ctkServiceRegistration> handleRegistrations;
  47. QList<MyAppHandle*> handles;
  48. QList<MyAppDescriptor*> descriptors;
  49. QHash<MyAppDescriptor*, ctkServiceRegistration> descriptorRegistrations;
  50. };
  51. class MyAppHandle : public QObject, public ctkApplicationRunnable, public ctkApplicationHandle
  52. {
  53. Q_OBJECT
  54. Q_INTERFACES(ctkApplicationHandle)
  55. public:
  56. MyAppHandle(const QString& instanceId, ctkApplicationDescriptor* descriptor);
  57. virtual ctkApplicationDescriptor* getApplicationDescriptor() const;
  58. virtual QString getState() const;
  59. virtual QVariant getExitValue(long timeout) const;
  60. virtual QString getInstanceId() const;
  61. virtual void destroy();
  62. virtual QVariant run(const QVariant &context);
  63. virtual void stop();
  64. private:
  65. ctkApplicationDescriptor* descriptor;
  66. QString instanceId;
  67. };
  68. class MyAppDescriptor : public QObject, public ctkApplicationDescriptor
  69. {
  70. Q_OBJECT
  71. Q_INTERFACES(ctkApplicationDescriptor)
  72. public:
  73. MyAppDescriptor(const QString& id, MyAppContainer* container);
  74. virtual QString getApplicationId() const;
  75. virtual ctkProperties getProperties(const QLocale& locale) const;
  76. virtual ctkProperties getProperties() const;
  77. virtual ctkApplicationHandle* launch(const QHash<QString, QVariant>& arguments);
  78. private:
  79. MyAppHandle* createAppHandle(const ctkProperties& arguments);
  80. QString getInstanceId() const;
  81. const QString id;
  82. MyAppContainer* container;
  83. };
  84. #endif // CTKTESTAPP_P_H