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

  1. // ****************************************************************************
  2. //
  3. // Module:  ipcsem.C
  4. // Author:  Dick Lam
  5. //
  6. // Purpose: C++ class source file for ipcSemaphore
  7. //
  8. // Notes:  This is an abstract base class.  It is the interface class for
  9. //         semaphores used in signalling between processes and threads.
  10. //
  11. // ****************************************************************************
  12.  
  13. #include "ipcsem.h"
  14. #include "ossem.h"
  15.  
  16. // ****************************************************************************
  17.  
  18. // ipcSemaphore - constructor
  19.  
  20. ipcSemaphore::ipcSemaphore(const char *name, ipcSemaphoreType type,
  21.                            ipcSemaphoreOp operation)
  22.  
  23. {
  24.    // init instance variables
  25.    myState = good;
  26.    myImpl = new osSemaphore(this, name, type, operation);
  27.    if (!myImpl)
  28.       myState = bad;
  29. }
  30.  
  31. // ----------------------------------------------------------------------------
  32.  
  33. // ~ipcSemaphore - destructor
  34.  
  35. ipcSemaphore::~ipcSemaphore()
  36.  
  37. {
  38.    delete myImpl;
  39. }
  40.  
  41. // ----------------------------------------------------------------------------
  42.  
  43. // Name - returns the name of the semaphore
  44.  
  45. char *ipcSemaphore::Name() const
  46.  
  47. {
  48.    if (!myImpl)
  49.       return 0;
  50.  
  51.    return myImpl->Name();
  52. }
  53.  
  54. // ----------------------------------------------------------------------------
  55.  
  56. // ID - returns the semaphore id
  57.  
  58. unsigned long ipcSemaphore::ID() const
  59.  
  60. {
  61.    if (!myImpl)
  62.       return 0L;
  63.  
  64.    return myImpl->ID();
  65. }
  66.  
  67. // ----------------------------------------------------------------------------
  68.  
  69. // Type - returns the type of semaphore
  70.  
  71. ipcSemaphoreType ipcSemaphore::Type() const
  72.  
  73. {
  74.    if (!myImpl)
  75.       return unknown;
  76.  
  77.    return myImpl->Type();
  78. }
  79.  
  80. // ----------------------------------------------------------------------------
  81.  
  82. // Owner - returns 1 if this is the owner (creator), and 0 otherwise
  83.  
  84. int ipcSemaphore::Owner() const
  85.  
  86. {
  87.    if (!myImpl)
  88.       return 0;
  89.  
  90.    return myImpl->Owner();
  91. }
  92.  
  93. // ****************************************************************************
  94.  
  95. // end of ipcsem.C
  96.