home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OMuxWaitSem.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  4KB  |  187 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OMuxWaitSem.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OMuxWaitSem.cpp 1.50 1996/08/11 23:49:24 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OMuxWaitSem.hpp>
  40. #include <OMessage.hpp>
  41.  
  42.  
  43. OMuxWaitSem::OMuxWaitSem(HMUX handle) throw (OVioException&)
  44.   : hmux((HMUX)NULL),
  45.     muxwaitState(0)
  46. {
  47.  if (!openMuxWaitSem(handle))
  48.    throw OVioException(OCL::apierror(120, muxwaitState), muxwaitState);
  49. }
  50.  
  51.  
  52. OMuxWaitSem::OMuxWaitSem(PCSZ name, 
  53.                          ULONG numSem, 
  54.                          PSEMRECORD semArray,  
  55.                          ULONG action,
  56.                          ULONG attrib) throw (OVioException&)
  57.   : hmux((HMUX)NULL),
  58.     muxwaitState(0)
  59. {
  60.  switch(action)
  61.   {
  62.    case OMuxWaitSem::create: {
  63.     APIRET rc;
  64.  
  65.     if ((rc=DosCreateMuxWaitSem(name, &hmux, numSem, semArray, attrib))!=0)
  66.       throw OVioException(OCL::apierror(121, rc), rc);
  67.     break; }
  68.  
  69.    case OMuxWaitSem::open:
  70.     if (!openMuxWaitSem(name))
  71.       throw OVioException(OCL::apierror(122, muxwaitState), muxwaitState);
  72.     break;
  73.   }
  74. }
  75.  
  76.  
  77. OMuxWaitSem::~OMuxWaitSem()
  78. {
  79.  if (hmux)
  80.    closeMuxWaitSem();
  81. }
  82.  
  83.  
  84. PSZ OMuxWaitSem::isOfType() const
  85.  return("OMuxWaitSem"); 
  86. }
  87.  
  88.  
  89. ULONG OMuxWaitSem::waitMuxWaitSem(ULONG timeout)
  90. {
  91.  ULONG posted = 0;
  92.  
  93.  muxwaitState = DosWaitMuxWaitSem(hmux, timeout, &posted);
  94.  if (muxwaitState)
  95.    return(0);
  96.  return(posted);
  97. }
  98.  
  99.  
  100.  
  101. BOOL OMuxWaitSem::openMuxWaitSem(HMUX handle)
  102. {
  103.  muxwaitState = DosOpenMuxWaitSem((PSZ)NULL, &handle);
  104.  return(muxwaitState == 0);
  105. }
  106.  
  107.  
  108. BOOL OMuxWaitSem::openMuxWaitSem(PCSZ name)
  109. {
  110.  hmux = (HMUX)NULL;
  111.  muxwaitState = DosOpenMuxWaitSem((PSZ)name, &hmux);
  112.  return(muxwaitState == 0);
  113. }
  114.  
  115.  
  116.  
  117. BOOL OMuxWaitSem::addSemaphore(PSEMRECORD record)
  118. {
  119.  muxwaitState = DosAddMuxWaitSem(hmux, record);
  120.  return(muxwaitState == 0);
  121. }
  122.  
  123.  
  124. BOOL OMuxWaitSem::addSemaphore(ONSem *sema)
  125. {
  126.  SEMRECORD semRec;
  127.  
  128.  if (!sema) {
  129.    muxwaitState = ERROR_INVALID_PARAMETER;
  130.    return(FALSE); }
  131.  
  132.  semRec.hsemCur = (HSEM) sema->getSemHandle();
  133.  return(addSemaphore(&semRec));
  134. }
  135.  
  136.  
  137. BOOL OMuxWaitSem::addSemaphore(OMuxSem *sema)
  138. {
  139.  SEMRECORD semRec;
  140.  
  141.  if (!sema) {
  142.    muxwaitState = ERROR_INVALID_PARAMETER;
  143.    return(FALSE); }
  144.  
  145.  semRec.hsemCur = (HSEM) sema->getMuxSemHandle();
  146.  return(addSemaphore(&semRec));
  147. }
  148.  
  149.  
  150. BOOL OMuxWaitSem::delSemaphore(HSEM handle)
  151. {
  152.  muxwaitState = DosDeleteMuxWaitSem(hmux, handle);
  153.  return(muxwaitState == 0);
  154. }
  155.  
  156.  
  157. BOOL OMuxWaitSem::queryMuxWaitSem(PULONG num,
  158.                                   PSEMRECORD semArray,
  159.                                   PULONG attributes)
  160. {
  161.  muxwaitState = DosQueryMuxWaitSem(hmux, num, semArray, attributes);
  162.  return(muxwaitState == 0);
  163. }
  164.  
  165.  
  166. void OMuxWaitSem::setMuxWaitSemHandle(HMUX handle)
  167. {
  168.  hmux = handle;
  169. }
  170.  
  171.  
  172. HMUX OMuxWaitSem::getMuxWaitSemHandle()
  173. {
  174.  return(hmux);
  175. }
  176.  
  177.  
  178. BOOL OMuxWaitSem::closeMuxWaitSem()
  179. {
  180.  muxwaitState = DosCloseMuxWaitSem(hmux);
  181.  return(muxwaitState == 0);
  182. }
  183.  
  184.  
  185. // end of source
  186.