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

  1. // ****************************************************************************
  2. //
  3. // Module:  ipcsem.h
  4. // Author:  Dick Lam
  5. //
  6. // Purpose: C++ class header 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. #ifndef MODULE_ipcSemaphoreh
  14. #define MODULE_ipcSemaphoreh
  15.  
  16. #include "ipcos.h"
  17.  
  18. // semaphore type designation and operation type
  19. enum ipcSemaphoreType { unknown = 0, mutex = 1, event = 2 };
  20. enum ipcSemaphoreOp { semcreate = 0, semaccess = 1 };
  21.  
  22. // forward declaration
  23. class osSemaphore;
  24.  
  25. // class declaration
  26. class EXPORT ipcSemaphore {
  27.  
  28. friend class osSemaphore;
  29.  
  30. public:
  31.  
  32.    // constructor and destructor
  33.    ipcSemaphore(const char *name,            // unique name for semaphore
  34.                 ipcSemaphoreType type,       // mutex or event
  35.                 ipcSemaphoreOp operation);   // create or access the semaphore
  36.    virtual ~ipcSemaphore();
  37.  
  38.    // methods for getting semaphore parameters [name, semaphore id, type
  39.    // of semaphore (mutex or event) and whether this is the owner (creator)
  40.    // of the semaphore]
  41.    char *Name() const;
  42.    unsigned long ID() const;
  43.    ipcSemaphoreType Type() const;
  44.    int Owner() const;
  45.  
  46.    // pure virtual query method for number of requests made for the semaphore
  47.    // (must be redefined in derived classes)
  48.    virtual unsigned long Query() = 0;
  49.  
  50.    // class version and object state data types
  51.    enum version { MajorVersion = 1, MinorVersion = 0 };
  52.    enum state { good = 0, bad = 1, badname = 2, notfound = 3 };
  53.  
  54.    // methods to get the object state
  55.    inline int rdstate() const { return myState; }
  56.    inline int operator!() const { return(myState != good); }
  57.  
  58. protected:
  59.  
  60.    osSemaphore *myImpl;    // implementation
  61.    state myState;          // (object state (good, bad, etc.)
  62.  
  63. private:
  64.  
  65.    // private copy constructor and operator= (define these and make them
  66.    // public to enable copy and assignment of the class)
  67.    ipcSemaphore(const ipcSemaphore&);
  68.    ipcSemaphore& operator=(const ipcSemaphore&);
  69.  
  70. };
  71.  
  72. #endif
  73.  
  74. // ****************************************************************************
  75.  
  76. // end of ipcsem.h
  77.