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

  1. /* NOSHIP */
  2. #ifndef _IASYNTHR_
  3. #define _IASYNTHR_
  4. /*******************************************************************************
  5. * FILE NAME: iasynthr.hpp
  6. *
  7. * DESCRIPTION:
  8. *   Declaration of the class(es):
  9. *     IAsyncNotifierThread - Base class for asynchronous notifier threads.
  10. *
  11. * COPYRIGHT:
  12. *   Licensed Materials - Property of IBM
  13. *   (C) Copyright IBM Corporation 1995
  14. *   All Rights Reserved
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.
  17. *
  18. *******************************************************************************/
  19. #ifndef _IVBASE_
  20.   #include <ivbase.hpp>
  21. #endif
  22.  
  23. // Other dependency classes.
  24. #ifndef  _IHANDLE_
  25.   #include <ihandle.hpp>
  26. #endif
  27.  
  28. #ifndef  _INOTIFY_
  29.   #include <inotify.hpp>
  30. #endif
  31.  
  32. class INotificationEvent;
  33. class IAsyncNotifier;
  34.  
  35. // Align classes on four byte boundary.
  36. #pragma pack(4)
  37.  
  38. class IAsyncNotifierThread : public IVBase {
  39. /*******************************************************************************
  40. *
  41. * This abstract base class defines the interface for asynchronous notifier
  42. * thread objects.  Subclasses define the actual queue mechanism to be used
  43. * for this thread.
  44. *
  45. *******************************************************************************/
  46.  
  47. public:
  48. /*------------------------------ Constructors ----------------------------------
  49. | You can not directly construct an object of this abstract base class.        |
  50. | Subclasses can initialize this class as follows:                             |
  51. |   - With the default constructor.  This object takes on the identity of the  |
  52. |     current thread.  The reference count is initially zero.                  |
  53. |   - Use the make constructor to create the appropriate subclass for the      |
  54. |     current thread.  By default it will make one for any thread.  Of true is |
  55. |     passed and the current thread is not a GUI thread, an invalid request    |
  56. |     exception is thrown.                                                     |
  57. |-----------------------------------------------------------------------------*/
  58. IAsyncNotifierThread ( );
  59.  
  60. static IAsyncNotifierThread * make ( IBoolean guiOnly = false );
  61.  
  62. virtual ~IAsyncNotifierThread ( );
  63.  
  64. /*-------------------------------- Thread Id -----------------------------------
  65. | Use this function to query the thread Id for this thread.                    |
  66. |   threadId - Returns the thread Id.                                          |
  67. |-----------------------------------------------------------------------------*/
  68. const IThreadId & threadId ( ) const;
  69.  
  70. /*--------------------------- Reference Counting -------------------------------
  71. | Used by IAsyncNotifier objects to add and remove references to this object.  |
  72. |   addRef    - Bumps and returns the reference count.                         |
  73. |   removeRef - Decrements and returns the reference count.                    |
  74. |-----------------------------------------------------------------------------*/
  75. virtual unsigned long addRef ( );
  76. virtual unsigned long removeRef ( );
  77.  
  78. /*-------------------------- Enqueue Notification ------------------------------
  79. | Used by IAsyncNotifier objects to enque notifications.                       |
  80. |   enqueueNotification - Places the notification on this thread's queue.      |
  81. |-----------------------------------------------------------------------------*/
  82. virtual IAsyncNotifierThread & enqueueNotification (
  83.                                  const INotificationEvent & anEvent ) = 0;
  84.  
  85. /*----------------------------- Process Messages -------------------------------
  86. | Use this to start dispatching notifications for this thread.                 |
  87. |   processMsgs - Throws an invalid request exception if the current thread is |
  88. |                 not this thread.  This function does not return until        |
  89. |                 notification processing is done for this thread.  This       |
  90. |                 function should be called once by IAsyncNotifier::run and    |
  91. |                 this object should be deleted after this function returns.   |
  92. |   isRunning   - Returns true if messages are being processed.                |
  93. |-----------------------------------------------------------------------------*/
  94. virtual IAsyncNotifierThread & processMsgs ( ) = 0;
  95. IBoolean isRunning ( ) const;
  96.  
  97. /*-------------------------- Delete Notifications ------------------------------
  98. | IAsyncNotifier calls this from its destructor to have all pending            |
  99. | notifications deleted.                                                       |
  100. |   deleteNotificationsFor - Ensures that all notifications for the passed     |
  101. |                            object are never dispatched.  Throws an invalid   |
  102. |                            request exception if the current thread is not    |
  103. |                            this thread.                                      |
  104. |   deleteThisId           - Used by IAsyncNotifier and this class to signal   |
  105. |                            async deletion of an IAsyncNotifier.              |
  106. |-----------------------------------------------------------------------------*/
  107. virtual IAsyncNotifierThread & deleteNotificationsFor (
  108.                                  const IAsyncNotifier & asyncNotifier ) = 0;
  109. static INotificationId const deleteThisId;
  110.  
  111.  
  112. protected:
  113. unsigned long refCount ( ) const;
  114. IAsyncNotifierThread & setIsRunning ( IBoolean running );
  115.  
  116.  
  117. private:
  118. // The private copy constructor and assignment operator are not implemented.
  119. IAsyncNotifierThread ( const IAsyncNotifierThread & rhs );
  120. IAsyncNotifierThread & operator = ( const IAsyncNotifierThread & rhs );
  121.  
  122. /*--------------------------- Private State Data -----------------------------*/
  123. unsigned long asyncNotifierCount;
  124. IThreadId     theThreadId;
  125. IBoolean      bRunning;
  126.  
  127. }; // IAsyncNotifierThread
  128.  
  129.  
  130. /*---------------------- Collection Class Key Function -------------------------
  131. | Used by collections of pointers to objects of this class,                    |
  132. |   key - Returns a reference to the thread Id.                                |
  133. |-----------------------------------------------------------------------------*/
  134. const IThreadId & key ( IAsyncNotifierThread * const & object );
  135.  
  136. // Resume compiler default packing.
  137. #pragma pack()
  138.  
  139. #endif // _IASYNTHR_
  140.