home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / mmos2 / mmtoolkt / samples / fssht / shstop.c < prev   
Encoding:
C/C++ Source or Header  |  1992-05-06  |  6.8 KB  |  139 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992                    */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHSTOP.C                                               */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Stop stream routine                    */
  9. /*                                                                          */
  10. /* FUNCTION: This function stops a stream instance.                         */
  11. /*                                                                          */
  12. /* ENTRY POINTS: ShcStop                                                    */
  13. /*                                                                          */
  14. /*************************** END OF SPECIFICATIONS **************************/
  15. #define  INCL_NOPMAPI                  /* no PM include files required */
  16. #define  INCL_DOSSEMAPHORES
  17. #define  INCL_DOSPROCESS
  18. #include <os2.h>
  19. #include <os2me.h>
  20. #include <hhpheap.h>
  21. #include <shi.h>
  22.  
  23. /************************** START OF SPECIFICATIONS *************************/
  24. /*                                                                          */
  25. /* SUBROUTINE NAME: ShcStop                                                 */
  26. /*                                                                          */
  27. /* DESCRIPTIVE NAME: Stream Handler Command Stop stream routine             */
  28. /*                                                                          */
  29. /* FUNCTION: This stops the specified stream.  The flags passed indicate    */
  30. /*           if this should discard all buffers or not.                     */
  31. /*                                                                          */
  32. /* NOTES:                                                                   */
  33. /*                                                                          */
  34. /* ENTRY POINT: ShcStop                                                     */
  35. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  36. /*                                                                          */
  37. /* INPUT:                                                                   */
  38. /*                                                                          */
  39. /* EXIT-NORMAL:                                                             */
  40. /*                                                                          */
  41. /* EXIT-ERROR:                                                              */
  42. /*                                                                          */
  43. /* SIDE EFFECTS:                                                            */
  44. /*                                                                          */
  45. /* INTERNAL REFERENCES:                                                     */
  46. /*        ROUTINES:                                                         */
  47. /*                                                                          */
  48. /* EXTERNAL REFERENCES:                                                     */
  49. /*        ROUTINES:                                                         */
  50. /*        DATA STRUCTURES:                                                  */
  51. /*                                                                          */
  52. /*************************** END OF SPECIFICATIONS **************************/
  53.  
  54. RC ShcStop(pstparm)
  55. PPARM_STOP pstparm;
  56.  
  57. { /* Start of ShcStop */
  58.  
  59. RC    rc = NO_ERROR;                    // local return code
  60. PSIB  psib;                             // Stream instance block
  61. ULONG ulPostCount;                      // dummy
  62.  
  63.   /*
  64.    * Find our Stream Instance Block
  65.    */
  66.   if (!(rc = ShFindSib(&psib, pstparm->hstream, pstparm->hid)))
  67.     { /* We have SIB */
  68.       //
  69.       // Don't bother checking most states since the stream manager does this
  70.       // for us before the command gets here.
  71.       //
  72.       // If this is stop Flush and we are the target then we will stop when we
  73.       // run out of buffers.  So ignore the stop command.
  74.       //
  75.       if (!((pstparm->ulFlags & SPI_STOP_FLUSH) && (pstparm->hid == TgtHandlerID)))
  76.         { /* not flush and target handler */
  77.           if (pstparm->ulFlags & SPI_STOP_DISCARD+SPI_STOP_FLUSH)
  78.             { /* We must release all buffers */
  79.               if (psib->ThreadID)
  80.                 {
  81.                   //
  82.                   //  Update action flags to stop the independent thread, and wait on the
  83.                   //  command sync semaphore to wait until it gets the command.
  84.                   //
  85.                   DosResetEventSem(psib->hevCmdSync, &ulPostCount);
  86.                   if (pstparm->ulFlags & SPI_STOP_DISCARD)
  87.                     psib->ulActionFlags |= SIBACTFLG_STOP_DISCARD;
  88.                   if (pstparm->ulFlags & SPI_STOP_FLUSH)
  89.                     psib->ulActionFlags |= SIBACTFLG_STOP_FLUSH;
  90.  
  91.                   DosPostEventSem(psib->hevStop);
  92.                   if (psib->ulStatus == SIB_PAUSED)
  93.                     {
  94.                       psib->ulStatus = SIB_RUNNING;
  95.                       DosResumeThread(psib->ThreadID);
  96.                     }
  97.                   if (!(psib->ulActionFlags & SIBACTFLG_THREAD_DEAD))
  98.                     DosWaitEventSem(psib->hevCmdSync, SEM_INDEFINITE_WAIT);
  99.                 }
  100.               else
  101.                 {
  102.                   if (pstparm->ulFlags & SPI_STOP_DISCARD)
  103.                     psib->ulActionFlags |= SIBACTFLG_STOP_DISCARD;
  104.                   if (pstparm->ulFlags & SPI_STOP_FLUSH)
  105.                     psib->ulActionFlags |= SIBACTFLG_STOP_FLUSH;
  106.                 }
  107.             } /* We must release all buffers */
  108.           else
  109.             { /* Assume stop pause command*/
  110.  
  111.               if (psib->ulStatus == SIB_RUNNING)
  112.                 {
  113.                   psib->ulStatus = SIB_PAUSED;
  114.                   //
  115.                   // Check for NULL threadid (filter stream handlers)
  116.                   //
  117.                   if ((psib->ThreadID) &&
  118.                       !(psib->ulActionFlags & SIBACTFLG_THREAD_DEAD))
  119.                     {
  120.                       rc = DosSuspendThread(psib->ThreadID);
  121.                     }
  122.                 }
  123.             } /* Assume stop pause command*/
  124.         } /* not flush and target handler */
  125.       else
  126.         { /* flush and target */
  127.  
  128.           if (psib->ulStatus == SIB_PAUSED)
  129.             {
  130.               psib->ulStatus = SIB_RUNNING;
  131.               DosResumeThread(psib->ThreadID);
  132.             }
  133.         } /* flush and target */
  134.     } /* We have SIB */
  135.  
  136.   return(rc);
  137.  
  138. } /* End of ShcStop */
  139.