ctkApplicationHandle.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 CTKAPPLICATIONHANDLE_H
  16. #define CTKAPPLICATIONHANDLE_H
  17. #include <ctkPluginFrameworkExport.h>
  18. #include <QObject>
  19. #include <QString>
  20. class QVariant;
  21. struct ctkApplicationDescriptor;
  22. /**
  23. * ApplicationHandle is a service interface which represents an instance
  24. * of an application. It provides the functionality to query and manipulate the
  25. * lifecycle state of the represented application instance. It defines constants
  26. * for the lifecycle states.
  27. */
  28. struct CTK_PLUGINFW_EXPORT ctkApplicationHandle
  29. {
  30. /**
  31. * The property key for the unique identifier (PID) of the application
  32. * instance.
  33. */
  34. static const QString APPLICATION_PID; // = ctkPluginConstants::SERVICE_PID;
  35. /**
  36. * The property key for the pid of the corresponding application descriptor.
  37. */
  38. static const QString APPLICATION_DESCRIPTOR; // = "application.descriptor";
  39. /**
  40. * The property key for the state of this application instance.
  41. */
  42. static const QString APPLICATION_STATE; // = "application.state";
  43. /**
  44. * The property key for the supports exit value property of this application
  45. * instance.
  46. */
  47. static const QString APPLICATION_SUPPORTS_EXITVALUE; // = "application.supports.exitvalue";
  48. /**
  49. * The application instance is running. This is the initial state of a newly
  50. * created application instance.
  51. */
  52. static const QString RUNNING; // = "RUNNING";
  53. /**
  54. * The application instance is being stopped. This is the state of the
  55. * application instance during the execution of the <code>destroy()</code>
  56. * method.
  57. */
  58. static const QString STOPPING; // = "STOPPING";
  59. virtual ~ctkApplicationHandle() {}
  60. /**
  61. * Retrieves the <code>IApplicationDescriptor</code> to which this
  62. * <code>IApplicationHandle</code> belongs.
  63. *
  64. * @return The corresponding <code>IApplicationDescriptor</code>
  65. */
  66. virtual ctkApplicationDescriptor* getApplicationDescriptor() const = 0;
  67. /**
  68. * Get the state of the application instance.
  69. *
  70. * @return the state of the application.
  71. *
  72. * @throws ctkIllegalStateException
  73. * if the application handle is unregistered
  74. */
  75. virtual QString getState() const = 0;
  76. /**
  77. * Returns the exit value for the application instance. The timeout
  78. * specifies how the method behaves when the application has not yet
  79. * terminated. A negative, zero or positive value may be used.
  80. * <ul>
  81. * <li> negative - The method does not wait for termination. If the
  82. * application has not terminated then an <code>ctkApplicationException</code>
  83. * is thrown.</li>
  84. *
  85. * <li> zero - The method waits until the application terminates.</li>
  86. *
  87. * <li> positive - The method waits until the application terminates or the
  88. * timeout expires. If the timeout expires and the application has not
  89. * terminated then an <code>ctkApplicationException</code> is thrown.</li>
  90. * </ul>
  91. *
  92. * @param timeout The maximum time in milliseconds to wait for the
  93. * application to timeout.
  94. * @return The exit value for the application instance. The value is
  95. * application specific.
  96. * @throws ctkUnsupportedOperationException If the application model does not
  97. * support exit values.
  98. * @throws ctkApplicationException If the application has not terminated. The
  99. * error code will be
  100. * ctkApplicationException::APPLICATION_EXITVALUE_NOT_AVAILABLE.
  101. */
  102. virtual QVariant getExitValue(long timeout) const = 0;
  103. /**
  104. * Returns the unique identifier of this instance. This value is also
  105. * available as a service property of this application handle's service.pid.
  106. *
  107. * @return the unique identifier of the instance
  108. */
  109. virtual QString getInstanceId() const = 0;
  110. /**
  111. * The application instance's lifecycle state can be influenced by this
  112. * method. It lets the application instance perform operations to stop
  113. * the application safely, e.g. saving its state to a permanent storage.
  114. * <p>
  115. * The method must check if the lifecycle transition is valid; a STOPPING
  116. * application cannot be stopped. If it is invalid then the method must
  117. * exit. Otherwise the lifecycle state of the application instance must be
  118. * set to STOPPING. Then the destroySpecific() method must be called to
  119. * perform any application model specific steps for safe stopping of the
  120. * represented application instance.
  121. * <p>
  122. * At the end the <code>ctkApplicationHandle</code> must be unregistered.
  123. * This method should free all the resources related to this
  124. * <code>ctkApplicationHandle</code>.
  125. * <p>
  126. * When this method is completed the application instance has already made
  127. * its operations for safe stopping, the IApplicationHandle has been
  128. * unregistered and its related resources has been freed. Further calls on
  129. * this application should not be made because they may have unexpected
  130. * results.
  131. *
  132. * @throws ctkIllegalStateException
  133. * if the application handle is unregistered
  134. */
  135. virtual void destroy() = 0;
  136. };
  137. Q_DECLARE_INTERFACE(ctkApplicationHandle, "org.commontk.service.application.ApplicationHandle")
  138. #endif // CTKAPPLICATIONHANDLE_H