home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / threads.zip / iasynbkg.hpp < prev    next >
Text File  |  1995-11-11  |  5KB  |  110 lines

  1. /* NOSHIP */
  2. #ifndef _IASYNBKG_
  3. #define _IASYNBKG_
  4. /*******************************************************************************
  5. * FILE NAME: iasynbkg.hpp
  6. *
  7. * DESCRIPTION:
  8. *   Declaration of the class(es):
  9. *     IAsyncNotifierBackgroundThread - Class for asynchronous notifier
  10. *                                      background threads.
  11. *
  12. * COPYRIGHT:
  13. *   Licensed Materials - Property of IBM
  14. *   (C) Copyright IBM Corporation 1995
  15. *   All Rights Reserved
  16. *   US Government Users Restricted Rights - Use, duplication, or disclosure
  17. *   restricted by GSA ADP Schedule Contract with IBM Corp.
  18. *
  19. *******************************************************************************/
  20. #ifndef _IASYNTHR_
  21.   #include <iasynthr.hpp>
  22. #endif
  23.  
  24. // Other dependency classes:
  25. #ifndef _IRESLOCK_
  26.   #include <ireslock.hpp>
  27. #endif
  28.  
  29. #ifndef _IEVNTSEM_
  30.   #include <ievntsem.hpp>
  31. #endif
  32.  
  33. class INotificationEvent;
  34. template <class Element> class ISequence;
  35.  
  36. // Align classes on four byte boundary.
  37. #pragma pack(4)
  38.  
  39. class IAsyncNotifierBackgroundThread : public IAsyncNotifierThread {
  40. /*******************************************************************************
  41. *
  42. * This class implements the interface for asynchronous notifier background
  43. * thread objects.
  44. *
  45. *******************************************************************************/
  46.  
  47. public:
  48. /*------------------------------ Constructors ----------------------------------
  49. | You can construct an object of this class as follows:                        |
  50. |   - With the default constructor.                                            |
  51. |-----------------------------------------------------------------------------*/
  52. IAsyncNotifierBackgroundThread ( );
  53.  
  54. virtual ~IAsyncNotifierBackgroundThread ( );
  55.  
  56. /*--------------------------- Reference Counting -------------------------------
  57. | Used by IAsyncNotifier objects to remove references to this object.          |
  58. |   removeRef - Calls base class implementation.  Then if the count is zero    |
  59. |               and the queue is empty, the queueEventSem is posted so that    |
  60. |               processMsgs will see that it is time to exit.                  |
  61. |-----------------------------------------------------------------------------*/
  62. virtual unsigned long removeRef ( );
  63.  
  64. /*-------------------------- Enqueue Notification ------------------------------
  65. | Used by IAsyncNotifier objects to enque notifications.                       |
  66. |   enqueueNotification - Places the notification on this thread's queue.      |
  67. |-----------------------------------------------------------------------------*/
  68. virtual IAsyncNotifierBackgroundThread & enqueueNotification (
  69.                                            const INotificationEvent & anEvent );
  70.  
  71. /*---------------------------- Process Messages --------------------------------
  72. | Use this to start dispatching notifications for this thread.                 |
  73. |   processMsgs - Throws an invalid request exception if the current thread is |
  74. |                 not this thread.  This function does not return until        |
  75. |                 asyncNotifierCount reaches zero.  This function should be    |
  76. |                 called once by IAsyncNotifier::run and this object should be |
  77. |                 deleted after this function returns.                         |
  78. |-----------------------------------------------------------------------------*/
  79. virtual IAsyncNotifierBackgroundThread & processMsgs ( );
  80.  
  81. /*-------------------------- Delete Notifications ------------------------------
  82. | IAsyncNotifier calls this from its destructor to have all pending            |
  83. | notifications deleted.                                                       |
  84. |   deleteNotificationsFor - Ensures that all notifications for the passed     |
  85. |                            object are never dispatched.  Throws an invalid   |
  86. |                            request exception if the current thread is not    |
  87. |                            this thread.                                      |
  88. |-----------------------------------------------------------------------------*/
  89. virtual IAsyncNotifierBackgroundThread & deleteNotificationsFor (
  90.                                          const IAsyncNotifier & asyncNotifier );
  91.  
  92.  
  93. private:
  94. // The private copy constructor and assignment operator are not implemented.
  95. IAsyncNotifierBackgroundThread ( const IAsyncNotifierBackgroundThread & rhs );
  96. IAsyncNotifierBackgroundThread & operator = (
  97.                                    const IAsyncNotifierBackgroundThread & rhs );
  98.  
  99. /*--------------------------- Private State Data -----------------------------*/
  100. ISequence<INotificationEvent> * queue;
  101. IPrivateResource                queueKey;
  102. IEventSem                       queueEventSem;
  103.  
  104. }; // IAsyncNotifierBackgroundThread
  105.  
  106. // Resume compiler default packing.
  107. #pragma pack()
  108.  
  109. #endif // _IASYNBKG_
  110.