home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oclsrc15.zip / OCL / Include / ONSem.hpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  3KB  |  106 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // ONSem.hpp    
  5. // Named Semaphores
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31. // $Header: W:/Projects/OCL/Include/rcs/ONSem.hpp 1.50 1996/08/11 23:47:24 B.STEIN Release $
  32.  
  33. #ifndef ONSEM_INCLUDED
  34.   #define ONSEM_INCLUDED
  35.  
  36.  
  37. #ifndef OSTRING_INCLUDED
  38.   #include <OString.hpp>
  39. #endif
  40.  
  41. #ifndef OVIOEXCEPTION_INCLUDED
  42.   #include <OVioException.hpp>
  43. #endif
  44.  
  45. typedef class ONSem *pONSem;
  46.  
  47.  
  48. class __CPP_EXPORT__ ONSem
  49.   : public OCLObject
  50. {
  51.  private:
  52.    OString          semName;
  53.    HEV              sema;
  54.    ULONG            semState;
  55.  
  56.  public:
  57.  
  58.  enum ONSemStates  {
  59.                     indefinite = SEM_INDEFINITE_WAIT,
  60.                     immediate = SEM_IMMEDIATE_RETURN 
  61.                    };
  62.  
  63.  enum ONSemCtorActions 
  64.                    {
  65.                     create = 0, // constructor should try to create the semaphore
  66.                     open        // constructor should try to open the semaphore
  67.                    };
  68.  
  69.                                 // construct from an existing semaphore
  70.    ONSem           (HEV handle) throw (OVioException&);
  71.  
  72.    ONSem           (PCSZ name = NULL,
  73.                     ULONG action = ONSem::create,
  74.                     BOOL initialState = FALSE) throw (OVioException&); 
  75.  
  76.  
  77.    virtual
  78.       ~ONSem       ();
  79.  
  80.    virtual
  81.       PSZ isOfType () const;
  82.  
  83.  
  84.    BOOL
  85.       waitSem      (const ULONG timeout = ONSem::indefinite),
  86.       postSem      (),               // post the semaphore
  87.       closeSem     (),               // close the semaphore
  88.       openSem      (PCSZ name),      // open existing semaphore by name
  89.       openSem      (const HEV aSem); // open existing semaphore by handle
  90.  
  91.    ULONG
  92.       resetSem     (),               // reset semaphore, returns postCount since last reset
  93.       querySem     ();               // query semaphore, returns postCount
  94.  
  95.    void
  96.       setSemHandle (HEV hev);
  97.  
  98.    HEV
  99.       getSemHandle ();          // retrieve sema
  100. };
  101.  
  102.  
  103. #endif // ONSEM_INCLUDED
  104.  
  105. // end of source
  106.