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

  1. /*******************************************************************************
  2. * FILE NAME: iasynthr.cpp
  3. *
  4. * DESCRIPTION:
  5. *   Functions to implement the class(es):
  6. *     IAsyncNotifierThread
  7. *
  8. * COPYRIGHT:
  9. *   Licensed Materials - Property of IBM
  10. *   (C) Copyright IBM Corporation 1995
  11. *   All Rights Reserved
  12. *   US Government Users Restricted Rights - Use, duplication, or disclosure
  13. *   restricted by GSA ADP Schedule Contract with IBM Corp.
  14. *
  15. *******************************************************************************/
  16. #include <iasynthr.hpp>
  17.  
  18. #ifndef _ITHREAD_
  19.   #include <ithread.hpp>
  20. #endif
  21.  
  22. #ifndef _IASYNTFY_
  23.   #include <iasyntfy.hpp>
  24. #endif
  25.  
  26. #ifndef _IASYNGUI_
  27.   #include <iasyngui.hpp>
  28. #endif
  29.  
  30. #ifndef _IASYNBKG_
  31.   #include <iasynbkg.hpp>
  32. #endif
  33.  
  34. #ifndef _IEXCEPT_
  35.   #include <iexcept.hpp>
  36. #endif
  37.  
  38. INotificationId const IAsyncNotifierThread::deleteThisId
  39.                         = "IAsyncNotifierThread::deleteThis";
  40.  
  41.  
  42. /*------------------------------------------------------------------------------
  43. | Function Name: IAsyncNotifierThread :: IAsyncNotifierThread
  44. |
  45. | Implementation:
  46. |   Initialize the base class then find our thread id.
  47. |-----------------------------------------------------------------------------*/
  48. IAsyncNotifierThread :: IAsyncNotifierThread ( ) :
  49.                    IVBase ( ),
  50.                    asyncNotifierCount ( 0 ),
  51.                    theThreadId ( IThread::currentId() ),
  52.                    bRunning ( false )
  53. {
  54. }
  55.  
  56. /*------------------------------------------------------------------------------
  57. | Function Name: IAsyncNotifierThread :: make
  58. |
  59. | Implementation:
  60. |   Get the current thread and see if it is a GUI thread or not.
  61. |   Create the appropriate subclass object and return it.
  62. |-----------------------------------------------------------------------------*/
  63. IAsyncNotifierThread * IAsyncNotifierThread :: make ( IBoolean guiOnly )
  64. {
  65.   IAsyncNotifierThread * result = NULL;
  66.  
  67.   IBoolean isGUI = IThread::current().isGUIInitialized();
  68.  
  69.   IASSERTSTATE ( ( isGUI ) || ( !guiOnly ) );
  70.  
  71.   if ( isGUI )
  72.     result = new IAsyncNotifierGUIThread;
  73.   else
  74.     result = new IAsyncNotifierBackgroundThread;
  75.  
  76.   return result;
  77. }
  78.  
  79. /*------------------------------------------------------------------------------
  80. | Function Name: IAsyncNotifierThread :: ~IAsyncNotifierThread
  81. |
  82. | Implementation:
  83. |   Nothing to delete.
  84. |-----------------------------------------------------------------------------*/
  85. IAsyncNotifierThread :: ~IAsyncNotifierThread ( )
  86. {
  87. }
  88.  
  89. /*------------------------------------------------------------------------------
  90. | Function Name: IAsyncNotifierThread :: threadId
  91. |
  92. | Implementation:
  93. |   Return the thread id.
  94. |-----------------------------------------------------------------------------*/
  95. const IThreadId & IAsyncNotifierThread :: threadId ( ) const
  96. {
  97.   return theThreadId;
  98. }
  99.  
  100. /*------------------------------------------------------------------------------
  101. | Function Name: IAsyncNotifierThread :: addRef
  102. |
  103. | Implementation:
  104. |   Bump and return the reference count.
  105. |-----------------------------------------------------------------------------*/
  106. unsigned long IAsyncNotifierThread :: addRef ( )
  107. {
  108.   asyncNotifierCount++;
  109.   return asyncNotifierCount;
  110. }
  111.  
  112. /*------------------------------------------------------------------------------
  113. | Function Name: IAsyncNotifierThread :: removeRef
  114. |
  115. | Implementation:
  116. |   Decrement and return the reference count.
  117. |-----------------------------------------------------------------------------*/
  118. unsigned long IAsyncNotifierThread :: removeRef ( )
  119. {
  120.   asyncNotifierCount--;
  121.   return asyncNotifierCount;
  122. }
  123.  
  124. /*------------------------------------------------------------------------------
  125. | Function Name: IAsyncNotifierThread :: refCount
  126. |
  127. | Implementation:
  128. |   Return the current reference count.
  129. |-----------------------------------------------------------------------------*/
  130. unsigned long IAsyncNotifierThread :: refCount ( ) const
  131. {
  132.   return asyncNotifierCount;
  133. }
  134.  
  135. /*------------------------------------------------------------------------------
  136. | Function Name: IAsyncNotifierThread :: isRunning
  137. |
  138. | Implementation:
  139. |   Return the running flag.
  140. |-----------------------------------------------------------------------------*/
  141. IBoolean IAsyncNotifierThread :: isRunning ( ) const
  142. {
  143.   return bRunning;
  144. }
  145.  
  146. /*------------------------------------------------------------------------------
  147. | Function Name: IAsyncNotifierThread :: setIsRunning
  148. |
  149. | Implementation:
  150. |   Set the running flag.
  151. |-----------------------------------------------------------------------------*/
  152. IAsyncNotifierThread & IAsyncNotifierThread :: setIsRunning ( IBoolean running )
  153. {
  154.   bRunning = running;
  155.   return *this;
  156. }
  157.  
  158. /*------------------------------------------------------------------------------
  159. | Function Name: key
  160. |
  161. | Implementation:
  162. |   Return the thread id for the referenced object.
  163. |-----------------------------------------------------------------------------*/
  164. const IThreadId & key ( IAsyncNotifierThread * const & object )
  165. {
  166.   return ( object->threadId() );
  167. }
  168.