home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / baclsema.zip / IPCEVENT.C < prev    next >
C/C++ Source or Header  |  1994-06-23  |  2KB  |  97 lines

  1. // ****************************************************************************
  2. //
  3. // Module:  ipcevent.C
  4. // Author:  Dick Lam
  5. //
  6. // Purpose: C++ class source file for ipcEventSemaphore
  7. //
  8. // Notes:  This class is derived from ipcSemaphore.  It is an interface class
  9. //         for event semaphores that can be used to signal events across
  10. //         processes or threads.
  11. //
  12. // ****************************************************************************
  13.  
  14. #include "ipcevent.h"
  15. #include "ossem.h"
  16.  
  17. // ****************************************************************************
  18.  
  19. // ipcEventSemaphore - constructor
  20.  
  21. ipcEventSemaphore::ipcEventSemaphore(const char *name, ipcSemaphoreOp operation)
  22.    : ipcSemaphore(name, event, operation)
  23.  
  24. {
  25.    // check the state of the object
  26.    if (myState != good)
  27.       return;
  28.  
  29.    // create or open the semaphore
  30.    if (operation == semcreate)
  31.       myImpl->CreateEvent();
  32.    else if (operation == semaccess)
  33.       myImpl->OpenEvent();
  34. }
  35.  
  36. // ----------------------------------------------------------------------------
  37.  
  38. // ~ipcEventSemaphore - destructor
  39.  
  40. ipcEventSemaphore::~ipcEventSemaphore()
  41.  
  42. {
  43.    // close the semaphore
  44.    if (myState == good)
  45.       myImpl->CloseEvent();
  46. }
  47.  
  48. // ----------------------------------------------------------------------------
  49.  
  50. // Query - returns the number of requests made of the semaphore
  51.  
  52. unsigned long ipcEventSemaphore::Query()
  53.  
  54. {
  55.    if (myState == good)
  56.       return myImpl->QueryEvent();
  57.  
  58.    return 0L;
  59. }
  60.  
  61. // ----------------------------------------------------------------------------
  62.  
  63. // Post - posts the semaphore
  64.  
  65. void ipcEventSemaphore::Post()
  66.  
  67. {
  68.    if (myState == good)
  69.       myImpl->PostEvent();
  70. }
  71.  
  72. // ----------------------------------------------------------------------------
  73.  
  74. // Reset - resets the semaphore
  75.  
  76. void ipcEventSemaphore::Reset()
  77.  
  78. {
  79.    if (myState == good)
  80.       myImpl->ResetEvent();
  81. }
  82.  
  83. // ----------------------------------------------------------------------------
  84.  
  85. // Wait - waits for a semaphore event to be posted
  86.  
  87. void ipcEventSemaphore::Wait()
  88.  
  89. {
  90.    if (myState == good)
  91.       myImpl->WaitEvent();
  92. }
  93.  
  94. // ****************************************************************************
  95.  
  96. // end of ipcevent.C
  97.